osgi

ServiceFactory

tomato13 2009. 4. 2. 14:01

http://knopflerfish.org/releases/current/docs/javadoc/org/osgi/framework/ServiceFactory.html


먼저 간단하게 설명을 보면 아래와 같다. 

Allows services to provide customized service objects in the OSGi environment.


When registering a service, a ServiceFactory object can be used instead of a service object, so that the bundle developer can gain control of the specific service object granted to a bundle that is using the service.


example을 보면 쉽게 이해할 수 있을 듯 하다.


example)

registration = bundlecontext.registerService((com.samsung.xoa.test.lib.TestCaseLinkImpl.class).getName(), this, null);            // (1)


this 는 MainAgent라는 class로 ServiceFactory를 implement한다. TestCaseLinkImpl과는 직접적인 상관이 없기 때문에 무언가 이상하게 보일 수 있다.


만일 another bundle에서 

linkRef = context.getServiceReference((com.samsung.xoa.test.lib.TestCaseLinkImpl.class).getName());

하게되면


(1)에서 정의한 getService()가 호출된다.


public Object getService(Bundle bundle, ServiceRegistration serviceregistration)
{
TestCaseLinkImpl testcaselinkimpl = getTestCaseLink(bundle);
return testcaselinkimpl;
}

그리고 TestCaseLinkImpl이 return 되는 것을 확인할 수 있다.

이제 다시 상단의 description을 읽어보면 이해하기 쉬울 듯 하다.