Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2009-03-21 21:37:02 +0000
committerslewis2009-03-21 21:37:02 +0000
commit07e883771f5a568570efbc32ee281ce2ea8bd77b (patch)
tree4393b06cbce2001b2cd7709842db27b8e20c075d /providers/bundles
parent3d7d292b3840fa25247d1374702ca701ce03a3e5 (diff)
downloadorg.eclipse.ecf-07e883771f5a568570efbc32ee281ce2ea8bd77b.tar.gz
org.eclipse.ecf-07e883771f5a568570efbc32ee281ce2ea8bd77b.tar.xz
org.eclipse.ecf-07e883771f5a568570efbc32ee281ce2ea8bd77b.zip
Changes to make getRemoteServiceReferences more robust
Diffstat (limited to 'providers/bundles')
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/AddRegistrationRequest.java32
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RegistrySharedObject.java125
2 files changed, 98 insertions, 59 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/AddRegistrationRequest.java b/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/AddRegistrationRequest.java
index 2239723b2..cb7f98ec1 100644
--- a/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/AddRegistrationRequest.java
+++ b/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/AddRegistrationRequest.java
@@ -14,9 +14,11 @@ package org.eclipse.ecf.provider.remoteservice.generic;
import java.io.Serializable;
import java.security.AccessControlException;
import org.eclipse.core.runtime.Assert;
+import org.eclipse.ecf.core.identity.ID;
public class AddRegistrationRequest implements Serializable {
private static final long serialVersionUID = -2671778516104780091L;
+ ID targetID;
String service;
String filter;
AccessControlException acc;
@@ -24,7 +26,11 @@ public class AddRegistrationRequest implements Serializable {
private boolean done = false;
- public AddRegistrationRequest(String service, String filter, AddRegistrationRequest parent) {
+ /**
+ * @since 3.0
+ */
+ public AddRegistrationRequest(ID targetID, String service, String filter, AddRegistrationRequest parent) {
+ this.targetID = null;
Assert.isNotNull(service);
this.service = service;
this.filter = filter;
@@ -66,17 +72,23 @@ public class AddRegistrationRequest implements Serializable {
return acc;
}
- public void notifyResponse(AccessControlException exception) {
- this.acc = exception;
- synchronized (this) {
- done = true;
- if (parent != null) {
- parent.notifyResponse(exception);
- } else {
- synchronized (this) {
- this.notify();
+ /**
+ * @since 3.0
+ */
+ public void notifyResponse(ID from, AccessControlException exception) {
+ if (targetID == null || targetID.equals(from)) {
+ this.acc = exception;
+ synchronized (this) {
+ done = true;
+ if (parent != null) {
+ parent.notifyResponse(from, exception);
+ } else {
+ synchronized (this) {
+ this.notify();
+ }
}
}
}
}
+
} \ No newline at end of file
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 8111c05be..2c2019e46 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
@@ -41,6 +41,11 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
protected Map addRegistrationRequests = new Hashtable();
+ /**
+ * @since 3.0
+ */
+ protected int addRegistrationRequestTimeout = ADD_REGISTRATION_REQUEST_TIMEOUT;
+
protected List requests = Collections.synchronizedList(new ArrayList());
/**
@@ -97,70 +102,78 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
return remoteService;
}
- /* (non-Javadoc)
- * @see org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter#getRemoteServiceReferences(org.eclipse.ecf.core.identity.ID[], java.lang.String, java.lang.String)
- */
- public IRemoteServiceReference[] getRemoteServiceReferences(ID[] idFilter, String clazz, String filter) throws InvalidSyntaxException {
- Trace.entering(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.METHODS_ENTERING, this.getClass(), "getRemoteServiceReferences", new Object[] {idFilter, clazz, filter}); //$NON-NLS-1$
- if (clazz == null)
- return null;
- final IRemoteFilter remoteFilter = (filter == null) ? null : new RemoteFilterImpl(filter);
- final List references = new ArrayList();
+ 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, references);
+ 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, references);
+ addReferencesFromRegistry(clazz, remoteFilter, registry, referencesFound);
}
}
}
}
+ }
+
+ /**
+ * @since 3.0
+ */
+ protected int getAddRegistrationRequestTimeout() {
+ return addRegistrationRequestTimeout;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter#getRemoteServiceReferences(org.eclipse.ecf.core.identity.ID[], java.lang.String, java.lang.String)
+ */
+ public IRemoteServiceReference[] getRemoteServiceReferences(ID[] idFilter, String clazz, String filter) throws InvalidSyntaxException {
+ Trace.entering(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.METHODS_ENTERING, this.getClass(), "getRemoteServiceReferences", new Object[] {idFilter, clazz, filter}); //$NON-NLS-1$
+ if (clazz == null)
+ return null;
+ final IRemoteFilter remoteFilter = (filter == null) ? null : new RemoteFilterImpl(filter);
+ final List references = new ArrayList();
+ // Lookup from remote registrys...add to given references List
+ addReferencesFromRemoteRegistrys(idFilter, clazz, remoteFilter, references);
+ // Add any from local registry
synchronized (localRegistry) {
addReferencesFromRegistry(clazz, remoteFilter, localRegistry, references);
}
+ // If none found the first time we send a registration request and wait
if (references.size() == 0) {
- // It's not already here...so send out AddRegistrationRequests
- if (idFilter == null)
- return null;
AddRegistrationRequest first = null;
List ourAddRegistrationRequests = new ArrayList();
- for (int i = 0; i < idFilter.length; i++) {
- ID target = idFilter[i];
- if (target != null) {
- AddRegistrationRequest request = new AddRegistrationRequest(clazz, filter, first);
- if (i == 0)
- first = request;
- // Add to list of all know
- ourAddRegistrationRequests.add(request);
- addRegistrationRequests.put(request.getId(), request);
- sendAddRegistrationRequest(target, request, getAddRegistrationRequestCredentials(request));
- }
- }
- if (first != null) {
- // Wait here for timeout or response
- first.waitForResponse(ADD_REGISTRATION_REQUEST_TIMEOUT);
- // Now...if we got a response, and there was no exception then we look again
- if (first.isDone()) {
- for (int i = 0; i < idFilter.length; i++) {
- final RemoteServiceRegistryImpl registry = (RemoteServiceRegistryImpl) remoteRegistrys.get(idFilter[i]);
- if (registry != null) {
- addReferencesFromRegistry(clazz, remoteFilter, registry, references);
- }
+ // It's not already here...so send out AddRegistrationRequests
+ if (idFilter == null) {
+ first = new AddRegistrationRequest(null, clazz, filter, first);
+ ourAddRegistrationRequests.add(first);
+ } else {
+ for (int i = 0; i < idFilter.length; i++) {
+ ID target = idFilter[i];
+ if (target != null) {
+ AddRegistrationRequest request = new AddRegistrationRequest(target, clazz, filter, first);
+ if (i == 0)
+ first = request;
+ // Add to list of all know
+ ourAddRegistrationRequests.add(request);
+ addRegistrationRequests.put(request.getId(), request);
+ sendAddRegistrationRequest(target, request, getAddRegistrationRequestCredentials(request));
}
}
- // In either case, remove all the addRegistrationRequests
- for (Iterator i = ourAddRegistrationRequests.iterator(); i.hasNext();) {
- AddRegistrationRequest request = (AddRegistrationRequest) i.next();
- addRegistrationRequests.remove(request.getId());
- }
+ }
+ // Wait here for timeout or response
+ first.waitForResponse(ADD_REGISTRATION_REQUEST_TIMEOUT);
+ // Now look again
+ addReferencesFromRemoteRegistrys(idFilter, clazz, remoteFilter, references);
+ // In either case, remove all the addRegistrationRequests
+ for (Iterator i = ourAddRegistrationRequests.iterator(); i.hasNext();) {
+ AddRegistrationRequest request = (AddRegistrationRequest) i.next();
+ addRegistrationRequests.remove(request.getId());
}
}
@@ -565,7 +578,7 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
private static final String REGISTRY_UPDATE_REQUEST = "handleRegistryUpdateRequest"; //$NON-NLS-1$
- private static final int ADD_REGISTRATION_REQUEST_TIMEOUT = 10000;
+ private static final int ADD_REGISTRATION_REQUEST_TIMEOUT = 5000;
protected void sendRegistryUpdateRequest() {
Trace.entering(Activator.PLUGIN_ID, IRemoteServiceProviderDebugOptions.METHODS_ENTERING, this.getClass(), "sendRegistryUpdateRequest"); //$NON-NLS-1$
@@ -669,7 +682,7 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
if (remoteContainerID == null || requestId == null)
return;
// else lookup AddRegistrationRequest and notify
- notifyAddRegistrationResponse(requestId, e);
+ notifyAddRegistrationResponse(remoteContainerID, requestId, e);
}
protected void handleAddRegistration(ID remoteContainerID, final RemoteServiceRegistrationImpl registration) {
@@ -698,7 +711,7 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
registry.publishService(registration);
localRegisterService(registration);
}
- notifyAddRegistrationResponse(requestId, null);
+ notifyAddRegistrationResponse(remoteContainerID, requestId, null);
}
// notify IRemoteServiceListeners
if (added)
@@ -709,12 +722,26 @@ public class RegistrySharedObject extends BaseSharedObject implements IRemoteSer
/**
* @param requestId
*/
- private void notifyAddRegistrationResponse(Integer requestId, AccessControlException exception) {
- if (requestId == null)
+ private void notifyAddRegistrationResponse(ID remoteContainerID, Integer requestId, AccessControlException exception) {
+ if (remoteContainerID == null)
return;
- AddRegistrationRequest request = (AddRegistrationRequest) addRegistrationRequests.remove(requestId);
- if (request != null) {
- request.notifyResponse(exception);
+ List pendingRequests = new ArrayList();
+ // If the requestId is null, this isn't in response to any particular request,
+ // So we get all AddRegistrationRequests
+ synchronized (addRegistrationRequests) {
+ if (requestId == null) {
+ for (Iterator i = addRegistrationRequests.keySet().iterator(); i.hasNext();) {
+ Integer key = (Integer) i.next();
+ pendingRequests.add(addRegistrationRequests.get(key));
+ }
+ } else
+ pendingRequests.add(addRegistrationRequests.get(requestId));
+ }
+ // Then notify each one of the response from given remoteContainerID
+ for (Iterator i = pendingRequests.iterator(); i.hasNext();) {
+ AddRegistrationRequest request = (AddRegistrationRequest) i.next();
+ if (request != null)
+ request.notifyResponse(remoteContainerID, exception);
}
}

Back to the top