protected void createServiceDescription() { List<Operation> opList = new ArrayList<Operation>(); for (Method operation : this.getClass().getMethods()) { if (operation.getAnnotation(ServiceOperation.class) != null) { ServiceOperation serviceOperation = operation.getAnnotation(ServiceOperation.class); Operation op = new Operation( operation.getName(), operation.getParameterTypes(), operation.getReturnType().getName()); op.setOpCost(serviceOperation.OperationCost()); opList.add(op); } } description.setOperationList(opList); description.setServiceType(this.getClass().getSimpleName()); }
/** Helps to dynamically update the service description */ public void updateServiceDescription() { if (description.getRegisterID() > 0) this.sendRequest( ServiceRegistryInterface.NAME, ServiceRegistryInterface.ADDRESS, true, "update", this.description); else System.err.println("Service is not registered in the registy yet. It can't be updated."); }
private void register() { myServ.config = new ConfigParameters(); myServ.config.put("codec", CODEC.toString()); myServ.config.put("sample-rate", audioConf.sampleRate); myServ.config.put("frame-size", audioConf.frameSize); byte[] cb = audioRec.getConfigBytes(); if (cb != null) { myServ.config.put("config-bytes", cb); } myId = airtube.registerService(myServ, this); LOG.info("registered myself as " + myId); }
public void action() { ServiceDescription sd = new ServiceDescription(); sd.setType(SERVER_AGENT); sd.setName(getName()); sd.setOwnership("Prof6802"); DFAgentDescription dfd = new DFAgentDescription(); dfd.setName(getAID()); dfd.addServices(sd); try { DFAgentDescription[] dfds = DFService.search(myAgent, dfd); if (dfds.length > 0) { DFService.deregister(myAgent, dfd); } DFService.register(myAgent, dfd); System.out.println(getLocalName() + " is ready."); } catch (Exception ex) { System.out.println("Failed registering with DF! Shutting down..."); ex.printStackTrace(); doDelete(); } }
public DFAgentDescription[] findDocumentAgent() { final DFAgentDescription template = new DFAgentDescription(); final ServiceDescription sd = new ServiceDescription(); sd.setType(DocumentAgent.serviceType); sd.setName(DocumentAgent.serviceName); template.addServices(sd);findDocumentAgent()[0].getName() try { DFAgentDescription[] result = DFService.search(this, template); if(result != null && result.length > 0) { return result; }else { System.err.println("Aucun destinataire trouvé"); } }catch(FIPAException fe) { fe.printStackTrace(); } return null; }
/** Register to the service registry */ public void register() { int registerId = (int) this.sendRequest( ServiceRegistryInterface.NAME, ServiceRegistryInterface.ADDRESS, true, "register", description); this.description.setRegisterID(registerId); System.out.println( "The service " + description.getServiceType() + " has been registered. The registerID is " + this.description.getRegisterID()); }
private ServiceDescription getServiceDescription() { ServiceDescription result = null; DatagramPacket packet = getReceivedDatagramPacket(); if (packet != null) { String s = new String(packet.getData()); int pos = s.indexOf((char) 0); if (pos > -1) { s = s.substring(0, pos); } StringTokenizer tokens = new StringTokenizer(s.substring(15 + getEncodedServiceName().length())); if (tokens.countTokens() == 3) { result = ServiceDescription.parse(tokens.nextToken(), tokens.nextToken(), tokens.nextToken()); } } return (result); }