summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Campo2008-01-17 08:08:48 (EST)
committerChristian Campo2008-01-17 08:08:48 (EST)
commit21fff6a688cd9fb81e0a3feecd57f18ee9ff4cb1 (patch)
tree0495da7334e390550615748626732425db5f26ed
parent35054313b2495ae248152c9cc06f0c55596479dc (diff)
downloadorg.eclipse.riena.old-21fff6a688cd9fb81e0a3feecd57f18ee9ff4cb1.zip
org.eclipse.riena.old-21fff6a688cd9fb81e0a3feecd57f18ee9ff4cb1.tar.gz
org.eclipse.riena.old-21fff6a688cd9fb81e0a3feecd57f18ee9ff4cb1.tar.bz2
initial checkin
-rw-r--r--org.eclipse.riena.communication.discovery/.classpath7
-rw-r--r--org.eclipse.riena.communication.discovery/.project28
-rw-r--r--org.eclipse.riena.communication.discovery/.settings/org.eclipse.pde.core.prefs4
-rw-r--r--org.eclipse.riena.communication.discovery/META-INF/MANIFEST.MF10
-rw-r--r--org.eclipse.riena.communication.discovery/about.html24
-rw-r--r--org.eclipse.riena.communication.discovery/build.properties4
-rw-r--r--org.eclipse.riena.communication.discovery/src/org/eclipse/riena/internal/communication/discovery/Activator.java111
-rw-r--r--org.eclipse.riena.communication.discovery/src/org/eclipse/riena/internal/communication/discovery/RemoteServiceDiscovery.java202
8 files changed, 390 insertions, 0 deletions
diff --git a/org.eclipse.riena.communication.discovery/.classpath b/org.eclipse.riena.communication.discovery/.classpath
new file mode 100644
index 0000000..751c8f2
--- /dev/null
+++ b/org.eclipse.riena.communication.discovery/.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.discovery/.project b/org.eclipse.riena.communication.discovery/.project
new file mode 100644
index 0000000..bec4093
--- /dev/null
+++ b/org.eclipse.riena.communication.discovery/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.riena.communication.discovery</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.discovery/.settings/org.eclipse.pde.core.prefs b/org.eclipse.riena.communication.discovery/.settings/org.eclipse.pde.core.prefs
new file mode 100644
index 0000000..2775cef
--- /dev/null
+++ b/org.eclipse.riena.communication.discovery/.settings/org.eclipse.pde.core.prefs
@@ -0,0 +1,4 @@
+#Thu Mar 22 20:36:02 CET 2007
+eclipse.preferences.version=1
+pluginProject.extensions=false
+resolve.requirebundle=false
diff --git a/org.eclipse.riena.communication.discovery/META-INF/MANIFEST.MF b/org.eclipse.riena.communication.discovery/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..a521d2e
--- /dev/null
+++ b/org.eclipse.riena.communication.discovery/META-INF/MANIFEST.MF
@@ -0,0 +1,10 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Riena Communication Discovery (Incubation)
+Bundle-SymbolicName: org.eclipse.riena.communication.discovery
+Bundle-Version: 0.0.1
+Bundle-Activator: org.eclipse.riena.internal.communication.discovery.Activator
+Import-Package: com.caucho.hessian.client,
+ org.osgi.framework;version="1.4.0"
+Require-Bundle: org.eclipse.riena.communication.core,
+ org.eclipse.riena.core
diff --git a/org.eclipse.riena.communication.discovery/about.html b/org.eclipse.riena.communication.discovery/about.html
new file mode 100644
index 0000000..fc81119
--- /dev/null
+++ b/org.eclipse.riena.communication.discovery/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.discovery/build.properties b/org.eclipse.riena.communication.discovery/build.properties
new file mode 100644
index 0000000..34d2e4d
--- /dev/null
+++ b/org.eclipse.riena.communication.discovery/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/org.eclipse.riena.communication.discovery/src/org/eclipse/riena/internal/communication/discovery/Activator.java b/org.eclipse.riena.communication.discovery/src/org/eclipse/riena/internal/communication/discovery/Activator.java
new file mode 100644
index 0000000..33737a9
--- /dev/null
+++ b/org.eclipse.riena.communication.discovery/src/org/eclipse/riena/internal/communication/discovery/Activator.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * 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.discovery;
+
+import org.eclipse.riena.communication.core.IRemoteServiceRegistration;
+import org.eclipse.riena.communication.core.IRemoteServiceRegistry;
+import org.eclipse.riena.communication.core.factory.IRemoteServiceFactory;
+import org.eclipse.riena.communication.core.factory.RemoteServiceFactory;
+import org.eclipse.riena.communication.core.publisher.IServicePublishEventDispatcher;
+import org.eclipse.riena.core.service.ServiceInjector;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+
+
+public class Activator implements BundleActivator {
+
+ private RemoteServiceDiscovery discovery;
+ private ServiceInjector registryInjector;
+ private String HOST_ID = Activator.class.getName();
+ private IRemoteServiceRegistration servicePublisherReg;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ RemoteServiceFactory factory = new RemoteServiceFactory();
+
+ discovery = new RemoteServiceDiscovery(context);
+ discovery.setRemoteServiceFactory(factory);
+
+ registryInjector = new ServiceInjector(context, IRemoteServiceRegistry.ID, discovery, "setRemoteServiceRegistry", "setRemoteServiceRegistry");
+ registryInjector.start();
+ discovery.start();
+
+ // Thread t = new Thread() {
+ // public void run() {
+ // boolean firstRun = true;
+ // agent.start();
+ // System.out.println("thread start");
+ // while (true) {
+ // try {
+ // if (firstRun) {
+ // Thread.sleep(1000);
+ // } else {
+ // Thread.sleep(10000);
+ // }
+ // firstRun = false;
+ // } catch (InterruptedException e) {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ // if (agent != null) {
+ // agent.update();
+ // } else {
+ // break;
+ // }
+ // }
+ // System.out.println("thread end");
+ // }
+ // };
+ // t.start();
+
+ servicePublisherReg = factory.createAndRegisterProxy(IServicePublishEventDispatcher.class, "http://${localhost}/hessian/ServicePublisherWS", "hessian",
+ null, HOST_ID);
+
+ ProtocolNotifier protNotifier = new ProtocolNotifier();
+ context.addServiceListener(protNotifier, "(objectClass=" + IRemoteServiceFactory.ID + ")");
+
+ // ToDo Service Update Listener
+
+ discovery.update();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ discovery.stop();
+ registryInjector.dispose();
+ if (servicePublisherReg != null) {
+ servicePublisherReg.unregister();
+ }
+ discovery = null;
+ registryInjector = null;
+ servicePublisherReg = null;
+ }
+
+ class ProtocolNotifier implements ServiceListener {
+ public void serviceChanged(ServiceEvent event) {
+ if (event.getType() == ServiceEvent.REGISTERED) {
+ String protocol = (String) event.getServiceReference().getProperty(IRemoteServiceFactory.PROP_PROTOCOL);
+ discovery.checkForUnpublishedServices(protocol);
+ }
+ }
+
+ }
+}
diff --git a/org.eclipse.riena.communication.discovery/src/org/eclipse/riena/internal/communication/discovery/RemoteServiceDiscovery.java b/org.eclipse.riena.communication.discovery/src/org/eclipse/riena/internal/communication/discovery/RemoteServiceDiscovery.java
new file mode 100644
index 0000000..1749322
--- /dev/null
+++ b/org.eclipse.riena.communication.discovery/src/org/eclipse/riena/internal/communication/discovery/RemoteServiceDiscovery.java
@@ -0,0 +1,202 @@
+/*******************************************************************************
+ * 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.discovery;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+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.communication.core.RemoteServiceDescription;
+import org.eclipse.riena.communication.core.factory.RemoteServiceFactory;
+import org.eclipse.riena.communication.core.publisher.IServicePublishEventDispatcher;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+import com.caucho.hessian.client.HessianRuntimeException;
+
+/**
+ * @author Alexander Ziegler
+ *
+ */
+public class RemoteServiceDiscovery {
+ private static final String HOST_ID = RemoteServiceDiscovery.class.getName();
+ private static final RemoteServiceDescription[] EMPTY_SERVICE_ENTRY_ARRAY = new RemoteServiceDescription[0];
+ private IRemoteServiceRegistry registry;
+ private RemoteServiceFactory rsFactory;
+ private Map<String, RemoteServiceDescription> unpublishedServices = new HashMap<String, RemoteServiceDescription>();
+ private BundleContext context;
+
+ RemoteServiceDiscovery(BundleContext context) {
+ super();
+ this.context = context;
+ }
+
+ /**
+ * Returns all services this publisher has
+ *
+ * @return
+ */
+ private synchronized RemoteServiceDescription[] getAllServices() {
+ ServiceReference refPublisher = context.getServiceReference(IServicePublishEventDispatcher.ID);
+ if (refPublisher == null) {
+ System.out.println("Riena::RemoteServiceDiscovery:: WARN no IServicePublishEventDispatcher service available [" + IServicePublishEventDispatcher.ID
+ + "]");
+ return EMPTY_SERVICE_ENTRY_ARRAY;
+ }
+ IServicePublishEventDispatcher servicePublisher = (IServicePublishEventDispatcher) context.getService(refPublisher);
+ try {
+ RemoteServiceDescription[] rsDescriptions = servicePublisher.getAllServices();
+ if (rsDescriptions == null) {
+ return EMPTY_SERVICE_ENTRY_ARRAY;
+ }
+ return rsDescriptions;
+ } finally {
+ context.ungetService(refPublisher);
+ }
+ }
+
+ private synchronized void updateInRegistry(RemoteServiceDescription[] rsDescriptions) {
+ // get all services not just the service created with discovery
+ List<IRemoteServiceRegistration> registeredServices = registry.registeredServices(null);
+ Map<String, IRemoteServiceRegistration> existingPathsMap = new HashMap<String, IRemoteServiceRegistration>();
+ // copy array to Map
+ for (IRemoteServiceRegistration registeredService : registeredServices) {
+ String url = registeredService.getReference().getURL();
+ existingPathsMap.put(url, registeredService);
+ }
+
+ // newServices contains those that did not exist previously
+ List<RemoteServiceDescription> newServices = new ArrayList<RemoteServiceDescription>();
+ // remove those that still exist in the new list from the list of
+ // existing paths
+ for (RemoteServiceDescription rsDescription : rsDescriptions) {
+ if (existingPathsMap.get(rsDescription.getURL()) != null) {
+ existingPathsMap.remove(rsDescription.getURL());
+ } else {
+ newServices.add(rsDescription);
+ }
+ }
+
+ // all other paths are now longer in the current list rsDescriptions and
+ // have to be unpublished if they were created with my HOST_ID
+ for (IRemoteServiceRegistration serviceReg : existingPathsMap.values()) {
+ if (serviceReg.getReference().getHostId().equals(HOST_ID)) {
+ serviceReg.unregister();
+ }
+ }
+
+ // go through the newService Descriptions and create a new proxy for each of them
+ List<IRemoteServiceReference> rsReferences = new ArrayList<IRemoteServiceReference>();
+ for (RemoteServiceDescription rsDesc : newServices) {
+ Class<?> interfaceClass = loadClass(rsDesc);
+ rsDesc.setServiceInterfaceClass(interfaceClass);
+
+ System.out.println("creating service with uri=" + rsDesc.getURL());
+ IRemoteServiceReference rsRef = createReference(rsDesc);
+ if (rsRef != null) {
+ rsReferences.add(rsRef);
+ } else {
+ System.out.println("*****************");
+ addAsUnpublished(rsDesc);
+ }
+
+ }
+ for (IRemoteServiceReference rsRef : rsReferences) {
+ // publish the new remote service references in the registry
+ registry.registerService(rsRef);
+ }
+ }
+
+ private IRemoteServiceReference createReference(RemoteServiceDescription rsDesc) {
+ IRemoteServiceReference rsRef = rsFactory.createProxy(rsDesc);
+ rsRef.setHostId(HOST_ID);
+ return rsRef;
+ }
+
+ private void addAsUnpublished(RemoteServiceDescription rsDesc) {
+ unpublishedServices.put(rsDesc.getURL(), rsDesc);
+ }
+
+ protected void checkForUnpublishedServices(String protocol) {
+ Set<Entry<String, RemoteServiceDescription>> set = unpublishedServices.entrySet();
+ for (Map.Entry<String, RemoteServiceDescription> entry : set) {
+ RemoteServiceDescription rsDesc = entry.getValue();
+ if (rsDesc.getProtocol().equals(protocol)) {
+ IRemoteServiceReference rsRef = createReference(rsDesc);
+
+ if (rsRef != null) {
+ registry.registerService(rsRef);
+ set.remove(entry); // also removes the entry from the map
+ }
+ }
+ }
+
+ }
+
+ private Class<?> loadClass(RemoteServiceDescription endpoint) {
+ if (endpoint.getServiceInterfaceClass() != null) {
+ // Maybe the interface was transfered from server
+ return endpoint.getServiceInterfaceClass();
+ }
+ String interfaceClassName = endpoint.getServiceInterfaceClassName();
+
+ try {
+ // Class loading: Maybe the host bundle of the interface is a buddy
+ // friend of the service registry
+ return new RemoteServiceFactory().loadClass(interfaceClassName);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException("Riena:Communication::RemoteServiceDiscovery:: ERROR could not create web service interface for [" + interfaceClassName + "]", e);
+ }
+ }
+
+ public void setRemoteServiceRegistry(IRemoteServiceRegistry registry) {
+ this.registry = registry;
+
+ }
+
+ void start() {
+ update();
+ }
+
+ void update() {
+ if (registry != null) {
+ try {
+ RemoteServiceDescription[] serviceDescriptions = getAllServices();
+ if (serviceDescriptions.length > 0) {
+ updateInRegistry(serviceDescriptions);
+ }
+ } catch (HessianRuntimeException ex) {
+ System.out.println("System::Riena:Communication::update of services from server failed. " + ex.getLocalizedMessage());
+ }
+ }
+ }
+
+ void stop() {
+ if (registry != null) {
+ // unregister all services I registered
+ List<IRemoteServiceRegistration> registeredServices = registry.registeredServices(HOST_ID);
+ for (IRemoteServiceRegistration rsReg : registeredServices) {
+ rsReg.unregister();
+ }
+ }
+ }
+
+ void setRemoteServiceFactory(RemoteServiceFactory remoteServiceFactory) {
+ this.rsFactory = remoteServiceFactory;
+ }
+}