All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jadex.base.test.impl.SharedService Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 4.0.267
Show newest version
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());
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy