本文整理匯總了Java中java.util.concurrent.TimeoutException類的典型用法代碼示例。如果您正苦於以下問題:Java TimeoutException類的具體用法?Java TimeoutException怎麽用?Java TimeoutException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TimeoutException類屬於java.util.concurrent包,在下文中一共展示了TimeoutException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: waitTableEnabled
import java.util.concurrent.TimeoutException; //導入依賴的package包/類
private void waitTableEnabled(final long deadlineTs)
throws IOException, TimeoutException {
waitForState(deadlineTs, new WaitForStateCallable() {
@Override
public boolean checkState(int tries) throws IOException {
boolean enabled;
try {
enabled = getAdmin().isTableEnabled(tableName);
} catch (TableNotFoundException tnfe) {
return false;
}
return enabled && getAdmin().isTableAvailable(tableName);
}
@Override
public void throwInterruptedException() throws InterruptedIOException {
throw new InterruptedIOException("Interrupted when waiting for table to be enabled");
}
@Override
public void throwTimeoutException(long elapsedTime) throws TimeoutException {
throw new TimeoutException("Table " + tableName + " not yet enabled after " +
elapsedTime + "msec");
}
});
}
示例2: verifyDoesNotInlineContinuations
import java.util.concurrent.TimeoutException; //導入依賴的package包/類
/**
* Verifies that continuations scheduled on a future will not be executed inline with the specified completing
* action.
*
* @param antecedent The future to test.
* @param completingAction The action that results in the synchronous completion of the future.
*/
protected static void verifyDoesNotInlineContinuations(@NotNull CompletableFuture<?> antecedent, @NotNull Runnable completingAction) {
Requires.notNull(antecedent, "antecedent");
Requires.notNull(completingAction, "completingAction");
CompletableFuture<Void> completingActionFinished = new CompletableFuture<>();
CompletableFuture<Void> continuation = antecedent.handle((result, exception) -> {
try {
return completingActionFinished.get(ASYNC_DELAY.toMillis(), TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException ex) {
throw new CompletionException(ex);
}
});
completingAction.run();
completingActionFinished.complete(null);
// Rethrow the exception if it turned out it deadlocked.
continuation.join();
}
示例3: serverRunsAndRespondsCorrectly
import java.util.concurrent.TimeoutException; //導入依賴的package包/類
@Test
public void serverRunsAndRespondsCorrectly() throws ExecutionException,
IOException,
InterruptedException,
TimeoutException {
final String name = UUID.randomUUID().toString();
Server server = ServerBuilder.forPort(9999)
.addService(new GreeterImpl())
.build();
server.start();
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", server.getPort())
.usePlaintext(true)
.build();
GreeterGrpc8.GreeterCompletableFutureStub stub = GreeterGrpc8.newCompletableFutureStub(channel);
CompletableFuture<HelloResponse> response = stub.sayHello(HelloRequest.newBuilder().setName(name).build());
await().atMost(3, TimeUnit.SECONDS).until(() -> response.isDone() && response.get().getMessage().contains(name));
channel.shutdown();
channel.awaitTermination(1, TimeUnit.MINUTES);
channel.shutdownNow();
server.shutdown();
server.awaitTermination(1, TimeUnit.MINUTES);
server.shutdownNow();
}
示例4: awaitRunning
import java.util.concurrent.TimeoutException; //導入依賴的package包/類
@Override
public final void awaitRunning(long timeout, TimeUnit unit) throws TimeoutException {
if (monitor.enterWhenUninterruptibly(hasReachedRunning, timeout, unit)) {
try {
checkCurrentState(RUNNING);
} finally {
monitor.leave();
}
} else {
// It is possible due to races the we are currently in the expected state even though we
// timed out. e.g. if we weren't event able to grab the lock within the timeout we would never
// even check the guard. I don't think we care too much about this use case but it could lead
// to a confusing error message.
throw new TimeoutException("Timed out waiting for " + this + " to reach the RUNNING state.");
}
}
示例5: get
import java.util.concurrent.TimeoutException; //導入依賴的package包/類
public synchronized T get(long timeout, final TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException {
long msecs = unit.toMillis(timeout);
long startTime = (msecs <= 0) ? 0 : System.currentTimeMillis();
long waitTime = msecs;
if (this.completed) {
return getResult();
} else if (waitTime <= 0) {
throw new TimeoutException();
} else {
for (;;) {
wait(waitTime);
if (this.completed) {
return getResult();
} else {
waitTime = msecs - (System.currentTimeMillis() - startTime);
if (waitTime <= 0) {
throw new TimeoutException();
}
}
}
}
}
示例6: service
import java.util.concurrent.TimeoutException; //導入依賴的package包/類
/**
* 服務端開啟服務
*/
public void service() throws IOException, TimeoutException {
RabbitMQChannel channel = new RabbitMQChannel().channel();
channel.getChannel().queueDeclare(RPC_QUEUE_NAME, false, false, false, null);
channel.getChannel().basicQos(1);
System.out.println("等待rpc客戶端連接...");
Consumer consumer = new DefaultConsumer(channel.getChannel()) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
AMQP.BasicProperties replyProps = new AMQP.BasicProperties
.Builder()
.correlationId(properties.getCorrelationId())
.build();
String response = "";
try {
String message = new String(body, "UTF-8");
System.out.println("服務端接受到消息:" + message);
response = message + UUID.randomUUID().toString();
} catch (RuntimeException e) {
e.printStackTrace();
} finally {
channel.getChannel().basicPublish("", properties.getReplyTo(), replyProps, response.getBytes("UTF-8"));
channel.getChannel().basicAck(envelope.getDeliveryTag(), false);
System.out.println("服務端將處理結果:" + response + ",返回客戶單\n");
}
}
};
channel.getChannel().basicConsume(RPC_QUEUE_NAME, false, consumer);
}
示例7: basicBeforeEach
import java.util.concurrent.TimeoutException; //導入依賴的package包/類
/**
* Set up application before each test.
* Afterwards, calls the {@link #beforeEach()} method.
*
* @throws TimeoutException if unable to set up application
* @throws UIInitialisationException if ui was not properly initialized
* @see FxToolkit#setupApplication(Class, String...)
*/
@BeforeEach
public final void basicBeforeEach() throws TimeoutException, UIInitialisationException {
this.primaryStage = FxToolkit.registerPrimaryStage();
this.application = (Hygene) FxToolkit.setupApplication(Hygene.class);
this.context = Hygene.getInstance().getContext();
FxToolkit.showStage();
beforeEach();
}
示例8: testSubmitPromiseResolvesWhenExecutorPromiseResolves2
import java.util.concurrent.TimeoutException; //導入依賴的package包/類
@Test
public void testSubmitPromiseResolvesWhenExecutorPromiseResolves2() throws InterruptedException, ExecutionException, TimeoutException {
final CancelablePromise<JobExecutionResult> p = new SimpleCancelablePromise<>();
final JobExecutor jobExecutor = MockJobExecutor.thatUses(p);
final JobManager jobManager = createManagerWith(jobExecutor);
final CancelablePromise<FinalizedJob> ret =
jobManager.submit(STANDARD_VALID_REQUEST).getRight();
p.complete(JobExecutionResult.fromExitCode(0));
assertThat(ret.get(DEFAULT_TIMEOUT, MILLISECONDS)).isNotNull();
}
示例9: stop
import java.util.concurrent.TimeoutException; //導入依賴的package包/類
@Override
public void stop() throws Exception {
LOG.info("Attempting to shutdown TinkerPop cluster connection.");
CompletableFuture<Void> future = cluster.closeAsync();
try {
future.get(shutdownTimeout.toMilliseconds(), TimeUnit.MILLISECONDS);
} catch (TimeoutException ex) {
LOG.warn("Unable to close TinkerPop cluster after {}", shutdownTimeout);
}
}
示例10: actorCreation_is_set_when_actor_fails
import java.util.concurrent.TimeoutException; //導入依賴的package包/類
@Test
public void actorCreation_is_set_when_actor_fails()
throws ExecutionException, InterruptedException, TimeoutException {
Actors.ActorHandle actorHandle = actors.create(actorConfig);
verifyActorFailureThrowsFor(actorHandle.actorCreation());
}
示例11: waitUntilEmpty
import java.util.concurrent.TimeoutException; //導入依賴的package包/類
public void waitUntilEmpty(long timeoutMillis)
throws TimeoutException, InterruptedException {
add(mStopRequest);
if (!mStopEvent.tryAcquire(timeoutMillis, TimeUnit.MILLISECONDS)) {
throw new TimeoutException();
}
}
示例12: get
import java.util.concurrent.TimeoutException; //導入依賴的package包/類
/**
* Waits if necessary for at most the given time for this future to complete, and then returns
* its result, if available.
*/
@Override
public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException,
TimeoutException {
SingleWaiter<T> waiter = new SingleWaiter<T>();
addWaiter(waiter);
return waiter.await(timeout, unit);
}
示例13: testNegativeIntegerKeys
import java.util.concurrent.TimeoutException; //導入依賴的package包/類
@Test
public void testNegativeIntegerKeys()
throws TestFailure, ExecutionException, TimeoutException, InterruptedException {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
new WriteFuture(ref,
new MapBuilder().put("-1", "minus-one").put("0", "zero").put("1", "one").build())
.timedGet();
DataSnapshot snap = TestHelpers.getSnap(ref);
Map<String, Object> expected = new MapBuilder().put("-1", "minus-one").put("0", "zero")
.put("1", "one").build();
Object result = snap.getValue();
TestHelpers.assertDeepEquals(expected, result);
}
示例14: shouldMeasureHello
import java.util.concurrent.TimeoutException; //導入依賴的package包/類
@Test
public void shouldMeasureHello() throws InterruptedException, ExecutionException, TimeoutException {
ContentResponse response = client.GET(url + "/hello");
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContentAsString()).isEqualTo("Hello World!");
assertThat(registry.get("jetty.Response.Invocations", "2xx-responses")).isEqualTo(1L);
assertThat(registry.get("jetty.Response.Durations", "2xx-responses")).isEqualTo(123456789L);
}
示例15: get
import java.util.concurrent.TimeoutException; //導入依賴的package包/類
@Override
public SyncReply
get(long timeout, TimeUnit unit) throws InterruptedException,
ExecutionException,
TimeoutException {
if (reply != null) return reply;
synchronized (notify) {
notify.wait(TimeUnit.MILLISECONDS.convert(timeout, unit));
}
if (reply == null) throw new TimeoutException();
return reply;
}