summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Campo2008-03-14 06:48:39 (EDT)
committerChristian Campo2008-03-14 06:48:39 (EDT)
commitdeb8852b4f93896177b308adfe19f3b8335d1546 (patch)
tree2b856bd953de58de448886c3b0990c2e75207097
parent17f0548eb945b6f26b9dbaab2a074597a13b332c (diff)
downloadorg.eclipse.riena-deb8852b4f93896177b308adfe19f3b8335d1546.zip
org.eclipse.riena-deb8852b4f93896177b308adfe19f3b8335d1546.tar.gz
org.eclipse.riena-deb8852b4f93896177b308adfe19f3b8335d1546.tar.bz2
removed project org.eclipse.riena.communication.registry, added LazyProxy in RemoteServiceFactory
-rw-r--r--org.eclipse.riena.communication.core/src/org/eclipse/riena/communication/core/IRemoteServiceReference.java6
-rw-r--r--org.eclipse.riena.communication.core/src/org/eclipse/riena/communication/core/RemoteServiceDescription.java4
-rw-r--r--org.eclipse.riena.communication.core/src/org/eclipse/riena/communication/core/factory/RemoteServiceFactory.java307
-rw-r--r--org.eclipse.riena.communication.core/src/org/eclipse/riena/communication/core/factory/RemoteServiceReference.java24
-rw-r--r--org.eclipse.riena.communication.core/src/org/eclipse/riena/internal/communication/core/Activator.java19
-rw-r--r--org.eclipse.riena.communication.core/src/org/eclipse/riena/internal/communication/core/registry/RemoteServiceRegistration.java67
-rw-r--r--org.eclipse.riena.communication.core/src/org/eclipse/riena/internal/communication/core/registry/RemoteServiceRegistry.java161
7 files changed, 502 insertions, 86 deletions
diff --git a/org.eclipse.riena.communication.core/src/org/eclipse/riena/communication/core/IRemoteServiceReference.java b/org.eclipse.riena.communication.core/src/org/eclipse/riena/communication/core/IRemoteServiceReference.java
index 31493a6..26f8cc3 100644
--- a/org.eclipse.riena.communication.core/src/org/eclipse/riena/communication/core/IRemoteServiceReference.java
+++ b/org.eclipse.riena.communication.core/src/org/eclipse/riena/communication/core/IRemoteServiceReference.java
@@ -101,9 +101,11 @@ public interface IRemoteServiceReference {
ManagedService getConfigServiceInstance();
/**
- * @return the ServicePID for the ConfigService Instance
+ * @param configServiceInstance
+ * Service Instance of the ManagedService that can handle this
+ * remote service reference
*/
- String getConfigServicePID();
+ void setConfigServiceInstance(ManagedService configServiceInstance);
/**
* @param configServiceRegistration
diff --git a/org.eclipse.riena.communication.core/src/org/eclipse/riena/communication/core/RemoteServiceDescription.java b/org.eclipse.riena.communication.core/src/org/eclipse/riena/communication/core/RemoteServiceDescription.java
index 49bccbb..f1d9b3a 100644
--- a/org.eclipse.riena.communication.core/src/org/eclipse/riena/communication/core/RemoteServiceDescription.java
+++ b/org.eclipse.riena.communication.core/src/org/eclipse/riena/communication/core/RemoteServiceDescription.java
@@ -299,11 +299,11 @@ public class RemoteServiceDescription {
this.url = url;
}
- public String getConfigid() {
+ public String getConfigPID() {
return configid;
}
- public void setConfigid(String configid) {
+ public void setConfigPID(String configid) {
this.configid = configid;
}
diff --git a/org.eclipse.riena.communication.core/src/org/eclipse/riena/communication/core/factory/RemoteServiceFactory.java b/org.eclipse.riena.communication.core/src/org/eclipse/riena/communication/core/factory/RemoteServiceFactory.java
index 45545cb..c4421a5 100644
--- a/org.eclipse.riena.communication.core/src/org/eclipse/riena/communication/core/factory/RemoteServiceFactory.java
+++ b/org.eclipse.riena.communication.core/src/org/eclipse/riena/communication/core/factory/RemoteServiceFactory.java
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.riena.communication.core.factory;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Hashtable;
@@ -20,24 +22,25 @@ import org.eclipse.riena.communication.core.IRemoteServiceRegistry;
import org.eclipse.riena.communication.core.RemoteServiceDescription;
import org.eclipse.riena.communication.core.publisher.RSDPublisherProperties;
import org.eclipse.riena.core.RienaStartupStatus;
+import org.eclipse.riena.core.service.ServiceId;
import org.eclipse.riena.internal.communication.core.Activator;
import org.eclipse.riena.internal.communication.core.factory.CallHooksProxy;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceEvent;
-import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
import org.osgi.service.cm.ConfigurationPlugin;
+import org.osgi.service.cm.ManagedService;
import org.osgi.service.log.LogService;
/**
* The IRemoteServiceFactory creates {@link IRemoteServiceReference} for given
- * service end point description. The IRemoteServiceReference holds a proxy
- * reference instance to the service end point. The RemoteService Factory can
- * register an IRemoteServiceReference into the {@link IRemoteServiceRegistry}.
- * To create a {@link IRemoteServiceReference} call {@link #createProxy(..)}.
- * To create and register a "remote" OSGi Service in one step call
- * {@link #createAndRegisterProxy(..)}
+ * service end point description. The IRemoteServiceReference holds a
+ * serviceInstance reference instance to the service end point. The
+ * RemoteService Factory can register an IRemoteServiceReference into the
+ * {@link IRemoteServiceRegistry}. To create a {@link IRemoteServiceReference}
+ * call {@link #createProxy(..)}. To create and register a "remote" OSGi
+ * Service in one step call {@link #createAndRegisterProxy(..)}
* <p>
* This RemoteServiceFactory do not create IRemoteServiceReference itself. This
* RemoteServiceFactory delegates the behaviour to a protocol specifically
@@ -63,6 +66,7 @@ public class RemoteServiceFactory {
private static final String HOST_ID = RemoteServiceFactory.class.getName();
private BundleContext context;
private Logger LOGGER = Activator.getDefault().getLogger(RemoteServiceFactory.class.getName());
+ private IRemoteServiceRegistry registry;
/**
* Creates a RemoteServiceFactory instance with the default bundle context.
@@ -74,6 +78,17 @@ public class RemoteServiceFactory {
*/
public RemoteServiceFactory() {
this(Activator.getContext());
+ new ServiceId(IRemoteServiceRegistry.ID).injectInto(this).andStart(Activator.getContext());
+ }
+
+ public void bind(IRemoteServiceRegistry registry) {
+ this.registry = registry;
+ }
+
+ public void unbind(IRemoteServiceRegistry registry) {
+ if (this.registry == registry) {
+ this.registry = null;
+ }
}
/**
@@ -94,7 +109,7 @@ public class RemoteServiceFactory {
* for the reference. If no protocol specific {@link IRemoteServiceFactory}
* OSGI Service available answers <code>null</code>.
*
- * @param interfaceClass
+ * @param serviceClass
* @param url
* @param protocol
* @return the registration object or <code>null</code>
@@ -116,7 +131,7 @@ public class RemoteServiceFactory {
* The hostId identifies who is responsible for this remote service
* registration
*
- * @param interfaceClass
+ * @param serviceClass
* @param url
* @param protocol
* @param hostId
@@ -159,51 +174,39 @@ public class RemoteServiceFactory {
* @return the registration object or <code>null</code>
*/
public IRemoteServiceRegistration createAndRegisterProxy(RemoteServiceDescription rsDesc, String hostId) {
- // create proxy first
- final IRemoteServiceReference rsRef = createProxy(rsDesc);
+ // create serviceInstance first
+ IRemoteServiceReference rsRef = createProxy(rsDesc);
+ if (rsRef == null) {
+ rsRef = createLazyProxy(rsDesc);
+ }
if (rsRef == null) {
- LOGGER.log(LogService.LOG_ERROR, "could not create proxy for " + rsDesc);
+ LOGGER
+ .log(LogService.LOG_ERROR,
+ "could not create serviceInstance (neither serviceInstance nor lazy serviceInstance) for "
+ + rsDesc);
return null;
}
rsRef.setHostId(hostId);
- // get registry and register directly
- ServiceReference refRegistry = context.getServiceReference(IRemoteServiceRegistry.ID);
- if (refRegistry != null) {
- IRemoteServiceRegistry registry = (IRemoteServiceRegistry) context.getService(refRegistry);
- if (registry != null) {
- IRemoteServiceRegistration reg = registry.registerService(rsRef);
- return reg;
- }
- }
- ServiceListener sl = new ServiceListener() {
- public void serviceChanged(ServiceEvent event) {
- ServiceReference refRegistry = event.getServiceReference();
- IRemoteServiceRegistry registry = (IRemoteServiceRegistry) Activator.getContext().getService(
- refRegistry);
- if (registry != null) {
- registry.registerService(rsRef);
- }
- }
- };
- try {
- Activator.getContext().addServiceListener(sl, "(objectClass=" + IRemoteServiceRegistry.ID + ")");
- } catch (InvalidSyntaxException e) {
- e.printStackTrace();
+ // register directly
+ if (registry != null) {
+ IRemoteServiceRegistration reg = registry.registerService(rsRef);
+ return reg;
}
return null;
}
/**
- * Creates a protocol specifically proxy reference (IRemoteServcieRefernce)
- * with given end point parameters. Answers the IRemoteServiceReference. If
- * no protocol specific {@link IRemoteServiceFactory} OSGI Service available
- * answers <code>null</code>.
+ * Creates a protocol specifically serviceInstance reference
+ * (IRemoteServcieRefernce) with given end point parameters. Answers the
+ * IRemoteServiceReference. If no protocol specific
+ * {@link IRemoteServiceFactory} OSGI Service available answers
+ * <code>null</code>.
*
- * @param interfaceClass
+ * @param serviceClass
* @param url
* @param protocol
- * @return the proxy references or <code>null</code>
+ * @return the serviceInstance references or <code>null</code>
*/
public IRemoteServiceReference createProxy(Class<?> interfaceClass, String url, String protocol, String configid) {
RemoteServiceDescription rsd = createDescription(interfaceClass, url, protocol, configid);
@@ -217,7 +220,7 @@ public class RemoteServiceFactory {
rsd.setServiceInterfaceClassName(interfaceClass.getName());
rsd.setURL(url);
rsd.setProtocol(protocol);
- rsd.setConfigid(configid);
+ rsd.setConfigPID(configid);
return rsd;
}
@@ -228,11 +231,11 @@ public class RemoteServiceFactory {
* <code>null</code>.
*
* @param rsd
- * @return the proxy references or <code>null</code>
+ * @return the serviceInstance references or <code>null</code>
*/
public IRemoteServiceReference createProxy(RemoteServiceDescription rsd) {
if (!RienaStartupStatus.getInstance().isStarted()) {
- LOGGER.log(LogService.LOG_WARNING, "riena.core is not started. This will probably not work.");
+ LOGGER.log(LogService.LOG_WARNING, "riena.core is not started. This will probably not work."); //$NON-NLS-1$
}
// consult ConfigurationPlugins for URL
try {
@@ -257,7 +260,7 @@ public class RemoteServiceFactory {
return null;
}
// find a factory for this specific protocol
- String filter = "(" + IRemoteServiceFactory.PROP_PROTOCOL + "=" + rsd.getProtocol() + ")";
+ String filter = "(" + IRemoteServiceFactory.PROP_PROTOCOL + "=" + rsd.getProtocol() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
try {
references = context.getServiceReferences(IRemoteServiceFactory.ID, filter);
} catch (InvalidSyntaxException e) {
@@ -266,8 +269,8 @@ public class RemoteServiceFactory {
}
// no factory for this protocol
if (references == null) {
- LOGGER.log(LogService.LOG_WARNING, "no IRemoteServiceFactory serviceRef available protocol ["
- + rsd.getProtocol() + "]");
+ LOGGER.log(LogService.LOG_WARNING, "no IRemoteServiceFactory serviceRef available protocol [" //$NON-NLS-1$
+ + rsd.getProtocol() + "]"); //$NON-NLS-1$
return null;
}
@@ -283,13 +286,14 @@ public class RemoteServiceFactory {
// could not get instance for existing reference
if (factory == null) {
- LOGGER.log(LogService.LOG_WARNING, "no IRemoteServiceFactory service available protocol ["
- + rsd.getProtocol() + "] id [" + rsd.getServiceInterfaceClassName() + "]");
+ LOGGER.log(LogService.LOG_WARNING, "no IRemoteServiceFactory service available protocol [" //$NON-NLS-1$
+ + rsd.getProtocol() + "] id [" + rsd.getServiceInterfaceClassName() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
return null;
}
- LOGGER.log(LogService.LOG_INFO, "found protocol [" + rsd.getProtocol() + "] " + factory);
+ LOGGER.log(LogService.LOG_INFO, "found protocol [" + rsd.getProtocol() + "] " + factory); //$NON-NLS-1$ //$NON-NLS-2$
- // ask factory to create a proxy for me, and intercept the calls with a
+ // ask factory to create a serviceInstance for me, and intercept the
+ // calls with a
// CallHooksProxy instance
try {
IRemoteServiceReference rsr = factory.createProxy(rsd);
@@ -304,15 +308,28 @@ public class RemoteServiceFactory {
}
}
- /**
- * This RemoteServiceFactory is responsible for all protocols because it
- * delegates the behavior to {@link IRemoteServiceFactory} OSGi Services.
- *
- * @return all protocols
- */
- // public String getProtocol() {
- // return "*";
- // }
+ private IRemoteServiceReference createLazyProxy(RemoteServiceDescription rsd) {
+ try {
+ LazyProxyHandler lazyProxyHandler = new LazyProxyHandler(rsd);
+ Class<?> serviceClass;
+ serviceClass = RemoteServiceFactory.class.getClassLoader().loadClass(rsd.getServiceInterfaceClassName());
+ Object serviceInstance = Proxy.newProxyInstance(this.getClass().getClassLoader(),
+ new Class[] { serviceClass }, lazyProxyHandler);
+ LazyRemoteServiceReference ref = new LazyRemoteServiceReference(serviceInstance, rsd
+ .getServiceInterfaceClassName(), rsd);
+
+ LazyProxyBuilder proxyBuilder = new LazyProxyBuilder(rsd, ref, lazyProxyHandler);
+ String filter = "(" + IRemoteServiceFactory.PROP_PROTOCOL + "=" + rsd.getProtocol() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new ServiceId(IRemoteServiceFactory.class.getName()).useFilter(filter).injectInto(proxyBuilder).andStart(
+ Activator.getContext());
+ return ref;
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return null;
+ }
+ }
+
/**
* Load class types for the given intefaceClassName.
*
@@ -326,4 +343,172 @@ public class RemoteServiceFactory {
return getClass().getClassLoader().loadClass(interfaceClassName);
}
+ public class LazyProxyBuilder {
+
+ private RemoteServiceDescription rsd;
+ private LazyRemoteServiceReference lazyRef;
+ private LazyProxyHandler lazyProxyHandler;
+
+ protected LazyProxyBuilder(RemoteServiceDescription rsd, LazyRemoteServiceReference ref,
+ LazyProxyHandler lazyProxyHandler) {
+ super();
+ this.rsd = rsd;
+ this.lazyRef = ref;
+ this.lazyProxyHandler = lazyProxyHandler;
+ }
+
+ public void bind(IRemoteServiceFactory factory) {
+ if (rsd != null) {
+ IRemoteServiceReference ref = createProxy(rsd);
+ Object proxyInstance = ref.getServiceInstance();
+ lazyProxyHandler.setDelegateHandler(Proxy.getInvocationHandler(proxyInstance));
+ lazyRef.setDelegateRef(ref);
+ rsd = null;
+ }
+
+ }
+
+ public void unbind(IRemoteServiceFactory factory) {
+
+ }
+ }
+
+ class LazyProxyHandler implements InvocationHandler {
+
+ private InvocationHandler delegateHandler;
+ private RemoteServiceDescription rsd;
+
+ protected LazyProxyHandler(RemoteServiceDescription rsd) {
+ super();
+ this.rsd = rsd;
+ }
+
+ public void setDelegateHandler(InvocationHandler delegateHandler) {
+ this.delegateHandler = delegateHandler;
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ if (delegateHandler == null) {
+ throw new RuntimeException(
+ "LazyProxy: missing IRemoteServiceFactory to create proxy for " + "protocol=" + rsd.getProtocol() + " url=" //$NON-NLS-1$ //$NON-NLS-2$
+ + rsd.getURL() + " interface=" + rsd.getServiceInterfaceClassName());
+ }
+
+ return delegateHandler.invoke(proxy, method, args);
+ }
+
+ }
+
+ class LazyRemoteServiceReference implements IRemoteServiceReference {
+
+ private Object serviceInstance;
+ private String serviceClass;
+ private IRemoteServiceReference delegateReference;
+ private String tempHostId;
+ private RemoteServiceDescription rsd;
+ private ServiceRegistration serviceRegistration;
+
+ protected LazyRemoteServiceReference(Object serviceInstance, String serviceClass, RemoteServiceDescription rsd) {
+ super();
+ this.serviceInstance = serviceInstance;
+ this.serviceClass = serviceClass;
+ this.rsd = rsd;
+ }
+
+ public void setDelegateRef(IRemoteServiceReference delegateRef) {
+ this.delegateReference = delegateRef;
+ if (tempHostId != null) {
+ delegateRef.setHostId(tempHostId);
+ }
+ }
+
+ public void dispose() {
+ delegateReference.dispose();
+ }
+
+ public boolean equals(Object obj) {
+ return delegateReference.equals(obj);
+ }
+
+ public ManagedService getConfigServiceInstance() {
+ if (delegateReference == null) {
+ return null;
+ }
+ return delegateReference.getConfigServiceInstance();
+ }
+
+ public ServiceRegistration getConfigServiceRegistration() {
+ return delegateReference.getConfigServiceRegistration();
+ }
+
+ public RemoteServiceDescription getDescription() {
+ if (delegateReference == null) {
+ return rsd;
+ }
+ return delegateReference.getDescription();
+ }
+
+ public String getHostId() {
+ if (delegateReference == null) {
+ return tempHostId;
+ } else {
+ return delegateReference.getHostId();
+ }
+ }
+
+ public Object getServiceInstance() {
+ if (delegateReference == null) {
+ return serviceInstance;
+ }
+ return delegateReference.getServiceInstance();
+ }
+
+ public String getServiceInterfaceClassName() {
+ if (delegateReference == null) {
+ return serviceClass;
+ }
+ return delegateReference.getServiceInterfaceClassName();
+ }
+
+ public ServiceRegistration getServiceRegistration() {
+ return serviceRegistration;
+ }
+
+ public String getURL() {
+ return delegateReference.getURL();
+ }
+
+ public int hashCode() {
+ return delegateReference.hashCode();
+ }
+
+ public void setConfigServiceInstance(ManagedService configServiceInstance) {
+ delegateReference.setConfigServiceInstance(configServiceInstance);
+ }
+
+ public void setConfigServiceRegistration(ServiceRegistration configServiceRegistration) {
+ delegateReference.setConfigServiceRegistration(configServiceRegistration);
+ }
+
+ public void setHostId(String hostId) {
+ if (delegateReference == null) {
+ tempHostId = hostId;
+ } else {
+ delegateReference.setHostId(hostId);
+ }
+ }
+
+ public void setServiceInstance(Object serviceInstance) {
+ delegateReference.setServiceInstance(serviceInstance);
+ }
+
+ public void setServiceRegistration(ServiceRegistration serviceRegistration) {
+ this.serviceRegistration = serviceRegistration;
+ }
+
+ public String toString() {
+ return delegateReference.toString();
+ }
+
+ }
}
diff --git a/org.eclipse.riena.communication.core/src/org/eclipse/riena/communication/core/factory/RemoteServiceReference.java b/org.eclipse.riena.communication.core/src/org/eclipse/riena/communication/core/factory/RemoteServiceReference.java
index f4ce7e4..0de9925 100644
--- a/org.eclipse.riena.communication.core/src/org/eclipse/riena/communication/core/factory/RemoteServiceReference.java
+++ b/org.eclipse.riena.communication.core/src/org/eclipse/riena/communication/core/factory/RemoteServiceReference.java
@@ -25,7 +25,6 @@ public class RemoteServiceReference implements IRemoteServiceReference {
private ServiceRegistration serviceRegistration;
private RemoteServiceDescription description;
private ManagedService configServiceInstance;
- private String configServicePID;
private ServiceRegistration configServiceRegistration;
private String hostId;
@@ -139,22 +138,13 @@ public class RemoteServiceReference implements IRemoteServiceReference {
return configServiceInstance;
}
- /**
- * @param configServiceInstance
- * Service Instance of the ManagedService that can handle this
- * remote service reference
- */
- public void setConfigServiceInstance(ManagedService configServiceInstance) {
- this.configServiceInstance = configServiceInstance;
- }
-
/*
* (non-Javadoc)
*
- * @see org.eclipse.riena.communication.core.IRemoteServiceReference#getConfigServicePID()
+ * @see org.eclipse.riena.communication.core.IRemoteServiceReference#setConfigServiceInstance(org.osgi.service.cm.ManagedService)
*/
- public String getConfigServicePID() {
- return configServicePID;
+ public void setConfigServiceInstance(ManagedService configServiceInstance) {
+ this.configServiceInstance = configServiceInstance;
}
/*
@@ -175,14 +165,6 @@ public class RemoteServiceReference implements IRemoteServiceReference {
this.configServiceRegistration = configServiceRegistration;
}
- /**
- * @param configServicePID
- * sets the ServicePID for the ManagedService entry
- */
- public void setConfigServicePID(String configServicePID) {
- this.configServicePID = configServicePID;
- }
-
@Override
public String toString() {
return "hostId= " + hostId + ", end point=(" + getDescription() + ")";
diff --git a/org.eclipse.riena.communication.core/src/org/eclipse/riena/internal/communication/core/Activator.java b/org.eclipse.riena.communication.core/src/org/eclipse/riena/internal/communication/core/Activator.java
index 496a8fb..2a56076 100644
--- a/org.eclipse.riena.communication.core/src/org/eclipse/riena/internal/communication/core/Activator.java
+++ b/org.eclipse.riena.communication.core/src/org/eclipse/riena/internal/communication/core/Activator.java
@@ -10,10 +10,12 @@
*******************************************************************************/
package org.eclipse.riena.internal.communication.core;
+import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import org.eclipse.equinox.log.Logger;
+import org.eclipse.riena.communication.core.IRemoteServiceRegistry;
import org.eclipse.riena.communication.core.hooks.CallContext;
import org.eclipse.riena.communication.core.hooks.ICallHook;
import org.eclipse.riena.communication.core.ssl.ISSLProperties;
@@ -22,8 +24,10 @@ import org.eclipse.riena.core.RienaActivator;
import org.eclipse.riena.core.extension.ExtensionId;
import org.eclipse.riena.core.extension.ExtensionInjector;
import org.eclipse.riena.core.service.ServiceId;
+import org.eclipse.riena.internal.communication.core.registry.RemoteServiceRegistry;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
import org.osgi.service.log.LogService;
/**
@@ -34,6 +38,8 @@ import org.osgi.service.log.LogService;
public class Activator extends RienaActivator {
private static Activator plugin;
+ private RemoteServiceRegistry serviceRegistry;
+ private ServiceRegistration regServiceRegistry;
private ServiceReference sslConfigServiceReference;
private ExtensionInjector sslInjector;
@@ -47,6 +53,12 @@ public class Activator extends RienaActivator {
super.start(context);
plugin = this;
+ serviceRegistry = new RemoteServiceRegistry();
+ serviceRegistry.start();
+
+ Hashtable<String, Object> properties = ServiceId.newDefaultServiceProperties();
+ regServiceRegistry = context.registerService(IRemoteServiceRegistry.ID, serviceRegistry, properties);
+
final Logger logger = getLogger(Activator.class.getName());
context.registerService(ICallHook.ID, new ICallHook() {
@@ -92,6 +104,13 @@ public class Activator extends RienaActivator {
sslInjector.stop();
if (sslConfigServiceReference != null)
context.ungetService(sslConfigServiceReference);
+
+ regServiceRegistry.unregister();
+ regServiceRegistry = null;
+
+ serviceRegistry.stop();
+ serviceRegistry = null;
+
plugin = null;
super.stop(context);
diff --git a/org.eclipse.riena.communication.core/src/org/eclipse/riena/internal/communication/core/registry/RemoteServiceRegistration.java b/org.eclipse.riena.communication.core/src/org/eclipse/riena/internal/communication/core/registry/RemoteServiceRegistration.java
new file mode 100644
index 0000000..0495e74
--- /dev/null
+++ b/org.eclipse.riena.communication.core/src/org/eclipse/riena/internal/communication/core/registry/RemoteServiceRegistration.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.internal.communication.core.registry;
+
+import org.eclipse.riena.communication.core.IRemoteServiceReference;
+import org.eclipse.riena.communication.core.IRemoteServiceRegistration;
+import org.eclipse.riena.communication.core.IRemoteServiceRegistry;
+
+/**
+ * This is a Implementation of the IRemoteServiceRegistration. It refers registered
+ * RemoteServiceReference. By invoke {@link #unregister()} the RemoteServiceReference becomes
+ * unregistered from the {@link RemoteServiceRegistry}.
+ *
+ * @author Alexander Ziegler
+ *
+ */
+public class RemoteServiceRegistration implements IRemoteServiceRegistration {
+ private IRemoteServiceReference reference;
+ private IRemoteServiceRegistry registry;
+
+ /**
+ * Creates a instance with the given reference an registry
+ *
+ * @param reference
+ * @param registry
+ */
+ public RemoteServiceRegistration(IRemoteServiceReference reference,
+ IRemoteServiceRegistry registry) {
+ super();
+ this.reference = reference;
+ this.registry = registry;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.riena.communication.core.IRemoteServiceRegistration#getReference()
+ */
+ public IRemoteServiceReference getReference() {
+ return reference;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.riena.communication.core.IRemoteServiceRegistration#unregister()
+ */
+ public void unregister() {
+ if (registry != null) {
+ registry.unregisterService(getReference());
+ registry = null;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.riena.communication.core.IRemoteServiceRegistration#setReference(org.eclipse.riena.communication.core.IRemoteServiceReference)
+ */
+ public void setReference(IRemoteServiceReference reference) {
+ this.reference = reference;
+
+ }
+
+}
diff --git a/org.eclipse.riena.communication.core/src/org/eclipse/riena/internal/communication/core/registry/RemoteServiceRegistry.java b/org.eclipse.riena.communication.core/src/org/eclipse/riena/internal/communication/core/registry/RemoteServiceRegistry.java
new file mode 100644
index 0000000..55cfa2f
--- /dev/null
+++ b/org.eclipse.riena.communication.core/src/org/eclipse/riena/internal/communication/core/registry/RemoteServiceRegistry.java
@@ -0,0 +1,161 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.internal.communication.core.registry;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.eclipse.equinox.log.Logger;
+import org.eclipse.riena.communication.core.IRemoteServiceReference;
+import org.eclipse.riena.communication.core.IRemoteServiceRegistration;
+import org.eclipse.riena.communication.core.IRemoteServiceRegistry;
+import org.eclipse.riena.internal.communication.core.Activator;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ManagedService;
+import org.osgi.service.log.LogService;
+
+/**
+ * @author Alexander Ziegler
+ * @author Christian Campo
+ *
+ */
+public class RemoteServiceRegistry implements IRemoteServiceRegistry {
+ private Map<String, IRemoteServiceRegistration> registeredServices;
+ private Logger LOGGER = Activator.getDefault().getLogger(RemoteServiceRegistry.class.getName());
+
+ public synchronized void start() {
+ registeredServices = new HashMap<String, IRemoteServiceRegistration>();
+ }
+
+ public synchronized void stop() {
+ // @TODO unregisterService changes the registeredServices collection,
+ // the for loop collapses with ConcurrentModificationException
+ IRemoteServiceRegistration[] arrayRS = registeredServices.values().toArray(
+ new IRemoteServiceRegistration[registeredServices.values().size()]);
+ for (IRemoteServiceRegistration serviceReg : arrayRS) {
+ // unregisters all services for this registry
+ unregisterService(serviceReg.getReference());
+ }
+ registeredServices.clear();
+ registeredServices = null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.riena.communication.core.IRemoteServiceRegistry#registerService(org.eclipse.riena.communication.core.IRemoteServiceReference)
+ */
+ public IRemoteServiceRegistration registerService(IRemoteServiceReference reference) {
+
+ String pid = reference.getDescription().getConfigPID();
+ if (pid != null) {
+ ServiceReference[] refs;
+ try {
+ refs = Activator.getContext().getServiceReferences(ManagedService.class.getName(),
+ "(" + Constants.SERVICE_PID + "=" + pid + ")");
+ if (refs != null && refs.length > 0) {
+ LOGGER.log(LogService.LOG_ERROR, "duplicate configuration " + Constants.SERVICE_PID + " = "
+ + reference.getDescription().getConfigPID() + " for service "
+ + reference.getServiceInterfaceClassName() + " service is set to NOT configurable");
+ pid = null;
+ }
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace();
+ }
+ }
+
+ String url = reference.getDescription().getURL();
+ synchronized (registeredServices) {
+ IRemoteServiceRegistration foundRemoteServiceReg = registeredServices.get(url);
+ if (foundRemoteServiceReg == null) {
+ // it is a new entry, set properties
+ Properties props = new Properties();
+ props.put("service.url", url);
+ props.put("service.protocol", reference.getDescription().getProtocol());
+ ServiceRegistration serviceRegistration = Activator.getContext().registerService(
+ reference.getServiceInterfaceClassName(), reference.getServiceInstance(), props);
+ reference.setServiceRegistration(serviceRegistration);
+
+ if (reference.getConfigServiceInstance() != null && pid != null) {
+ Hashtable<String, String> ht = new Hashtable<String, String>();
+ ht.put(Constants.SERVICE_PID, pid);
+ reference.setConfigServiceRegistration(Activator.getContext().registerService(
+ ManagedService.class.getName(), reference.getConfigServiceInstance(), ht));
+ }
+
+ RemoteServiceRegistration remoteServiceReg = new RemoteServiceRegistration(reference, this);
+ registeredServices.put(url, remoteServiceReg);
+
+ LOGGER.log(LogService.LOG_DEBUG, "OSGi NEW service registered id: "
+ + reference.getServiceInterfaceClassName());
+ return remoteServiceReg;
+ } else {
+ // for existing services copy over the service registration
+ // @TODO review this logic
+ reference.setServiceRegistration(foundRemoteServiceReg.getReference().getServiceRegistration());
+ foundRemoteServiceReg.setReference(reference);
+ return foundRemoteServiceReg;
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.riena.communication.core.IRemoteServiceRegistry#unregisterService(org.eclipse.riena.communication.core.IRemoteServiceReference)
+ */
+ public void unregisterService(IRemoteServiceReference reference) {
+ assert reference != null : "RemoteServiceReference must not be null";
+ synchronized (registeredServices) {
+ ServiceRegistration serviceRegistration = reference.getServiceRegistration();
+ serviceRegistration.unregister();
+ if (reference.getConfigServiceRegistration() != null) {
+ reference.getConfigServiceRegistration().unregister();
+ }
+ String id = reference.getServiceInterfaceClassName();
+ registeredServices.remove(reference.getURL());
+ reference.dispose();
+ LOGGER.log(LogService.LOG_DEBUG, "OSGi service removed id: " + id);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.riena.communication.core.IRemoteServiceRegistry#registeredServices(java.lang.String)
+ */
+ public List<IRemoteServiceRegistration> registeredServices(String hostId) {
+ synchronized (registeredServices) {
+ Collection<IRemoteServiceRegistration> values = registeredServices.values();
+ // Answers all service registrations when hostId is null or "*"
+ if (hostId == null || hostId.equals("*")) {
+ return new ArrayList<IRemoteServiceRegistration>(values);
+ }
+
+ List<IRemoteServiceRegistration> result = new ArrayList<IRemoteServiceRegistration>();
+ for (IRemoteServiceRegistration serviceReg : values) {
+ String registeredHostId = serviceReg.getReference().getHostId();
+ if (hostId.equals(registeredHostId)) {
+ result.add(serviceReg);
+ }
+ }
+ return result;
+ }
+ }
+}