/** Register a new component */ public synchronized void registerComponent(final String agentID, final String componentID) { ITELogger.log(Level.INFO, "component " + componentID + " is registered on agent " + agentID); RegistrationData agentData = getAgentData(agentID); FITTESTComponent component = new FITTESTComponent(componentID); if (agentData != null) { if (agentData.getEntity() != null) { component.setContainerAgent((FITTESTAgent) agentData.getEntity()); } } RegistrationData componentData = new RegistrationData( 0, component, _registry.findService(IIdentityService.class).getMyIdentity()); _routingTable.put(componentData, agentID); String agentAddress = _routingTable.get(new RegistrationData(0, new FITTESTAgent(agentID), null)); _registry .findService(IConnectionService.class) .map( componentID, _registry .findService(IConnectionService.class) .getConnection( agentAddress.split(":")[0], new Integer(agentAddress.split(":")[1]))); fireEvent( new RegistrationEvent(this, componentData, RegistrationEventKind.componentRegistration)); }
public List<String> getAllComponentsOnAgent(final String agentID) { List<String> components = new ArrayList<String>(); synchronized (_routingTable) { Set<RegistrationData> keys = _routingTable.keySet(); RegistrationData[] datas = keys.toArray(new RegistrationData[keys.size()]); for (RegistrationData key : datas) { if (_routingTable.get(key).equals(agentID)) components.add(key.getEntity().getId()); } } return components; }
public RegistrationData getAgentData(String agentId) { RegistrationData data = null; synchronized (_routingTable) { Iterator<RegistrationData> it = _routingTable.keySet().iterator(); while (data == null && it.hasNext()) { RegistrationData current = it.next(); if (current.getEntity().getId().equals(agentId)) { data = current; } } } return data; }
public void run() { ITELogger.log(Level.INFO, "checking lease..."); synchronized (_routingTable) { Set<RegistrationData> keys = _routingTable.keySet(); RegistrationData[] datas = keys.toArray(new RegistrationData[keys.size()]); for (RegistrationData data : datas) { if (data.getLease() != 0 && System.currentTimeMillis() > data.getLease() * 1000) { ITELogger.log( Level.INFO, "deregistering due to expried lease: " + data.getEntity().getId()); deregister(data.getEntity().getId()); } } } }
/** Register a new agent or the agent renew its lease */ public synchronized RegistrationData registerAgent( final String publicIP, final int publicPort, final HUTEnvironment environment, final HUTType type, String description, String oldId) { ITELogger.log(Level.INFO, "agent " + publicIP + ":" + publicPort + " is registered"); RegistrationData data = findAgentRegistrationData(publicIP, publicPort); if (data != null) { // agent is already registered, renew lease data.setLease( System.currentTimeMillis() / 1000 + FITTESTConstants.REGISTRATION_LEASE_DURATION); fireEvent(new RegistrationEvent(this, data, RegistrationEventKind.leaseRenewal)); } else { FITTESTAgent agent = null; if (oldId != null && isUnique(oldId)) { // check if agent has been // registered in the past agent = new FITTESTAgent(oldId, environment, type, description); // reusing // same // id } else { agent = new FITTESTAgent(environment, type, description); } data = new RegistrationData( System.currentTimeMillis() / 1000 + FITTESTConstants.REGISTRATION_LEASE_DURATION, agent, _registry.findService(IIdentityService.class).getMyIdentity()); _routingTable.put(data, publicIP + ":" + publicPort); _registry .findService(IConnectionService.class) .map( agent.getId(), _registry.findService(IConnectionService.class).getConnection(publicIP, publicPort)); fireEvent(new RegistrationEvent(this, data, RegistrationEventKind.agentRegistration)); } return data; }
public synchronized void onReception(Connection connection, RegisterAgent message) throws FITTESTException { if (message.getType() != null) { // if null => possibility of a renew lease after the agent deregistered (or any // other possible cause) RegistrationData data = getService() .registerAgent( connection.getRemoteAddress().split(":")[0], new Integer(connection.getRemoteAddress().split(":")[1]), message.getEnvironment(), message.getType(), message.getDescription(), message.getFrom()); message.setFrom(data.getEntity().getId()); message.setTo(data.getIteid()); RegisterAgentReponse response = FITTESTSingleton.getObjectFactory().createRegisterAgentReponse(); response.setFittestAgentId(data.getEntity().getId()); response.setFittestIteId(data.getIteid()); response.setFittestLease(data.getLease()); reply(connection, message, response); } }