Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 128704 Details for
Bug 249240
[remotesvcs] Implement RFC 119
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
discovery patch
clipboard.txt (text/plain), 40.29 KB, created by
Markus Kuppe
on 2009-03-13 09:49:54 EDT
(
hide
)
Description:
discovery patch
Filename:
MIME Type:
Creator:
Markus Kuppe
Created:
2009-03-13 09:49:54 EDT
Size:
40.29 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.ecf.osgi.services.distribution >Index: src/org/eclipse/ecf/internal/osgi/services/distribution/RemoteServiceRegistrations.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.ecf/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/RemoteServiceRegistrations.java,v >retrieving revision 1.2 >diff -u -r1.2 RemoteServiceRegistrations.java >--- src/org/eclipse/ecf/internal/osgi/services/distribution/RemoteServiceRegistrations.java 5 Mar 2009 23:49:51 -0000 1.2 >+++ src/org/eclipse/ecf/internal/osgi/services/distribution/RemoteServiceRegistrations.java 13 Mar 2009 13:38:45 -0000 >@@ -11,29 +11,29 @@ > > import java.util.*; > import org.eclipse.ecf.core.IContainer; >-import org.eclipse.ecf.discovery.identity.IServiceID; > import org.eclipse.ecf.remoteservice.*; > import org.osgi.framework.ServiceRegistration; >+import org.osgi.service.discovery.ServiceEndpointDescription; > > public class RemoteServiceRegistrations { > >- private final IServiceID serviceID; >+ private final ServiceEndpointDescription serviceEndpointDescription; > private final IContainer container; > private final IRemoteServiceContainerAdapter containerAdapter; > private IRemoteServiceListener listener; > private Map serviceRegistrations = new HashMap(); > >- public RemoteServiceRegistrations(IServiceID serviceID, IContainer c, >+ public RemoteServiceRegistrations(ServiceEndpointDescription sed, IContainer c, > IRemoteServiceContainerAdapter adapter, IRemoteServiceListener l) { >- this.serviceID = serviceID; >+ this.serviceEndpointDescription = sed; > this.container = c; > this.containerAdapter = adapter; > this.listener = l; > this.containerAdapter.addRemoteServiceListener(this.listener); > } > >- public IServiceID getServiceID() { >- return serviceID; >+ public ServiceEndpointDescription getServiceEndpointDescription() { >+ return serviceEndpointDescription; > } > > public IContainer getContainer() { >Index: src/org/eclipse/ecf/internal/osgi/services/distribution/ServiceEndpointDescriptionHelper.java >=================================================================== >RCS file: src/org/eclipse/ecf/internal/osgi/services/distribution/ServiceEndpointDescriptionHelper.java >diff -N src/org/eclipse/ecf/internal/osgi/services/distribution/ServiceEndpointDescriptionHelper.java >--- src/org/eclipse/ecf/internal/osgi/services/distribution/ServiceEndpointDescriptionHelper.java 7 Mar 2009 22:19:00 -0000 1.6 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,107 +0,0 @@ >-/******************************************************************************* >- * 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.osgi.services.distribution; >- >-import java.util.Collection; >-import org.eclipse.ecf.core.identity.*; >-import org.eclipse.ecf.discovery.identity.IServiceID; >-import org.eclipse.ecf.osgi.services.discovery.ECFServicePublication; >-import org.eclipse.ecf.osgi.services.discovery.ServiceEndpointDescriptionImpl; >- >-class ServiceEndpointDescriptionHelper { >- private static final long DEFAULT_FUTURE_TIMEOUT = new Long(System >- .getProperty("ecf.rs.lookup.timeout", new Long(30000).toString())) >- .longValue(); >- >- private final ServiceEndpointDescriptionImpl description; >- private final ID localDiscoveryContainerID; >- private final IServiceID serviceID; >- private final String serviceName; >- private ID endpointID; >- >- public ServiceEndpointDescriptionHelper(ServiceEndpointDescriptionImpl d) >- throws NullPointerException { >- description = d; >- // Get ECF discovery container ID...if not found there is a problem >- localDiscoveryContainerID = description.getLocalDiscoveryContainerID(); >- if (localDiscoveryContainerID == null) >- throw new NullPointerException( >- "ServiceEndpointDescription localDiscoveryContainerID cannot be null"); >- // Get serviceName from description >- serviceID = description.getServiceID(); >- if (serviceID == null) >- throw new NullPointerException( >- "ServiceEndpointDescription serviceID cannot be null"); >- serviceName = serviceID.getServiceName(); >- if (serviceName == null) >- throw new NullPointerException( >- "ServiceEndpointDescription serviceName is null"); >- } >- >- public ServiceEndpointDescriptionImpl getDescription() { >- return description; >- } >- >- public ID getLocalDiscoveryContainerID() { >- return localDiscoveryContainerID; >- } >- >- public IServiceID getServiceID() { >- return serviceID; >- } >- >- public String getServiceName() { >- return serviceName; >- } >- >- public Collection getProvidedInterfaces() { >- Collection c = description.getProvidedInterfaces(); >- if (c == null) >- throw new NullPointerException( >- "ServiceEndpointDescription providedInterfaces cannot be null"); >- return c; >- } >- >- public Long getRemoteServiceID() throws NullPointerException { >- String longStr = (String) description >- .getProperty(org.eclipse.ecf.remoteservice.Constants.SERVICE_ID); >- if (longStr == null) >- throw new NullPointerException( >- "ServiceEndpointDescriptoin remote service ID cannot be null"); >- return new Long(longStr); >- } >- >- public synchronized ID getEndpointID() throws IDCreateException { >- if (endpointID == null) { >- byte[] endpointBytes = description >- .getPropertyBytes(ECFServicePublication.PROP_KEY_ENDPOINT_CONTAINERID); >- if (endpointBytes == null) >- throw new IDCreateException( >- "ServiceEndpointDescription endpointBytes cannot be null"); >- String endpointStr = new String(endpointBytes); >- String namespaceStr = description >- .getPropertyString(ECFServicePublication.PROP_KEY_ENDPOINT_CONTAINERID_NAMESPACE); >- if (namespaceStr == null) >- throw new IDCreateException( >- "ServiceEndpointDescription namespaceStr cannot be null"); >- endpointID = IDFactory.getDefault().createID(namespaceStr, >- endpointStr); >- } >- return endpointID; >- } >- >- public long getFutureTimeout() { >- return DEFAULT_FUTURE_TIMEOUT; >- } >- >-} >\ No newline at end of file >Index: src/org/eclipse/ecf/internal/osgi/services/distribution/DiscoveredServiceTrackerImpl.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.ecf/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/src/org/eclipse/ecf/internal/osgi/services/distribution/DiscoveredServiceTrackerImpl.java,v >retrieving revision 1.21 >diff -u -r1.21 DiscoveredServiceTrackerImpl.java >--- src/org/eclipse/ecf/internal/osgi/services/distribution/DiscoveredServiceTrackerImpl.java 12 Mar 2009 01:33:39 -0000 1.21 >+++ src/org/eclipse/ecf/internal/osgi/services/distribution/DiscoveredServiceTrackerImpl.java 13 Mar 2009 13:38:45 -0000 >@@ -16,9 +16,8 @@ > import org.eclipse.ecf.core.identity.ID; > import org.eclipse.ecf.core.identity.Namespace; > import org.eclipse.ecf.core.util.Trace; >-import org.eclipse.ecf.discovery.identity.IServiceID; >+import org.eclipse.ecf.osgi.services.discovery.ECFServiceEndpointDescription; > import org.eclipse.ecf.osgi.services.discovery.ECFServicePublication; >-import org.eclipse.ecf.osgi.services.discovery.ServiceEndpointDescriptionImpl; > import org.eclipse.ecf.osgi.services.distribution.ECFServiceConstants; > import org.eclipse.ecf.remoteservice.*; > import org.eclipse.ecf.remoteservice.events.IRemoteServiceEvent; >@@ -50,6 +49,9 @@ > ECFServicePublication.PROP_KEY_SERVICE_INTERFACE_VERSION, > ECFServicePublication.PROP_KEY_SERVICE_PROPERTIES }); > >+ /* (non-Javadoc) >+ * @see org.osgi.service.discovery.DiscoveredServiceTracker#serviceChanged(org.osgi.service.discovery.DiscoveredServiceNotification) >+ */ > public void serviceChanged(DiscoveredServiceNotification notification) { > if (notification == null) { > logWarning("serviceChanged", >@@ -83,32 +85,20 @@ > ServiceEndpointDescription sed) { > // If the service endpoint description is not ECF's then we > // don't process it >- if (!(sed instanceof ServiceEndpointDescriptionImpl)) { >- return; >- } >- ServiceEndpointDescriptionHelper sedh = null; >- // Now create a ServiceEndpointDescriptionHelper from sed >- try { >- sedh = new ServiceEndpointDescriptionHelper( >- (ServiceEndpointDescriptionImpl) sed); >- } catch (Exception e) { >- logError( >- "handleDiscoveredServiceUnavailable", >- "Error getting data from ServiceEndpointDescription=" + sed, >- e); >+ if (!(sed instanceof ECFServiceEndpointDescription)) { > return; > } >+ ECFServiceEndpointDescription ecfSED = (ECFServiceEndpointDescription) sed; > // Remove existing proxy service registrations that correspond to the > // given serviceID >- ServiceRegistration[] proxyServiceRegistrations = removeProxyServiceRegistrations(sedh >- .getServiceID()); >+ ServiceRegistration[] proxyServiceRegistrations = removeProxyServiceRegistrations(ecfSED); > // Then unregister them > if (proxyServiceRegistrations != null) { > for (int i = 0; i < proxyServiceRegistrations.length; i++) { > trace("handleDiscoveredServiceUnavailable", > "proxyServiceRegistrations=" >- + proxyServiceRegistrations[i] + ",serviceID=" >- + sedh.getServiceID()); >+ + proxyServiceRegistrations[i] + ",serviceEndpointDesc=" >+ + ecfSED); > unregisterProxyServiceRegistration(proxyServiceRegistrations[i]); > } > } >@@ -117,43 +107,30 @@ > private void handleDiscoveredServiceAvailable(ServiceEndpointDescription sed) { > // If the service endpoint description is not ECF's then we > // don't process it >- if (!(sed instanceof ServiceEndpointDescriptionImpl)) { >- return; >- } >- ServiceEndpointDescriptionHelper sedh = null; >- // Now create a ServiceEndpointDescriptionHelper from sed >- Collection providedInterfaces = null; >- ID endpointID = null; >- try { >- sedh = new ServiceEndpointDescriptionHelper( >- (ServiceEndpointDescriptionImpl) sed); >- providedInterfaces = sedh.getProvidedInterfaces(); >- endpointID = sedh.getEndpointID(); >- } catch (Exception e) { >- logError( >- "handleDiscoveredServiceAvailable", >- "Error getting data from ServiceEndpointDescription=" + sed, >- e); >+ if (!(sed instanceof ECFServiceEndpointDescription)) { > return; > } >+ ECFServiceEndpointDescription ecfSED = (ECFServiceEndpointDescription) sed; > >+ ID endpointID = ecfSED.getECFEndpointID(); > // Find RSCAs for the given description >- ContainerAdapterHelper[] cahs = findRSCAs(endpointID, sedh); >+ ContainerAdapterHelper[] cahs = findRSCAs(endpointID, ecfSED); > if (cahs == null || cahs.length == 0) { > logError("handleDiscoveredServiceAvailable", > "No RemoteServiceContainerAdapters found for description=" >- + sedh.getDescription(), null); >+ + ecfSED, null); > return; > } > // Give warning if more than one ContainerAdapterHelper found > if (cahs.length > 1) { > logWarning("handleDiscoveredServiceAvailable", > "Multiple remote service containers=" + Arrays.asList(cahs) >- + " found for service endpoint description=" + sedh); >+ + " found for service endpoint description=" + ecfSED); > } > // For all remote service container adapters > // Get futureRemoteReferences...then create a thread > // to process the future >+ Collection providedInterfaces = ecfSED.getProvidedInterfaces(); > for (int i = 0; i < cahs.length; i++) { > for (Iterator j = providedInterfaces.iterator(); j.hasNext();) { > String providedInterface = (String) j.next(); >@@ -165,14 +142,14 @@ > new ID[] { endpointID }, providedInterface, > null); > // And process the future returned in separate thread >- processFutureForRemoteServiceReferences(sedh, >+ processFutureForRemoteServiceReferences(ecfSED, > futureRemoteReferences, cahs[i]); > } > } > } > > private void processFutureForRemoteServiceReferences( >- final ServiceEndpointDescriptionHelper sedh, >+ final ECFServiceEndpointDescription sed, > final IFuture futureRemoteReferences, > final ContainerAdapterHelper ch) { > Thread t = new Thread(new Runnable() { >@@ -183,7 +160,7 @@ > // This will block, but since we're in our own thread we're > // OK > IRemoteServiceReference[] remoteReferences = (IRemoteServiceReference[]) futureRemoteReferences >- .get(sedh.getFutureTimeout()); >+ .get(sed.getFutureTimeout()); > // Get the status > IStatus futureStatus = futureRemoteReferences.getStatus(); > if (futureStatus.isOK()) { >@@ -197,7 +174,7 @@ > .toString())); > if (remoteReferences != null > && remoteReferences.length > 0) { >- registerRemoteServiceReferences(sedh, ch, >+ registerRemoteServiceReferences(sed, ch, > remoteReferences); > } else { > logError( >@@ -232,14 +209,14 @@ > t.start(); > } > >- private void addProxyServiceRegistration(IServiceID serviceID, >+ private void addProxyServiceRegistration(ServiceEndpointDescription sed, > ContainerAdapterHelper ch, IRemoteServiceReference ref, > ServiceRegistration registration) { > ID containerID = ch.getContainer().getID(); > RemoteServiceRegistrations reg = (RemoteServiceRegistrations) discoveredRemoteServiceRegistrations > .get(containerID); > if (reg == null) { >- reg = new RemoteServiceRegistrations(serviceID, ch.getContainer(), >+ reg = new RemoteServiceRegistrations(sed, ch.getContainer(), > ch.getRSCA(), > new RemoteServiceReferenceUnregisteredListener()); > discoveredRemoteServiceRegistrations.put(containerID, reg); >@@ -252,20 +229,20 @@ > distributionProvider.addRemoteService(registration.getReference()); > } > >- private boolean findProxyServiceRegistration(IServiceID serviceID) { >+ private boolean findProxyServiceRegistration(ServiceEndpointDescription sed) { > for (Iterator i = discoveredRemoteServiceRegistrations.keySet() > .iterator(); i.hasNext();) { > ID containerID = (ID) i.next(); > RemoteServiceRegistrations reg = (RemoteServiceRegistrations) discoveredRemoteServiceRegistrations > .get(containerID); >- if (serviceID.equals(reg.getServiceID())) >+ if (sed.equals(reg.getServiceEndpointDescription())) > return true; > } > return false; > } > > private ServiceRegistration[] removeProxyServiceRegistrations( >- IServiceID serviceID) { >+ ServiceEndpointDescription sed) { > List results = new ArrayList(); > for (Iterator i = discoveredRemoteServiceRegistrations.keySet() > .iterator(); i.hasNext();) { >@@ -276,7 +253,7 @@ > // RemoteServiceRegistration > // Get the service registrations and then dispose of the > // RemoteServiceRegistrations instance >- if (serviceID.equals(reg.getServiceID())) { >+ if (sed.equals(reg.getServiceEndpointDescription())) { > i.remove(); > results.addAll(reg.removeAllServiceRegistrations()); > reg.dispose(); >@@ -348,13 +325,13 @@ > } > > private void registerRemoteServiceReferences( >- ServiceEndpointDescriptionHelper sedh, ContainerAdapterHelper ch, >+ ECFServiceEndpointDescription sed, ContainerAdapterHelper ch, > IRemoteServiceReference[] remoteReferences) { > > synchronized (discoveredRemoteServiceRegistrations) { >- if (findProxyServiceRegistration(sedh.getServiceID())) { >- logError("registerRemoteServiceReferences", "serviceID=" >- + sedh.getServiceID() >+ if (findProxyServiceRegistration(sed)) { >+ logError("registerRemoteServiceReferences", "serviceEndpointDesc=" >+ + sed > + " previously registered locally...ignoring", null); > return; > } >@@ -382,7 +359,7 @@ > } > > // Get service properties for the proxy >- Dictionary properties = getPropertiesForRemoteService(sedh, ch >+ Dictionary properties = getPropertiesForRemoteService(sed, ch > .getRSCA(), remoteReferences[i], remoteService); > > // Create proxy right here >@@ -400,7 +377,7 @@ > ServiceRegistration registration = Activator.getDefault() > .getContext().registerService(clazzes, proxy, > properties); >- addProxyServiceRegistration(sedh.getServiceID(), ch, >+ addProxyServiceRegistration(sed, ch, > remoteReferences[i], registration); > } catch (Exception e) { > logError("registerRemoteServiceReferences", >@@ -417,7 +394,7 @@ > } > > private Dictionary getPropertiesForRemoteService( >- ServiceEndpointDescriptionHelper description, >+ ServiceEndpointDescription description, > IRemoteServiceContainerAdapter containerAdapter, > IRemoteServiceReference remoteReference, > IRemoteService remoteService) { >@@ -434,7 +411,7 @@ > } > > private ContainerAdapterHelper[] findRSCAs(ID endpointID, >- ServiceEndpointDescriptionHelper sedh) { >+ ServiceEndpointDescription sedh) { > IContainerManager containerManager = Activator.getDefault() > .getContainerManager(); > if (containerManager == null) >@@ -451,7 +428,7 @@ > .getAdapter(IRemoteServiceContainerAdapter.class); > if (adapter != null > && includeRCSAForDescription(containers[i], adapter, >- endpointID, sedh.getDescription())) { >+ endpointID, sedh)) { > results.add(new ContainerAdapterHelper(containers[i], adapter)); > } > } >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.ecf/compendium/bundles/org.eclipse.ecf.osgi.services.distribution/META-INF/MANIFEST.MF,v >retrieving revision 1.15 >diff -u -r1.15 MANIFEST.MF >--- META-INF/MANIFEST.MF 5 Mar 2009 06:29:49 -0000 1.15 >+++ META-INF/MANIFEST.MF 13 Mar 2009 13:38:45 -0000 >@@ -9,8 +9,6 @@ > Import-Package: org.eclipse.ecf.core, > org.eclipse.ecf.core.identity, > org.eclipse.ecf.core.util, >- org.eclipse.ecf.discovery, >- org.eclipse.ecf.discovery.identity, > org.eclipse.ecf.osgi.services.discovery, > org.eclipse.ecf.remoteservice, > org.eclipse.ecf.remoteservice.events, >#P org.eclipse.ecf.discovery >Index: src/org/eclipse/ecf/discovery/ServiceProperties.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.ecf/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/ServiceProperties.java,v >retrieving revision 1.12 >diff -u -r1.12 ServiceProperties.java >--- src/org/eclipse/ecf/discovery/ServiceProperties.java 17 Feb 2009 16:50:40 -0000 1.12 >+++ src/org/eclipse/ecf/discovery/ServiceProperties.java 13 Mar 2009 13:38:46 -0000 >@@ -144,6 +144,26 @@ > return props.size(); > } > >+ /** >+ * @return >+ * @since 3.0 >+ */ >+ public Properties asProperties() { >+ Properties result = new Properties(); >+ Set keySet = props.keySet(); >+ for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { >+ Object key = (Object) iterator.next(); >+ Object value = props.get(key); >+ if(value instanceof ByteArrayWrapper) { >+ ByteArrayWrapper baw = (ByteArrayWrapper) value; >+ result.put(key, baw.getByte()); >+ } else { >+ result.put(key, value); >+ } >+ } >+ return result; >+ } >+ > // proper equals/hashcode for byte[] > private static class ByteArrayWrapper implements Serializable { > >#P org.eclipse.ecf.osgi.services.discovery >Index: src/org/eclipse/ecf/internal/osgi/services/discovery/ServicePublicationHandler.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.ecf/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/internal/osgi/services/discovery/ServicePublicationHandler.java,v >retrieving revision 1.21 >diff -u -r1.21 ServicePublicationHandler.java >--- src/org/eclipse/ecf/internal/osgi/services/discovery/ServicePublicationHandler.java 10 Mar 2009 16:04:40 -0000 1.21 >+++ src/org/eclipse/ecf/internal/osgi/services/discovery/ServicePublicationHandler.java 13 Mar 2009 13:38:48 -0000 >@@ -31,16 +31,22 @@ > private Map serviceInfos = Collections.synchronizedMap(new HashMap()); > > private final IServiceListener serviceListener = new IServiceListener() { >+ /* (non-Javadoc) >+ * @see org.eclipse.ecf.discovery.IServiceListener#serviceDiscovered(org.eclipse.ecf.discovery.IServiceEvent) >+ */ > public void serviceDiscovered(IServiceEvent anEvent) { > handleServiceDiscovered(anEvent); > } > >+ /* (non-Javadoc) >+ * @see org.eclipse.ecf.discovery.IServiceListener#serviceUndiscovered(org.eclipse.ecf.discovery.IServiceEvent) >+ */ > public void serviceUndiscovered(IServiceEvent anEvent) { > handleServiceUndiscovered(anEvent); > } > }; > >- void handleServiceDiscovered(IServiceEvent event) { >+ private void handleServiceDiscovered(IServiceEvent event) { > IServiceInfo serviceInfo = event.getServiceInfo(); > IServiceID serviceID = serviceInfo.getServiceID(); > ID localContainerID = event.getLocalContainerID(); >@@ -62,7 +68,7 @@ > } > } > >- void handleServiceUndiscovered(IServiceEvent event) { >+ private void handleServiceUndiscovered(IServiceEvent event) { > IServiceInfo serviceInfo = event.getServiceInfo(); > IServiceID serviceID = serviceInfo.getServiceID(); > ID localContainerID = event.getLocalContainerID(); >@@ -112,18 +118,17 @@ > return false; > } > >- IServiceInfo addServiceInfo(ServiceReference sr, IServiceInfo si) { >+ private IServiceInfo addServiceInfo(ServiceReference sr, IServiceInfo si) { > return (IServiceInfo) serviceInfos.put(sr, si); > } > >- IServiceInfo removeServiceInfo(ServiceReference sr) { >+ private IServiceInfo removeServiceInfo(ServiceReference sr) { > return (IServiceInfo) serviceInfos.remove(sr); > } > >- IServiceInfo getServiceInfo(ServiceReference sr) { >- return (IServiceInfo) serviceInfos.get(sr); >- } >- >+ /* (non-Javadoc) >+ * @see org.osgi.util.tracker.ServiceTrackerCustomizer#addingService(org.osgi.framework.ServiceReference) >+ */ > public Object addingService(ServiceReference reference) { > handleServicePublication(reference); > return Activator.getDefault().getContext().getService(reference); >@@ -344,7 +349,7 @@ > return advertiser; > } > >- String getPropertyWithDefault(Map properties, String key, String def) { >+ private String getPropertyWithDefault(Map properties, String key, String def) { > String val = (String) properties.get(key); > return (val == null) ? def : val; > } >@@ -372,11 +377,17 @@ > namingAuthority); > } > >+ /* (non-Javadoc) >+ * @see org.osgi.util.tracker.ServiceTrackerCustomizer#modifiedService(org.osgi.framework.ServiceReference, java.lang.Object) >+ */ > public void modifiedService(ServiceReference reference, Object service) { > unpublishService(reference); > handleServicePublication(reference); > } > >+ /* (non-Javadoc) >+ * @see org.osgi.util.tracker.ServiceTrackerCustomizer#removedService(org.osgi.framework.ServiceReference, java.lang.Object) >+ */ > public void removedService(ServiceReference reference, Object service) { > unpublishService(reference); > } >Index: src/org/eclipse/ecf/internal/osgi/services/discovery/DiscoveredServiceNotificationImpl.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.ecf/compendium/bundles/org.eclipse.ecf.osgi.services.discovery/src/org/eclipse/ecf/internal/osgi/services/discovery/DiscoveredServiceNotificationImpl.java,v >retrieving revision 1.7 >diff -u -r1.7 DiscoveredServiceNotificationImpl.java >--- src/org/eclipse/ecf/internal/osgi/services/discovery/DiscoveredServiceNotificationImpl.java 5 Mar 2009 05:49:17 -0000 1.7 >+++ src/org/eclipse/ecf/internal/osgi/services/discovery/DiscoveredServiceNotificationImpl.java 13 Mar 2009 13:38:48 -0000 >@@ -11,7 +11,6 @@ > > import org.eclipse.ecf.core.identity.ID; > import org.eclipse.ecf.discovery.IServiceInfo; >-import org.eclipse.ecf.osgi.services.discovery.ServiceEndpointDescriptionImpl; > import org.osgi.service.discovery.DiscoveredServiceNotification; > import org.osgi.service.discovery.ServiceEndpointDescription; > >@@ -24,14 +23,20 @@ > public DiscoveredServiceNotificationImpl(ID localContainerID, int type, > IServiceInfo serviceInfo) { > this.type = type; >- this.serviceEndpointDescription = new ServiceEndpointDescriptionImpl( >+ this.serviceEndpointDescription = new ECFServiceEndpointDescriptionImpl( > localContainerID, serviceInfo); > } > >+ /* (non-Javadoc) >+ * @see org.osgi.service.discovery.DiscoveredServiceNotification#getServiceEndpointDescription() >+ */ > public ServiceEndpointDescription getServiceEndpointDescription() { > return serviceEndpointDescription; > } > >+ /* (non-Javadoc) >+ * @see org.osgi.service.discovery.DiscoveredServiceNotification#getType() >+ */ > public int getType() { > return type; > } >Index: src/org/eclipse/ecf/osgi/services/discovery/ServiceEndpointDescriptionImpl.java >=================================================================== >RCS file: src/org/eclipse/ecf/osgi/services/discovery/ServiceEndpointDescriptionImpl.java >diff -N src/org/eclipse/ecf/osgi/services/discovery/ServiceEndpointDescriptionImpl.java >--- src/org/eclipse/ecf/osgi/services/discovery/ServiceEndpointDescriptionImpl.java 5 Mar 2009 05:49:17 -0000 1.5 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,180 +0,0 @@ >-/******************************************************************************* >- * 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.osgi.services.discovery; >- >-import java.net.MalformedURLException; >-import java.net.URL; >-import java.util.*; >-import org.eclipse.ecf.core.identity.ID; >-import org.eclipse.ecf.discovery.IServiceInfo; >-import org.eclipse.ecf.discovery.IServiceProperties; >-import org.eclipse.ecf.discovery.identity.IServiceID; >-import org.eclipse.ecf.internal.osgi.services.discovery.ServicePropertyUtils; >-import org.osgi.service.discovery.ServiceEndpointDescription; >-import org.osgi.service.discovery.ServicePublication; >- >-public class ServiceEndpointDescriptionImpl implements >- ServiceEndpointDescription { >- >- private final ID discoveryContainerID; >- private final IServiceInfo serviceInfo; >- >- public ServiceEndpointDescriptionImpl(ID localContainerID, >- IServiceInfo serviceInfo) { >- this.discoveryContainerID = localContainerID; >- this.serviceInfo = serviceInfo; >- } >- >- public ID getLocalDiscoveryContainerID() { >- return discoveryContainerID; >- } >- >- public IServiceID getServiceID() { >- return this.serviceInfo.getServiceID(); >- } >- >- public String getEndpointID() { >- return ServicePropertyUtils.getStringProperty(serviceInfo >- .getServiceProperties(), >- ServicePublication.PROP_KEY_ENDPOINT_ID); >- } >- >- public String getEndpointInterfaceName(String interfaceName) { >- if (interfaceName == null) >- return null; >- String intfNames = serviceInfo.getServiceProperties() >- .getPropertyString( >- ServicePublication.PROP_KEY_ENDPOINT_INTERFACE_NAME); >- if (intfNames == null) >- return null; >- Collection c = ServicePropertyUtils >- .createCollectionFromString(intfNames); >- if (c == null) >- return null; >- // >- for (Iterator i = c.iterator(); i.hasNext();) { >- String intfName = (String) i.next(); >- if (intfName != null && intfName.startsWith(interfaceName)) { >- // return just endpointInterfaceName >- return intfName >- .substring( >- intfName.length() >- + ServicePropertyUtils.ENDPOINT_INTERFACE_NAME_SEPARATOR >- .length()).trim(); >- } >- } >- return null; >- } >- >- public URL getLocation() { >- String urlExternalForm = ServicePropertyUtils.getStringProperty( >- serviceInfo.getServiceProperties(), >- ServicePublication.PROP_KEY_ENDPOINT_LOCATION); >- if (urlExternalForm == null) >- return null; >- URL url = null; >- try { >- url = new URL(urlExternalForm); >- } catch (MalformedURLException e) { >- // XXX log to error >- } >- return url; >- } >- >- public Map getProperties() { >- Map result = new HashMap(); >- IServiceProperties serviceProperties = serviceInfo >- .getServiceProperties(); >- if (serviceProperties != null) { >- for (Enumeration e = serviceProperties.getPropertyNames(); e >- .hasMoreElements();) { >- String propName = (String) e.nextElement(); >- Object val = serviceProperties.getProperty(propName); >- result.put(propName, val); >- } >- } >- return result; >- } >- >- public Object getProperty(String key) { >- IServiceProperties serviceProperties = serviceInfo >- .getServiceProperties(); >- if (key == null) >- return null; >- return serviceProperties.getProperty(key); >- } >- >- public byte[] getPropertyBytes(String key) { >- IServiceProperties serviceProperties = serviceInfo >- .getServiceProperties(); >- if (key == null) >- return null; >- return serviceProperties.getPropertyBytes(key); >- } >- >- public Collection getPropertyKeys() { >- IServiceProperties serviceProperties = serviceInfo >- .getServiceProperties(); >- List result = new ArrayList(); >- for (Enumeration e = serviceProperties.getPropertyNames(); e >- .hasMoreElements();) { >- String name = (String) e.nextElement(); >- result.add(name); >- } >- return result; >- } >- >- public Collection getProvidedInterfaces() { >- String providedInterfacesStr = serviceInfo.getServiceProperties() >- .getPropertyString( >- ServicePublication.PROP_KEY_SERVICE_INTERFACE_NAME); >- return ServicePropertyUtils >- .createCollectionFromString(providedInterfacesStr); >- } >- >- public String getVersion(String interfaceName) { >- String intfNames = serviceInfo.getServiceProperties() >- .getPropertyString( >- ServicePublication.PROP_KEY_SERVICE_INTERFACE_VERSION); >- if (intfNames == null) >- return null; >- Collection c = ServicePropertyUtils >- .createCollectionFromString(intfNames); >- if (c == null) >- return null; >- // >- for (Iterator i = c.iterator(); i.hasNext();) { >- String intfName = (String) i.next(); >- if (intfName != null && intfName.startsWith(interfaceName)) { >- // return just version string >- return intfName >- .substring( >- intfName.length() >- + ServicePropertyUtils.INTERFACE_VERSION_SEPARATOR >- .length()).trim(); >- } >- } >- return null; >- } >- >- public String toString() { >- StringBuffer sb = new StringBuffer("ServiceEndpointDescriptionImpl["); //$NON-NLS-1$ >- sb.append("localContainerID=" + getLocalDiscoveryContainerID()); //$NON-NLS-1$ >- sb.append(";providedinterfaces=").append(getProvidedInterfaces()); //$NON-NLS-1$ >- sb.append(";location=").append(getLocation()); //$NON-NLS-1$ >- sb.append(";props=").append(getProperties()).append("]"); //$NON-NLS-1$ //$NON-NLS-2$ >- return sb.toString(); >- } >- >- public String getPropertyString(String propKeyEndpointContainerid) { >- return ServicePropertyUtils.getStringProperty(serviceInfo >- .getServiceProperties(), propKeyEndpointContainerid); >- } >-} >Index: src/org/eclipse/ecf/internal/osgi/services/discovery/ECFServiceEndpointDescriptionImpl.java >=================================================================== >RCS file: src/org/eclipse/ecf/internal/osgi/services/discovery/ECFServiceEndpointDescriptionImpl.java >diff -N src/org/eclipse/ecf/internal/osgi/services/discovery/ECFServiceEndpointDescriptionImpl.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/ecf/internal/osgi/services/discovery/ECFServiceEndpointDescriptionImpl.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,104 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Markus Alexander Kuppe. >+ * 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: >+ * Markus Alexander Kuppe (ecf-dev_eclipse.org <at> lemmster <dot> de) - initial API and implementation >+ ******************************************************************************/ >+package org.eclipse.ecf.internal.osgi.services.discovery; >+ >+import org.eclipse.ecf.discovery.ServiceProperties; >+ >+import org.eclipse.ecf.core.identity.IDFactory; >+import org.eclipse.ecf.discovery.IServiceProperties; >+import org.eclipse.ecf.discovery.identity.IServiceID; >+import org.eclipse.ecf.osgi.services.discovery.ECFServicePublication; >+ >+import org.eclipse.ecf.core.identity.IDCreateException; >+ >+import org.eclipse.ecf.core.identity.ID; >+import org.eclipse.ecf.discovery.IServiceInfo; >+ >+import org.eclipse.ecf.osgi.services.discovery.ECFServiceEndpointDescription; >+ >+public class ECFServiceEndpointDescriptionImpl extends >+ ECFServiceEndpointDescription { >+ >+ private static final long DEFAULT_FUTURE_TIMEOUT = new Long(System >+ .getProperty("ecf.rs.lookup.timeout", new Long(30000).toString())) >+ .longValue(); >+ >+ private final ID endpointId; >+ private final IServiceID serviceId; >+ >+ public ECFServiceEndpointDescriptionImpl(ID localContainerID, >+ IServiceInfo serviceInfo) { >+ super(localContainerID, ((ServiceProperties)serviceInfo.getServiceProperties()).asProperties()); >+ this.serviceId = serviceInfo.getServiceID(); >+ >+ // create the endpoint id >+ IServiceProperties serviceProperties = serviceInfo.getServiceProperties(); >+ final byte[] endpointBytes = >+ serviceProperties.getPropertyBytes(ECFServicePublication.PROP_KEY_ENDPOINT_CONTAINERID); >+ if (endpointBytes == null) >+ throw new IDCreateException( >+ "ServiceEndpointDescription endpointBytes cannot be null"); >+ final String endpointStr = new String(endpointBytes); >+ final String namespaceStr = >+ serviceProperties.getPropertyString(ECFServicePublication.PROP_KEY_ENDPOINT_CONTAINERID_NAMESPACE); >+ if (namespaceStr == null) { >+ throw new IDCreateException( >+ "ServiceEndpointDescription namespaceStr cannot be null"); >+ } >+ endpointId = IDFactory.getDefault().createID(namespaceStr, >+ endpointStr); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ecf.osgi.services.discovery.ECFServiceEndpointDescription#getECFEndpointID() >+ */ >+ public ID getECFEndpointID() throws IDCreateException { >+ return endpointId; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ecf.osgi.services.discovery.ECFServiceEndpointDescription#getFutureTimeout() >+ */ >+ public long getFutureTimeout() { >+ //TODO get from service properties? >+ return DEFAULT_FUTURE_TIMEOUT; >+ } >+ >+ /* (non-Javadoc) >+ * @see java.lang.Object#hashCode() >+ */ >+ public int hashCode() { >+ final int prime = 31; >+ int result = 1; >+ result = prime * result >+ + ((serviceId == null) ? 0 : serviceId.hashCode()); >+ return result; >+ } >+ >+ /* (non-Javadoc) >+ * @see java.lang.Object#equals(java.lang.Object) >+ */ >+ public boolean equals(Object obj) { >+ if (this == obj) >+ return true; >+ if (obj == null) >+ return false; >+ if (getClass() != obj.getClass()) >+ return false; >+ ECFServiceEndpointDescriptionImpl other = (ECFServiceEndpointDescriptionImpl) obj; >+ if (serviceId == null) { >+ if (other.serviceId != null) >+ return false; >+ } else if (!serviceId.equals(other.serviceId)) >+ return false; >+ return true; >+ } >+} >Index: src/org/eclipse/ecf/osgi/services/discovery/ECFServiceEndpointDescription.java >=================================================================== >RCS file: src/org/eclipse/ecf/osgi/services/discovery/ECFServiceEndpointDescription.java >diff -N src/org/eclipse/ecf/osgi/services/discovery/ECFServiceEndpointDescription.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/ecf/osgi/services/discovery/ECFServiceEndpointDescription.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,163 @@ >+/******************************************************************************* >+ * 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.osgi.services.discovery; >+ >+import java.net.MalformedURLException; >+import java.net.URL; >+import java.util.*; >+import org.eclipse.ecf.core.identity.ID; >+import org.eclipse.ecf.internal.osgi.services.discovery.ServicePropertyUtils; >+import org.osgi.service.discovery.ServiceEndpointDescription; >+import org.osgi.service.discovery.ServicePublication; >+ >+public abstract class ECFServiceEndpointDescription implements >+ ServiceEndpointDescription { >+ private final ID discoveryContainerID; >+ private final Map serviceProperties; >+ >+ public ECFServiceEndpointDescription(ID localContainerID, >+ Map properties) { >+ this.discoveryContainerID = localContainerID; >+ this.serviceProperties = properties; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.osgi.service.discovery.ServiceEndpointDescription#getEndpointID() >+ */ >+ public String getEndpointID() { >+ Object o = serviceProperties.get( >+ ServicePublication.PROP_KEY_ENDPOINT_ID); >+ if (o instanceof String) { >+ return (String) o; >+ } >+ return null; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.osgi.service.discovery.ServiceEndpointDescription#getEndpointInterfaceName(java.lang.String) >+ */ >+ public String getEndpointInterfaceName(String interfaceName) { >+ if (interfaceName == null) >+ return null; >+ Object o = serviceProperties.get( >+ ServicePublication.PROP_KEY_ENDPOINT_INTERFACE_NAME); >+ if (o == null || !(o instanceof String)) { >+ return null; >+ } >+ String intfNames = (String) o; >+ Collection c = ServicePropertyUtils.createCollectionFromString(intfNames); >+ if (c == null) >+ return null; >+ for (Iterator i = c.iterator(); i.hasNext();) { >+ String intfName = (String) i.next(); >+ if (intfName != null && intfName.startsWith(interfaceName)) { >+ // return just endpointInterfaceName >+ return intfName >+ .substring( >+ intfName.length() >+ + ServicePropertyUtils.ENDPOINT_INTERFACE_NAME_SEPARATOR >+ .length()).trim(); >+ } >+ } >+ return null; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.osgi.service.discovery.ServiceEndpointDescription#getLocation() >+ */ >+ public URL getLocation() { >+ Object o = serviceProperties.get( >+ ServicePublication.PROP_KEY_ENDPOINT_LOCATION); >+ if (o == null || !(o instanceof String)) { >+ return null; >+ } >+ String urlExternalForm = (String) o; >+ URL url = null; >+ try { >+ url = new URL(urlExternalForm); >+ } catch (MalformedURLException e) { >+ // XXX log to error >+ } >+ return url; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.osgi.service.discovery.ServiceEndpointDescription#getProperties() >+ */ >+ public Map getProperties() { >+ return serviceProperties; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.osgi.service.discovery.ServiceEndpointDescription#getProperty(java.lang.String) >+ */ >+ public Object getProperty(String key) { >+ return serviceProperties.get(key); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.osgi.service.discovery.ServiceEndpointDescription#getPropertyKeys() >+ */ >+ public Collection getPropertyKeys() { >+ return serviceProperties.keySet(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.osgi.service.discovery.ServiceEndpointDescription#getProvidedInterfaces() >+ */ >+ public Collection getProvidedInterfaces() { >+ Object o = serviceProperties >+ .get( >+ ServicePublication.PROP_KEY_SERVICE_INTERFACE_NAME); >+ if(o == null || !(o instanceof String)) { >+ return null; >+ } >+ String providedInterfacesStr = (String) o; >+ return ServicePropertyUtils.createCollectionFromString(providedInterfacesStr); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.osgi.service.discovery.ServiceEndpointDescription#getVersion(java.lang.String) >+ */ >+ public String getVersion(String interfaceName) { >+ Collection c = getProvidedInterfaces(); >+ if (c == null) { >+ return null; >+ } >+ for (Iterator i = c.iterator(); i.hasNext();) { >+ String intfName = (String) i.next(); >+ if (intfName != null && intfName.startsWith(interfaceName)) { >+ // return just version string >+ return intfName >+ .substring( >+ intfName.length() >+ + ServicePropertyUtils.INTERFACE_VERSION_SEPARATOR >+ .length()).trim(); >+ } >+ } >+ return null; >+ } >+ >+ /* (non-Javadoc) >+ * @see java.lang.Object#toString() >+ */ >+ public String toString() { >+ StringBuffer sb = new StringBuffer("ServiceEndpointDescriptionImpl["); //$NON-NLS-1$ >+ sb.append("localContainerID=" + discoveryContainerID); //$NON-NLS-1$ >+ sb.append(";providedinterfaces=").append(getProvidedInterfaces()); //$NON-NLS-1$ >+ sb.append(";location=").append(getLocation()); //$NON-NLS-1$ >+ sb.append(";props=").append(getProperties()).append("]"); //$NON-NLS-1$ //$NON-NLS-2$ >+ return sb.toString(); >+ } >+ >+ public abstract ID getECFEndpointID(); >+ >+ public abstract long getFutureTimeout(); >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 249240
:
123177
|
126410
|
126703
| 128704 |
128705
|
131191
|
134797