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

jadex.bridge.component.impl.remotecommands.RemoteResultCommand 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.bridge.component.impl.remotecommands;

import java.util.Map;

import jadex.bridge.IInternalAccess;
import jadex.bridge.service.types.security.ISecurityInfo;
import jadex.commons.future.Future;
import jadex.commons.future.IFuture;

/**
 * Command for results.
 */
public class RemoteResultCommand	extends AbstractResultCommand
{
	/** The result. */
	protected T result;

	/** The exception. */
	protected Exception exception;
	
	/**
	 *  Create the command.
	 */
	public RemoteResultCommand()
	{
	}
	
	/**
	 *  Create the command.
	 */
	public RemoteResultCommand(T result, Map nonfunc)
	{
		super(nonfunc);
		setResult(result);
	}
	
	/**
	 *  Create the command.
	 */
	public RemoteResultCommand(Exception exception, Map nonfunc)
	{
		super(nonfunc);
		this.exception = exception;
	}
	
	/**
	 *  Execute a command.
	 *  @param access The agent to run the command on.
	 *  @param future Future of the active conversation.
	 *  @param secinf The established security level to decide if the command is allowed.
	 */
	@SuppressWarnings("unchecked")
	public void	doExecute(IInternalAccess access, IFuture future, ISecurityInfo secinf)
	{
//		if(result!=null)// && result.toString().indexOf("rt")!=-1)
//			System.out.println("exe result: "+result.getClass()+" "+result+" "+access.getId());
		
		if(exception!=null)
			((Future)future).setException(exception);
		else
			((Future)future).setResult(result);
	}
	
	/**
	 *  Get the result.
	 *  @return the result.
	 */
	public T getResult()
	{
		return result;
	}

	/**
	 *  Set the result.
	 *  @param result The result to set.
	 */
	public void setResult(T result)
	{
//		if(result!=null && result.getClass().getName().indexOf("Connection")!=-1)
//			System.out.println("rescom with: "+result);
		
//		if(result!=null)
//			System.out.println("created rrc: "+result.getClass()+" "+result);
//		Thread.dumpStack();
		this.result = result;
	}
	
	/**
	 *  Get the exception.
	 *  @return The exception.
	 */
	public Exception getException()
	{
		return exception;
	}

	/**
	 *  Set the exception.
	 *  @param exception The exception to set.
	 */
	public void setException(Exception exception)
	{
		this.exception = exception;
	}
	
	/**
	 *  Get a string representation.
	 */
	public String	toString()
	{
		return "RemoteResultCommand("+(exception!=null?"ex: "+exception:result)+")";
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy