jadex.bridge.service.component.RequiredServicesFeatureAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-platform-bridge Show documentation
Show all versions of jadex-platform-bridge Show documentation
Jadex bridge is a base package for kernels and platforms, i.e., it is used by both and provides commonly used interfaces and classes for active components and their management.
package jadex.bridge.service.component;
import java.util.Collection;
import jadex.bridge.service.IService;
import jadex.bridge.service.IServiceIdentifier;
import jadex.bridge.service.RequiredServiceInfo;
import jadex.bridge.service.search.ServiceQuery;
import jadex.commons.future.IFuture;
import jadex.commons.future.ISubscriptionIntermediateFuture;
import jadex.commons.future.ITerminableIntermediateFuture;
/**
* Adapter for the required services feature.
*/
public class RequiredServicesFeatureAdapter implements IRequiredServicesFeature
{
//-------- attributes --------
/** The delegate. */
protected IRequiredServicesFeature delegate;
//-------- constructors --------
/**
* Create a new adapter.
*/
public RequiredServicesFeatureAdapter(IRequiredServicesFeature delegate)
{
this.delegate = delegate;
}
//-------- accessors for declared services --------
/**
* Resolve a declared required service of a given name.
* Asynchronous method for locally as well as remotely available services.
* @param name The service name.
* @return The service.
*/
public IFuture getService(String name)
{
return delegate.getService(rename(name));
}
/**
* Resolve a required service of a given type.
* Synchronous method only for locally available services.
* @param type The service type.
* @return The service.
*/
public T getLocalService0(Class type)
{
return delegate.getLocalService0(type);
}
/**
* Resolve a required service of a given type.
* Asynchronous method for locally as well as remotely available services.
* @param type The service type.
* @return The service.
*/
public IFuture getService(Class type)
{
return delegate.getService(type);
}
/**
* Resolve a required services of a given name.
* Asynchronous method for locally as well as remotely available services.
* @param name The services name.
* @return Each service as an intermediate result and a collection of services as final result.
*/
public ITerminableIntermediateFuture getServices(String name)
{
return delegate.getServices(rename(name));
}
/**
* Resolve a required services of a given type.
* Asynchronous method for locally as well as remotely available services.
* @param type The services type.
* @return Each service as an intermediate result and a collection of services as final result.
*/
public ITerminableIntermediateFuture getServices(Class type)
{
return delegate.getServices(type);
}
/**
* Resolve a declared required service of a given name.
* Synchronous method only for locally available services.
* @param name The service name.
* @return The service.
*/
public T getLocalService(String name)
{
return delegate.getLocalService(rename(name));
}
/**
* Resolve a required service of a given type.
* Synchronous method only for locally available services.
* @param type The service type.
* @return The service.
*/
public T getLocalService(Class type)
{
return delegate.getLocalService(type);
}
/**
* Resolve a required services of a given name.
* Synchronous method only for locally available services.
* @param name The services name.
* @return Each service as an intermediate result and a collection of services as final result.
*/
public Collection getLocalServices(String name)
{
return delegate.getLocalServices(rename(name));
}
/**
* Resolve a required services of a given type.
* Synchronous method only for locally available services.
* @param type The services type.
* @return Each service as an intermediate result and a collection of services as final result.
*/
public Collection getLocalServices(Class type)
{
return delegate.getLocalServices(type);
}
//-------- methods for searching --------
/**
* Search for matching services and provide first result.
* @param query The search query.
* @return Future providing the corresponding service or ServiceNotFoundException when not found.
*/
public IFuture searchService(ServiceQuery query)
{
return delegate.searchService(query);
}
/**
* Search for matching services and provide first result.
* Synchronous method only for locally available services.
* @param query The search query.
* @return Future providing the corresponding service or ServiceNotFoundException when not found.
*/
public T getLocalService(ServiceQuery query)
{
return delegate.getLocalService(query);
}
/**
* Search for all matching services.
* @param query The search query.
* @return Future providing the corresponding services or ServiceNotFoundException when not found.
*/
public ITerminableIntermediateFuture searchServices(ServiceQuery query)
{
return delegate.searchServices(query);
}
/**
* Search for all matching services.
* Synchronous method only for locally available services.
* @param query The search query.
* @return Future providing the corresponding services or ServiceNotFoundException when not found.
*/
public Collection getLocalServices(ServiceQuery query)
{
return delegate.getLocalServices(query);
}
/**
* Performs a sustained search for a service. Attempts to find a service
* for a maximum duration until timeout occurs.
*
* @param query The search query.
* @param timeout Maximum time period to search.
* @return Service matching the query, exception if service is not found.
*/
public IFuture searchService(ServiceQuery query, long timeout)
{
return delegate.searchService(query, timeout);
}
//-------- query methods --------
/**
* Add a query for a declared required service.
* Continuously searches for matching services.
* @param name The name of the required service declaration.
* @return Future providing the corresponding services as intermediate results.
*/
public ISubscriptionIntermediateFuture addQuery(String name)
{
return delegate.addQuery(rename(name));
}
/**
* Add a query for a declared required service.
* Continuously searches for matching services.
* @param type The type of the required service declaration.
* @return Future providing the corresponding services as intermediate results.
*/
public ISubscriptionIntermediateFuture addQuery(Class type)
{
return delegate.addQuery(type);
}
/**
* Add a service query.
* Continuously searches for matching services.
* @param query The search query.
* @return Future providing the corresponding service or ServiceNotFoundException when not found.
*/
public ISubscriptionIntermediateFuture addQuery(ServiceQuery query)
{
return delegate.addQuery(query);
}
/**
* Add a service query.
* Continuously searches for matching services.
* @param query The search query.
* @return Future providing the corresponding service or ServiceNotFoundException when not found.
*/
public ISubscriptionIntermediateFuture addQuery(ServiceQuery query, long timeout)
{
return delegate.addQuery(query, timeout);
}
/**
* Create the user-facing object from the received search or query result.
* Result may be service object, service identifier (local or remote), or event.
* User object is either event or service (with or without required proxy).
*/
public IService getServiceProxy(IServiceIdentifier sid, RequiredServiceInfo info)
{
return delegate.getServiceProxy(sid, info);
}
/**
* Get a service query for a required service info (as defined in the agent under that name).
* @param name The name.
* @return The service query.
*/
public ServiceQuery> getServiceQuery(String name)
{
return delegate.getServiceQuery(name);
}
//-------- template methods --------
/**
* Rename if necessary.
*/
public String rename(String name)
{
return name;
}
}