Example #1
0
  public MessageAwaiterImpl(AgentItem agent, String canvasId, Phase phase) {
    this.agent = agent;
    this.canvasId = canvasId;
    this.phase = phase;

    agent.addMessageListener(CHANNEL, this);
    agent.addConnectionListener(this);
    agent.sendMessage(CHANNEL, new Object[] {canvasId, phase.toString()});
  }
Example #2
0
  @Override
  public boolean await() {
    synchronized (this) {
      deadline = System.currentTimeMillis() + TIMEOUT;
      while (!done) {
        try {
          if (agent.isReady()) {
            wait(deadline - System.currentTimeMillis());
          }
          if (!done && System.currentTimeMillis() >= deadline) {
            log.error("Timed out waiting for Agent: {}", agent);
            complete();
            return false;
          }
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }

      return true;
    }
  }
Example #3
0
 synchronized void complete() {
   agent.removeMessageListener(this);
   agent.removeConnectionListener(this);
   done = true;
   notifyAll();
 }