jadex.base.service.remote.commands.RemoteGetExternalAccessCommand Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-platform-base Show documentation
Show all versions of jadex-platform-base Show documentation
The Jadex platform base package contains
functionality useful for constructing platforms.
The newest version!
package jadex.base.service.remote.commands;
import jadex.base.service.remote.IRemoteCommand;
import jadex.base.service.remote.RemoteServiceManagementService;
import jadex.bridge.IComponentIdentifier;
import jadex.bridge.IExternalAccess;
import jadex.bridge.service.annotation.Security;
import jadex.bridge.service.search.SServiceProvider;
import jadex.bridge.service.types.cms.IComponentManagementService;
import jadex.commons.future.IIntermediateFuture;
import jadex.commons.future.IResultListener;
import jadex.commons.future.IntermediateFuture;
import jadex.micro.IMicroExternalAccess;
/**
* Command for getting a remote external access.
*/
public class RemoteGetExternalAccessCommand extends AbstractRemoteCommand
{
//-------- attributes --------
/** The providerid (i.e. the component to start with searching). */
protected IComponentIdentifier cid;
/** The callid. */
protected String callid;
//-------- constructors --------
/**
* Create a new remote search command.
*/
public RemoteGetExternalAccessCommand()
{
}
/**
* Create a new remote search command.
*/
public RemoteGetExternalAccessCommand(IComponentIdentifier cid, String callid)
{
this.cid = cid;
this.callid = callid;
}
//-------- methods --------
/**
* Get the security level of the request.
*/
public String getSecurityLevel()
{
// Todo: customize security levels for external accesses?
// Specify security level at component start!?
return Security.PASSWORD;
}
/**
* Execute the command.
* @param lrms The local remote management service.
* @return An optional result command that will be
* sent back to the command origin.
*/
public IIntermediateFuture execute(final IMicroExternalAccess component, RemoteServiceManagementService rsms)
{
final IntermediateFuture ret = new IntermediateFuture();
// fetch component via provider/component id
final IComponentIdentifier compid = cid!=null?
(IComponentIdentifier)cid: component.getComponentIdentifier();
SServiceProvider.getServiceUpwards(component.getServiceProvider(), IComponentManagementService.class)
.addResultListener(new IResultListener()
// .addResultListener(component.createResultListener(new IResultListener()
{
public void resultAvailable(IComponentManagementService cms)
{
// IComponentManagementService cms = (IComponentManagementService)result;
cms.getExternalAccess(compid).addResultListener(new IResultListener()
{
public void resultAvailable(IExternalAccess exta)
{
// IExternalAccess exta = (IExternalAccess)result;
// ProxyInfo pi = RemoteServiceManagementService.getProxyInfo(component.getComponentIdentifier(), cid, exta);
// ret.setResult(new RemoteResultCommand(exta, null, callid, true));
ret.addIntermediateResult(new RemoteResultCommand(null, exta, null, callid,
true, null, getNonFunctionalProperties()));
ret.setFinished();
}
public void exceptionOccurred(Exception exception)
{
// ret.setResult(new RemoteResultCommand(null, exception, callid, false));
ret.addIntermediateResult(new RemoteResultCommand(null, null, exception, callid, false,
null, getNonFunctionalProperties()));
ret.setFinished();
}
});
}
public void exceptionOccurred(Exception exception)
{
// ret.setResult(new RemoteResultCommand(null, exception, callid, false));
ret.addIntermediateResult(new RemoteResultCommand(null, null, exception, callid, false,
null, getNonFunctionalProperties()));
ret.setFinished();
}
});
return ret;
}
/**
* Get the target id.
* @return the target id.
*/
public Object getTargetId()
{
return cid;
}
/**
* Set the target id.
* @param providerid The target id to set.
*/
public void setTargetId(IComponentIdentifier providerid)
{
this.cid = providerid;
}
/**
* Get the callid.
* @return the callid.
*/
public String getCallId()
{
return callid;
}
/**
* Set the callid.
* @param callid The callid to set.
*/
public void setCallId(String callid)
{
this.callid = callid;
}
}