org.eclipse.ecf.provider.discovery
Class SingletonDiscoveryContainer

java.lang.Object
  extended by org.eclipse.ecf.provider.discovery.SingletonDiscoveryContainer
All Implemented Interfaces:
org.eclipse.core.runtime.IAdaptable, IContainer, IIdentifiable, IDiscoveryAdvertiser, IDiscoveryContainerAdapter, IDiscoveryLocator

public class SingletonDiscoveryContainer
extends java.lang.Object
implements IDiscoveryContainerAdapter, IContainer


Field Summary
 
Fields inherited from interface org.eclipse.ecf.discovery.IDiscoveryLocator
CONTAINER_NAME
 
Fields inherited from interface org.eclipse.ecf.discovery.IDiscoveryAdvertiser
CONTAINER_NAME
 
Constructor Summary
SingletonDiscoveryContainer(IContainer container)
           
 
Method Summary
 void addListener(IContainerListener listener)
          Add listener to IContainer.
 void addServiceListener(IServiceListener listener)
          Add a service listener.
 void addServiceListener(IServiceTypeID type, IServiceListener listener)
          Add a service listener.
 void addServiceTypeListener(IServiceTypeListener listener)
          Add a service type listener.
 void connect(ID targetID, IConnectContext connectContext)
          Connect to a target remote process or process group.
 void disconnect()
          Disconnect.
 void dispose()
          Dispose this IContainer instance.
 java.lang.Object getAdapter(java.lang.Class adapter)
          This specialization of IAdaptable.getAdapter() returns additional services supported by this container.
 org.eclipse.equinox.concurrent.future.IFuture getAsyncServiceInfo(IServiceID aServiceID)
          Asynchronously retrieve info about the service
 org.eclipse.equinox.concurrent.future.IFuture getAsyncServices()
          Asynchronously get service info about all known services
 org.eclipse.equinox.concurrent.future.IFuture getAsyncServices(IServiceTypeID aServiceTypeID)
          Asynchronously get service info about all known services of given service type
 org.eclipse.equinox.concurrent.future.IFuture getAsyncServiceTypes()
          Asynchronously get service info about all known services of given service type
 ID getConnectedID()
          Get the target ID that this container instance has connected to.
 Namespace getConnectNamespace()
          Get the Namespace for creating a targetID suitable for use as the first parameter in subsequent calls to IContainer.connect(ID, IConnectContext).
 ID getID()
          Return the ID for this 'identifiable' object.
 IServiceInfo getServiceInfo(IServiceID service)
          Synchronously retrieve info about the service
 IServiceInfo[] getServices()
          Synchronously get service info about all known services
 IServiceInfo[] getServices(IServiceTypeID type)
          Synchronously get service info about all known services of given service type
 Namespace getServicesNamespace()
          Get a Namespace for services associated with this discovery container adapter.
 IServiceTypeID[] getServiceTypes()
          Synchronously get service info about all known services of given service type
 IServiceInfo[] purgeCache()
          Purges the underlying IServiceInfo cache if available in the current provider
 void registerService(IServiceInfo serviceInfo)
          Register the given service.
 void removeListener(IContainerListener listener)
          Remove listener from IContainer.
 void removeServiceListener(IServiceListener listener)
          Remove a service listener.
 void removeServiceListener(IServiceTypeID type, IServiceListener listener)
          Remove a service listener.
 void removeServiceTypeListener(IServiceTypeListener listener)
          Remove a service type listener.
 void unregisterAllServices()
          Unregister all previously registered service.
 void unregisterService(IServiceInfo serviceInfo)
          Unregister a previously registered service defined by serviceInfo.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SingletonDiscoveryContainer

public SingletonDiscoveryContainer(IContainer container)
Parameters:
container -
Method Detail

connect

public void connect(ID targetID,
                    IConnectContext connectContext)
             throws ContainerConnectException
Description copied from interface: IContainer
Connect to a target remote process or process group. The target identified by the first parameter (targetID) is connected the implementation class. If authentication information is required, the required information is given via via the second parameter (connectContext). Callers note that depending upon the provider implementation this method may block. It is suggested that callers use a separate thread to call this method. This method provides an implementation independent way for container implementations to connect, authenticate, and communicate with a remote service or group of services. Providers are responsible for implementing this operation in a way appropriate to the given remote service (or group) via expected protocol.

Specified by:
connect in interface IContainer
Parameters:
targetID - the ID of the remote server or group to connect to. See IContainer.getConnectNamespace() for a explanation of the constraints upon this parameter.
connectContext - any required context to allow this container to authenticate. May be null if underlying provider does not have any authentication requirements for connection.
Throws:
ContainerConnectException - thrown if communication cannot be established with remote service. Causes can include network connection failure, authentication failure, server error, or if container is already connected.

disconnect

public void disconnect()
Description copied from interface: IContainer
Disconnect. This operation will disconnect the local container instance from any previously joined target or group. Subsequent calls to getConnectedID() will return null.

Specified by:
disconnect in interface IContainer

dispose

public void dispose()
Description copied from interface: IContainer
Dispose this IContainer instance. The container instance will be made inactive after the completion of this method and will be unavailable for subsequent usage.

Specified by:
dispose in interface IContainer

getAdapter

public java.lang.Object getAdapter(java.lang.Class adapter)
Description copied from interface: IContainer
This specialization of IAdaptable.getAdapter() returns additional services supported by this container. A container that supports additional services over and above the methods on IContainer should return them using this method. It is recommended that clients use this method rather than instanceof checks and downcasts to find out about the capabilities of a specific container.

Typically, after obtaining an IContainer, a client would use this method as a means to obtain a more meaningful interface to the container. This interface may or may not extend IContainer. For example, a client could use the following code to obtain an instance of ISharedObjectContainer:

 IContainer newContainer = ContainerFactory.createContainer(type);
 ISharedObjectContainer soContainer = (ISharedObjectContainer) newContainer
                .getAdapter(ISharedObjectContainer.class);
 if (soContainer == null)
        throw new ContainerCreateException(message);
 

Implementations of this method should delegate to IAdapterManager.loadAdapter() if the service cannot be provided directly to ensure extensibility by third-party plug-ins.

Specified by:
getAdapter in interface org.eclipse.core.runtime.IAdaptable
Specified by:
getAdapter in interface IContainer
Parameters:
adapter - the service type to look up
Returns:
the service instance castable to the given class, or null if this container does not support the given service

addServiceListener

public void addServiceListener(IServiceTypeID type,
                               IServiceListener listener)
Description copied from interface: IDiscoveryLocator
Add a service listener. The given listener will have its method called when a service with a type matching that specified by the first parameter is discovered.

Specified by:
addServiceListener in interface IDiscoveryLocator
Parameters:
type - String type to listen for. Must not be null. Must be formatted according to this specific IDiscoveryContainer
listener - IServiceListener to be notified. Must not be null .

addServiceTypeListener

public void addServiceTypeListener(IServiceTypeListener listener)
Description copied from interface: IDiscoveryLocator
Add a service type listener. The given listener will have its method called when a service type is discovered.

Specified by:
addServiceTypeListener in interface IDiscoveryLocator
Parameters:
listener - the listener to be notified. Must not be null.

getServiceInfo

public IServiceInfo getServiceInfo(IServiceID service)
Description copied from interface: IDiscoveryLocator
Synchronously retrieve info about the service

Specified by:
getServiceInfo in interface IDiscoveryLocator
Parameters:
service - IServiceID of the service to get info about. Must not be null.
Returns:
IServiceInfo the service info retrieved. null if no information retrievable.

getServices

public IServiceInfo[] getServices(IServiceTypeID type)
Description copied from interface: IDiscoveryLocator
Synchronously get service info about all known services of given service type

Specified by:
getServices in interface IDiscoveryLocator
Parameters:
type - IServiceTypeID defining the type of service we are interested in getting service info about. Must not be null
Returns:
IServiceInfo[] the resulting array of service info instances. Will not be null. May be of length 0.

getServicesNamespace

public Namespace getServicesNamespace()
Description copied from interface: IDiscoveryLocator
Get a Namespace for services associated with this discovery container adapter. The given Namespace may be used via IServiceIDFactory to create IServiceIDs rather than simple IDs. For example:
 IServiceID serviceID = ServiceIDFactory.getDefault().createServiceID(container.getServicesNamespace(),
                serviceType, serviceName);
 

Specified by:
getServicesNamespace in interface IDiscoveryAdvertiser
Specified by:
getServicesNamespace in interface IDiscoveryLocator
Returns:
Namespace for creating service IDs. Will not be null .

registerService

public void registerService(IServiceInfo serviceInfo)
Description copied from interface: IDiscoveryAdvertiser
Register the given service. This publishes the service defined by the serviceInfo to the underlying publishing mechanism

Specified by:
registerService in interface IDiscoveryAdvertiser
Parameters:
serviceInfo - IServiceInfo of the service to be published. Must not be null.

removeServiceListener

public void removeServiceListener(IServiceTypeID type,
                                  IServiceListener listener)
Description copied from interface: IDiscoveryLocator
Remove a service listener. Remove the listener associated with the type specified by the first parameter.

Specified by:
removeServiceListener in interface IDiscoveryLocator
Parameters:
type - String of the desired type to remove the listener. Must not be null. Must be formatted according to this specific IDiscoveryContainer
listener - IServiceListener listener to be removed. Must not be null.

removeServiceTypeListener

public void removeServiceTypeListener(IServiceTypeListener listener)
Description copied from interface: IDiscoveryLocator
Remove a service type listener. Remove the type listener.

Specified by:
removeServiceTypeListener in interface IDiscoveryLocator
Parameters:
listener - IServiceTypeListener to be removed. Must not be null.

unregisterService

public void unregisterService(IServiceInfo serviceInfo)
Description copied from interface: IDiscoveryAdvertiser
Unregister a previously registered service defined by serviceInfo.

Specified by:
unregisterService in interface IDiscoveryAdvertiser
Parameters:
serviceInfo - IServiceInfo defining the service to unregister. Must not be null.

addListener

public void addListener(IContainerListener listener)
Description copied from interface: IContainer
Add listener to IContainer. The listener's handleEvent method will be synchronously called when container methods are called. Minimally, the events delivered to the listener are as follows
container action Event
connect start IContainerConnectingEvent
connect complete IContainerConnectedEvent
disconnect start IContainerDisconnectingEvent
disconnect complete IContainerDisconnectedEvent

Specified by:
addListener in interface IContainer
Parameters:
listener - the IContainerListener to add

getConnectedID

public ID getConnectedID()
Description copied from interface: IContainer
Get the target ID that this container instance has connected to. Returns null if not connected.

Specified by:
getConnectedID in interface IContainer
Returns:
ID of the target we are connected to. Returns null if container not connected.

getConnectNamespace

public Namespace getConnectNamespace()
Description copied from interface: IContainer
Get the Namespace for creating a targetID suitable for use as the first parameter in subsequent calls to IContainer.connect(ID, IConnectContext). If this method returns null, then it means that null is expected as a valid parameter in subsequent calls to IContainer.connect(ID, IConnectContext). If this method returns a non-null Namespace, then the targetID parameter in IContainer.connect(ID, IConnectContext) must be non-null instance created of the returned Namespace.

Specified by:
getConnectNamespace in interface IContainer
Returns:
Namespace the namespace associated with subsequent calls to IContainer.connect(ID, IConnectContext). If null, then the targetID instances passed to IContainer.connect(ID, IConnectContext) may be null. If not null, then targetID instances passed to IContainer.connect(ID, IConnectContext) must be instances of the returned Namespace.

getID

public ID getID()
Description copied from interface: IIdentifiable
Return the ID for this 'identifiable' object. The returned ID should be unique within its namespace. May return null.

Specified by:
getID in interface IIdentifiable
Returns:
the ID for this identifiable object. May return null.

removeListener

public void removeListener(IContainerListener listener)
Description copied from interface: IContainer
Remove listener from IContainer.

Specified by:
removeListener in interface IContainer
Parameters:
listener - the IContainerListener to remove

getServices

public IServiceInfo[] getServices()
Description copied from interface: IDiscoveryLocator
Synchronously get service info about all known services

Specified by:
getServices in interface IDiscoveryLocator
Returns:
IServiceInfo[] the resulting array of service info instances. Will not be null. May be of length 0.

getServiceTypes

public IServiceTypeID[] getServiceTypes()
Description copied from interface: IDiscoveryLocator
Synchronously get service info about all known services of given service type

Specified by:
getServiceTypes in interface IDiscoveryLocator
Returns:
IServiceTypeID[] the resulting array of service type IDs. Will not be null. May be of length 0.

addServiceListener

public void addServiceListener(IServiceListener listener)
Description copied from interface: IDiscoveryLocator
Add a service listener. The given listener will have its method called when a service is discovered.

Specified by:
addServiceListener in interface IDiscoveryLocator
Parameters:
listener - IServiceListener to be notified. Must not be null .

removeServiceListener

public void removeServiceListener(IServiceListener listener)
Description copied from interface: IDiscoveryLocator
Remove a service listener. Remove the listener from this container

Specified by:
removeServiceListener in interface IDiscoveryLocator
Parameters:
listener - IServiceListener listener to be removed. Must not be null.

purgeCache

public IServiceInfo[] purgeCache()
Description copied from interface: IDiscoveryLocator
Purges the underlying IServiceInfo cache if available in the current provider

Specified by:
purgeCache in interface IDiscoveryLocator
Returns:
The previous cache content

getAsyncServiceInfo

public org.eclipse.equinox.concurrent.future.IFuture getAsyncServiceInfo(IServiceID aServiceID)
Description copied from interface: IDiscoveryLocator
Asynchronously retrieve info about the service

Specified by:
getAsyncServiceInfo in interface IDiscoveryLocator
Parameters:
aServiceID - IServiceID of the service to get info about. Must not be null.
Returns:
IFuture a future status wrapping an IServiceInfo or null if no information retrievable.

getAsyncServiceTypes

public org.eclipse.equinox.concurrent.future.IFuture getAsyncServiceTypes()
Description copied from interface: IDiscoveryLocator
Asynchronously get service info about all known services of given service type

Specified by:
getAsyncServiceTypes in interface IDiscoveryLocator
Returns:
IFuture wrapping an IServiceTypeID[]. The resulting array of service type IDs will not be null. May be of length 0.

getAsyncServices

public org.eclipse.equinox.concurrent.future.IFuture getAsyncServices()
Description copied from interface: IDiscoveryLocator
Asynchronously get service info about all known services

Specified by:
getAsyncServices in interface IDiscoveryLocator
Returns:
IFuture wrapping an IServiceTypeID[]. The resulting array of service type IDs will not be null. May be of length 0.

getAsyncServices

public org.eclipse.equinox.concurrent.future.IFuture getAsyncServices(IServiceTypeID aServiceTypeID)
Description copied from interface: IDiscoveryLocator
Asynchronously get service info about all known services of given service type

Specified by:
getAsyncServices in interface IDiscoveryLocator
Parameters:
aServiceTypeID - IServiceTypeID defining the type of service we are interested in getting service info about. Must not be null
Returns:
IFuture wrapping an IServiceTypeID[]. The resulting array of service type IDs will not be null. May be of length 0.

unregisterAllServices

public void unregisterAllServices()
Description copied from interface: IDiscoveryAdvertiser
Unregister all previously registered service.

Specified by:
unregisterAllServices in interface IDiscoveryAdvertiser