Beispiel #1
0
  public RemoteRecorder(Action action, boolean append, String threadId) throws RecorderException {
    super(null, append, DTFConstants.DEFAULT_ENCODING);
    _threadId = threadId;

    try {
      RemoteStorage.init();
      _uri = RemoteStorage.createUniqueURI("events-", ".txt");
      _recorder = new TextRecorder(_uri, append, DTFConstants.DEFAULT_ENCODING);

      if (Action.getLogger().isDebugEnabled()) Action.getLogger().debug("Created file " + _uri);
    } catch (StorageException e) {
      throw new RecorderException("Unable to open remote storage.", e);
    } catch (URISyntaxException e) {
      throw new RecorderException("Unable to open remote storage.", e);
    } catch (ParseException e) {
      throw new RecorderException("Unable to open remote storage.", e);
    }
  }
Beispiel #2
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);
      }
    }
  }