ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [ OSGi ] 3 - OSGi plugin 의존 관계
    JAVA 2014. 8. 20. 19:34
    728x90


    [ OSGi ] 2 - OSGi Plugin Project 에서 OSGi에서 구동될 Plugin을 개발할 프로젝트 생성과 install, start를 해보았다.


    여기서는 여러 Plugin 간의 의존 관계를 보도록 하자.


    이전에 만들었던 HelloWorldOSGi의 Plugin에 HelloOSGiWorldPrinter.java를 추가하고

    HelloWoldOSGiSub Plugin을 추가로 만들어서 HelloOSGiWorldPrinter에 정의된 메소드를 호출해보도록 하겠다.



    추가 프로젝트 생성

    1. HelloWorldOSGi Project에 다른 Plugin에서 호출할 HelloOSGiWorldPtinter.java를 생성한다.

         그리고 printer method를 추가한다.


    2. 위에서 만든 HelloOSGiWorldPrinter.java를 호출할 다른 Plugin 프로젝트 HelloWorldOSGiSub을 생성한다.

        Activator 이름은 HelloWorldOSGi 프로젝트와 구분하기위해 SubActivator로 바꾸었다.


         다음은 프로젝트가 생성된 모습이다. 



    HelloWorldOSGi 프로젝트의 class 참조하기

    1. SubActivator.java의 start method에 HelloWorldOSGi 프로젝트의 HelloOSGiWorldPrinter 를 생성해보면 다음과 같이 에러가 난다. 

        당연하겠지만 참조를 못하는 것이다.


    2. HelloWorldOSGi 의 MANIFAST.MF에 

        Export-Package: kr.co.jabsiri.helloworldosgi 를 추가 한다. ( 다음 한줄을 비워 두는 것을 잊지 말자 )


    3. HelloWorldOSGiSub 프로젝트의  MANIFAST.MF를 열고 

        Import-Package에 kr.co.jabsiri.helloworldosgi 를 추가한다. ( 다음 한줄을 비워 두는 것을 잊지 말자 )




    4. 다음 화면 처럼 syntax error가 사라졌다



    배포 및 install

    1. 프로젝트에서 마우스 오른쪽 버튼 클릭 후 Export에서 Deployable plug-ins and fragments를 선택하고 배포할 plugin을 체크한후 배포한다.

    2. ss 명령어로 현재 설치되어 있는 plugin을 확인 후 

        install file:sample.HelloWorldOSGiSub_1.0.0.jar를 입력하여 plugin을 설치한다.

    osgi> ss

    "Framework is launched."



    id      State       Bundle

    0       ACTIVE      org.eclipse.osgi_3.10.0.v20140606-1445

    1       ACTIVE      org.eclipse.equinox.common_3.6.200.v20130402-1505

    2       ACTIVE      org.eclipse.equinox.console_1.1.0.v20140131-1639

    3       ACTIVE      org.apache.felix.gogo.shell_0.10.0.v201212101605

    4       ACTIVE      org.apache.felix.gogo.command_0.10.0.v201209301215

    5       ACTIVE      org.apache.felix.gogo.runtime_0.10.0.v201209301036

    6       RESOLVED    sample.HelloWorldOSGi_1.0.0


    osgi> install file:sample.HelloWorldOSGiSub_1.0.0.jar

    Bundle id is 7

    Location             file:sample.HelloWorldOSGiSub_1.0.0.jar

    State                2

    Bundle                   7|Installed  |    1|sample.HelloWorldOSGiSub (1.0.0)

    Version              1.0.0

    LastModified         1408530147306

    Headers               Bundle-Activator = kr.co.jabsiri.helloworldosgisub.SubActi

    vator

     Bundle-ManifestVersion = 2

     Bundle-Name = HelloWorldOSGiSub

     Bundle-RequiredExecutionEnvironment = JavaSE-1.6

     Bundle-SymbolicName = sample.HelloWorldOSGiSub

     Bundle-Version = 1.0.0

     Import-Package = org.osgi.framework;version="1.3.0",kr.co.jabsiri.helloworldosg

    i

     Manifest-Version = 1.0



    BundleContext        null

    BundleId             7

    SymbolicName         sample.HelloWorldOSGiSub

    RegisteredServices   null

    ServicesInUse        null

    Module               osgi.identity; osgi.identity="sample.HelloWorldOSGiSub"; ty

    pe="osgi.bundle"; version:Version="1.0.0" [id=7]


    osgi> 



    3. ss 명령어로 설치된 plugin을 확인 해보자

    osgi> ss

    "Framework is launched."



    id      State       Bundle

    0       ACTIVE      org.eclipse.osgi_3.10.0.v20140606-1445

    1       ACTIVE      org.eclipse.equinox.common_3.6.200.v20130402-1505

    2       ACTIVE      org.eclipse.equinox.console_1.1.0.v20140131-1639

    3       ACTIVE      org.apache.felix.gogo.shell_0.10.0.v201212101605

    4       ACTIVE      org.apache.felix.gogo.command_0.10.0.v201209301215

    5       ACTIVE      org.apache.felix.gogo.runtime_0.10.0.v201209301036

    6       RESOLVED    sample.HelloWorldOSGi_1.0.0

    7       INSTALLED   sample.HelloWorldOSGiSub_1.0.0

    osgi> 



    Plugin 의존도 확인 

    1. sample.HelloWorldOSGi 가 start 상태가 아닐 때 (위에서는 stop 시켜서 RESOLVED 상태임 ) sample.HelloWorldOSGiSub을 start 시켜보자.

        아래 처럼 Exception이 발생 한다.

    osgi> start 7

    gogo: BundleException: Could not resolve module: sample.HelloWorldOSGiSub [7]

      Unresolved requirement: Import-Package: kr.co.jabsiri.helloworldosgi


    osgi> 


    2. sample.HelloWorldOSGi 는 새로 배포 되었으므로 update를 하고 

        다시 sample.HelloWorldOSGiSub을 start 시켜보자.    

    osgi> update 6

    osgi> ss

    "Framework is launched."



    id      State       Bundle

    0       ACTIVE      org.eclipse.osgi_3.10.0.v20140606-1445

    1       ACTIVE      org.eclipse.equinox.common_3.6.200.v20130402-1505

    2       ACTIVE      org.eclipse.equinox.console_1.1.0.v20140131-1639

    3       ACTIVE      org.apache.felix.gogo.shell_0.10.0.v201212101605

    4       ACTIVE      org.apache.felix.gogo.command_0.10.0.v201209301215

    5       ACTIVE      org.apache.felix.gogo.runtime_0.10.0.v201209301036

    6       INSTALLED   sample.HelloWorldOSGi_1.0.0

    7       INSTALLED   sample.HelloWorldOSGiSub_1.0.0

    osgi> start 6

    start hello osgi world

    osgi> ss

    "Framework is launched."



    id      State       Bundle

    0       ACTIVE      org.eclipse.osgi_3.10.0.v20140606-1445

    1       ACTIVE      org.eclipse.equinox.common_3.6.200.v20130402-1505

    2       ACTIVE      org.eclipse.equinox.console_1.1.0.v20140131-1639

    3       ACTIVE      org.apache.felix.gogo.shell_0.10.0.v201212101605

    4       ACTIVE      org.apache.felix.gogo.command_0.10.0.v201209301215

    5       ACTIVE      org.apache.felix.gogo.runtime_0.10.0.v201209301036

    6       ACTIVE      sample.HelloWorldOSGi_1.0.0

    7       ACTIVE      sample.HelloWorldOSGiSub_1.0.0

    osgi> stop 7

    osgi> start 7


    위와같이 start, stop을 반복해도 Exception이 발생 하지 않는다.

    ( ** 그런데 6번을 start시켰을때 7번이 같이 install start 될줄은 몰랐다. 관련된 것이 있으면 같이 start 되나보다.. start를 따로 해야할줄 알았는데...)


    확실하게 눈으로 확인...

    1. 눈으로 정확히 확인을 해보기 위해 SubActivator start, stop method에 다음과 같이 printer.printer("")를 추가하였다.


    2. 재 배포후 다음처럼 명령어를 입력해보자

    osgi> update 7

    print string : I am sub activator !!!

    osgi> stop 7

    print string : Bye Bye !!!

    osgi>


    HelloWorldOSGi plugin에 있는 HelloOSGiWorldPrinter.printer method가 호출된 것을 확인 할 수 있다.




    첨부 1 : HelloWorldOSGi plugin Eclipse Project

    HelloWorldOSGi_3.zip



    첨부 2 : OSGi Framework

    plugins_osgi_3.zip



    참고 자료


    [1] Guru's Blog

    OSGi 시작하기 

    http://xguru.net/page/2?s=osgi 





    728x90

    'JAVA' 카테고리의 다른 글

    [ OSGi ] 6 - Spring DM 3  (0) 2014.08.28
    [ OSGi ] 5 - Spring DM 2  (0) 2014.08.26
    [ OSGi ] 4 - Spring DM 1  (0) 2014.08.25
    [ OSGi ] 2 - OSGi plugin project  (2) 2014.08.19
    [ OSGi ] 1 - OSGi 기초  (0) 2014.06.24
Designed by Tistory.