summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Campo2008-01-17 08:21:41 (EST)
committerChristian Campo2008-01-17 08:21:41 (EST)
commita458efa1e7d92b22abf48de635ab899ac2a6f9f5 (patch)
tree3ad22dff5ef714319babf24e0f6fa562a9ac249b
parentfa21ccdda10e2e061351ad285093d65f259b944f (diff)
downloadorg.eclipse.riena-a458efa1e7d92b22abf48de635ab899ac2a6f9f5.zip
org.eclipse.riena-a458efa1e7d92b22abf48de635ab899ac2a6f9f5.tar.gz
org.eclipse.riena-a458efa1e7d92b22abf48de635ab899ac2a6f9f5.tar.bz2
initial checkin
-rw-r--r--org.eclipse.riena.communication.publisher/.classpath7
-rw-r--r--org.eclipse.riena.communication.publisher/.project28
-rw-r--r--org.eclipse.riena.communication.publisher/.settings/org.eclipse.pde.core.prefs3
-rw-r--r--org.eclipse.riena.communication.publisher/META-INF/MANIFEST.MF9
-rw-r--r--org.eclipse.riena.communication.publisher/about.html24
-rw-r--r--org.eclipse.riena.communication.publisher/build.properties4
-rw-r--r--org.eclipse.riena.communication.publisher/src/org/eclipse/riena/internal/communication/publisher/Activator.java129
-rw-r--r--org.eclipse.riena.communication.publisher/src/org/eclipse/riena/internal/communication/publisher/ServiceHooksProxy.java101
-rw-r--r--org.eclipse.riena.communication.publisher/src/org/eclipse/riena/internal/communication/publisher/ServicePublishEventDispatcher.java226
9 files changed, 531 insertions, 0 deletions
diff --git a/org.eclipse.riena.communication.publisher/.classpath b/org.eclipse.riena.communication.publisher/.classpath
new file mode 100644
index 0000000..751c8f2
--- /dev/null
+++ b/org.eclipse.riena.communication.publisher/.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.publisher/.project b/org.eclipse.riena.communication.publisher/.project
new file mode 100644
index 0000000..723edea
--- /dev/null
+++ b/org.eclipse.riena.communication.publisher/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.riena.communication.publisher</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.publisher/.settings/org.eclipse.pde.core.prefs b/org.eclipse.riena.communication.publisher/.settings/org.eclipse.pde.core.prefs
new file mode 100644
index 0000000..cedd448
--- /dev/null
+++ b/org.eclipse.riena.communication.publisher/.settings/org.eclipse.pde.core.prefs
@@ -0,0 +1,3 @@
+#Mon Mar 26 17:25:47 CEST 2007
+eclipse.preferences.version=1
+pluginProject.extensions=false
diff --git a/org.eclipse.riena.communication.publisher/META-INF/MANIFEST.MF b/org.eclipse.riena.communication.publisher/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..7c2631b
--- /dev/null
+++ b/org.eclipse.riena.communication.publisher/META-INF/MANIFEST.MF
@@ -0,0 +1,9 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Riena Communication Publisher (Incubation)
+Bundle-SymbolicName: org.eclipse.riena.communication.publisher
+Bundle-Version: 0.0.1
+Require-Bundle: org.eclipse.riena.communication.core,
+ org.eclipse.riena.core
+Import-Package: org.osgi.framework;version="1.4.0"
+Bundle-Activator: org.eclipse.riena.internal.communication.publisher.Activator
diff --git a/org.eclipse.riena.communication.publisher/about.html b/org.eclipse.riena.communication.publisher/about.html
new file mode 100644
index 0000000..fc81119
--- /dev/null
+++ b/org.eclipse.riena.communication.publisher/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.publisher/build.properties b/org.eclipse.riena.communication.publisher/build.properties
new file mode 100644
index 0000000..34d2e4d
--- /dev/null
+++ b/org.eclipse.riena.communication.publisher/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/org.eclipse.riena.communication.publisher/src/org/eclipse/riena/internal/communication/publisher/Activator.java b/org.eclipse.riena.communication.publisher/src/org/eclipse/riena/internal/communication/publisher/Activator.java
new file mode 100644
index 0000000..162326e
--- /dev/null
+++ b/org.eclipse.riena.communication.publisher/src/org/eclipse/riena/internal/communication/publisher/Activator.java
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * 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.publisher;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.riena.communication.core.hooks.IServiceHook;
+import org.eclipse.riena.communication.core.hooks.ServiceContext;
+import org.eclipse.riena.communication.core.publisher.IServicePublishEventDispatcher;
+import org.eclipse.riena.communication.core.publisher.IServicePublisher;
+import org.eclipse.riena.communication.core.publisher.RSDPublisherProperties;
+import org.eclipse.riena.communication.core.util.CommunicationUtil;
+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;
+import org.osgi.framework.ServiceReference;
+
+
+public class Activator implements BundleActivator {
+
+ private ServicePublishEventDispatcher dispachter;
+ private ServiceInjector publisherInjector;
+ private UpdateNotifierRemoteService updateNotifierRemoteService;
+ private static BundleContext context;
+
+ /*
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ Activator.context = context;
+
+ dispachter = new ServicePublishEventDispatcher(context);
+ publisherInjector = new ServiceInjector(context, IServicePublisher.ID, dispachter, "addServicePublisher", "removeServicePublisher");
+ publisherInjector.start();
+
+ // register as OSGi service, the start will pick up the OSGi service and
+ // publish it
+ Dictionary<String, Object> properties = new Hashtable<String, Object>(3);
+ properties.put(RSDPublisherProperties.PROP_IS_REMOTE, "true");
+ properties.put(RSDPublisherProperties.PROP_REMOTE_PROTOCOL, "hessian");
+ properties.put(RSDPublisherProperties.PROP_REMOTE_PATH, "/ServicePublisherWS");
+
+ context.registerService(IServicePublishEventDispatcher.ID, dispachter, properties);
+
+ dispachter.start();
+
+ // register UpdateNotified so all services trigger the
+ // servicePublishEventDispatcher
+ updateNotifierRemoteService = new UpdateNotifierRemoteService(dispachter);
+ context.addServiceListener(updateNotifierRemoteService);
+ context.registerService(IServiceHook.ID, new IServiceHook() {
+
+ public void afterService(ServiceContext context) {
+ System.out.println("after service (in hook)");
+ context.getMessageContext().addResponseHeader("Set-Cookie", "x-scpserver-test-sessionid=11");
+ }
+
+ public void beforeService(ServiceContext context) {
+ System.out.println("before service (in hook)");
+ Map<String, List<String>> headers = context.getMessageContext().listRequestHeaders();
+ for (String hName : headers.keySet()) {
+ StringBuffer sb = new StringBuffer();
+ for (String hValue : headers.get(hName)) {
+ sb.append(hValue + ", ");
+ }
+ System.out.println("header: name:" + hName + " value:" + sb);
+ }
+ }
+ }, null);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ context.removeServiceListener(updateNotifierRemoteService);
+ dispachter.stop();
+ dispachter = null;
+ publisherInjector.dispose();
+ publisherInjector = null;
+ updateNotifierRemoteService = null;
+ Activator.context = null;
+ }
+
+ public static BundleContext getContext() {
+ return context;
+ }
+
+ class UpdateNotifierRemoteService implements ServiceListener {
+ ServicePublishEventDispatcher dispatcher;
+
+ UpdateNotifierRemoteService(ServicePublishEventDispatcher dispatcher) {
+ this.dispatcher = dispatcher;
+ }
+
+ public void serviceChanged(ServiceEvent event) {
+ ServiceReference serviceRef = event.getServiceReference();
+
+ // check if we are getting the event for a new remote service
+ String isRemote = CommunicationUtil.accessProperty(serviceRef.getProperty(RSDPublisherProperties.PROP_IS_REMOTE), null);
+ String remoteType = CommunicationUtil.accessProperty(serviceRef.getProperty(RSDPublisherProperties.PROP_REMOTE_PROTOCOL), null);
+ if (remoteType == null || remoteType.length() == 0) {
+ return;
+ }
+ if ("true".equals(isRemote)) {
+ if (event.getType() == ServiceEvent.UNREGISTERING) {
+ dispatcher.unpublish(event.getServiceReference());
+ } else if (event.getType() == ServiceEvent.REGISTERED) {
+ dispatcher.publish(event.getServiceReference());
+ }
+ }
+ }
+ }
+}
diff --git a/org.eclipse.riena.communication.publisher/src/org/eclipse/riena/internal/communication/publisher/ServiceHooksProxy.java b/org.eclipse.riena.communication.publisher/src/org/eclipse/riena/internal/communication/publisher/ServiceHooksProxy.java
new file mode 100644
index 0000000..50ed4a5
--- /dev/null
+++ b/org.eclipse.riena.communication.publisher/src/org/eclipse/riena/internal/communication/publisher/ServiceHooksProxy.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * 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.publisher;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashSet;
+
+import javax.security.auth.Subject;
+
+import org.eclipse.riena.communication.core.RemoteServiceDescription;
+import org.eclipse.riena.communication.core.hooks.AbstractHooksProxy;
+import org.eclipse.riena.communication.core.hooks.IServiceHook;
+import org.eclipse.riena.communication.core.hooks.IServiceMessageContext;
+import org.eclipse.riena.communication.core.hooks.IServiceMessageContextAccessor;
+import org.eclipse.riena.communication.core.hooks.ServiceContext;
+import org.eclipse.riena.core.service.ServiceInjector;
+
+public class ServiceHooksProxy extends AbstractHooksProxy implements InvocationHandler {
+
+ private HashSet<IServiceHook> serviceHooks = new HashSet<IServiceHook>();
+ private ServiceInjector si;
+ private RemoteServiceDescription rsd;
+ private IServiceMessageContextAccessor mca;
+ private Subject subject;
+
+ public ServiceHooksProxy(Object serviceInstance) {
+ super(serviceInstance);
+ si = new ServiceInjector(Activator.getContext(), IServiceHook.ID, this, "addServiceHook", "removeServiceHook");
+ si.start();
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ IServiceMessageContext mc = null;
+ if (mca != null) {
+ mc = mca.getMessageContext();
+ }
+
+ ServiceContext context = null;
+ // only create context (it might be expensive), if you have serviceHooks
+ if (serviceHooks.size() > 0) {
+ context = new ServiceContext(rsd, method.getName(), mc);
+
+ // call before service hook
+ for (IServiceHook sHook : serviceHooks) {
+ sHook.beforeService(context);
+ }
+ }
+
+ try {
+ Object s = context.getProperty("riena.subject");
+ if (s != null && s instanceof Subject) {
+ subject = (Subject) s;
+ }
+ return super.invoke(proxy, method, args);
+ } catch (InvocationTargetException e) {
+ throw e.getTargetException();
+ } finally {
+ // context might be null, but serviceHooks were injected during
+ // invoke
+ if (context != null) {
+ for (IServiceHook sHook : serviceHooks) {
+ sHook.afterService(context);
+ }
+ }
+ }
+ }
+
+ public void addServiceHook(IServiceHook serviceHook) {
+ serviceHooks.add(serviceHook);
+ }
+
+ public void removeServiceHook(IServiceHook serviceHook) {
+ serviceHooks.remove(serviceHook);
+ }
+
+ public Object getServiceInstance() {
+ return getProxiedInstance();
+ }
+
+ public void setRemoteServiceDescription(RemoteServiceDescription rsd) {
+ this.rsd = rsd;
+ }
+
+ public void setMessageContextAccessor(IServiceMessageContextAccessor mca) {
+ this.mca = mca;
+ }
+
+ public Subject getSubject() {
+ return subject;
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.riena.communication.publisher/src/org/eclipse/riena/internal/communication/publisher/ServicePublishEventDispatcher.java b/org.eclipse.riena.communication.publisher/src/org/eclipse/riena/internal/communication/publisher/ServicePublishEventDispatcher.java
new file mode 100644
index 0000000..9b233f6
--- /dev/null
+++ b/org.eclipse.riena.communication.publisher/src/org/eclipse/riena/internal/communication/publisher/ServicePublishEventDispatcher.java
@@ -0,0 +1,226 @@
+/*******************************************************************************
+ * 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.publisher;
+
+import static org.eclipse.riena.communication.core.publisher.RSDPublisherProperties.PROP_IS_REMOTE;
+import static org.eclipse.riena.communication.core.publisher.RSDPublisherProperties.PROP_REMOTE_PATH;
+import static org.eclipse.riena.communication.core.publisher.RSDPublisherProperties.PROP_REMOTE_PROTOCOL;
+
+import java.lang.reflect.Proxy;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.riena.communication.core.RemoteServiceDescription;
+import org.eclipse.riena.communication.core.publisher.IServicePublishEventDispatcher;
+import org.eclipse.riena.communication.core.publisher.IServicePublisher;
+import org.eclipse.riena.communication.core.publisher.RSDPublisherProperties;
+import org.eclipse.riena.communication.core.util.CommunicationUtil;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+/**
+ *
+ * @author Alexander Ziegler
+ * @author Christian Campo
+ *
+ */
+public class ServicePublishEventDispatcher implements IServicePublishEventDispatcher {
+
+ public static final String FILTER_REMOTE = "(&(" + PROP_IS_REMOTE + "=true)(" + PROP_REMOTE_PROTOCOL + "=*)" + ")";
+
+ private Map<String, RemoteServiceDescription> rsDescs;
+ private Map<String, IServicePublisher> servicePublishers;
+
+ private BundleContext context;
+
+ public ServicePublishEventDispatcher(BundleContext context) {
+ super();
+ this.context = context;
+ rsDescs = new HashMap<String, RemoteServiceDescription>();
+ servicePublishers = new HashMap<String, IServicePublisher>(3);
+ }
+
+ public void start() {
+ update();
+ }
+
+ protected synchronized void update() {
+ ServiceReference[] serviceReferences = null;
+ try {
+ serviceReferences = context.getAllServiceReferences(null, FILTER_REMOTE);
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace();
+ }
+ if (serviceReferences != null) {
+
+ for (ServiceReference serviceReference : serviceReferences) {
+ if (!isPublished(serviceReference)) {
+ publish(serviceReference);
+ }
+ }
+ }
+ }
+
+ private boolean isPublished(ServiceReference serviceRef) {
+ String remoteType = CommunicationUtil.accessProperty(serviceRef.getProperty(RSDPublisherProperties.PROP_REMOTE_PROTOCOL), null);
+ String path = CommunicationUtil.accessProperty(serviceRef.getProperty(PROP_REMOTE_PATH), null);
+ RemoteServiceDescription rsDesc = rsDescs.get(remoteType + "::" + path);
+ if (rsDesc == null) {
+ return false;
+ }
+ return rsDesc.getType() == RemoteServiceDescription.STATUS_REGISTERED;
+ }
+
+ public void addServicePublisher(IServicePublisher publisher) {
+ servicePublishers.put(publisher.getProtocol(), publisher);
+ System.out.println("Riena::UpdatServicePublishEventDispatcher: DEBUG servicePublish=" + publisher.getProtocol()
+ + " REGISTER...publishing all services that were waiting for him");
+ // check for services which are missing a publisher
+
+ update();
+ }
+
+ public void removeServicePublisher(IServicePublisher publisher) {
+ String protocol = publisher.getProtocol();
+ System.out.println("Riena::ServicePublishEventDispatcher:: DEBUG servicePublish=" + publisher.getProtocol()
+ + " UNREGISTER...unpublishing all its services");
+ // unregister all web services for this type
+
+ for (RemoteServiceDescription rsDesc : rsDescs.values()) {
+ if (protocol.equals(rsDesc.getProtocol())) {
+ unpublish(rsDesc);
+ }
+ }
+ servicePublishers.remove(protocol);
+ }
+
+ protected void publish(ServiceReference serviceRef) {
+ if (servicePublishers.size() == 0) {
+ return;
+ }
+ synchronized (rsDescs) {
+ try {
+ Object service = context.getService(serviceRef);
+ ServiceHooksProxy handler = new ServiceHooksProxy(service);
+ // create remote service description
+ String[] interfaces = (String[]) serviceRef.getProperty("objectClass");
+ assert interfaces.length == 1 : "OSGi only with one interface supported";
+ String interfaceName = interfaces[0];
+ Class interfaceClazz = serviceRef.getBundle().loadClass(interfaceName);
+ service = Proxy.newProxyInstance(interfaceClazz.getClassLoader(), new Class[] { interfaceClazz }, handler);
+ RemoteServiceDescription rsDesc = new RemoteServiceDescription(serviceRef, service, interfaceClazz);
+ handler.setRemoteServiceDescription(rsDesc);
+ RemoteServiceDescription rsDescFound = rsDescs.get(rsDesc.getProtocol() + "::" + rsDesc.getPath());
+ if (rsDescFound != null && rsDescFound.getType() == RemoteServiceDescription.STATUS_REGISTERED) {
+ System.out.println("Riena::ServicePublishEventDispatcher:: WARN: A service endpoint with path=[" + rsDesc.getPath() + "] and remoteType=["
+ + rsDesc.getProtocol() + "] already published... ignored");
+ return;
+ }
+
+ if (rsDescFound == null) {
+ if (rsDesc.getPath() == null) {
+ System.out.println("Riena::ServicePublishEventDispatcher:: WARN: no path for service: " + service.toString()
+ + " Service not published remote");
+ return;
+ }
+ if (!servicePublishers.containsKey(rsDesc.getProtocol())) {
+ System.out.println("Riena::ServicePublishEventDispatcher:: DEBUG: no publisher found for protocol " + rsDesc.getProtocol());
+ return;
+ }
+ rsDescs.put(rsDesc.getProtocol() + "::" + rsDesc.getPath(), rsDesc);
+ System.out.println("Riena::ServicePublishEventDispatcher:: DEBUG: service endpoints count: " + rsDescs.size());
+
+ } else if (rsDescFound.getType() == RemoteServiceDescription.STATUS_UNREGISTERED) {
+ rsDesc = rsDescFound;
+ }
+
+ publish(rsDesc, handler);
+ } catch (ClassNotFoundException e) {
+ System.out.println(e);
+ }
+ }
+
+ }
+
+ private void publish(RemoteServiceDescription rsDesc, ServiceHooksProxy handler) {
+ IServicePublisher publisher = servicePublishers.get(rsDesc.getProtocol());
+ if (publisher == null) {
+ return;
+ }
+ String url = publisher.publishService(rsDesc);
+ // set full URL under which the service is available
+ rsDesc.setURL(url);
+ handler.setMessageContextAccessor(publisher.getMessageContextAccessor());
+
+ rsDesc.setType(RemoteServiceDescription.STATUS_REGISTERED);
+
+ }
+
+ // @remote
+ public RemoteServiceDescription[] getAllServices() {
+ RemoteServiceDescription[] result = new RemoteServiceDescription[rsDescs.size()];
+ synchronized (rsDescs) {
+ rsDescs.values().toArray(result);
+ }
+ return result;
+ }
+
+ protected void unpublish(ServiceReference serviceRef) {
+ synchronized (rsDescs) {
+ try {
+
+ String path = CommunicationUtil.accessProperty(serviceRef.getProperty(PROP_REMOTE_PATH), null);
+ String remoteType = CommunicationUtil.accessProperty(serviceRef.getProperty(PROP_REMOTE_PROTOCOL), null);
+ RemoteServiceDescription toRemove = null;
+ for (RemoteServiceDescription rsDesc : rsDescs.values()) {
+ if (rsDesc.getPath().equals(path) && rsDesc.getProtocol().equals(remoteType)) {
+ toRemove = rsDesc;
+ break;
+ }
+ }
+ if (toRemove != null) {
+ rsDescs.remove(remoteType + "::" + path);
+ if (servicePublishers.containsKey(toRemove.getProtocol())) {
+ unpublish(toRemove);
+ }
+ // TODO notify all discovery services about this
+ }
+ } finally {
+ context.ungetService(serviceRef);
+ }
+ System.out.println("Riena::ServicePublisherHessian:: DEBUG: service endpoints count: " + rsDescs.size());
+ }
+ }
+
+ private void unpublish(RemoteServiceDescription rsDesc) {
+ IServicePublisher publisher = servicePublishers.get(rsDesc.getProtocol());
+ if (publisher == null) {
+ return;
+ }
+
+ publisher.unpublishService(rsDesc.getPath());
+
+ rsDesc.setType(RemoteServiceDescription.STATUS_UNREGISTERED);
+ }
+
+ public void stop() {
+ synchronized (rsDescs) {
+ for (RemoteServiceDescription rsDesc : rsDescs.values()) {
+ if (servicePublishers.containsKey(rsDesc.getProtocol())) {
+ unpublish(rsDesc);
+ }
+ rsDesc.dispose();
+ }
+ rsDescs.clear();
+ }
+ }
+}