summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Campo2008-02-11 10:31:03 (EST)
committerChristian Campo2008-02-11 10:31:03 (EST)
commit20859bac54136fae383980bc116cce9e7717ce8e (patch)
tree29f89b6aa20a70ad81f10c15c421228a6a2d5f28
parentcfdfd045f3da09f46b5ea7fba60ec92bf4d43954 (diff)
downloadorg.eclipse.riena.old-20859bac54136fae383980bc116cce9e7717ce8e.zip
org.eclipse.riena.old-20859bac54136fae383980bc116cce9e7717ce8e.tar.gz
org.eclipse.riena.old-20859bac54136fae383980bc116cce9e7717ce8e.tar.bz2
improved error handling for duplicated SERVICE_PIDs, logging introduced
-rw-r--r--org.eclipse.riena.communication.registry/META-INF/MANIFEST.MF8
-rw-r--r--org.eclipse.riena.communication.registry/src/org/eclipse/riena/internal/communication/registry/Activator.java92
-rw-r--r--org.eclipse.riena.communication.registry/src/org/eclipse/riena/internal/communication/registry/RemoteServiceRegistry.java39
3 files changed, 92 insertions, 47 deletions
diff --git a/org.eclipse.riena.communication.registry/META-INF/MANIFEST.MF b/org.eclipse.riena.communication.registry/META-INF/MANIFEST.MF
index 7ac85b1..517bd09 100644
--- a/org.eclipse.riena.communication.registry/META-INF/MANIFEST.MF
+++ b/org.eclipse.riena.communication.registry/META-INF/MANIFEST.MF
@@ -4,7 +4,11 @@ Bundle-Name: Riena Communication Registry (Incubation)
Bundle-SymbolicName: org.eclipse.riena.communication.registry
Bundle-Version: 0.0.1
Bundle-Activator: org.eclipse.riena.internal.communication.registry.Activator
-Require-Bundle: org.eclipse.riena.communication.core
+Require-Bundle: org.eclipse.riena.communication.core,
+ org.eclipse.equinox.log,
+ org.eclipse.riena.core,
+ org.eclipse.core.runtime
Import-Package: org.osgi.framework;version="1.4.0",
- org.osgi.service.cm;version="1.2.0"
+ org.osgi.service.cm;version="1.2.0",
+ org.osgi.service.log;version="1.3.0"
Riena-ForceStart: true
diff --git a/org.eclipse.riena.communication.registry/src/org/eclipse/riena/internal/communication/registry/Activator.java b/org.eclipse.riena.communication.registry/src/org/eclipse/riena/internal/communication/registry/Activator.java
index 55f9583..c90dd70 100644
--- a/org.eclipse.riena.communication.registry/src/org/eclipse/riena/internal/communication/registry/Activator.java
+++ b/org.eclipse.riena.communication.registry/src/org/eclipse/riena/internal/communication/registry/Activator.java
@@ -12,59 +12,75 @@ package org.eclipse.riena.internal.communication.registry;
import java.util.Hashtable;
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.equinox.log.Logger;
import org.eclipse.riena.communication.core.IRemoteServiceRegistry;
-import org.osgi.framework.BundleActivator;
+import org.eclipse.riena.core.logging.LogUtil;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
-
/**
* @author Alexander Ziegler
* @author Christian Campo
*
*/
-public class Activator implements BundleActivator {
+public class Activator extends Plugin {
+
+ private static BundleContext CONTEXT;
+ private static Activator plugin;
+ private RemoteServiceRegistry serviceRegistry;
+ private ServiceRegistration regServiceRegistry;
+ private LogUtil logUtil;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
- private static BundleContext CONTEXT;
- private RemoteServiceRegistry serviceRegistry;
- private ServiceRegistration regServiceRegistry;
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ CONTEXT = context;
+ plugin = this;
+ serviceRegistry = new RemoteServiceRegistry();
+ serviceRegistry.start();
- /**
- * The constructor
- */
- public Activator() {
- }
+ Hashtable<String, Object> properties = new Hashtable<String, Object>(1);
+ regServiceRegistry = context.registerService(IRemoteServiceRegistry.ID, serviceRegistry, properties);
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
- */
- public void start(BundleContext context) throws Exception {
- CONTEXT = context;
- serviceRegistry = new RemoteServiceRegistry();
- serviceRegistry.start();
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ regServiceRegistry.unregister();
+ regServiceRegistry = null;
- Hashtable<String, Object> properties = new Hashtable<String, Object>(1);
- regServiceRegistry = context.registerService(IRemoteServiceRegistry.ID, serviceRegistry, properties);
- }
+ serviceRegistry.stop();
+ serviceRegistry = null;
+ CONTEXT = null;
+ plugin = null;
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
- */
- public void stop(BundleContext context) throws Exception {
- regServiceRegistry.unregister();
- regServiceRegistry = null;
+ public static BundleContext getContext() {
+ return CONTEXT;
+ }
- serviceRegistry.stop();
- serviceRegistry = null;
- CONTEXT = null;
- }
+ public static Activator getDefault() {
+ return plugin;
+ }
- public static BundleContext getContext() {
- return CONTEXT;
- }
+ public Logger getLogger(String name) {
+ if (logUtil == null) {
+ logUtil = new LogUtil(CONTEXT);
+ }
+ return logUtil.getLogger(name);
+ }
}
diff --git a/org.eclipse.riena.communication.registry/src/org/eclipse/riena/internal/communication/registry/RemoteServiceRegistry.java b/org.eclipse.riena.communication.registry/src/org/eclipse/riena/internal/communication/registry/RemoteServiceRegistry.java
index 6de37eb..354a4af 100644
--- a/org.eclipse.riena.communication.registry/src/org/eclipse/riena/internal/communication/registry/RemoteServiceRegistry.java
+++ b/org.eclipse.riena.communication.registry/src/org/eclipse/riena/internal/communication/registry/RemoteServiceRegistry.java
@@ -18,13 +18,17 @@ 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.osgi.framework.BundleContext;
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
@@ -34,6 +38,7 @@ import org.osgi.service.cm.ManagedService;
public class RemoteServiceRegistry implements IRemoteServiceRegistry {
private Map<String, IRemoteServiceRegistration> registeredServices;
private BundleContext context;
+ private Logger LOGGER = Activator.getDefault().getLogger(RemoteServiceRegistry.class.getName());
synchronized void start() {
registeredServices = new HashMap<String, IRemoteServiceRegistration>();
@@ -43,7 +48,8 @@ public class RemoteServiceRegistry implements IRemoteServiceRegistry {
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()]);
+ IRemoteServiceRegistration[] arrayRS = registeredServices.values().toArray(
+ new IRemoteServiceRegistration[registeredServices.values().size()]);
for (IRemoteServiceRegistration serviceReg : arrayRS) {
// unregisters all services for this registry
unregisterService(serviceReg.getReference());
@@ -59,6 +65,23 @@ public class RemoteServiceRegistry implements IRemoteServiceRegistry {
*/
public IRemoteServiceRegistration registerService(IRemoteServiceReference reference) {
+ String pid = reference.getConfigServicePID();
+ 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.getConfigServicePID() + " 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);
@@ -67,20 +90,22 @@ public class RemoteServiceRegistry implements IRemoteServiceRegistry {
Properties props = new Properties();
props.put("service.url", url);
props.put("service.protocol", reference.getDescription().getProtocol());
- ServiceRegistration serviceRegistration = context.registerService(reference.getServiceInterfaceClassName(), reference.getServiceInstance(),
- props);
+ ServiceRegistration serviceRegistration = context.registerService(reference
+ .getServiceInterfaceClassName(), reference.getServiceInstance(), props);
reference.setServiceRegistration(serviceRegistration);
- if (reference.getConfigServiceInstance() != null && reference.getConfigServicePID() != null) {
+ if (reference.getConfigServiceInstance() != null && pid != null) {
Hashtable<String, String> ht = new Hashtable<String, String>();
- ht.put(Constants.SERVICE_PID, reference.getConfigServicePID());
- reference.setConfigServiceRegistration(context.registerService(ManagedService.class.getName(), reference.getConfigServiceInstance(), ht));
+ ht.put(Constants.SERVICE_PID, pid);
+ reference.setConfigServiceRegistration(context.registerService(ManagedService.class.getName(),
+ reference.getConfigServiceInstance(), ht));
}
RemoteServiceRegistration remoteServiceReg = new RemoteServiceRegistration(reference, this);
registeredServices.put(url, remoteServiceReg);
- System.out.println("Riena::RemoteServiceRegistry:: DEBUG: OSGi NEW service registered id: " + reference.getServiceInterfaceClassName());
+ System.out.println("Riena::RemoteServiceRegistry:: DEBUG: OSGi NEW service registered id: "
+ + reference.getServiceInterfaceClassName());
return remoteServiceReg;
} else {
// for existing services copy over the service registration