Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis@composent.com2010-10-19 20:19:53 +0000
committerslewis@composent.com2010-10-19 20:19:53 +0000
commit5ca18be58259810472aa3741b2e411b55f3a45a1 (patch)
tree4aa03342854be1abc10f2a4c7888a753b66f66af /providers
parentc2db36986539d6d39bf96398d58f635e488fb059 (diff)
downloadorg.eclipse.ecf-5ca18be58259810472aa3741b2e411b55f3a45a1.tar.gz
org.eclipse.ecf-5ca18be58259810472aa3741b2e411b55f3a45a1.tar.xz
org.eclipse.ecf-5ca18be58259810472aa3741b2e411b55f3a45a1.zip
Fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=327919
Diffstat (limited to 'providers')
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RegistrySharedObject.java729
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceRegistrationImpl.java3
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceRegistryImpl.java13
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp.remoteservice/src/org/eclipse/ecf/internal/provider/xmpp/XMPPRemoteServiceAdapterFactory.java44
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/XMPPContainer.java20
5 files changed, 505 insertions, 304 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RegistrySharedObject.java b/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RegistrySharedObject.java
index 3e814bff9..dfdd989ef 100644
--- a/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RegistrySharedObject.java
+++ b/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RegistrySharedObject.java
@@ -14,7 +14,6 @@ import java.lang.reflect.InvocationTargetException;
import java.security.*;
import java.util.*;
import org.eclipse.core.runtime.*;
-import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.ecf.core.ContainerConnectException;
import org.eclipse.ecf.core.events.*;
import org.eclipse.ecf.core.identity.*;
@@ -35,7 +34,17 @@ import org.osgi.framework.*;
public class RegistrySharedObject extends BaseSharedObject implements IRemoteServiceContainerAdapter {
- private static final boolean DEBUG = false;
+ /**
+ * @since 3.3
+ */
+ protected static final int ADD_REGISTRATION_REQUEST_TIMEOUT = new Integer(System.getProperty("org.eclipse.ecf.provider.remoteservice.addRegistrationRequestTimeout", "7000")).intValue(); //$NON-NLS-1$ //$NON-NLS-2$
+
+ private static int uniqueRequestId = 0;
+
+ private static Integer createNextRequestId() {
+ return new Integer(uniqueRequestId++);
+ }
+
/**
* registry impl for local remote service registrations
*/
@@ -103,11 +112,24 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
*/
private EventManager rsListenerDispatchEventManager;
+ /**
+ * @since 3.4
+ */
+ protected long registryUpdateRequestTimeout = new Long(System.getProperty("org.eclipse.ecf.provider.remoteservice.registryUpdateRequestTimeout", "5000")).longValue(); //$NON-NLS-1$ //$NON-NLS-2$
+
+ private Hashtable pendingUpdateContainers = new Hashtable();
+ private List registryUpdateRequests = new ArrayList();
+
+ // system property allowing the executorType to be configured. Currently types are: jobs, threads, immediate.
+ private static final String DEFAULT_EXECUTOR_TYPE = System.getProperty("org.eclipse.ecf.provider.remoteservice.executorType", "jobs"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ private IExecutor requestExecutor;
+
public RegistrySharedObject() {
//
}
- // Get remote service references methods
+ // IRemoteServiceContainerAdapter methods
/**
* @since 3.4
*/
@@ -118,7 +140,7 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
if (target != null)
connectToRemoteServiceTarget(target);
// Wait for any pending remote registry updates...whether we've connected or not
- waitForPendingUpdates(idFilter, getAddRegistrationRequestTimeout());
+ waitForPendingUpdates(idFilter);
// Now we lookup remote service references
final List references = new ArrayList();
// first from remote registrys
@@ -160,43 +182,6 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
return (result.length == 0) ? null : result;
}
- /**
- * @since 3.3
- */
- protected int getRSConnectTimeout() {
- return rsConnectTimeout;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ecf.core.sharedobject.BaseSharedObject#dispose(org.eclipse.ecf.core.identity.ID)
- */
- public void dispose(ID containerID) {
- super.dispose(containerID);
- unregisterAllServiceRegistrations();
- synchronized (remoteRegistrys) {
- remoteRegistrys.clear();
- localServiceRegistrations.clear();
- }
- synchronized (serviceListeners) {
- serviceListeners.clear();
- }
- synchronized (addRegistrationRequests) {
- addRegistrationRequests.clear();
- }
- synchronized (requests) {
- requests.clear();
- }
- synchronized (pendingUpdateContainers) {
- pendingUpdateContainers.clear();
- }
- synchronized (rsQueueLock) {
- if (rsListenerDispatchEventManager != null) {
- rsListenerDispatchEventManager.close();
- rsListenerDispatchEventManager = null;
- }
- }
- }
-
/* Begin implementation of IRemoteServiceContainerAdapter public interface */
/* (non-Javadoc)
* @see org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter#addRemoteServiceListener(org.eclipse.ecf.remoteservice.IRemoteServiceListener)
@@ -229,96 +214,6 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
return remoteService;
}
- private void addReferencesFromRemoteRegistrys(ID[] idFilter, String clazz, IRemoteFilter remoteFilter, List referencesFound) {
- synchronized (remoteRegistrys) {
- if (idFilter == null) {
- final ArrayList registrys = new ArrayList(remoteRegistrys.values());
- for (final Iterator i = registrys.iterator(); i.hasNext();) {
- final RemoteServiceRegistryImpl registry = (RemoteServiceRegistryImpl) i.next();
- // Add IRemoteServiceReferences from each remote registry
- addReferencesFromRegistry(clazz, remoteFilter, registry, referencesFound);
- }
- } else {
- for (int i = 0; i < idFilter.length; i++) {
- final RemoteServiceRegistryImpl registry = (RemoteServiceRegistryImpl) remoteRegistrys.get(idFilter[i]);
- if (registry != null) {
- addReferencesFromRegistry(clazz, remoteFilter, registry, referencesFound);
- }
- }
- }
- }
- }
-
- private void addReferencesFromLocalRegistry(ID[] idFilter, String clazz, IRemoteFilter remoteFilter, List referencesFound) {
- ID localContainerID = getLocalContainerID();
- if (idFilter == null || Arrays.asList(idFilter).contains(localContainerID)) {
- synchronized (localRegistry) {
- // Add any from local registry
- addReferencesFromRegistry(clazz, remoteFilter, localRegistry, referencesFound);
- }
- }
- }
-
- /**
- * @since 3.0
- */
- protected int getAddRegistrationRequestTimeout() {
- return addRegistrationRequestTimeout;
- }
-
- /**
- * @since 3.3 for preventing issues like bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=304427
- */
- protected void connectToRemoteServiceTarget(ID targetID) throws ContainerConnectException {
- ISharedObjectContext context = getContext();
- ID connectedID = context.getConnectedID();
- // If we're already connected to something then we don't need to connect...and we return
- if (connectedID != null)
- return;
-
- synchronized (rsConnectLock) {
- // we just try to connect to target with our given connectContext
- context.connect(targetID, connectContext);
- // wait to receive connected event
- // Wait until we receive the IContainerConnectedEvent on the shared object thread
- long startTime = System.currentTimeMillis();
- int rsTimeout = getRSConnectTimeout();
- long endTime = startTime + rsTimeout;
- while (!rsConnected && (endTime >= System.currentTimeMillis())) {
- try {
- rsConnectLock.wait(rsTimeout / 10);
- } catch (InterruptedException e) {
- throw new ContainerConnectException("No notification of registry connect complete for connect targetID=" + targetID); //$NON-NLS-1$
- }
- }
- if (!rsConnected)
- throw new ContainerConnectException("Could not complete registry connect for targetID=" + targetID); //$NON-NLS-1$
- }
- }
-
- protected Serializable getAddRegistrationRequestCredentials(AddRegistrationRequest request) {
- return null;
- }
-
- protected ID[] getTargetsFromProperties(Dictionary properties) {
- if (properties == null)
- return null;
- List results = new ArrayList();
- Object o = properties.get(Constants.SERVICE_REGISTRATION_TARGETS);
- if (o != null) {
- if (o instanceof ID)
- results.add(o);
- if (o instanceof ID[]) {
- ID[] targets = (ID[]) o;
- for (int i = 0; i < targets.length; i++)
- results.add(targets[i]);
- }
- }
- if (results.size() == 0)
- return null;
- return (ID[]) results.toArray(new ID[] {});
- }
-
/* (non-Javadoc)
* @see org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter#registerRemoteService(java.lang.String[], java.lang.Object, java.util.Dictionary)
*/
@@ -343,7 +238,7 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
if (invalidService != null) {
throw new IllegalArgumentException("Service=" + invalidService + " is invalid"); //$NON-NLS-1$ //$NON-NLS-2$
}
-
+ // Add to local registry
final RemoteServiceRegistrationImpl reg = new RemoteServiceRegistrationImpl();
reg.publish(this, localRegistry, service, clazzes, properties);
@@ -367,6 +262,8 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
* @see org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter#ungetRemoteService(org.eclipse.ecf.remoteservice.IRemoteServiceReference)
*/
public boolean ungetRemoteService(IRemoteServiceReference ref) {
+ if (ref == null)
+ return false;
IRemoteServiceID serviceID = ref.getID();
if (serviceID == null)
return false;
@@ -377,18 +274,127 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
}
synchronized (remoteRegistrys) {
final RemoteServiceRegistryImpl registry = (RemoteServiceRegistryImpl) remoteRegistrys.get(serviceID.getContainerID());
- if (registry != null) {
+ if (registry != null)
return true;
- }
}
return false;
}
- protected ISharedObjectContext getSOContext() {
- return super.getContext();
+ /**
+ * @since 3.0
+ */
+ public IFuture asyncGetRemoteServiceReferences(final ID[] idFilter, final String clazz, final String filter) {
+ IExecutor executor = new JobsExecutor("asyncGetRemoteServiceReferences"); //$NON-NLS-1$
+ return executor.execute(new IProgressRunnable() {
+ public Object run(IProgressMonitor monitor) throws Exception {
+ return getRemoteServiceReferences(idFilter, clazz, filter);
+ }
+ }, null);
+ }
+
+ /**
+ * @since 3.4
+ */
+ public IFuture asyncGetRemoteServiceReferences(final ID target, final ID[] idFilter, final String clazz, final String filter) {
+ IExecutor executor = new JobsExecutor("asyncGetRemoteServiceReferences"); //$NON-NLS-1$
+ return executor.execute(new IProgressRunnable() {
+ public Object run(IProgressMonitor monitor) throws Exception {
+ return getRemoteServiceReferences(target, idFilter, clazz, filter);
+ }
+ }, null);
+ }
+
+ /**
+ * @since 3.0
+ */
+ public IFuture asyncGetRemoteServiceReferences(final ID target, final String clazz, final String filter) {
+ IExecutor executor = new JobsExecutor("asyncGetRemoteServiceReferences"); //$NON-NLS-1$
+ return executor.execute(new IProgressRunnable() {
+ public Object run(IProgressMonitor monitor) throws Exception {
+ return getRemoteServiceReferences(target, clazz, filter);
+ }
+ }, null);
+ }
+
+ /**
+ * @since 3.0
+ */
+ public Namespace getRemoteServiceNamespace() {
+ return IDFactory.getDefault().getNamespaceByName(RemoteServiceNamespace.NAME);
}
- /* End implementation of IRemoteServiceContainerAdapter public interface */
+ /**
+ * @since 3.0
+ */
+ public IRemoteFilter createRemoteFilter(String filter) throws InvalidSyntaxException {
+ return new RemoteFilterImpl(filter);
+ }
+
+ /**
+ * @since 3.0
+ */
+ public IRemoteServiceReference getRemoteServiceReference(IRemoteServiceID serviceId) {
+ ID containerID = serviceId.getContainerID();
+ if (containerID == null)
+ return null;
+ RemoteServiceRegistrationImpl registration = null;
+ waitForPendingUpdates(new ID[] {containerID});
+ ID localContainerID = getLocalContainerID();
+ if (containerID.equals(localContainerID)) {
+ synchronized (localRegistry) {
+ registration = localRegistry.findRegistrationForServiceId(serviceId.getContainerRelativeID());
+ if (registration != null)
+ return registration.getReference();
+ }
+ } else {
+ synchronized (remoteRegistrys) {
+ final ArrayList registrys = new ArrayList(remoteRegistrys.values());
+ for (final Iterator i = registrys.iterator(); i.hasNext();) {
+ final RemoteServiceRegistryImpl registry = (RemoteServiceRegistryImpl) i.next();
+ registration = registry.findRegistrationForServiceId(serviceId.getContainerRelativeID());
+ }
+ }
+ }
+ return (registration == null) ? null : registration.getReference();
+ }
+
+ /**
+ * @since 3.0
+ */
+ public IRemoteServiceID getRemoteServiceID(ID containerId, long containerRelativeId) {
+ if (containerId == null)
+ return null;
+ ID localContainerID = getLocalContainerID();
+ if (containerId.equals(localContainerID)) {
+ synchronized (localRegistry) {
+ RemoteServiceRegistrationImpl reg = localRegistry.findRegistrationForServiceId(containerRelativeId);
+ if (reg != null)
+ return reg.getID();
+ }
+ } else {
+ synchronized (remoteRegistrys) {
+ final ArrayList registrys = new ArrayList(remoteRegistrys.values());
+ for (final Iterator i = registrys.iterator(); i.hasNext();) {
+ final RemoteServiceRegistryImpl registry = (RemoteServiceRegistryImpl) i.next();
+ RemoteServiceRegistrationImpl reg = registry.findRegistrationForServiceId(containerRelativeId);
+ if (reg != null)
+ return reg.getID();
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @since 3.0
+ */
+ public void setConnectContextForAuthentication(IConnectContext connectContext) {
+ this.connectContext = connectContext;
+ }
+
+ // End IRemoteServiceContainerAdapter methods
+
+ // ISharedObject overrides
/* (non-Javadoc)
* @see org.eclipse.ecf.core.sharedobject.BaseSharedObject#initialize()
@@ -396,7 +402,8 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
public void initialize() throws SharedObjectInitException {
super.initialize();
Trace.entering(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.METHODS_ENTERING, this.getClass(), "initialize"); //$NON-NLS-1$
- localRegistry = new RemoteServiceRegistryImpl(getLocalContainerID());
+ ID localContainerID = getLocalContainerID();
+ localRegistry = (localContainerID == null) ? new RemoteServiceRegistryImpl() : new RemoteServiceRegistryImpl(localContainerID);
super.addEventProcessor(new IEventProcessor() {
public boolean processEvent(Event arg0) {
if (arg0 instanceof IContainerConnectedEvent) {
@@ -416,17 +423,206 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
Trace.exiting(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.METHODS_EXITING, this.getClass(), "initialize"); //$NON-NLS-1$
}
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.core.sharedobject.BaseSharedObject#dispose(org.eclipse.ecf.core.identity.ID)
+ */
+ public void dispose(ID containerID) {
+ unregisterAllServiceRegistrations();
+
+ synchronized (rsQueueLock) {
+ if (rsListenerDispatchEventManager != null) {
+ rsListenerDispatchEventManager.close();
+ rsListenerDispatchEventManager = null;
+ rsListenerDispatchQueue = null;
+ }
+ }
+ synchronized (remoteRegistrys) {
+ remoteRegistrys.clear();
+ localServiceRegistrations.clear();
+ }
+ synchronized (serviceListeners) {
+ serviceListeners.clear();
+ }
+ synchronized (addRegistrationRequests) {
+ addRegistrationRequests.clear();
+ }
+ synchronized (requests) {
+ requests.clear();
+ }
+ synchronized (pendingUpdateContainers) {
+ pendingUpdateContainers.clear();
+ }
+ synchronized (registryUpdateRequests) {
+ registryUpdateRequests.clear();
+ }
+ super.dispose(containerID);
+ }
+
+ // End ISharedObject overrides
+ /**
+ * @since 3.3
+ */
+ protected int getRSConnectTimeout() {
+ return rsConnectTimeout;
+ }
+
+ /**
+ * @since 3.4
+ */
+ protected long getRegistryUpdateRequestTimeout() {
+ return registryUpdateRequestTimeout;
+ }
+
+ private void sendRegistryUpdateRequestAndWait(ID targetContainerID) {
+ synchronized (registryUpdateRequests) {
+ // create request id
+ Integer requestId = createNextRequestId();
+ // add it to the registryUpdateRequests list
+ registryUpdateRequests.add(requestId);
+ // send registry update request message to targetContainerID
+ sendRegistryUpdateRequest(targetContainerID, requestId);
+ // Get timeout
+ long timeOut = System.currentTimeMillis() + getRegistryUpdateRequestTimeout();
+ while ((timeOut - System.currentTimeMillis()) >= 0) {
+ if (!registryUpdateRequests.contains(requestId)) {
+ Trace.trace(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.DEBUG, this.getClass(), "sendRegistryUpdateRequestAndWait", "localContainerID=" + getLocalContainerID() + " returning because response received"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ return;
+ }
+ try {
+ registryUpdateRequests.wait(500);
+ } catch (InterruptedException e) {
+ return;
+ }
+ }
+ Trace.trace(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.DEBUG, this.getClass(), "sendRegistryUpdateRequestAndWait", "localContainerID=" + getLocalContainerID() + " returning because of timeout"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ }
+
+ private void addReferencesFromRemoteRegistrys(ID[] idFilter, String clazz, IRemoteFilter remoteFilter, List referencesFound) {
+ // If no idFilter, then we add all known references from all remote registrys
+ if (idFilter == null) {
+ synchronized (remoteRegistrys) {
+ final ArrayList registrys = new ArrayList(remoteRegistrys.values());
+ for (final Iterator i = registrys.iterator(); i.hasNext();) {
+ final RemoteServiceRegistryImpl registry = (RemoteServiceRegistryImpl) i.next();
+ // Add IRemoteServiceReferences from each remote registry
+ addReferencesFromRegistry(clazz, remoteFilter, registry, referencesFound);
+ }
+ }
+ // Otherwise there is a filter
+ } else {
+ for (int i = 0; i < idFilter.length; i++) {
+ ID targetContainerID = idFilter[i];
+ // Skip if the targetContainerID is null
+ if (targetContainerID == null)
+ continue;
+ RemoteServiceRegistryImpl remoteRegistryForContainer = null;
+ // No change to the registrys while we look for the appropriate registry
+ synchronized (remoteRegistrys) {
+ remoteRegistryForContainer = (RemoteServiceRegistryImpl) remoteRegistrys.get(targetContainerID);
+ // If one is found, then we simply add any entrys to referencesFound and we're done
+ // for that container
+ if (remoteRegistryForContainer != null) {
+ addReferencesFromRegistry(clazz, remoteFilter, remoteRegistryForContainer, referencesFound);
+ continue;
+ }
+ }
+ // This block is only reached if remoteRegistryForContainer is null
+ sendRegistryUpdateRequestAndWait(targetContainerID);
+ // Now we check remoteRegistrys again
+ synchronized (remoteRegistrys) {
+ remoteRegistryForContainer = (RemoteServiceRegistryImpl) remoteRegistrys.get(targetContainerID);
+ if (remoteRegistryForContainer != null)
+ addReferencesFromRegistry(clazz, remoteFilter, remoteRegistryForContainer, referencesFound);
+ }
+ }
+ }
+ }
+
+ private void addReferencesFromLocalRegistry(ID[] idFilter, String clazz, IRemoteFilter remoteFilter, List referencesFound) {
+ ID localContainerID = getLocalContainerID();
+ if (idFilter == null || Arrays.asList(idFilter).contains(localContainerID)) {
+ synchronized (localRegistry) {
+ // Add any from local registry
+ addReferencesFromRegistry(clazz, remoteFilter, localRegistry, referencesFound);
+ }
+ }
+ }
+
+ /**
+ * @since 3.0
+ */
+ protected int getAddRegistrationRequestTimeout() {
+ return addRegistrationRequestTimeout;
+ }
+
+ /**
+ * @since 3.3 for preventing issues like bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=304427
+ */
+ protected void connectToRemoteServiceTarget(ID targetID) throws ContainerConnectException {
+ ISharedObjectContext context = getContext();
+ ID connectedID = context.getConnectedID();
+ // If we're already connected to something then we don't need to connect...and we return
+ if (connectedID != null)
+ return;
+
+ synchronized (rsConnectLock) {
+ // we just try to connect to target with our given connectContext
+ context.connect(targetID, connectContext);
+ // wait to receive connected event
+ // Wait until we receive the IContainerConnectedEvent on the shared object thread
+ int rsTimeout = getRSConnectTimeout();
+ long endTime = System.currentTimeMillis() + rsTimeout;
+ while (!rsConnected && (endTime >= System.currentTimeMillis())) {
+ try {
+ // wait for asynchronous notification of getting connected
+ rsConnectLock.wait(rsTimeout / 10);
+ } catch (InterruptedException e) {
+ throw new ContainerConnectException("No notification of registry connect complete for connect targetID=" + targetID); //$NON-NLS-1$
+ }
+ }
+ if (!rsConnected)
+ throw new ContainerConnectException("Could not complete registry connect for targetID=" + targetID); //$NON-NLS-1$
+ }
+ }
+
+ protected Serializable getAddRegistrationRequestCredentials(AddRegistrationRequest request) {
+ return null;
+ }
+
+ protected ID[] getTargetsFromProperties(Dictionary properties) {
+ if (properties == null)
+ return null;
+ List results = new ArrayList();
+ Object o = properties.get(Constants.SERVICE_REGISTRATION_TARGETS);
+ if (o != null) {
+ if (o instanceof ID)
+ results.add(o);
+ if (o instanceof ID[]) {
+ ID[] targets = (ID[]) o;
+ for (int i = 0; i < targets.length; i++)
+ results.add(targets[i]);
+ }
+ }
+ if (results.size() == 0)
+ return null;
+ return (ID[]) results.toArray(new ID[] {});
+ }
+
+ protected ISharedObjectContext getSOContext() {
+ return super.getContext();
+ }
+
/**
* @since 3.4
*/
protected void handleRegistryActivatedEvent() {
+ Trace.entering(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.METHODS_ENTERING, this.getClass(), "handleRegistryActivatedEvent"); //$NON-NLS-1$
// Only do something with this if we're already connected
ID[] members = getGroupMemberIDs();
ID localContainerID = getLocalContainerID();
ID connectedID = getConnectedID();
- if (DEBUG) {
- System.out.println("handleRegistryActivatedEvent localContainerID=" + getLocalContainerID() + ",members=" + Arrays.asList(members)); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ Trace.trace(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.DEBUG, this.getClass(), "handleRegistryActivatedEvent", "localContainerID=" + getLocalContainerID() + ",members=" + Arrays.asList(members)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
// Only do this if we've already been connected
if (isConnected()) {
for (int i = 0; i < members.length; i++) {
@@ -452,6 +648,33 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
handleTargetGoneEvent(arg0.getTargetID());
}
+ /**
+ * @since 3.4
+ */
+ protected void clearRemoteRegistrys() {
+ List registrations = new ArrayList();
+ synchronized (remoteRegistrys) {
+ for (Iterator i = remoteRegistrys.keySet().iterator(); i.hasNext();) {
+ ID containerID = (ID) i.next();
+ RemoteServiceRegistryImpl registry = (RemoteServiceRegistryImpl) remoteRegistrys.get(containerID);
+ if (registry != null) {
+ removeRemoteRegistry(containerID);
+ RemoteServiceRegistrationImpl[] regs = registry.getRegistrations();
+ if (regs != null) {
+ for (int j = 0; j < regs.length; j++) {
+ registry.unpublishService(regs[j]);
+ unregisterServiceRegistrationsForContainer(regs[j].getContainerID());
+ registrations.add(regs[j]);
+ }
+ }
+ }
+ }
+ }
+ for (Iterator i = registrations.iterator(); i.hasNext();) {
+ fireRemoteServiceListeners(createUnregisteredEvent((RemoteServiceRegistrationImpl) i.next()));
+ }
+ }
+
private void handleTargetGoneEvent(ID targetID) {
RemoteServiceRegistrationImpl registrations[] = null;
synchronized (remoteRegistrys) {
@@ -469,8 +692,16 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
}
// Remove from pending updates
removePendingContainers(targetID);
+
if (!isConnected())
setRegistryConnected(false);
+
+ ID localContainerID = getLocalContainerID();
+ if (localContainerID == null) {
+ synchronized (localRegistry) {
+ localRegistry.setContainerID(null);
+ }
+ }
// Do notification outside synchronized block
if (registrations != null) {
for (int i = 0; i < registrations.length; i++) {
@@ -490,28 +721,31 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
}
protected void handleContainerDisconnectedEvent(IContainerDisconnectedEvent event) {
- Trace.entering(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.METHODS_ENTERING, this.getClass(), "handleContainerDisconnectedEvent", event); //$NON-NLS-1$
handleTargetGoneEvent(event.getTargetID());
- Trace.exiting(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.METHODS_EXITING, this.getClass(), "handleContainerDisconnectedEvent"); //$NON-NLS-1$
}
protected void sendRegistryUpdate(ID targetContainerID) {
+ sendRegistryUpdate(targetContainerID, null);
+ }
+
+ /**
+ * @since 3.4
+ */
+ protected void sendRegistryUpdate(ID targetContainerID, Integer requestId) {
synchronized (localRegistry) {
final RemoteServiceRegistrationImpl registrations[] = localRegistry.getRegistrations();
- sendAddRegistrations(targetContainerID, null, registrations);
+ sendAddRegistrations(targetContainerID, requestId, registrations);
}
}
- private Hashtable pendingUpdateContainers = new Hashtable();
-
private void addPendingContainers(ID[] ids) {
if (ids == null)
return;
+ ID localContainerID = getLocalContainerID();
synchronized (pendingUpdateContainers) {
for (int i = 0; i < ids.length; i++) {
- if (!ids[i].equals(getLocalContainerID())) {
+ if (!ids[i].equals(localContainerID)) {
pendingUpdateContainers.put(ids[i], ids[i]);
- Trace.trace(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.DEBUG, this.getClass(), getLocalContainerID() + ".addPendingContainers", "added containerIDs=" + ((ids == null) ? "null" : Arrays.asList(ids).toString()) + ",pendingUpdateContainer=" + pendingUpdateContainers); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
}
}
@@ -521,38 +755,31 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
if (id == null)
return false;
ID localContainerID = getLocalContainerID();
- if (localContainerID.equals(id))
- return false;
synchronized (pendingUpdateContainers) {
Object result = pendingUpdateContainers.remove(id);
- if (DEBUG) {
- if (result != null)
- System.out.println("removePendingContainers localContainerID=" + getLocalContainerID() + ",REMOVED=" + result + ",pendingUpdateContainers=" + pendingUpdateContainers); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- Trace.trace(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.DEBUG, this.getClass(), getLocalContainerID() + ".removePendingContainers", "removed containerID=" + id + ",pendingUpdateContainer=" + pendingUpdateContainers); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Trace.trace(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.DEBUG, this.getClass(), "removePendingContainers", "localContainerID=" + localContainerID + ",REMOVED=" + result + ",pendingUpdateContainers=" + pendingUpdateContainers); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
pendingUpdateContainers.notify();
return result != null;
}
}
- private boolean anyPending(ID[] containerIDs) {
- if (containerIDs == null)
+ private boolean anyPending(ID[] idFilter) {
+ if (idFilter == null)
return pendingUpdateContainers.size() > 0;
- for (int i = 0; i < containerIDs.length; i++) {
- if (pendingUpdateContainers.containsKey(containerIDs[i]))
+ for (int i = 0; i < idFilter.length; i++) {
+ if (pendingUpdateContainers.containsKey(idFilter[i]))
return true;
}
return false;
}
- private void waitForPendingUpdates(ID[] containerIDs, long timeout) {
- Trace.entering(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.METHODS_ENTERING, this.getClass(), getLocalContainerID() + ".waitForPendingUpdates", new Object[] {containerIDs, new Long(timeout), pendingUpdateContainers}); //$NON-NLS-1$
- long startTime = System.currentTimeMillis();
- long endTime = startTime + timeout;
+ private void waitForPendingUpdates(ID[] idFilter) {
+ long timeout = getAddRegistrationRequestTimeout();
+ long endTime = System.currentTimeMillis() + timeout;
synchronized (pendingUpdateContainers) {
- while (anyPending(containerIDs) && (endTime >= System.currentTimeMillis())) {
+ // If there are any requred
+ while (anyPending(idFilter) && (endTime >= System.currentTimeMillis())) {
try {
- Trace.trace(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.DEBUG, this.getClass(), "waitForPendingUpdates", "waiting containerIDs=" + ((containerIDs == null) ? "null" : Arrays.asList(containerIDs).toString()) + ",pendingUpdateContainer=" + pendingUpdateContainers); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
pendingUpdateContainers.wait(timeout / 10);
} catch (InterruptedException e) {
// just return
@@ -560,7 +787,6 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
}
}
}
- Trace.exiting(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.METHODS_EXITING, this.getClass(), "waitForPendingUpdates", new Object[] {containerIDs, new Long(timeout), pendingUpdateContainers}); //$NON-NLS-1$
}
protected void handleContainerConnectedEvent(IContainerConnectedEvent event) {
@@ -571,9 +797,7 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
* @since 3.4
*/
protected void handleTargetConnected(ID targetID) {
- if (DEBUG) {
- System.out.println("handleTargetConnected localContainerID=" + getLocalContainerID() + ",targetID=" + targetID); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ Trace.trace(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.DEBUG, this.getClass(), "handleTargetConnected", "localContainerID=" + getLocalContainerID() + ",targetID=" + targetID); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
// Add the target to the set of pending update containers. These are the ones we expect
// to hear from about their registry contents
addPendingContainers(new ID[] {targetID});
@@ -845,9 +1069,25 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
private static final String REGISTRY_UPDATE_REQUEST = "handleRegistryUpdateRequest"; //$NON-NLS-1$
/**
- * @since 3.3
+ * @since 3.4
+ */
+ protected void sendRegistryUpdateRequest(ID receiver, Integer requestId) {
+ ID localContainerID = getLocalContainerID();
+ Trace.trace(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.DEBUG, this.getClass(), "sendRegistryUpdateRequest", "localContainerID=" + localContainerID + ",targetContainerID=" + receiver + ",requestId=" + requestId); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ try {
+ sendSharedObjectMsgTo(receiver, SharedObjectMsg.createMsg(null, REGISTRY_UPDATE_REQUEST, new Object[] {localContainerID, requestId}));
+ } catch (IOException e) {
+ log(ADD_REGISTRATION_ERROR_CODE, "Exception sending registry update request/2 message", e); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * @since 3.4
*/
- protected static final int ADD_REGISTRATION_REQUEST_TIMEOUT = new Integer(System.getProperty("ecf.addregistrationrequest.timeout", "7000")).intValue(); //$NON-NLS-1$ //$NON-NLS-2$
+ protected void handleRegistryUpdateRequest(ID remoteContainerID, Integer requestId) {
+ Trace.trace(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.DEBUG, this.getClass(), "handleRegistryUpdateRequest", "localContainerID=" + getLocalContainerID() + ",remoteContainerID=" + remoteContainerID + ",requestId=" + requestId); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ sendRegistryUpdate(remoteContainerID, requestId);
+ }
protected void sendRegistryUpdateRequest() {
Trace.entering(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.METHODS_ENTERING, this.getClass(), "sendRegistryUpdateRequest"); //$NON-NLS-1$
@@ -861,14 +1101,23 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
protected void handleRegistryUpdateRequest(ID remoteContainerID) {
Trace.entering(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.METHODS_ENTERING, this.getClass(), REGISTRY_UPDATE_REQUEST);
- ID localContainerID = getLocalContainerID();
- if (remoteContainerID == null || localContainerID == null || localContainerID.equals(remoteContainerID)) {
+ if (remoteContainerID == null)
return;
- }
sendRegistryUpdate(remoteContainerID);
Trace.exiting(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.METHODS_EXITING, this.getClass(), REGISTRY_UPDATE_REQUEST);
}
+ private boolean removeRegistryUpdateRequest(Integer requestId) {
+ if (requestId == null)
+ return false;
+ synchronized (registryUpdateRequests) {
+ boolean result = registryUpdateRequests.remove(requestId);
+ Trace.trace(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.DEBUG, this.getClass(), "removeRegistryUpdateRequest", "localContainerID=" + getLocalContainerID() + ", REMOVED requestId=" + requestId); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ registryUpdateRequests.notify();
+ return result;
+ }
+ }
+
protected AddRegistrationRequest sendAddRegistrationRequest(ID receiver, AddRegistrationRequest request, Serializable credentials) {
Trace.entering(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.METHODS_ENTERING, this.getClass(), "sendAddRegistrationRequest", new Object[] {receiver, request, credentials}); //$NON-NLS-1$
Assert.isNotNull(receiver);
@@ -951,9 +1200,6 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
* @since 3.3
*/
protected void sendAddRegistrations(ID receiver, Integer requestId, RemoteServiceRegistrationImpl[] regs) {
- if (DEBUG) {
- System.out.println("sendAddRegistrations localContainerID=" + getLocalContainerID() + ",remoteContainerID=" + receiver + ",requestId=" + requestId + ",registrations=" + Arrays.asList(regs)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- }
Trace.entering(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.METHODS_ENTERING, this.getClass(), "sendAddRegistrations", new Object[] {receiver, requestId, regs}); //$NON-NLS-1$
try {
sendSharedObjectMsgTo(receiver, SharedObjectMsg.createMsg(null, ADD_REGISTRATIONS, getLocalContainerID(), requestId, regs));
@@ -988,10 +1234,6 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
* @since 3.3
*/
protected void handleAddRegistrations(ID remoteContainerID, Integer requestId, final RemoteServiceRegistrationImpl[] registrations) {
- if (DEBUG) {
- System.out.println("handleAddRegistrations localContainerID=" + getLocalContainerID() + ",remoteContainerID=" + remoteContainerID + ",requestId=" + requestId + ",registrations=" + Arrays.asList(registrations)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- }
-
Trace.entering(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.METHODS_ENTERING, this.getClass(), ADD_REGISTRATIONS, new Object[] {remoteContainerID, registrations});
ID localContainerID = getLocalContainerID();
if (remoteContainerID == null || localContainerID == null || localContainerID.equals(remoteContainerID)) {
@@ -1021,6 +1263,9 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
// remove pending containers
removePendingContainers(remoteContainerID);
+ // remove from pending update requests
+ if (requestId != null)
+ removeRegistryUpdateRequest(requestId);
for (Iterator i = addedRegistrations.iterator(); i.hasNext();) {
fireRemoteServiceListeners(createRegisteredEvent((RemoteServiceRegistrationImpl) i.next()));
@@ -1029,9 +1274,6 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
}
protected void handleAddRegistration(ID remoteContainerID, Integer requestId, final RemoteServiceRegistrationImpl registration) {
- if (DEBUG) {
- System.out.println("handleAddRegistration localContainerID=" + getLocalContainerID() + ",requestId=" + requestId + ",registration=" + registration); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
Trace.entering(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.METHODS_ENTERING, this.getClass(), ADD_REGISTRATION, new Object[] {remoteContainerID, registration});
ID localContainerID = getLocalContainerID();
if (remoteContainerID == null || localContainerID == null || localContainerID.equals(remoteContainerID)) {
@@ -1140,11 +1382,6 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
return request;
}
- // system property allowing the executorType to be configured. Currently types are: jobs, threads, immediate.
- private static final String DEFAULT_EXECUTOR_TYPE = System.getProperty("org.eclipse.ecf.provider.remoteservice.executorType", "jobs"); //$NON-NLS-1$ //$NON-NLS-2$
-
- private IExecutor requestExecutor;
-
private IExecutor getRequestExecutor(Request request) {
if (requestExecutor == null) {
requestExecutor = createRequestExecutor(request);
@@ -1152,7 +1389,10 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
return requestExecutor;
}
- private IExecutor createRequestExecutor(final Request request) {
+ /**
+ * @since 3.4
+ */
+ protected IExecutor createRequestExecutor(final Request request) {
IExecutor executor = null;
if (DEFAULT_EXECUTOR_TYPE.equals("jobs")) { //$NON-NLS-1$
executor = new JobsExecutor("Remote Request Handler") { //$NON-NLS-1$
@@ -1575,113 +1815,4 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
return false;
}
- IProgressMonitor progressMonitor = Job.getJobManager().createProgressGroup();
-
- /**
- * @since 3.0
- */
- public IFuture asyncGetRemoteServiceReferences(final ID[] idFilter, final String clazz, final String filter) {
- IExecutor executor = new JobsExecutor("asyncGetRemoteServiceReferences"); //$NON-NLS-1$
- return executor.execute(new IProgressRunnable() {
- public Object run(IProgressMonitor monitor) throws Exception {
- return getRemoteServiceReferences(idFilter, clazz, filter);
- }
- }, null);
- }
-
- /**
- * @since 3.4
- */
- public IFuture asyncGetRemoteServiceReferences(final ID target, final ID[] idFilter, final String clazz, final String filter) {
- IExecutor executor = new JobsExecutor("asyncGetRemoteServiceReferences"); //$NON-NLS-1$
- return executor.execute(new IProgressRunnable() {
- public Object run(IProgressMonitor monitor) throws Exception {
- return getRemoteServiceReferences(target, idFilter, clazz, filter);
- }
- }, null);
- }
-
- /**
- * @since 3.0
- */
- public IFuture asyncGetRemoteServiceReferences(final ID target, final String clazz, final String filter) {
- IExecutor executor = new JobsExecutor("asyncGetRemoteServiceReferences"); //$NON-NLS-1$
- return executor.execute(new IProgressRunnable() {
- public Object run(IProgressMonitor monitor) throws Exception {
- return getRemoteServiceReferences(target, clazz, filter);
- }
- }, null);
- }
-
- /**
- * @since 3.0
- */
- public Namespace getRemoteServiceNamespace() {
- return IDFactory.getDefault().getNamespaceByName(RemoteServiceNamespace.NAME);
- }
-
- /**
- * @since 3.0
- */
- public IRemoteFilter createRemoteFilter(String filter) throws InvalidSyntaxException {
- return new RemoteFilterImpl(filter);
- }
-
- /**
- * @since 3.0
- */
- public IRemoteServiceReference getRemoteServiceReference(IRemoteServiceID serviceId) {
- ID containerID = serviceId.getContainerID();
- RemoteServiceRegistrationImpl registration = null;
- waitForPendingUpdates(new ID[] {serviceId.getContainerID()}, getAddRegistrationRequestTimeout());
- if (this.localRegistry.containerID.equals(containerID)) {
- synchronized (localRegistry) {
- registration = localRegistry.findRegistrationForServiceId(serviceId.getContainerRelativeID());
- if (registration != null)
- return registration.getReference();
- }
- } else {
- synchronized (remoteRegistrys) {
- final ArrayList registrys = new ArrayList(remoteRegistrys.values());
- for (final Iterator i = registrys.iterator(); i.hasNext();) {
- final RemoteServiceRegistryImpl registry = (RemoteServiceRegistryImpl) i.next();
- registration = registry.findRegistrationForServiceId(serviceId.getContainerRelativeID());
- }
- }
- }
- return (registration == null) ? null : registration.getReference();
- }
-
- /**
- * @since 3.0
- */
- public IRemoteServiceID getRemoteServiceID(ID containerId, long containerRelativeId) {
- if (containerId == null)
- return null;
- synchronized (localRegistry) {
- if (localRegistry.containerID.equals(containerId)) {
- RemoteServiceRegistrationImpl reg = localRegistry.findRegistrationForServiceId(containerRelativeId);
- if (reg != null)
- return reg.getID();
- }
- }
- synchronized (remoteRegistrys) {
- final ArrayList registrys = new ArrayList(remoteRegistrys.values());
- for (final Iterator i = registrys.iterator(); i.hasNext();) {
- final RemoteServiceRegistryImpl registry = (RemoteServiceRegistryImpl) i.next();
- RemoteServiceRegistrationImpl reg = registry.findRegistrationForServiceId(containerRelativeId);
- if (reg != null)
- return reg.getID();
- }
- }
- return null;
- }
-
- /**
- * @since 3.0
- */
- public void setConnectContextForAuthentication(IConnectContext connectContext) {
- this.connectContext = connectContext;
- }
-
}
diff --git a/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceRegistrationImpl.java b/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceRegistrationImpl.java
index fdeeb55c6..bad05f2d2 100644
--- a/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceRegistrationImpl.java
+++ b/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceRegistrationImpl.java
@@ -78,6 +78,9 @@ public class RemoteServiceRegistrationImpl implements IRemoteServiceRegistration
this.clazzes = clzzes;
this.reference = new RemoteServiceReferenceImpl(this);
synchronized (registry) {
+ ID containerID = registry.getContainerID();
+ if (containerID == null)
+ throw new NullPointerException("Local containerID must be non-null to register remote services"); //$NON-NLS-1$
this.remoteServiceID = registry.createRemoteServiceID(registry.getNextServiceId());
this.properties = createProperties(props);
registry.publishService(this);
diff --git a/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceRegistryImpl.java b/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceRegistryImpl.java
index 2e2c6f532..a1137d2c3 100644
--- a/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceRegistryImpl.java
+++ b/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceRegistryImpl.java
@@ -26,8 +26,6 @@ public class RemoteServiceRegistryImpl implements Serializable {
protected static final String REMOTESERVICE_RANKING = Constants.SERVICE_RANKING;
- protected ID containerID;
-
public RemoteServiceRegistryImpl() {
//
}
@@ -38,6 +36,8 @@ public class RemoteServiceRegistryImpl implements Serializable {
*/
protected HashMap publishedServicesByClass = new HashMap(50);
+ protected ID containerID;
+
/** All published services */
protected ArrayList allPublishedServices = new ArrayList(50);
@@ -54,6 +54,13 @@ public class RemoteServiceRegistryImpl implements Serializable {
return containerID;
}
+ /**
+ * @since 3.4
+ */
+ public void setContainerID(ID containerID) {
+ this.containerID = containerID;
+ }
+
public void publishService(RemoteServiceRegistrationImpl serviceReg) {
// Add the ServiceRegistration to the list of Services published by
@@ -204,7 +211,7 @@ public class RemoteServiceRegistryImpl implements Serializable {
* @since 3.0
*/
public IRemoteServiceID createRemoteServiceID(long serviceid) {
- return (IRemoteServiceID) IDFactory.getDefault().createID(IDFactory.getDefault().getNamespaceByName(RemoteServiceNamespace.NAME), new Object[] {containerID, new Long(serviceid)});
+ return (IRemoteServiceID) IDFactory.getDefault().createID(IDFactory.getDefault().getNamespaceByName(RemoteServiceNamespace.NAME), new Object[] {getContainerID(), new Long(serviceid)});
}
}
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp.remoteservice/src/org/eclipse/ecf/internal/provider/xmpp/XMPPRemoteServiceAdapterFactory.java b/providers/bundles/org.eclipse.ecf.provider.xmpp.remoteservice/src/org/eclipse/ecf/internal/provider/xmpp/XMPPRemoteServiceAdapterFactory.java
index c24f2c12a..e668fb07b 100644
--- a/providers/bundles/org.eclipse.ecf.provider.xmpp.remoteservice/src/org/eclipse/ecf/internal/provider/xmpp/XMPPRemoteServiceAdapterFactory.java
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp.remoteservice/src/org/eclipse/ecf/internal/provider/xmpp/XMPPRemoteServiceAdapterFactory.java
@@ -11,6 +11,10 @@
package org.eclipse.ecf.internal.provider.xmpp;
+import java.util.Dictionary;
+
+import org.eclipse.ecf.core.events.IContainerConnectedEvent;
+import org.eclipse.ecf.core.events.IContainerDisconnectedEvent;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.sharedobject.ISharedObject;
import org.eclipse.ecf.core.sharedobject.ISharedObjectContainer;
@@ -22,11 +26,47 @@ public class XMPPRemoteServiceAdapterFactory extends
RemoteServiceContainerAdapterFactory {
class XMPPRegistrySharedObject extends RegistrySharedObject {
+
protected ID getLocalContainerID() {
- // For XMPP, the local container ID is its connected ID.
return getContext().getConnectedID();
}
-
+
+ protected void handleContainerConnectedEvent(
+ IContainerConnectedEvent event) {
+ ID targetID = event.getTargetID();
+ if (targetID != null) {
+ synchronized (localRegistry) {
+ localRegistry.setContainerID(targetID);
+ }
+ }
+ }
+
+ protected void handleContainerDisconnectedEvent(
+ IContainerDisconnectedEvent event) {
+ ID targetID = event.getTargetID();
+ if (targetID.equals(event.getLocalContainerID())) {
+ clearRemoteRegistrys();
+ synchronized (localRegistry) {
+ localRegistry.setContainerID(null);
+ }
+ }
+ }
+
+ protected void handleRegistryActivatedEvent() {
+ // do nothing
+ }
+
+ protected ID[] getGroupMemberIDs() {
+ return new ID[0];
+ }
+
+ protected ID[] getTargetsFromProperties(Dictionary properties) {
+ ID[] targets = super.getTargetsFromProperties(properties);
+ // returning ID[0] means that no sending of registrations should occur on
+ // remote service registration (i.e. in RegistrySharedObject.registerRemoteService
+ return (targets == null)?new ID[0]:targets;
+
+ }
}
public XMPPRemoteServiceAdapterFactory() {
diff --git a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/XMPPContainer.java b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/XMPPContainer.java
index 75362ae3a..e57a4fb30 100644
--- a/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/XMPPContainer.java
+++ b/providers/bundles/org.eclipse.ecf.provider.xmpp/src/org/eclipse/ecf/provider/xmpp/XMPPContainer.java
@@ -148,6 +148,26 @@ public class XMPPContainer extends ClientSOContainer implements
userhost)), ka);
}
+ /**
+ * @since 3.2
+ */
+ protected boolean verifySharedObjectMessageTarget(ID containerID) {
+ return true;
+ }
+
+ protected void sendMessage(ContainerMessage data) throws IOException {
+ super.sendMessage(data);
+ synchronized (getConnectLock()) {
+ ID connectedID = getConnectedID();
+ if (connectedID == null)
+ throw new ConnectException("Container not connected"); //$NON-NLS-1$
+ synchronized (getGroupMembershipLock()) {
+ if (connectedID.equals(data.getToContainerID()))
+ queueContainerMessage(data);
+ }
+ }
+ }
+
public IRosterManager getRosterManager() {
return presenceHelper.getRosterManager();
}

Back to the top