当前位置: 首页>>代码示例>>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;未经允许,请勿转载。