public synchronized void start() {
    if (isRun) {
      return;
    }

    if (null == scheduledExecutor || scheduledExecutor.isTerminated()) {
      scheduledExecutor = Executors.newSingleThreadScheduledExecutor();
    }

    localConfigInfoProcessor.start(this.diamondConfigure.getFilePath() + "/" + DATA_DIR);
    serverAddressProcessor =
        new ServerAddressProcessor(this.diamondConfigure, this.scheduledExecutor);
    serverAddressProcessor.start();

    this.snapshotConfigInfoProcessor =
        new SnapshotConfigInfoProcessor(this.diamondConfigure.getFilePath() + "/" + SNAPSHOT_DIR);
    randomDomainNamePos();
    initHttpClient();

    isRun = true;

    if (log.isInfoEnabled()) {
      log.info("Current using domains:" + this.diamondConfigure.getDomainNameList());
    }

    if (MockServer.isTestMode()) {
      bFirstCheck = false;
    } else {
      this.diamondConfigure.setPollingIntervalTime(Constants.POLLING_INTERVAL_TIME);
    }
    rotateCheckConfigInfo();

    addShutdownHook();
  }
示例#2
0
  @Override
  public void stop() {
    logger.info("Avro source {} stopping: {}", getName(), this);

    server.close();

    try {
      server.join();
    } catch (InterruptedException e) {
      logger.info(
          "Avro source "
              + getName()
              + ": Interrupted while waiting "
              + "for Avro server to stop. Exiting. Exception follows.",
          e);
    }
    sourceCounter.stop();
    connectionCountUpdater.shutdown();
    while (!connectionCountUpdater.isTerminated()) {
      try {
        Thread.sleep(100);
      } catch (InterruptedException ex) {
        logger.error(
            "Interrupted while waiting for connection count executor " + "to terminate", ex);
        Throwables.propagate(ex);
      }
    }
    super.stop();
    logger.info("Avro source {} stopped. Metrics: {}", getName(), sourceCounter);
  }
 @Override
 public boolean isTerminated() {
   boolean result = true;
   for (ScheduledExecutorService w : workers) {
     result = result && w.isTerminated();
   }
   return result;
 }
示例#4
0
 /**
  * The finalize method shuts down the timer. This is a fail-safe shutdown, in case the original
  * shutdown method was never called.
  *
  * <p>This should not be relied upon! It will cause shutdown to happen much later than if manual
  * shutdown is attempted, and cause threads to linger for longer than needed.
  */
 @Override
 protected void finalize() throws Throwable {
   super.finalize();
   if (timerService != null) {
     if (!timerService.isTerminated()) {
       LOG.warn("Timer service was not shut down. Shutting down in finalize().");
     }
     timerService.shutdown();
   }
 }
示例#5
0
  /**
   * The finalize method shuts down the timer. This is a fail-safe shutdown, in case the original
   * shutdown method was never called.
   *
   * <p>This should not be relied upon! It will cause shutdown to happen much later than if manual
   * shutdown is attempted, and cause threads to linger for longer than needed.
   */
  @Override
  protected void finalize() throws Throwable {
    super.finalize();
    if (timerService != null) {
      if (!timerService.isTerminated()) {
        LOG.warn("Timer service was not shut down. Shutting down in finalize().");
      }
      timerService.shutdown();
    }

    if (asyncCheckpointThreads != null) {
      for (Thread checkpointThread : asyncCheckpointThreads) {
        checkpointThread.interrupt();
      }
    }
  }
示例#6
0
    public void disconnect() {

      if ((m_task != null) && (!m_task.isDone())) {
        s_logger.debug("disconnect() :: Cancelling GpsSerialCommunicate task ...");
        m_task.cancel(true);
        s_logger.info("disconnect() :: GpsSerialCommunicate task cancelled? = {}", m_task.isDone());
        m_task = null;
      }

      if (m_executor != null) {
        s_logger.debug("disconnect() :: Terminating GpsSerialCommunicate Thread ...");
        m_executor.shutdownNow();
        try {
          m_executor.awaitTermination(THREAD_TERMINATION_TOUT, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
          s_logger.warn("Interrupted", e);
        }
        s_logger.info(
            "disconnect() :: GpsSerialCommunicate Thread terminated? - {}",
            m_executor.isTerminated());
        m_executor = null;
      }

      if (conn != null) {
        try {
          if (in != null) {
            in.close();
            in = null;
          }
          conn.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
        conn = null;
      }
    }
示例#7
0
文件: SyncIT.java 项目: p2p-sync/sync
  @Test
  public void test() throws NoSuchAlgorithmException, InterruptedException, InputOutputException {

    Sync.init(STORAGE_ADAPTER_1);

    assertTrue(
        "ObjectStoreFolder should exist",
        Files.exists(ROOT_TEST_DIR1.resolve(Config.DEFAULT.getOsFolderName())));
    assertTrue(
        "ObjectFolder should exist",
        Files.exists(
            ROOT_TEST_DIR1
                .resolve(Config.DEFAULT.getOsFolderName())
                .resolve(Config.DEFAULT.getOsObjectFolderName())));
    assertTrue(
        "SharedWithOthers (read-write) should exist",
        Files.exists(
            ROOT_TEST_DIR1.resolve(Config.DEFAULT.getSharedWithOthersReadWriteFolderName())));
    assertTrue(
        "SharedWithOthers (read-only) should exist",
        Files.exists(
            ROOT_TEST_DIR1.resolve(Config.DEFAULT.getSharedWithOthersReadOnlyFolderName())));

    Sync sync = new Sync(STORAGE_ADAPTER_1);

    assertNull("Node should be null before connecting", sync.getNode());
    assertNull("Event Aggregator should be null before connecting", sync.getEventAggregator());
    assertNull(
        "Background Syncer Executor Service should be null before connecting",
        sync.getBackgroundSyncerExecutorService());
    assertNull("File Syncer should be null before connecting", sync.getFileSyncer());
    assertNull("Sharing Syncer should be null before connecting", sync.getSharingSyncer());
    assertNull("Object Store should be null before connecting", sync.getObjectStore());
    assertEquals("Storage Adapter should be the same", STORAGE_ADAPTER_1, sync.getStorageAdapter());

    ApplicationConfig appConfig = ApplicationConfigFactory.createBootstrapApplicationConfig();

    appConfig.setUserName(USER_1.getUserName());
    appConfig.setPassword(USER_1.getPassword());
    appConfig.setSalt(USER_1.getSalt());

    sync.connect(appConfig);

    INode node = sync.getNode();
    assertNotNull("Node should not be null after connecting", node);
    assertNotNull("Client Device Id should not be null", node.getClientDeviceId());
    assertNotNull("PeerAddress should not be null", node.getPeerAddress());
    assertTrue("Node should be connected", node.isConnected());

    assertEquals("UserName should be equals", USER_1.getUserName(), node.getUser().getUserName());
    assertEquals("Salt should be equals", USER_1.getSalt(), node.getUser().getSalt());
    assertEquals("Password should be equals", USER_1.getPassword(), node.getUser().getPassword());

    assertNotNull("Node Manager should not be null", node.getNodeManager());
    assertNotNull("Identifier Manager should not be null", node.getIdentifierManager());
    assertNotNull("UserManager should not be null", node.getUserManager());

    ObjectDataReplyHandler objectDataReplyHandler = node.getObjectDataReplyHandler();
    assertNotNull("ObjectDataReplyHandler should not be null", objectDataReplyHandler);
    assertThat(
        "ObjectDataReplyHandler should be an instance of LocalStateObjectDataReplyHandler",
        objectDataReplyHandler,
        is(instanceOf(LocalStateObjectDataReplyHandler.class)));

    IEventAggregator eventAggregator = sync.getEventAggregator();
    assertNotNull("Event Aggregator should not be null after connecting", eventAggregator);
    assertEquals(
        "2 Listeners (ObjectStoreListener & PathChangeListener) should be registered",
        2,
        eventAggregator.getListeners().size());
    assertEquals(
        "4 modifiers (RelativePathModifier, AddDirectoryContentModifier, IgnorePathsModifier, SameHashModifier) should be registered",
        4,
        eventAggregator.getModifiers().size());
    assertEquals(
        "1 aggregator (HistoryMoveAggregator) should be registered",
        1,
        eventAggregator.getAggregators().size());

    ScheduledExecutorService backgroundExecutorService = sync.getBackgroundSyncerExecutorService();
    assertNotNull(
        "Background Syncer should be not null after connecting", backgroundExecutorService);
    assertFalse(
        "Background Syncer should not be shut down", backgroundExecutorService.isShutdown());
    assertFalse(
        "Background Syncer should not be terminated", backgroundExecutorService.isTerminated());

    IFileSyncer fileSyncer = sync.getFileSyncer();
    assertNotNull("FileSyncer should not be null after connecting", fileSyncer);

    ISharingSyncer sharingSyncer = sync.getSharingSyncer();
    assertNotNull("Sharing Syncer should not be null after connecting", sharingSyncer);

    IObjectStore objectStore = sync.getObjectStore();
    assertNotNull("Object Store should not be null after connecting", objectStore);

    ITreeStorageAdapter storageAdapter = sync.getStorageAdapter();
    assertEquals("Storage Adapter should still be equal", STORAGE_ADAPTER_1, storageAdapter);

    sync.shutdown();

    // wait until node is stopped
    Thread.sleep(appConfig.getShutdownAnnounceTimeout());

    assertFalse("Node should be stopped", node.isConnected());
    assertTrue(
        "Background Syncer should not be running anymore", backgroundExecutorService.isShutdown());
    assertTrue("Background Syncer should be terminated", backgroundExecutorService.isTerminated());
  }
 /**
  * {@inheritDoc}
  *
  * <p>This implementation is equivalent to calling <code>isShutdown()</code> on the wrapped
  * ScheduledExecutorService.
  */
 public boolean isTerminated() {
   return schedExec.isTerminated();
 }