public File zipAndGzip(File from) throws FITTESTException {
   File tmpzip = new File(_TMP_FOLDER, from.getName() + ".zip");
   File tmpgzip = new File(_TMP_FOLDER, from.getName() + ".gzip");
   ITELogger.log(Level.INFO, "zipping in " + tmpzip);
   zip(from, tmpzip.getAbsolutePath());
   ITELogger.log(Level.INFO, "Gzipping in " + tmpgzip);
   gzip(tmpzip, tmpgzip.getAbsolutePath());
   return tmpgzip;
 }
 public File gunzipAndUnzip(File from) throws FITTESTException {
   if (from.getName().endsWith(".gzip")) {
     File tmpzip = new File(_TMP_FOLDER, from.getName() + ".zip");
     ITELogger.log(Level.INFO, "GUnzipping in " + tmpzip);
     gunzip(from, tmpzip.getAbsolutePath());
     ITELogger.log(Level.INFO, "Unzipping in " + from);
     unzip(tmpzip, from.getParentFile().getAbsolutePath());
     return new File(
         from.getParentFile(), from.getName().substring(0, from.getName().lastIndexOf(".")));
   } else {
     throw new FITTESTException(from.getAbsolutePath() + " is not a file gzipped by FITTEST");
   }
 }
 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 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 synchronized void forward(Connection fromConnection, Message message)
     throws FITTESTException {
   ITELogger.log(Level.FINEST, "Trying to forward to " + message.getTo());
   if (message.getTo() != null
       && !_registry.findService(IIdentityService.class).getMyIdentity().equals(message.getTo())) {
     IConnectionService connectionService = _registry.findService(IConnectionService.class);
     if (connectionService.getConnection(message.getTo()) != null) {
       connectionService.sendMessage(message);
     } else {
       _registry.findService(IConnectionService.class).broadcastMessage(fromConnection, message);
     }
     ITELogger.log(
         Level.INFO,
         "Forwarding " + message.getClass().getSimpleName() + " to " + message.getTo());
     fireEvent(new ForwardServiceEvent(this, message));
   }
 }
 public void isChecksumValid(File file, long checksum) throws FITTESTException {
   if (checksum != 0L) {
     if (checksum(file) == checksum) {
       ITELogger.log(Level.INFO, "CRC OK for " + file);
     } else {
       throw new FITTESTException("CRC does not match");
     }
   }
 }
  /** 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;
  }