jadex.base.test.impl.SharedService 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.base.test.impl;
import jadex.bridge.IComponentIdentifier;
import jadex.bridge.service.BasicService;
import jadex.commons.future.IFuture;
/**
* Helper class to allow sharing a service across platforms in same VM.
*/
public abstract class SharedService extends BasicService
{
/** The factory from which this impl was created. */
protected SharedServiceFactory factory;
/**
* Get the instance.
*/
public SharedService(IComponentIdentifier provider, Class type, SharedServiceFactory factory)
{
super(provider, type, null);
this.factory = factory;
}
//-------- accessor methods --------
/**
* Get the shared instance to delegate calls to.
*/
public T getInstance()
{
return factory.instance;
}
//-------- BasicService methods --------
@Override
public IFuture startService()
{
// System.out.println("Starting shared service wrapper: "+this);
return super.startService().thenCompose(nix -> factory.startService());
}
@Override
public IFuture shutdownService()
{
// System.out.println("Terminating shared service wrapper: "+this);
return super.shutdownService().thenCompose(nix -> factory.shutdownService());
}
}