Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2009-04-16 20:09:24 -0400
committerslewis2009-04-16 20:09:24 -0400
commit9845c0dc2a9348cf491af2b2b7577c5855681430 (patch)
treee84cdace59400bfe50759eff6af562cd324d4ed3
parentcafd7cba1202a180cf10dc3c34c38be273dcbda4 (diff)
downloadorg.eclipse.ecf-9845c0dc2a9348cf491af2b2b7577c5855681430.tar.gz
org.eclipse.ecf-9845c0dc2a9348cf491af2b2b7577c5855681430.tar.xz
org.eclipse.ecf-9845c0dc2a9348cf491af2b2b7577c5855681430.zip
Added IRemoteServiceContainerAdapter.getAllRemoteServiceReferences
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/LocalRemoteServiceReferenceImpl.java53
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/R_OSGiRemoteServiceContainer.java44
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/RemoteServiceRegistrationImpl.java5
3 files changed, 97 insertions, 5 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/LocalRemoteServiceReferenceImpl.java b/providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/LocalRemoteServiceReferenceImpl.java
new file mode 100644
index 000000000..034ebf02a
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/LocalRemoteServiceReferenceImpl.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+* Copyright (c) 2009 EclipseSource 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:
+* EclipseSource - initial API and implementation
+******************************************************************************/
+package org.eclipse.ecf.internal.provider.r_osgi;
+
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.remoteservice.IRemoteServiceID;
+import org.eclipse.ecf.remoteservice.IRemoteServiceReference;
+import org.osgi.framework.ServiceReference;
+
+public class LocalRemoteServiceReferenceImpl implements IRemoteServiceReference {
+
+ private final IRemoteServiceID remoteServiceID;
+ private ServiceReference reference;
+
+ public LocalRemoteServiceReferenceImpl(IRemoteServiceID remoteServiceID, ServiceReference ref) {
+ this.remoteServiceID = remoteServiceID;
+ this.reference = ref;
+ }
+
+ public ID getContainerID() {
+ return remoteServiceID.getContainerID();
+ }
+
+ public IRemoteServiceID getID() {
+ return remoteServiceID;
+ }
+
+ public Object getProperty(String key) {
+ return reference.getProperty(key);
+ }
+
+ public String[] getPropertyKeys() {
+ return reference.getPropertyKeys();
+ }
+
+ public boolean isActive() {
+ return true;
+ }
+
+ public String toString() {
+ StringBuffer buf = new StringBuffer("LocalRemoteServiceReferenceImpl["); //$NON-NLS-1$
+ buf.append("remoteServiceID=").append(remoteServiceID); //$NON-NLS-1$
+ buf.append(";reference=").append(reference).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
+ return buf.toString();
+ }
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/R_OSGiRemoteServiceContainer.java b/providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/R_OSGiRemoteServiceContainer.java
index 31d20a777..ad5e32159 100644
--- a/providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/R_OSGiRemoteServiceContainer.java
+++ b/providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/R_OSGiRemoteServiceContainer.java
@@ -215,7 +215,8 @@ final class R_OSGiRemoteServiceContainer implements IRemoteServiceContainerAdapt
* java.lang.String, java.lang.String)
*/
public IRemoteServiceReference[] getRemoteServiceReferences(final ID[] idFilter, final String clazz, final String filter) throws InvalidSyntaxException {
- Assert.isNotNull(clazz);
+ if (clazz == null)
+ return null;
IRemoteFilter remoteFilter = (filter == null) ? null : createRemoteFilter(filter);
if (idFilter == null)
return (IRemoteServiceReference[]) getRemoteServiceReferencesConnected(clazz, remoteFilter).toArray(new IRemoteServiceReference[] {});
@@ -229,7 +230,8 @@ final class R_OSGiRemoteServiceContainer implements IRemoteServiceContainerAdapt
}
public IRemoteServiceReference[] getRemoteServiceReferences(ID targetID, String clazz, String filter) throws InvalidSyntaxException, ContainerConnectException {
- Assert.isNotNull(clazz);
+ if (clazz == null)
+ return null;
IRemoteFilter remoteFilter = (filter == null) ? null : createRemoteFilter(filter);
synchronized (this) {
List results = new ArrayList();
@@ -239,6 +241,40 @@ final class R_OSGiRemoteServiceContainer implements IRemoteServiceContainerAdapt
}
}
+ public IRemoteServiceReference[] getAllRemoteServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
+ List results = new ArrayList();
+ // Get remote service references from locally registered services first
+ synchronized (remoteServicesRegs) {
+ for (Iterator i1 = remoteServicesRegs.keySet().iterator(); i1.hasNext();) {
+ ServiceReference ref = (ServiceReference) i1.next();
+ Dictionary refProperties = prepareProperties(ref);
+ if (clazz == null) {
+ results.add(createLocalRemoteServiceReference(ref));
+ } else {
+ IRemoteFilter rf = createRemoteFilter(filter != null ? "(&" + filter + "(" //$NON-NLS-1$ //$NON-NLS-2$
+ + Constants.OBJECTCLASS + "=" + clazz + "))" : "(" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + Constants.OBJECTCLASS + "=" + clazz + ")"); //$NON-NLS-1$//$NON-NLS-2$
+ if (rf.match(refProperties)) {
+ results.add(createLocalRemoteServiceReference(ref));
+ }
+ }
+
+ }
+ }
+ IRemoteFilter remoteFilter = (filter == null) ? null : createRemoteFilter(filter);
+ if (getConnectedID() != null) {
+ final RemoteServiceReference[] refs = remoteService.getRemoteServiceReferences(connectedID.getURI(), clazz, remoteFilter);
+ if (refs != null)
+ for (int i = 0; i < refs.length; i++)
+ results.add(new RemoteServiceReferenceImpl(createRemoteServiceID(refs[i]), refs[i]));
+ }
+ return (IRemoteServiceReference[]) results.toArray(new IRemoteServiceReference[] {});
+ }
+
+ private IRemoteServiceReference createLocalRemoteServiceReference(ServiceReference ref) {
+ return new LocalRemoteServiceReferenceImpl(createRemoteServiceID(containerID, (Long) ref.getProperty(Constants.SERVICE_ID)), ref);
+ }
+
private List /*IRemoteServiceReference*/connectAndGetRemoteServiceReferencesForTarget(ID currentlyConnectedID, ID targetID, String clazz, IRemoteFilter remoteFilter) {
List results = new ArrayList();
if (currentlyConnectedID != null) {
@@ -340,7 +376,9 @@ final class R_OSGiRemoteServiceContainer implements IRemoteServiceContainerAdapt
// Set ECF remote service id property based upon local service property
reg.setProperties(prepareProperties(reg.getReference()));
- remoteServicesRegs.put(reg.getReference(), reg);
+ synchronized (remoteServicesRegs) {
+ remoteServicesRegs.put(reg.getReference(), reg);
+ }
// Construct a IRemoteServiceID, and provide to new registration impl instance
return new RemoteServiceRegistrationImpl(createRemoteServiceID(containerID, (Long) reg.getReference().getProperty(Constants.SERVICE_ID)), reg);
}
diff --git a/providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/RemoteServiceRegistrationImpl.java b/providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/RemoteServiceRegistrationImpl.java
index 7bc46d6af..a385a8a41 100644
--- a/providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/RemoteServiceRegistrationImpl.java
+++ b/providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/RemoteServiceRegistrationImpl.java
@@ -25,9 +25,9 @@ import org.osgi.framework.ServiceRegistration;
final class RemoteServiceRegistrationImpl implements IRemoteServiceRegistration {
private IRemoteServiceID remoteServiceID;
-
// the service registration.
private ServiceRegistration reg;
+ private IRemoteServiceReference remoteReference;
/**
* constructor.
@@ -42,6 +42,7 @@ final class RemoteServiceRegistrationImpl implements IRemoteServiceRegistration
Assert.isNotNull(reg);
this.remoteServiceID = remoteServiceID;
this.reg = reg;
+ this.remoteReference = new LocalRemoteServiceReferenceImpl(remoteServiceID, reg.getReference());
}
/**
@@ -84,7 +85,7 @@ final class RemoteServiceRegistrationImpl implements IRemoteServiceRegistration
* @see org.eclipse.ecf.remoteservice.IRemoteServiceRegistration#getReference()
*/
public IRemoteServiceReference getReference() {
- throw new UnsupportedOperationException("The R-OSGi provider does not provide remote service references for local registrations"); //$NON-NLS-1$
+ return remoteReference;
}
/**

Back to the top