개발/OSGI

3. 번들로 번들을 찾아서 제거하기

오제이튜브[OJ Tube] 2020. 2. 7. 02:03

번들이 다른 번들을 제거하는 내용이다.
 
번들을 하나 생성하고 아래와 같이 코드를 짜자..
우선 i 500으로 설정한게 만이 문제긴 한데.. 우선 테스트를 위해 그냥 넘어가자..
 
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
System.out.println("HelloWorldKiller searching...");
Bundle[] bundles = context.getBundles();
for (int i = 0;i<500; i++) {
if ("test".equals(bundles[i].getSymbolicName())) { //번들중 심볼네임이 test인 것을 찾는 부분.
try {
System.out.println("test found, " + "destroying!");
bundles[i].uninstall(); //찾으면 uninstall..
return;
} catch (BundleException e) {
System.err.println("Failed: " + e.getMessage());
}
}
}
System.out.println("Hello World bundle not found");
 
}
 
/*
* (non-Javadoc)
*
* @see
* org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext bundleContext) throws Exception {
Activator.context = null;
System.out.println("HelloWorldKiller shutting down"); //종료 메시지.
}
 
 
 
 
 
코드를 작성 하고 실행 해보면
“HelloWorldKiller searching...”
“test found, destroying!”
라고 출력 한다.
 
 
그리고 ss입력해보면
 
259 ACTIVE org.w3c.dom.smil_1.0.1.v200903091627
260 ACTIVE org.w3c.dom.svg_1.1.0.v201011041433
262 ACTIVE killer_1.0.0.qualifier
 
test번들이 있어야할 자리에 test가 없다.. ID : 261 없다.
자이제 다시 test를 설치해보자
 
 
osgi> install file:///C:/xxxxxx/equinox-master/ws/test
 
위에 install 명령어를 실행하자.
jar파일이 있으면 jar 파일을 입력하면 되는데..
그냥 이클립스에서 생성한 프로젝트 폴더 경로를 입력한다.
 
그럼 Bundle ID: 267 ”처럼 번들 ID를 알려준다
 
다시 ss 쳐보자
 
260 ACTIVE org.w3c.dom.svg_1.1.0.v201011041433
262 ACTIVE killer_1.0.0.qualifier
267 INSTALLED test_1.0.0.qualifier
 
라고 출력 된다.
 
start 267 하면 hello world를 출력한다. 원래는 ID 263이어야 하는데 여러번 테스트 했더니 267이 됐다.
 
stop 262하고
start 262를 하면
 
다시 test 번들이 사라진 것을 확인 할 수 가 있다.
 
 
 
 참고 자료 :

파트2 - 프레임워크와 연동하기.pdf