Пример #1
0
  public void register() throws DTFException {
    String id = Action.getLocalID();

    Connect connect;
    connect = new Connect(id);

    /*
     * Put default Attribs into connect message.
     */
    Iterator objs = _attribs.values().iterator();
    while (objs.hasNext()) {
      Attrib attrib = (Attrib) objs.next();
      connect.addAttrib(attrib);
    }

    connect.setAddress(_server.getAddress());
    connect.setPort(_server.getPort());
    connect.setBuildid(DTFNode.getBuildID());

    if (_logger.isDebugEnabled()) {
      _logger.debug("Registering " + connect);
    }

    try {
      _node.register(connect).execute();
    } catch (RemoteException e) {
      convertException(e, "Unable to register.");
    }
  }
Пример #2
0
  public void execute() throws DTFException {
    /*
     * For the case in which we're tunneling to this agent then we should
     * communicate with the DTFX using the controller. It is slower but its
     * the only guaranteed method.
     */
    if (!getTunneled()) {
      CommClient client = new CommRMIClient(getAddress(), getPort());
      if (client.heartbeat().booleanValue()) {
        if (getLogger().isDebugEnabled())
          getLogger().debug("Direction connection to component being used.");

        Comm.addClient(getOwner(), client);
      }
    }

    /*
     * Recreate the Agent base config from the main config that the agent
     * has when it starts for the first time and connects to the DTFC.
     */
    ActionState as = ActionState.getInstance();
    DTFState state = as.getState("main").duplicate();
    state.setGlobalContext((Hashtable) state.getGlobalContext().clone());
    as.setState(Node.BASE_CONFIG, state);

    DTFNode.setOwner(this);
    getLogger().info("This agent [" + getId() + "] in use by [" + getOwner() + "]");
  }
Пример #3
0
  public void stop() throws RecorderException {
    try {
      _recorder.stop();

      TxtQuery query = new TxtQuery();
      query.open(_uri, null, null, null, null, DTFConstants.DEFAULT_ENCODING);
      Cursor cursor = new Cursor(query);
      int count = 0;

      if (DTFNode.getOwner() != null) {
        String ownerId = DTFNode.getOwner().getOwner();

        Sequence seq = new Sequence();
        seq.setThreadID(_threadId);

        while (true) {
          HashMap<String, String> map = cursor.next(false);

          if (map == null) break;

          Event event = CLIUtil.hashMapToEvent(map);
          seq.addAction(event);
          count++;

          if (count > 100) {
            Action.getComm().sendAction(ownerId, seq);
            seq.clearChildren();
            count = 0;
          }
        }

        if (seq.children().size() != 0) Action.getComm().sendAction(ownerId, seq);
      }
    } catch (StorageException e) {
      throw new RecorderException("Error handling remote events.", e);
    } catch (DTFException e) {
      throw new RecorderException("Error handling remote events.", e);
    } finally {
      try {
        RemoteStorage.delete(_uri);
      } catch (StorageException e) {
        throw new RecorderException("Error cleaning up event file.", e);
      }
    }
  }