當前位置: 首頁>>代碼示例>>Java>>正文


Java Uninterruptibles.awaitUninterruptibly方法代碼示例

本文整理匯總了Java中com.google.common.util.concurrent.Uninterruptibles.awaitUninterruptibly方法的典型用法代碼示例。如果您正苦於以下問題:Java Uninterruptibles.awaitUninterruptibly方法的具體用法?Java Uninterruptibles.awaitUninterruptibly怎麽用?Java Uninterruptibles.awaitUninterruptibly使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.util.concurrent.Uninterruptibles的用法示例。


在下文中一共展示了Uninterruptibles.awaitUninterruptibly方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: write

import com.google.common.util.concurrent.Uninterruptibles; //導入方法依賴的package包/類
@Override
public void write(Message message) {
    Uninterruptibles.awaitUninterruptibly(transportInitialized);

    LOG.debug("Sending message: {}", message);

    try {
        final GelfMessageBuilder messageBuilder = new GelfMessageBuilder(message.getMessage(), message.getSource())
                .timestamp(message.getTimestamp().getMillis() / 1000.0)
                .additionalFields(message.getFields().asMap());

        if (message.getLevel() != null) {
            messageBuilder.level(GelfMessageLevel.valueOf(message.getLevel().toString()));
        } else {
            messageBuilder.level(null);
        }

        transport.send(messageBuilder.build());
    } catch (InterruptedException e) {
        LOG.error("Failed to send message", e);
    }
}
 
開發者ID:DevOpsStudio,項目名稱:Re-Collector,代碼行數:23,代碼來源:GelfOutput.java

示例2: AsyncCopier

import com.google.common.util.concurrent.Uninterruptibles; //導入方法依賴的package包/類
@VisibleForTesting
AsyncCopier(
    InputStream source,
    OutputStream sink,
    Supplier<Level> ioExceptionLogLevel,
    CopyStrategy copyStrategy,
    ExecutorService executorService) {
  this.source = source;
  this.sink = sink;
  this.ioExceptionLogLevel = ioExceptionLogLevel;
  this.copyStrategy = copyStrategy;

  // Submit the copy task and wait uninterruptibly, but very briefly, for it to actually start.
  copyFuture = executorService.submit(new Runnable() {
    @Override public void run() {
      copy();
    }
  });
  Uninterruptibles.awaitUninterruptibly(copyStarted);
}
 
開發者ID:google,項目名稱:ios-device-control,代碼行數:21,代碼來源:AsyncCopier.java

示例3: createCopycatServers

import com.google.common.util.concurrent.Uninterruptibles; //導入方法依賴的package包/類
/**
 * Creates a set of Copycat servers.
 */
protected List<CopycatServer> createCopycatServers(int nodes) throws Throwable {
    CountDownLatch latch = new CountDownLatch(nodes);
    List<CopycatServer> servers = new ArrayList<>();

    List<Address> members = new ArrayList<>();
    for (int i = 0; i < nodes; i++) {
        members.add(nextAddress());
    }

    for (int i = 0; i < nodes; i++) {
        CopycatServer server = createCopycatServer(members.get(i));
        server.bootstrap(members).thenRun(latch::countDown);
        servers.add(server);
    }

    Uninterruptibles.awaitUninterruptibly(latch);

    return servers;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:23,代碼來源:AtomixTestBase.java

示例4: testSendAsync

import com.google.common.util.concurrent.Uninterruptibles; //導入方法依賴的package包/類
@Test
public void testSendAsync() {
    CountDownLatch latch1 = new CountDownLatch(1);
    CompletableFuture<Void> response = netty1.sendAsync(ep2, "test-subject", "hello world".getBytes());
    response.whenComplete((r, e) -> {
        assertNull(e);
        latch1.countDown();
    });
    Uninterruptibles.awaitUninterruptibly(latch1);

    CountDownLatch latch2 = new CountDownLatch(1);
    response = netty1.sendAsync(invalidEndPoint, "test-subject", "hello world".getBytes());
    response.whenComplete((r, e) -> {
        assertNotNull(e);
        latch2.countDown();
    });
    Uninterruptibles.awaitUninterruptibly(latch2);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:19,代碼來源:NettyMessagingManagerTest.java

示例5: write

import com.google.common.util.concurrent.Uninterruptibles; //導入方法依賴的package包/類
@Override
public void write(Message message) {
    Uninterruptibles.awaitUninterruptibly(transportInitialized);
    LOG.debug("Sending message: {}", message);
    try {
        Producer<String, String> producer = getProducer(configuration);
        producer.send(new ProducerRecord<>(String.valueOf(configuration.getTopic()),
                "message", message.getMessage()));
    } catch (Exception e) {
        LOG.error("Failed to send message", e);
    }
}
 
開發者ID:DevOpsStudio,項目名稱:Re-Collector,代碼行數:13,代碼來源:KafkaOutput.java

示例6: waitForUserCode

import com.google.common.util.concurrent.Uninterruptibles; //導入方法依賴的package包/類
/**
 * Put a dummy task into the queue and wait for it to be run. Because it's single threaded, this means all
 * tasks submitted before this point are now completed. Usually you won't want to use this method - it's a
 * convenience primarily used in unit testing. If you want to wait for an event to be called the right thing
 * to do is usually to create a {@link com.google.common.util.concurrent.SettableFuture} and then call set
 * on it. You can then either block on that future, compose it, add listeners to it and so on.
 */
public static void waitForUserCode() {
    final CountDownLatch latch = new CountDownLatch(1);
    USER_THREAD.execute(new Runnable() {
        @Override public void run() {
            latch.countDown();
        }
    });
    Uninterruptibles.awaitUninterruptibly(latch);
}
 
開發者ID:creativechain,項目名稱:creacoinj,代碼行數:17,代碼來源:Threading.java

示例7: updateStoreAndWaitForNotificationHandling

import com.google.common.util.concurrent.Uninterruptibles; //導入方法依賴的package包/類
private void updateStoreAndWaitForNotificationHandling(ApplicationId appId,
                                                       Consumer<ApplicationId> storeUpdateTask) {
    CountDownLatch latch = new CountDownLatch(1);
    try {
        pendingOperations.put(appId, latch);
        storeUpdateTask.accept(appId);
    } catch (Exception e) {
        pendingOperations.invalidate(appId);
        latch.countDown();
        log.warn("Failed to update store for {}", appId.name(), e);
    }
    Uninterruptibles.awaitUninterruptibly(latch, DEFAULT_OPERATION_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:14,代碼來源:ApplicationManager.java

示例8: createAtomixClient

import com.google.common.util.concurrent.Uninterruptibles; //導入方法依賴的package包/類
/**
 * Creates a Atomix client.
 */
protected AtomixClient createAtomixClient() {
    CountDownLatch latch = new CountDownLatch(1);
    AtomixClient client = AtomixClient.builder()
            .withTransport(new LocalTransport(registry))
            .withSerializer(serializer.clone())
            .build();
    client.connect(members).thenRun(latch::countDown);
    atomixClients.add(client);
    Uninterruptibles.awaitUninterruptibly(latch);
    return client;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:15,代碼來源:AtomixTestBase.java

示例9: waitForSavedSnapshot

import com.google.common.util.concurrent.Uninterruptibles; //導入方法依賴的package包/類
public static <T> T waitForSavedSnapshot(String persistenceId, Class<T> type) {
    if (!Uninterruptibles.awaitUninterruptibly(SNAPSHOT_SAVED_LATCHES.get(persistenceId), 5, TimeUnit.SECONDS)) {
        throw new AssertionError("Snapshot was not saved");
    }

    return getSnapshots(persistenceId, type).get(0);
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:8,代碼來源:InMemorySnapshotStore.java

示例10: waitForChangeEvents

import com.google.common.util.concurrent.Uninterruptibles; //導入方法依賴的package包/類
public void waitForChangeEvents(YangInstanceIdentifier... expPaths) {
    boolean done = Uninterruptibles.awaitUninterruptibly(changeLatch, 5, TimeUnit.SECONDS);
    if (!done) {
        fail(String.format("Missing change notifications. Expected: %d. Actual: %d",
                expChangeEventCount, expChangeEventCount - changeLatch.getCount()));
    }

    for (int i = 0; i < expPaths.length; i++) {
        Map<YangInstanceIdentifier, NormalizedNode<?, ?>> createdData = changeList.get(i).getCreatedData();
        assertTrue(String.format("Change %d does not contain %s. Actual: %s", i + 1, expPaths[i], createdData),
                createdData.containsKey(expPaths[i]));
    }
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:14,代碼來源:MockDataChangeListener.java

示例11: awaitMessages

import com.google.common.util.concurrent.Uninterruptibles; //導入方法依賴的package包/類
List<BytesMessage> awaitMessages() {
    Uninterruptibles.awaitUninterruptibly(latch, 2, TimeUnit.SECONDS);
    return messages;
}
 
開發者ID:florentw,項目名稱:bench,代碼行數:5,代碼來源:JMSClientServerTest.java

示例12: testMultipleWaitersOnShortCircuitCache

import com.google.common.util.concurrent.Uninterruptibles; //導入方法依賴的package包/類
/**
 * Test the case where we have multiple threads waiting on the
 * ShortCircuitCache delivering a certain ShortCircuitReplica.
 *
 * In this case, there should only be one call to
 * createShortCircuitReplicaInfo.  This one replica should be shared
 * by all threads.
 */
@Test(timeout=60000)
public void testMultipleWaitersOnShortCircuitCache()
    throws Exception {
  final CountDownLatch latch = new CountDownLatch(1);
  final AtomicBoolean creationIsBlocked = new AtomicBoolean(true);
  final AtomicBoolean testFailed = new AtomicBoolean(false);
  DFSInputStream.tcpReadsDisabledForTesting = true;
  BlockReaderFactory.createShortCircuitReplicaInfoCallback =
    new ShortCircuitCache.ShortCircuitReplicaCreator() {
      @Override
      public ShortCircuitReplicaInfo createShortCircuitReplicaInfo() {
        Uninterruptibles.awaitUninterruptibly(latch);
        if (!creationIsBlocked.compareAndSet(true, false)) {
          Assert.fail("there were multiple calls to "
              + "createShortCircuitReplicaInfo.  Only one was expected.");
        }
        return null;
      }
    };
  TemporarySocketDirectory sockDir = new TemporarySocketDirectory();
  Configuration conf = createShortCircuitConf(
      "testMultipleWaitersOnShortCircuitCache", sockDir);
  MiniDFSCluster cluster =
      new MiniDFSCluster.Builder(conf).numDataNodes(1).build();
  cluster.waitActive();
  final DistributedFileSystem dfs = cluster.getFileSystem();
  final String TEST_FILE = "/test_file";
  final int TEST_FILE_LEN = 4000;
  final int SEED = 0xFADED;
  final int NUM_THREADS = 10;
  DFSTestUtil.createFile(dfs, new Path(TEST_FILE), TEST_FILE_LEN,
      (short)1, SEED);
  Runnable readerRunnable = new Runnable() {
    @Override
    public void run() {
      try {
        byte contents[] = DFSTestUtil.readFileBuffer(dfs, new Path(TEST_FILE));
        Assert.assertFalse(creationIsBlocked.get());
        byte expected[] = DFSTestUtil.
            calculateFileContentsFromSeed(SEED, TEST_FILE_LEN);
        Assert.assertTrue(Arrays.equals(contents, expected));
      } catch (Throwable e) {
        LOG.error("readerRunnable error", e);
        testFailed.set(true);
      }
    }
  };
  Thread threads[] = new Thread[NUM_THREADS];
  for (int i = 0; i < NUM_THREADS; i++) {
    threads[i] = new Thread(readerRunnable);
    threads[i].start();
  }
  Thread.sleep(500);
  latch.countDown();
  for (int i = 0; i < NUM_THREADS; i++) {
    Uninterruptibles.joinUninterruptibly(threads[i]);
  }
  cluster.shutdown();
  sockDir.close();
  Assert.assertFalse(testFailed.get());
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:70,代碼來源:TestBlockReaderFactory.java

示例13: waitForDeleteMessagesComplete

import com.google.common.util.concurrent.Uninterruptibles; //導入方法依賴的package包/類
public static void waitForDeleteMessagesComplete(String persistenceId) {
    if (!Uninterruptibles.awaitUninterruptibly(DELETE_MESSAGES_COMPLETE_LATCHES.get(persistenceId),
            5, TimeUnit.SECONDS)) {
        throw new AssertionError("Delete messages did not complete");
    }
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:7,代碼來源:InMemoryJournal.java

示例14: waitForWriteMessagesComplete

import com.google.common.util.concurrent.Uninterruptibles; //導入方法依賴的package包/類
public static void waitForWriteMessagesComplete(String persistenceId) {
    if (!Uninterruptibles.awaitUninterruptibly(WRITE_MESSAGES_COMPLETE.get(persistenceId).latch,
            5, TimeUnit.SECONDS)) {
        throw new AssertionError("Journal write messages did not complete");
    }
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:7,代碼來源:InMemoryJournal.java

示例15: waitForDeletedSnapshot

import com.google.common.util.concurrent.Uninterruptibles; //導入方法依賴的package包/類
public static void waitForDeletedSnapshot(String persistenceId) {
    if (!Uninterruptibles.awaitUninterruptibly(SNAPSHOT_DELETED_LATCHES.get(persistenceId), 5, TimeUnit.SECONDS)) {
        throw new AssertionError("Snapshot was not deleted");
    }
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:6,代碼來源:InMemorySnapshotStore.java


注:本文中的com.google.common.util.concurrent.Uninterruptibles.awaitUninterruptibly方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。