jadex.platform.service.remote.ProxyAgent Maven / Gradle / Ivy
package jadex.platform.service.remote;
import java.util.Map;
import jadex.bridge.IExternalAccess;
import jadex.bridge.IInternalAccess;
import jadex.bridge.ITransportComponentIdentifier;
import jadex.bridge.component.IExecutionFeature;
import jadex.bridge.component.INFPropertyComponentFeature;
import jadex.bridge.nonfunctional.INFMixedPropertyProvider;
import jadex.bridge.nonfunctional.annotation.NFProperties;
import jadex.bridge.nonfunctional.annotation.NFProperty;
import jadex.bridge.sensor.service.LatencyProperty;
import jadex.bridge.service.IService;
import jadex.bridge.service.RequiredServiceInfo;
import jadex.bridge.service.annotation.Service;
import jadex.bridge.service.component.IRequiredServicesFeature;
import jadex.bridge.service.types.address.TransportAddressBook;
import jadex.bridge.service.types.cms.IComponentManagementService;
import jadex.bridge.service.types.remote.IProxyAgentService;
import jadex.commons.concurrent.TimeoutException;
import jadex.commons.future.ExceptionDelegationResultListener;
import jadex.commons.future.Future;
import jadex.commons.future.IFuture;
import jadex.commons.future.IResultListener;
import jadex.micro.annotation.Agent;
import jadex.micro.annotation.AgentArgument;
import jadex.micro.annotation.AgentCreated;
import jadex.micro.annotation.Argument;
import jadex.micro.annotation.Arguments;
import jadex.micro.annotation.Description;
import jadex.micro.annotation.ProvidedService;
import jadex.micro.annotation.ProvidedServices;
/**
* A proxy agent is a pseudo component that mirrors services of a remote platform (or component).
*/
@Description("This agent represents a proxy for a remote component.")
@Arguments(@Argument(name="component", clazz=ITransportComponentIdentifier.class, defaultvalue="null", description="The component id of the remote component/platform."))
@ProvidedServices(@ProvidedService(type=IProxyAgentService.class))
@NFProperties(@NFProperty(ProxyLatencyProperty.class))
@Service
@Agent
//@RequiredServices(@RequiredService(name="cms", type=IComponentManagementService.class, multiple=true,
// binding=@Binding(scope=RequiredServiceInfo.SCOPE_GLOBAL, dynamic=true),
// nfprops=@NFRProperty(value=LatencyProperty.class, methodname="getConnectionState")))
public class ProxyAgent implements IProxyAgentService
{
//-------- attributes --------
/** The agent. */
@Agent
protected IInternalAccess agent;
/** The remote component identifier. */
@AgentArgument("component")
protected ITransportComponentIdentifier rcid;
/** The remote cms. */
protected IComponentManagementService rcms;
/** The injected flag. */
protected boolean injected;
//-------- methods --------
/**
* The agent created method.
*/
@AgentCreated
public IFuture agentCreated()
{
final Future ret = new Future();
agent.getComponentFeature(IRequiredServicesFeature.class).searchService(IComponentManagementService.class, rcid.getRoot())
.addResultListener(new IResultListener()
{
public void resultAvailable(IComponentManagementService cms)
{
rcms = cms;
// ServiceCall next = ServiceCall.getOrCreateNextInvocation();
// next.setProperty("debugsource", "ProxyAgent.agentCreated()");
cms.getExternalAccess(agent.getComponentIdentifier().getRoot())
.addResultListener(new IResultListener()
{
public void resultAvailable(IExternalAccess pl)
{
pl.getArguments().addResultListener(agent.getComponentFeature(IExecutionFeature.class).createResultListener(new IResultListener