번들이 다른 번들을 제거하는 내용이다.
번들을 하나 생성하고 아래와 같이 코드를 짜자..
우선 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 번들이 사라진 것을 확인 할 수 가 있다.
참고 자료 :
'개발 > OSGI' 카테고리의 다른 글
4. 의존관계있는 번들 생성하기 (0) | 2020.02.07 |
---|---|
2. 번들을 실행하고 멈춰 보자. (0) | 2020.02.07 |
0. OSGi 환경구축 (단독 실행 방법) (0) | 2020.02.07 |
0-1. 이클립스를 이용해 최대한 간단하게(최소한의 번들만 실행해서) OSGI 환경 구축하기 (0) | 2020.02.07 |