コード例 #1
0
    public ConsoleCommunication(Connector connector)
        throws CommunicationException, FileStore.FileStoreException {

      final ClientReceiver receiver =
          ClientReceiver.connect(connector, new AgentAddress(m_agentIdentity));
      m_sender = ClientSender.connect(receiver);
      m_connector = connector;

      if (m_fileStore == null) {
        // Only create the file store if we connected.
        m_fileStore =
            new FileStore(new File("./" + m_agentIdentity.getName() + "-file-store"), m_logger);
      }

      m_sender.send(
          new AgentProcessReportMessage(
              ProcessReport.STATE_STARTED, m_fileStore.getCacheHighWaterMark()));

      final MessageDispatchSender fileStoreMessageDispatcher = new MessageDispatchSender();
      m_fileStore.registerMessageHandlers(fileStoreMessageDispatcher);

      final MessageDispatchSender messageDispatcher = new MessageDispatchSender();
      m_consoleListener.registerMessageHandlers(messageDispatcher);

      // Everything that the file store doesn't handle is tee'd to the
      // worker processes and our message handlers.
      fileStoreMessageDispatcher.addFallback(
          new TeeSender(messageDispatcher, new IgnoreShutdownSender(m_fanOutStreamSender)));

      m_messagePump = new MessagePump(receiver, fileStoreMessageDispatcher, 1);

      m_reportRunningTask =
          new TimerTask() {
            public void run() {
              try {
                m_sender.send(
                    new AgentProcessReportMessage(
                        ProcessReport.STATE_RUNNING, m_fileStore.getCacheHighWaterMark()));
              } catch (CommunicationException e) {
                cancel();
                e.printStackTrace();
              }
            }
          };
    }
コード例 #2
0
    public void shutdown() {
      m_reportRunningTask.cancel();

      try {
        m_sender.send(
            new AgentProcessReportMessage(
                ProcessReport.STATE_FINISHED, m_fileStore.getCacheHighWaterMark()));
      } catch (CommunicationException e) {
        // Ignore - peer has probably shut down.
      } finally {
        m_messagePump.shutdown();
      }
    }