임베디드 osgi 프레임워크, 서비스 기능을 호출하는 방법은 무엇입니까? (Embedded osgi framework, how to call service functions?)


문제 설명

임베디드 osgi 프레임워크, 서비스 기능을 호출하는 방법은 무엇입니까? (Embedded osgi framework, how to call service functions?)

서버라는 간단한 자바 프로젝트가 있습니다. 또한 인터페이스 BlockProvider를 정의하는 osgi API 프로젝트가 있습니다. 다음으로 BlockProvider를 구현하는 서비스가 포함된 osgi 선언적 서비스 프로젝트가 있습니다.

내 자바 프로젝트 '서버'에는 임베디드 osgi 프레임워크(내 경우에는 felix)가 있습니다.

저는 gogo osgi 번들, scr 번들, 내 API 프로젝트 번들 및 서비스 프로젝트 번들을 설치하는 bundleactivator를 만들었습니다.

문제 없이 작동하고 내 서비스 번들을 검사할 수 있습니다.

내 서버에서 프로젝트 BlockProvider 인터페이스를 구현하는 서비스를 보고 싶습니다. 그래서 두 번째 매개변수(필터 1)로 "BlockProvider.class.getName()"을 사용하여 ServiceTracker를 구현합니다.

또한 문제 없이 작동합니다.


참조 솔루션

방법 1:

You can only access services from outside the OSGi framework if the API package is provided by the system bundle / the framework. So you should not install the API bundle and instead use the framework property org.osgi.framework.system.packages.extra to export your API package.

방법 2:

There are two important rules that apply here.

  1. When two bundles communicate via services, they MUST both import the API package from the same bundle. Normally you have a choice of which bundle actually exports the package. The provider of the service could export it, in which case the consumer must import it from the provider. Alternatively, you can have a separate "pure API" bundle exporting the API package, and both the provider and consumer import it from there. (Rarely, the consumer bundle exports the package, which is legal in OSGi but kind of weird design.)

  2. The system bundle — that is, the special bundle that represents the OSGi Framework itself from inside OSGi — cannot import packages from any ordinary bundle. It can only export.

When you embed OSGi, your application code outside of OSGi is seen as part of the system bundle. If you want the system bundle to talk to another bundle via services, then combining the two rules above implies that the API package must be exported by the system bundle. This remains true whether the system bundle is the provider or the consumer of the service.

Hence, the API package must be included on the system classpath of the embedding application, and exported from the system bundle when you setup the OSGi Framework using the org.osgi.framework.system.packages.extra property.

(by Tinus TateChristian SchneiderNeil Bartlett)

참조 문서

  1. Embedded osgi framework, how to call service functions? (CC BY‑SA 2.5/3.0/4.0)

#apache-felix #osgi #java






관련 질문

Apache Felix 웹 콘솔 브랜딩 (Branding Apache Felix web console)

포함된 Apache Felix를 시작할 수 없습니다. (Cannot start embeded Apache Felix)

Glassfish OSGI 웹 콘솔 자격 증명 (Glassfish OSGI Webconsole Credentials)

Android에 OSGi Felix 포함 (Embed OSGi Felix in Android)

Amdatu OSGI 이벤트 처리기 다른 수신기가 수신 대기 중일 때 수신 대기 시간 지연 (Amdatu OSGI Event Handler time delay to listen when other listener are listening)

OSGi 번들이 Felix 호스트 응용 프로그램으로 시작되지 않음 (OSGi Bundle not starting with Felix Host application)

임베디드 osgi 프레임워크, 서비스 기능을 호출하는 방법은 무엇입니까? (Embedded osgi framework, how to call service functions?)

kaldi 설치 시 libmkl_tbb_thread.so sth 관련 문제 (A problem related to libmkl_tbb_thread.so sth when installing kaldi)

OSGI(Apache Felix)에서 다른 사람의 번들에 대해 AOP를 구현하는 방법은 무엇입니까? (How to implement AOP for someone else's bundles in OSGI (Apache Felix)?)

OSGi r4.1의 ServiceTracker (ServiceTracker in OSGi r4.1)

번들 OSGI를 업데이트하는 동안 서비스/구성 요소를 계속 실행하는 방법 (How to keep service/componnet running while update bundle OSGI)

Equinox에서 Arquillian 실행 (Running Arquillian in Equinox)







코멘트