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