달력

2

« 2025/2 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
2011. 12. 20. 15:54

ecf 분석 - Container OSGi 이야기2011. 12. 20. 15:54

//host.rs start과정
public void start(BundleContext context) throws Exception {
this.context = context;
// 1. Create R-OSGi Container
IContainerManager containerManager = getContainerManagerService();
container = containerManager.getContainerFactory().createContainer(
"ecf.r_osgi.peer");
// 2. Get remote service container adapter
//이놈이 Proxy.newInstance()로 생성되는 객체.... 
IRemoteServiceContainerAdapter containerAdapter = (IRemoteServiceContainerAdapter) container
.getAdapter(IRemoteServiceContainerAdapter.class);
// 3. Lookup IRemoteServiceReference
                // Proxy 객체를 이용해서 interface를 가져오네.... containerAdapter가 proxy.invokeObject
//그런데, getRemoteServiceReferences를 구현한 클래스를 찾을 수 없다... 어떻게 구현한걸까? 
IRemoteServiceReference[] helloReferences = containerAdapter
.getRemoteServiceReferences(IDFactory.getDefault().createID(
container.getConnectNamespace(), ROSGI_SERVICE_HOST),
IHello.class.getName(), null);
Assert.isNotNull(helloReferences);
Assert.isTrue(helloReferences.length > 0);
// 4. Get remote service for reference
IRemoteService remoteService = containerAdapter
.getRemoteService(helloReferences[0]);
// 5. Get the proxy
IHello proxy = (IHello) remoteService.getProxy();
// 6. Finally...call the proxy
proxy.hello("RemoteService Consumer");

// Call asynchronously via listener
callViaListener(remoteService);
}


r-osgi에서는 local마다 container를 통해 서로 통신을 하게 된다.
container는 containerFactory에서 얻을 수 있으며, factory패턴을 이용해서 container를 가져온다.

createContainer는 여러가지로 오버로딩되어있으며, String, ID, ContainerType 객체를 파라미터로 받아 container를 생성한다.
예제에서는 String을 파라미터로 넘겨서 생성한다. 그 함수의 내용은
public IContainer createContainer(String containerTypeDescriptionName) throws ContainerCreateException {
return createContainer(getDescriptionByNameWithException(containerTypeDescriptionName), (Object[]) null);


다시 createrContainer를 호출함. 모든 createContainer는
 public IContainer createContainer(ContainerTypeDescription containerTypeDescription, Object[] parameters) throws ContainerCreateException; 이를 호출하게 되어있다.

public IContainer createContainer(ContainerTypeDescription containerTypeDescription, Object[] parameters) throws ContainerCreateException {
String method = "createContainer"; //$NON-NLS-1$
Trace.entering(ECFPlugin.PLUGIN_ID, ECFDebugOptions.METHODS_ENTERING, ContainerFactory.class, method, new Object[] {containerTypeDescription, Trace.getArgumentsString(parameters)});
if (containerTypeDescription == null)
throwContainerCreateException("ContainerTypeDescription cannot be null", null, method); //$NON-NLS-1$
//객체를 그냥 써도 되는데, 왜 함수를 호출해서 다시 결과를 받는가? containerTypes을 동기화를 걸어서 한순간에 하나의 스레드만 가져오게 하려고, 
ContainerTypeDescription cd = getDescription0(containerTypeDescription);
if (cd == null)
throwContainerCreateException("ContainerTypeDescription '" //$NON-NLS-1$
+ containerTypeDescription.getName() + "' not found", null, method); //$NON-NLS-1$
IContainerInstantiator instantiator = null;
try {
instantiator = cd.getInstantiator();
} catch (Exception e) {
throwContainerCreateException("createContainer cannot get IContainerInstantiator for description : " //$NON-NLS-1$
+ containerTypeDescription, e, method);
}
// Ask instantiator to actually create instance
IContainer container = instantiator.createInstance(containerTypeDescription, parameters);
if (container == null)
throwContainerCreateException("Instantiator returned null for '" //$NON-NLS-1$
+ cd.getName() + "'", null, method); //$NON-NLS-1$
// Add to containers map if container.getID() provides a valid value.
ID containerID = container.getID();
if (containerID != null)
addContainer(container, cd);
Trace.exiting(ECFPlugin.PLUGIN_ID, ECFDebugOptions.METHODS_EXITING, ContainerFactory.class, method, container);
return container;
}


//container의 getAdapter
//serviceType이 이 클래스 객체로 형변환 될 수 있으면 이 객체를 리턴.
public Object getAdapter(Class serviceType) {
if (serviceType == null)
return null;
if (serviceType.isInstance(this)) {
return this;
}
ECFPlugin plugin = ECFPlugin.getDefault();
if (plugin == null)
return null;
IAdapterManager adapterManager = plugin.getAdapterManager();
return (adapterManager == null) ? null : adapterManager.loadAdapter(this, serviceType.getName());

'OSGi 이야기' 카테고리의 다른 글

OSGi Extender  (0) 2011.12.27
OGEMA_SOURCE_URL  (0) 2011.12.20
OSGI_ANDROID  (0) 2011.12.20
android에 osgi 올리기  (0) 2011.12.08
Bundle jar파일로 만들기  (0) 2011.12.08
:
Posted by НooпeУ


Code Start Code End