Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2009-02-23 00:57:32 +0000
committerslewis2009-02-23 00:57:32 +0000
commit623de2bc398fb018f0a955e89ddaaba9ec267c89 (patch)
treef4864a801cb8d2865b68cf70adacddc33f291d48 /providers
parentc9419836d7a7410dfc63a652163248b426aeb040 (diff)
downloadorg.eclipse.ecf-623de2bc398fb018f0a955e89ddaaba9ec267c89.tar.gz
org.eclipse.ecf-623de2bc398fb018f0a955e89ddaaba9ec267c89.tar.xz
org.eclipse.ecf-623de2bc398fb018f0a955e89ddaaba9ec267c89.zip
Additions for RFC 119 support. See bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=249240#c11
Diffstat (limited to 'providers')
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/R_OSGiRemoteServiceContainer.java58
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/RemoteServiceReferenceImpl.java30
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/RemoteServiceRegistrationImpl.java19
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/provider/r_osgi/identity/R_OSGiRemoteServiceNamespace.java41
4 files changed, 118 insertions, 30 deletions
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 0bbb6c4fd..37c52e7c7 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
@@ -21,8 +21,7 @@ import org.eclipse.ecf.core.*;
import org.eclipse.ecf.core.events.*;
import org.eclipse.ecf.core.identity.*;
import org.eclipse.ecf.core.security.IConnectContext;
-import org.eclipse.ecf.provider.r_osgi.identity.R_OSGiID;
-import org.eclipse.ecf.provider.r_osgi.identity.R_OSGiNamespace;
+import org.eclipse.ecf.provider.r_osgi.identity.*;
import org.eclipse.ecf.remoteservice.*;
import org.eclipse.ecf.remoteservice.events.IRemoteServiceRegisteredEvent;
import org.eclipse.ecf.remoteservice.events.IRemoteServiceUnregisteredEvent;
@@ -134,16 +133,19 @@ final class R_OSGiRemoteServiceContainer implements IRemoteServiceContainerAdapt
switch (event.getType()) {
case RemoteServiceEvent.REGISTERED :
listener.handleServiceEvent(new IRemoteServiceRegisteredEvent() {
+
+ IRemoteServiceReference reference = new RemoteServiceReferenceImpl(createRemoteServiceID(event.getRemoteReference()), event.getRemoteReference());
+
public String[] getClazzes() {
return (String[]) event.getRemoteReference().getProperty(Constants.OBJECTCLASS);
}
public ID getContainerID() {
- return containerID;
+ return getReference().getContainerID();
}
public IRemoteServiceReference getReference() {
- return new RemoteServiceReferenceImpl(containerID, event.getRemoteReference());
+ return reference;
}
public String toString() {
@@ -153,6 +155,8 @@ final class R_OSGiRemoteServiceContainer implements IRemoteServiceContainerAdapt
return;
case RemoteServiceEvent.UNREGISTERING :
listener.handleServiceEvent(new IRemoteServiceUnregisteredEvent() {
+ IRemoteServiceReference reference = new RemoteServiceReferenceImpl(createRemoteServiceID(event.getRemoteReference()), event.getRemoteReference());
+
public String[] getClazzes() {
return (String[]) event.getRemoteReference().getProperty(Constants.OBJECTCLASS);
}
@@ -162,7 +166,7 @@ final class R_OSGiRemoteServiceContainer implements IRemoteServiceContainerAdapt
}
public IRemoteServiceReference getReference() {
- return new RemoteServiceReferenceImpl(containerID, event.getRemoteReference());
+ return reference;
}
public String toString() {
@@ -219,11 +223,19 @@ final class R_OSGiRemoteServiceContainer implements IRemoteServiceContainerAdapt
}
final IRemoteServiceReference[] result = new IRemoteServiceReference[refs.length];
for (int i = 0; i < refs.length; i++) {
- result[i] = new RemoteServiceReferenceImpl(containerID, refs[i]);
+ result[i] = new RemoteServiceReferenceImpl(createRemoteServiceID(refs[i]), refs[i]);
}
return result;
}
+ IRemoteServiceID createRemoteServiceID(R_OSGiID cID, Long l) {
+ return (IRemoteServiceID) IDFactory.getDefault().createID(getRemoteServiceNamespace(), new Object[] {cID, l});
+ }
+
+ IRemoteServiceID createRemoteServiceID(RemoteServiceReference rref) {
+ return createRemoteServiceID(new R_OSGiID(rref.getURI().toString()), (Long) rref.getProperty(Constants.SERVICE_ID));
+ }
+
/**
* register a service object as a remote service.
*
@@ -250,13 +262,13 @@ final class R_OSGiRemoteServiceContainer implements IRemoteServiceContainerAdapt
// remove the RFC 119 hint, if present, to avoid loops
props.remove("osgi.remote.interfaces"); //$NON-NLS-1$
props.put(org.eclipse.ecf.remoteservice.Constants.REMOTE_SERVICE_CONTAINER_ID, containerID);
-
// register the service with the local framework
final ServiceRegistration reg = context.registerService(clazzes, service, props);
remoteServicesRegs.put(reg.getReference(), reg);
-
- return new RemoteServiceRegistrationImpl(containerID, reg);
+ // Get service ID and container ID, construct a IRemoteServiceID, and provide to new registration
+ Long l = (Long) reg.getReference().getProperty(Constants.SERVICE_ID);
+ return new RemoteServiceRegistrationImpl(createRemoteServiceID(containerID, l), reg);
}
/**
@@ -547,10 +559,36 @@ final class R_OSGiRemoteServiceContainer implements IRemoteServiceContainerAdapt
}
public Namespace getRemoteServiceNamespace() {
- return getConnectNamespace();
+ return IDFactory.getDefault().getNamespaceByName(R_OSGiRemoteServiceNamespace.NAME);
}
public IRemoteFilter createRemoteFilter(String filter) throws InvalidSyntaxException {
return new RemoteFilterImpl(context, filter);
}
+
+ public IRemoteServiceID getRemoteServiceID(ID containerId, long containerRelativeId) {
+ return (IRemoteServiceID) IDFactory.getDefault().createID(getRemoteServiceNamespace(), new Object[] {containerID, new Long(containerRelativeId)});
+ }
+
+ public IRemoteServiceReference getRemoteServiceReference(IRemoteServiceID serviceId) {
+ if (serviceId == null)
+ return null;
+ ID cID = serviceId.getContainerID();
+ if (cID instanceof R_OSGiID) {
+ if (cID.equals(getConnectedID())) {
+ final String filter = "(" + Constants.SERVICE_ID + "=" + serviceId + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ try {
+ RemoteServiceReference[] refs = remoteService.getRemoteServiceReferences(((R_OSGiID) cID).getURI(), null, context.createFilter(filter));
+ // Refs should be null or one long
+ if (refs == null || refs.length == 0)
+ return null;
+ return new RemoteServiceReferenceImpl(createRemoteServiceID(refs[0]), refs[0]);
+ } catch (InvalidSyntaxException e) {
+ // shouldn't happen
+ return null;
+ }
+ }
+ }
+ return null;
+ }
}
diff --git a/providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/RemoteServiceReferenceImpl.java b/providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/RemoteServiceReferenceImpl.java
index 87dae0010..2ec4b7789 100644
--- a/providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/RemoteServiceReferenceImpl.java
+++ b/providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/internal/provider/r_osgi/RemoteServiceReferenceImpl.java
@@ -14,7 +14,9 @@ package org.eclipse.ecf.internal.provider.r_osgi;
import ch.ethz.iks.r_osgi.RemoteServiceReference;
import java.util.Dictionary;
import java.util.Properties;
+import org.eclipse.core.runtime.Assert;
import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.remoteservice.IRemoteServiceID;
import org.eclipse.ecf.remoteservice.IRemoteServiceReference;
/**
@@ -25,21 +27,15 @@ import org.eclipse.ecf.remoteservice.IRemoteServiceReference;
final class RemoteServiceReferenceImpl implements IRemoteServiceReference {
// the container ID from where the remote service reference was retrieved.
- private ID containerID;
+ private IRemoteServiceID remoteServiceID;
// the R-OSGi remote service reference.
private RemoteServiceReference ref;
- /**
- * constructor.
- *
- * @param containerID
- * the container ID.
- * @param rref
- * the R-OSGi remote service reference.
- */
- public RemoteServiceReferenceImpl(final ID containerID, final RemoteServiceReference rref) {
- this.containerID = containerID;
+ public RemoteServiceReferenceImpl(final IRemoteServiceID remoteServiceID, final RemoteServiceReference rref) {
+ Assert.isNotNull(remoteServiceID);
+ Assert.isNotNull(rref);
+ this.remoteServiceID = remoteServiceID;
this.ref = rref;
}
@@ -50,7 +46,7 @@ final class RemoteServiceReferenceImpl implements IRemoteServiceReference {
* @see org.eclipse.ecf.remoteservice.IRemoteServiceReference#getContainerID()
*/
public ID getContainerID() {
- return containerID;
+ return getID().getContainerID();
}
/**
@@ -119,7 +115,10 @@ final class RemoteServiceReferenceImpl implements IRemoteServiceReference {
* @see java.lang.Object#toString()
*/
public String toString() {
- return ref.toString();
+ StringBuffer buf = new StringBuffer("RemoteServiceReference["); //$NON-NLS-1$
+ buf.append("remoteServiceID=").append(getID()); //$NON-NLS-1$
+ buf.append(";ref=").append(ref).append("]"); //$NON-NLS-1$//$NON-NLS-2$
+ return buf.toString();
}
Dictionary getProperties() {
@@ -133,4 +132,9 @@ final class RemoteServiceReferenceImpl implements IRemoteServiceReference {
}
return p;
}
+
+ public IRemoteServiceID getID() {
+ return remoteServiceID;
+ }
+
}
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 e010c2ccb..7bc46d6af 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
@@ -12,9 +12,9 @@
package org.eclipse.ecf.internal.provider.r_osgi;
import java.util.Dictionary;
+import org.eclipse.core.runtime.Assert;
import org.eclipse.ecf.core.identity.ID;
-import org.eclipse.ecf.remoteservice.IRemoteServiceReference;
-import org.eclipse.ecf.remoteservice.IRemoteServiceRegistration;
+import org.eclipse.ecf.remoteservice.*;
import org.osgi.framework.ServiceRegistration;
/**
@@ -24,8 +24,7 @@ import org.osgi.framework.ServiceRegistration;
*/
final class RemoteServiceRegistrationImpl implements IRemoteServiceRegistration {
- // the container ID.
- private ID containerID;
+ private IRemoteServiceID remoteServiceID;
// the service registration.
private ServiceRegistration reg;
@@ -38,8 +37,10 @@ final class RemoteServiceRegistrationImpl implements IRemoteServiceRegistration
* @param reg
* the R-OSGi internal service registration.
*/
- public RemoteServiceRegistrationImpl(final ID containerID, final ServiceRegistration reg) {
- this.containerID = containerID;
+ public RemoteServiceRegistrationImpl(final IRemoteServiceID remoteServiceID, final ServiceRegistration reg) {
+ Assert.isNotNull(remoteServiceID);
+ Assert.isNotNull(reg);
+ this.remoteServiceID = remoteServiceID;
this.reg = reg;
}
@@ -50,7 +51,7 @@ final class RemoteServiceRegistrationImpl implements IRemoteServiceRegistration
* @see org.eclipse.ecf.remoteservice.IRemoteServiceRegistration#getContainerID()
*/
public ID getContainerID() {
- return containerID;
+ return getID().getContainerID();
}
/**
@@ -105,4 +106,8 @@ final class RemoteServiceRegistrationImpl implements IRemoteServiceRegistration
public void unregister() {
reg.unregister();
}
+
+ public IRemoteServiceID getID() {
+ return remoteServiceID;
+ }
}
diff --git a/providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/provider/r_osgi/identity/R_OSGiRemoteServiceNamespace.java b/providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/provider/r_osgi/identity/R_OSGiRemoteServiceNamespace.java
new file mode 100644
index 000000000..513fdb8cc
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.r_osgi/src/org/eclipse/ecf/provider/r_osgi/identity/R_OSGiRemoteServiceNamespace.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+* 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.provider.r_osgi.identity;
+
+import org.eclipse.ecf.core.identity.*;
+import org.eclipse.ecf.remoteservice.RemoteServiceID;
+
+public class R_OSGiRemoteServiceNamespace extends Namespace {
+
+ private static final long serialVersionUID = 3682739978873980993L;
+
+ private static final String REMOTE_SERVICE_SCHEME = "r_osgiremoteservice"; //$NON-NLS-1$
+
+ public static final String NAME = "r_osgi.namespace.remoteservice"; //$NON-NLS-1$
+
+ public R_OSGiRemoteServiceNamespace(String name, String desc) {
+ super(name, desc);
+ }
+
+ public ID createInstance(Object[] parameters) throws IDCreateException {
+ if (parameters == null || parameters.length != 2)
+ throw new IDCreateException("Parameters incorrect for remote ID creation"); //$NON-NLS-1$
+ try {
+ return new RemoteServiceID(this, (ID) parameters[0], ((Long) parameters[1]).longValue());
+ } catch (Exception e) {
+ throw new IDCreateException("Exception creating remoteID", e); //$NON-NLS-1$
+ }
+ }
+
+ public String getScheme() {
+ return REMOTE_SERVICE_SCHEME;
+ }
+
+}

Back to the top