summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Campo2008-01-17 09:34:55 (EST)
committerChristian Campo2008-01-17 09:34:55 (EST)
commit82d7b045e9868e519bec65813fed2f8de10cae2d (patch)
tree9f08f863782453a8ad8b7a5190d29297c70f297d
parent21fff6a688cd9fb81e0a3feecd57f18ee9ff4cb1 (diff)
downloadorg.eclipse.riena.old-82d7b045e9868e519bec65813fed2f8de10cae2d.zip
org.eclipse.riena.old-82d7b045e9868e519bec65813fed2f8de10cae2d.tar.gz
org.eclipse.riena.old-82d7b045e9868e519bec65813fed2f8de10cae2d.tar.bz2
initial checkin
-rw-r--r--org.eclipse.riena.communication.registry/.classpath7
-rw-r--r--org.eclipse.riena.communication.registry/.project28
-rw-r--r--org.eclipse.riena.communication.registry/META-INF/MANIFEST.MF9
-rw-r--r--org.eclipse.riena.communication.registry/about.html24
-rw-r--r--org.eclipse.riena.communication.registry/build.properties4
-rw-r--r--org.eclipse.riena.communication.registry/src/org/eclipse/riena/internal/communication/registry/Activator.java70
-rw-r--r--org.eclipse.riena.communication.registry/src/org/eclipse/riena/internal/communication/registry/RemoteServiceRegistration.java67
-rw-r--r--org.eclipse.riena.communication.registry/src/org/eclipse/riena/internal/communication/registry/RemoteServiceRegistry.java138
8 files changed, 347 insertions, 0 deletions
diff --git a/org.eclipse.riena.communication.registry/.classpath b/org.eclipse.riena.communication.registry/.classpath
new file mode 100644
index 0000000..751c8f2
--- /dev/null
+++ b/org.eclipse.riena.communication.registry/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.riena.communication.registry/.project b/org.eclipse.riena.communication.registry/.project
new file mode 100644
index 0000000..0fce6b1
--- /dev/null
+++ b/org.eclipse.riena.communication.registry/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.riena.communication.registry</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.riena.communication.registry/META-INF/MANIFEST.MF b/org.eclipse.riena.communication.registry/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..f469299
--- /dev/null
+++ b/org.eclipse.riena.communication.registry/META-INF/MANIFEST.MF
@@ -0,0 +1,9 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+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
+Import-Package: org.osgi.framework;version="1.4.0",
+ org.osgi.service.cm;version="1.2.0"
diff --git a/org.eclipse.riena.communication.registry/about.html b/org.eclipse.riena.communication.registry/about.html
new file mode 100644
index 0000000..fc81119
--- /dev/null
+++ b/org.eclipse.riena.communication.registry/about.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"><head>
+
+
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>About</title></head><body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 5, 2006</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, "Program" will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party ("Redistributor") and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+<div style="position: absolute; width: 28px; height: 28px; z-index: 1000; display: none;"></div><img style="position: absolute; width: 35px; height: 29px; z-index: 1000; display: none;" src="about-Dateien/launch.png"></body></html> \ No newline at end of file
diff --git a/org.eclipse.riena.communication.registry/build.properties b/org.eclipse.riena.communication.registry/build.properties
new file mode 100644
index 0000000..34d2e4d
--- /dev/null
+++ b/org.eclipse.riena.communication.registry/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
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
new file mode 100644
index 0000000..55f9583
--- /dev/null
+++ b/org.eclipse.riena.communication.registry/src/org/eclipse/riena/internal/communication/registry/Activator.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * 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.registry;
+
+import java.util.Hashtable;
+
+import org.eclipse.riena.communication.core.IRemoteServiceRegistry;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+
+/**
+ * @author Alexander Ziegler
+ * @author Christian Campo
+ *
+ */
+public class Activator implements BundleActivator {
+
+ private static BundleContext CONTEXT;
+ private RemoteServiceRegistry serviceRegistry;
+ private ServiceRegistration regServiceRegistry;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (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();
+
+ Hashtable<String, Object> properties = new Hashtable<String, Object>(1);
+ regServiceRegistry = context.registerService(IRemoteServiceRegistry.ID, serviceRegistry, properties);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ regServiceRegistry.unregister();
+ regServiceRegistry = null;
+
+ serviceRegistry.stop();
+ serviceRegistry = null;
+ CONTEXT = null;
+ }
+
+ public static BundleContext getContext() {
+ return CONTEXT;
+ }
+
+}
diff --git a/org.eclipse.riena.communication.registry/src/org/eclipse/riena/internal/communication/registry/RemoteServiceRegistration.java b/org.eclipse.riena.communication.registry/src/org/eclipse/riena/internal/communication/registry/RemoteServiceRegistration.java
new file mode 100644
index 0000000..3556b2e
--- /dev/null
+++ b/org.eclipse.riena.communication.registry/src/org/eclipse/riena/internal/communication/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.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.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
new file mode 100644
index 0000000..6de37eb
--- /dev/null
+++ b/org.eclipse.riena.communication.registry/src/org/eclipse/riena/internal/communication/registry/RemoteServiceRegistry.java
@@ -0,0 +1,138 @@
+/*******************************************************************************
+ * 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.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.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.ServiceRegistration;
+import org.osgi.service.cm.ManagedService;
+
+/**
+ * @author Alexander Ziegler
+ * @author Christian Campo
+ *
+ */
+public class RemoteServiceRegistry implements IRemoteServiceRegistry {
+ private Map<String, IRemoteServiceRegistration> registeredServices;
+ private BundleContext context;
+
+ synchronized void start() {
+ registeredServices = new HashMap<String, IRemoteServiceRegistration>();
+ this.context = Activator.getContext();
+ }
+
+ 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 url = reference.getDescription().getURL();
+ synchronized (registeredServices) {
+ IRemoteServiceRegistration foundRemoteServiceReg = registeredServices.get(url);
+ if (foundRemoteServiceReg == null) {
+ // it is a new entry, set properties to null since we have no
+ 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);
+ reference.setServiceRegistration(serviceRegistration);
+
+ if (reference.getConfigServiceInstance() != null && reference.getConfigServicePID() != 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));
+ }
+
+ RemoteServiceRegistration remoteServiceReg = new RemoteServiceRegistration(reference, this);
+ registeredServices.put(url, remoteServiceReg);
+
+ System.out.println("Riena::RemoteServiceRegistry:: 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();
+ System.out.println("Riena::RemoteServiceRegistry:: 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;
+ }
+ }
+}