jadex.bridge.component.impl.remotecommands.RemoteMethodInvocationCommand 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.bridge.component.impl.remotecommands;
import java.lang.reflect.Method;
import java.util.Map;
import jadex.bridge.IComponentIdentifier;
import jadex.bridge.IInternalAccess;
import jadex.bridge.component.IRemoteCommand;
import jadex.bridge.service.BasicService;
import jadex.bridge.service.IServiceIdentifier;
import jadex.bridge.service.annotation.Security;
import jadex.bridge.service.component.IProvidedServicesFeature;
import jadex.bridge.service.search.ServiceNotFoundException;
import jadex.bridge.service.search.ServiceQuery;
import jadex.bridge.service.types.registry.IRemoteRegistryService;
import jadex.bridge.service.types.security.ISecurityInfo;
import jadex.commons.MethodInfo;
import jadex.commons.SUtil;
import jadex.commons.future.Future;
import jadex.commons.future.IFuture;
/**
* Invoke a remote method.
*/
public class RemoteMethodInvocationCommand extends AbstractInternalRemoteCommand implements IRemoteCommand, ISecuredRemoteCommand
{
//-------- attributes --------
/** The target id. */
private Object target;
/** The remote method. */
private MethodInfo method;
/** The arguments. */
private Object[] args;
/**
* Create a remote method invocation command.
*/
public RemoteMethodInvocationCommand()
{
// Bean constructor.
}
/**
* Create a remote method invocation command.
*/
public RemoteMethodInvocationCommand(Object target, Method method, Object[] args, Map nonfunc)
{
super(nonfunc);
this.target = target;
this.method = new MethodInfo(method);
this.args = args;
// System.out.println("created rmi command: "+target+" "+method.getName());
if(method.toString().toLowerCase().indexOf("registryv2")!=-1)
System.out.println("Creating command for: "+method);
}
/**
* Get the target id.
*/
public Object getTargetId()
{
return target;
}
/**
* Set the target id.
*/
public void setTargetId(Object target)
{
this.target = target;
}
/**
* Get the method.
*/
public MethodInfo getMethod()
{
return method;
}
/**
* Set the method.
*/
public void setMethod(MethodInfo method)
{
this.method = method;
}
/**
* Get the arguments.
*/
public Object[] getArguments()
{
return args;
}
/**
* Set the arguments.
*/
public void setArguments(Object[] args)
{
this.args = args;
}
/**
* Execute the method.
*/
@Override
public IFuture execute(IInternalAccess access, ISecurityInfo secinf)
{
// if(method.toString().toLowerCase().indexOf("getdesc")!=-1)
// System.out.println("Executing requested remote method invocation: "+access.getId()+", "+method);
Object ret = null;
if(target instanceof IServiceIdentifier)
{
IServiceIdentifier sid = (IServiceIdentifier)target;
if(sid.getProviderId().equals(access.getId()))
{
try
{
Method m = method.getMethod(access.getClassLoader());
//if(m.getName().startsWith("method"))
// System.out.println("here");
Object service = access.getFeature(IProvidedServicesFeature.class).getProvidedService(sid);
if(service==null)
{
ret = new Future