コード例 #1
0
  /** 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;
  }