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

jadex.base.service.remote.commands.AbstractRemoteCommand Maven / Gradle / Ivy

Go to download

The Jadex platform base package contains functionality useful for constructing platforms.

The newest version!
package jadex.base.service.remote.commands;

import java.util.Map;

import jadex.base.service.remote.IRemoteCommand;
import jadex.base.service.remote.RemoteReferenceModule;
import jadex.bridge.IComponentIdentifier;
import jadex.bridge.IInternalAccess;
import jadex.bridge.service.IServiceIdentifier;
import jadex.bridge.service.RequiredServiceInfo;
import jadex.bridge.service.search.ServiceNotFoundException;
import jadex.bridge.service.types.security.DefaultAuthorizable;
import jadex.bridge.service.types.security.ISecurityService;
import jadex.commons.future.DelegationResultListener;
import jadex.commons.future.Future;
import jadex.commons.future.IFuture;
import jadex.commons.future.IResultListener;

/**
 *  Default base class for remote commands.
 */
public abstract class AbstractRemoteCommand	extends DefaultAuthorizable	implements IRemoteCommand
{
	/** The receiver (for processing the command in rmipreprocessor, will not be transferred). */
	protected IComponentIdentifier receiver;
	
	/** The non-functional properties. */
	protected Map nonfunc;
	
	//-------- constructors --------
	
	/**
	 *  Bean constructor.
	 */
	public AbstractRemoteCommand()
	{
	}
	
	/**
	 *  Bean constructor.
	 */
	public AbstractRemoteCommand(Map nonfunc)
	{
		this.nonfunc = nonfunc;
	}
	
	//-------- methods --------
	
	/**
	 *  Preprocess command and replace if they are remote references.
	 */
	public IFuture	preprocessCommand(IInternalAccess component, RemoteReferenceModule rrm, final IComponentIdentifier target)
	{
		// Hack needed for rmi preprocessor
		this.receiver = target;
		
		final Future	ret	= new Future();
		component.getServiceContainer().searchService(ISecurityService.class, RequiredServiceInfo.SCOPE_PLATFORM)
			.addResultListener(new IResultListener()
		{
			public void resultAvailable(ISecurityService sec)
			{
				sec.preprocessRequest(AbstractRemoteCommand.this, target)
					.addResultListener(new DelegationResultListener(ret));
			}
			
			public void exceptionOccurred(Exception exception)
			{
				if(exception instanceof ServiceNotFoundException)
				{
					ret.setResult(null);
				}
				else
				{
					ret.setException(exception);
				}
			}
		});
		return ret;
	}
	
	/**
	 *  Post-process a received command before execution
	 *  for e.g. setting security level.
	 */
	public IFuture	postprocessCommand(IInternalAccess component, RemoteReferenceModule rrm, final IComponentIdentifier target)
	{
		return IFuture.DONE;
	}

	/**
	 *  Get the receiver (rms of other side).
	 *  @return the receiver.
	 */
	public IComponentIdentifier getReceiver()
	{
		return receiver;
	}
	
	/**
	 *  Get the sender component (if other than rms).
	 */
	public IComponentIdentifier getSender()
	{
		return null;
	}
	
	/**
	 *  Get the real receiver (other than rms).
	 *  @return the real receiver.
	 */
	public IComponentIdentifier getRealReceiver()
	{
		return null;
	}
	
	/**
	 *  The origin of the request.
	 *  May be used for blacklist/whitelist authentication.
	 */
	public IComponentIdentifier	getOrigin()
	{
		return getSender();
	}
	
	/**
	 *  Get the non-functional properties of the call.
	 *  @return The non-functional properties of the call.
	 */
	public Map getNonFunctionalProperties()
	{
		return nonfunc;
	}
	
	/**
	 *  Get the non-functional properties of the call.
	 */
	public void setNonFunctionalProperties(Map nonfunc)
	{
		this.nonfunc = nonfunc;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy