/** * Hello world. * * @return the string */ @Access(AccessType.PUBLIC) public String helloWorld() { return ("Hello World"); }
@Access(AccessType.PUBLIC) class MySubAgent { public String helloWorld() { return ("Hello World"); } }
/** * Gets the id. * * @return the id */ @Access(AccessType.PUBLIC) @Override public String getId() { return agentId; }
/** * Gets the config. * * @return the config */ @Access(AccessType.PUBLIC) @Override public AgentConfig getConfig() { return config; }
/** * Gets the state. * * @return the state */ @Access(AccessType.UNAVAILABLE) @JsonIgnore protected State getState() { return state; }
/** * Throw exception. * * @throws IllegalStateException * the illegal state exception */ @Access(AccessType.PUBLIC) public void throwException() throws IllegalStateException { throw new IllegalStateException("Hi there!"); } }
/** * The Class CalcAgent. */ @Access(AccessType.PUBLIC) public class CalcAgent extends Agent { private static final String CALC_API_URL = "http://api.mathjs.org/v1/"; /** * Evaluate given expression For example expr="2.5 + 3 / sqrt(16)" will * return "3.25" * * @param expr * the expr * @return result * @throws IOException * Signals that an I/O exception has occurred. */ public String eval(@Name("expr") final String expr) throws IOException { final String url = CALC_API_URL + "?expr=" + URLEncoder.encode(expr, "UTF-8"); final HttpClient client = HttpClients.createDefault(); final HttpGet request = new HttpGet(url); final HttpResponse response = client.execute(request); return StringUtil.streamToString(response.getEntity().getContent()); } }
/** * Gets the type. * * @return the type */ @Access(AccessType.PUBLIC) @Override public String getType() { return this.getClass().getName(); }
/** * Gets the urls. * * @return the urls */ @Access(AccessType.PUBLIC) @Override @JsonIgnore public List<URI> getUrls() { return transport.getAddresses(); }
/** * Connect all transports. * * @throws IOException * Signals that an I/O exception has occurred. */ @Access(AccessType.UNAVAILABLE) public void connect() throws IOException { transport.connect(); }
@Access(AccessType.PUBLIC) public class TestScaleAgent extends Agent {
/** * Cancel. * * @param taskId * the task id */ @Access(AccessType.UNAVAILABLE) protected void cancel(final String taskId) { final Scheduler scheduler = this.scheduler; if (scheduler == null) return; scheduler.cancel(taskId); }
/** * Creates a proxy for given URL and interface, with this agent as sender. * * @param <T> * the generic type * @param url * the url * @param agentInterface * the agent interface * @return the t */ @Access(AccessType.UNAVAILABLE) protected final <T> T createAgentProxy(final URI url, final Class<T> agentInterface) { return AgentProxyFactory.genProxy(this, url, agentInterface); }
/** * Gets the methods. * * @return the methods */ @Access(AccessType.PUBLIC) @Override @JsonIgnore public List<Object> getMethods() { return ((JSONRpcProtocol) protocolStack.getLast()).getMethods(); }
/** * Schedule an RPC call at a specified due time. * * @param method * the method * @param params * the params * @param delay * the delay * @return the string */ @Access(AccessType.UNAVAILABLE) protected String schedule(final String method, final ObjectNode params, final int delay) { final Scheduler scheduler = this.scheduler; if (scheduler == null) return ""; return scheduler.schedule(new JSONRequest(method, params), delay); }
/** * Schedule an RPC call at a specified due time. * * @param method * the method * @param params * the params * @param due * the due * @return the string */ @Access(AccessType.UNAVAILABLE) protected String schedule(final String method, final ObjectNode params, final DateTime due) { final Scheduler scheduler = this.scheduler; if (scheduler == null) return ""; return scheduler.schedule(new JSONRequest(method, params), due); }
/** * Schedule an RPC call at a specified due time. * * @param method * the method * @param params * the params * @param delay * the delay * @return the string */ @Access(AccessType.UNAVAILABLE) protected String schedule(final String method, final ObjectNode params, final long delay) { final Scheduler scheduler = this.scheduler; if (scheduler == null) return ""; return scheduler.schedule(new JSONRequest(method, params), delay); }
@Access(AccessType.PUBLIC) @CanHibernate public class ExampleAgent extends Agent implements ExampleAgentInterface {
@Access(AccessType.UNAVAILABLE) @Override public void receive(final Object msg, final URI senderUrl, final String tag) { if (protocolStack == null) { // E.g. during destroy()! return; } final Object response = protocolStack.outbound( protocolStack.inbound(msg, senderUrl).getResult(), senderUrl).result; if ((tag != null || response != null) && transport != null) { try { transport.send(senderUrl, response, tag); } catch (final Exception e) { LOG.log(Level.WARNING, "Couldn't send message", e); } } }
/** * Destroy the agent. */ @Access(AccessType.UNAVAILABLE) protected void destroy() { eventCaller.on("destroy"); if (scheduler != null) { scheduler.delete(); scheduler = null; } if (transport != null) { transport.disconnect(); transport.delete(); transport = null; } if (protocolStack != null) { protocolStack.delete(); protocolStack = null; } if (state != null) { state.delete(); state = null; } if (is != null) { is.deregister(agentId); is = null; } }