/** * Create awareness info of myself. */ public IFuture<AwarenessInfo> createAwarenessInfo(final String state, final String masterid) { final Future<AwarenessInfo> ret = new Future<AwarenessInfo>(); IFuture<IMessageService> fut = agent.getServiceContainer().getRequiredService("ms"); fut.addResultListener(agent.createResultListener(new ExceptionDelegationResultListener<IMessageService, AwarenessInfo>(ret) { public void customResultAvailable(IMessageService cms) { cms.updateComponentIdentifier(getRoot()).addResultListener(agent.createResultListener( new ExceptionDelegationResultListener<IComponentIdentifier, AwarenessInfo>(ret) { public void customResultAvailable(IComponentIdentifier root) { AwarenessInfo info = new AwarenessInfo(root, state, getDelay(), getIncludes(), getExcludes(), masterid); ret.setResult(info); } })); } })); return ret; }
/** * Create a wrapper service implementation based on the JAXB generated * Java service class and the service mapping information. */ public Object createServiceImplementation(Class<?> type, WebServiceMappingInfo mapping) { return Proxy.newProxyInstance(agent.getClassLoader(), new Class[]{type}, new WebServiceWrapperInvocationHandler(agent, mapping)); } }
public void exceptionOccurred(Exception exception) { collectInjectedResults(); nosteps = true; exitState(); StringWriter sw = new StringWriter(); exception.printStackTrace(new PrintWriter(sw)); microagent.getLogger().severe(microagent.getComponentIdentifier()+", "+microagent.getModel().getFullName()+": Exception during cleanup: "+sw); ret.setResult(null); } }));
microagent.agentKilled().addResultListener(microagent.createResultListener(new DelegationResultListener<Void>(ret)
agent.getLogger().info("Awareness disconnected: "+address); IFuture<IAwarenessManagementService> msfut = agent.getRequiredService("management"); msfut.addResultListener(new ExceptionDelegationResultListener<IAwarenessManagementService, Void>(ret)
public void resultAvailable(AwarenessInfo info) { InetAddress address = SUtil.getInetAddress(); // AwarenessInfo info = createAwarenessInfo(AwarenessInfo.STATE_ONLINE, createMasterId()); // byte[] data = DiscoveryState.encodeObject(info, getMicroAgent().getModel().getClassLoader()); byte[] data = DiscoveryAgent.encodeObject(info, getDefaultCodecs(), getMicroAgent().getClassLoader()); ((BroadcastSendHandler)sender).send(data, address, port); // System.out.println("local slave at: "+SUtil.getInet4Address()+" "+socket.getLocalPort()); getMicroAgent().getLogger().info("local slave at: "+SUtil.getInetAddress()+" "+socket.getLocalPort()); }
public void customResultAvailable(IMessageService cms) { cms.updateComponentIdentifier(getRoot()).addResultListener(agent.createResultListener( new ExceptionDelegationResultListener<IComponentIdentifier, AwarenessInfo>(ret) { public void customResultAvailable(IComponentIdentifier root) { AwarenessInfo info = new AwarenessInfo(root, state, getDelay(), getIncludes(), getExcludes(), masterid); ret.setResult(info); } })); } }));
final String sendid = SUtil.createUniqueId(agent.getMicroAgent().getComponentIdentifier().getLocalName()); this.sendid = sendid; agent.getMicroAgent().scheduleStep(new IComponentStep<Void>()
public void exceptionOccurred(Exception exception) { sending = false; if(!(exception instanceof ComponentTerminatedException)) { // exception.printStackTrace(); agent.getLogger().info("Sending awareness info to server...failed: "+exception); } } });
/** * Get a required services of a given name. * @param name The services name. * @return The service. */ public <T> ITerminableIntermediateFuture<T> getRequiredServices(String name) { return getServiceContainer().getRequiredServices(name); }
public void run() { try { agent.scheduleStep(step); } catch(ComponentTerminatedException e) { // ignore } } }, delay);
/** * Get the root. * @return the root. */ public IComponentIdentifier getRoot() { if(root==null) this.root = agent.getComponentIdentifier().getRoot(); return root; }
agent.getLogger().info("Sending awareness info to server..."); final Future<Void> fut = new Future<Void>(); IFuture<IMessageService> msfut = agent.getServiceContainer().getRequiredService("ms"); msfut.addResultListener(new ExceptionDelegationResultListener<IMessageService, Void>(fut)
SServiceProvider.getServiceUpwards(agent.getServiceProvider(), IMessageService.class) .addResultListener(agent.createResultListener(new ExceptionDelegationResultListener<IMessageService, Void>(ret)
args.put("creator", agent.getComponentIdentifier()); String argsstr = AWriter.objectToXML(XMLWriterFactory.getInstance().createWriter(true, false, false), args, null, JavaWriter.getObjectHandler()); so.setProgramArguments(comstr); IFuture<IDaemonService> fut = agent.getRequiredService("daeser"); fut.addResultListener(new ExceptionDelegationResultListener<IDaemonService, IComponentIdentifier>(ret)
/** * Init the micro agent with the interpreter. * @param interpreter The interpreter. */ public void init(MicroAgentInterpreter interpreter, Object agent) { super.init(interpreter); this.agent = agent; }
/** * Deregister when agent is killed. */ @AgentKilled public IFuture<Void> agentkilled() { // Only wait 5 seconds for disconnect message. Future<Void> ret = new Future<Void>(); sendInfo(true).addResultListener(new TimeoutResultListener<Void>(5000, agent.getExternalAccess(), new DelegationResultListener<Void>(ret) { public void exceptionOccurred(Exception exception) { // Ignore exception. super.resultAvailable(null); } })); return ret; }
IFuture<IAwarenessManagementService> msfut = agent.getMicroAgent().getRequiredService("management"); msfut.addResultListener(new IResultListener<IAwarenessManagementService>()
public void resultAvailable(AwarenessInfo info) { InetAddress address = SUtil.getInetAddress(); // AwarenessInfo info = createAwarenessInfo(AwarenessInfo.STATE_ONLINE, createMasterId()); // byte[] data = DiscoveryState.encodeObject(info, getMicroAgent().getModel().getClassLoader()); byte[] data = DiscoveryAgent.encodeObject(info, getDefaultCodecs(), getMicroAgent().getClassLoader()); ((BroadcastSendHandler)sender).send(data, address, port); // System.out.println("local slave at: "+SUtil.getInet4Address()+" "+socket.getLocalPort()); getMicroAgent().getLogger().info("local slave at: "+SUtil.getInetAddress()+" "+socket.getLocalPort()); }
public void customResultAvailable(IMessageService cms) { cms.updateComponentIdentifier(getRoot()).addResultListener(agent.createResultListener( new ExceptionDelegationResultListener<IComponentIdentifier, AwarenessInfo>(ret) { public void customResultAvailable(IComponentIdentifier root) { AwarenessInfo info = new AwarenessInfo(root, AwarenessInfo.STATE_ONLINE, getDelay(), getIncludes(), getExcludes(), null); ret.setResult(info); } })); } }));