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


Java TimeoutException類代碼示例

本文整理匯總了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");
    }
  });
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:27,代碼來源:HBaseAdmin.java

示例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();
}
 
開發者ID:tunnelvisionlabs,項目名稱:java-threading,代碼行數:27,代碼來源:TestBase.java

示例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();
}
 
開發者ID:salesforce,項目名稱:grpc-java-contrib,代碼行數:32,代碼來源:CompletableFutureEndToEndTest.java

示例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.");
  }
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:17,代碼來源:AbstractService.java

示例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();
                }
            }
        }
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:24,代碼來源:BasicFuture.java

示例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);
}
 
開發者ID:mumudemo,項目名稱:mumu-rabbitmq,代碼行數:33,代碼來源:RabbitMQRPC.java

示例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();
}
 
開發者ID:ProgrammingLife2017,項目名稱:hygene,代碼行數:20,代碼來源:UITestBase.java

示例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();
}
 
開發者ID:adamkewley,項目名稱:jobson,代碼行數:14,代碼來源:JobManagerTest.java

示例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);
    }
}
 
開發者ID:experoinc,項目名稱:dropwizard-tinkerpop,代碼行數:12,代碼來源:TinkerPopManaged.java

示例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());
}
 
開發者ID:florentw,項目名稱:bench,代碼行數:8,代碼來源:ActorsTest.java

示例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();
    }
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:8,代碼來源:WaitableQueue.java

示例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);
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:12,代碼來源:KafkaFutureImpl.java

示例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);
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:16,代碼來源:DataTestIT.java

示例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);
}
 
開發者ID:mevdschee,項目名稱:tqdev-metrics,代碼行數:10,代碼來源:InstrumentedHandlerTest.java

示例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;
}
 
開發者ID:nsg-ethz,項目名稱:iTAP-controller,代碼行數:13,代碼來源:RemoteSyncFuture.java


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