Guava TimeLimiter - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Guava TimeLimiter class.

This code example shows how to use the following methods:newProxy
    } 
 
    private static <T> T timeLimited(T target, Class<T> clazz, Duration timeout, ExecutorService executor, int maxThreads)
    { 
        executor = new ExecutorServiceAdapter(new BoundedExecutor(executor, maxThreads));
        TimeLimiter limiter = new SimpleTimeLimiter(executor);
        return limiter.newProxy(target, clazz, timeout.toMillis(), MILLISECONDS);
    } 
} 
5
CodeRank
This code example shows how to use the following methods:callWithTimeout
   } 
 
   public void testMethodWithTimeoutRunsTimeLimiter() throws Exception {
      expect(config.getTimeoutNanos(asyncGet)).andReturn(Optional.of(250000000l));
      InvokeAndTransform invoke = invokeHttpMethod.new InvokeAndTransform("ns:get", getCommand);
      expect(timeLimiter.callWithTimeout(invoke, 250000000, TimeUnit.NANOSECONDS, true)).andReturn(response);
      replay(http, timeLimiter, fallback, config, future);
      invokeHttpMethod.apply(get);
   } 
 
   public void testMethodWithNoTimeoutCallGetDirectly() throws Exception {
      expect(config.getTimeoutNanos(asyncGet)).andReturn(Optional.<Long> absent());
      expect(http.invoke(new HttpCommand(getRequest))).andReturn(response);
      replay(http, timeLimiter, fallback, config, future);
      invokeHttpMethod.apply(get);
   } 
 
   public void testAsyncMethodSubmitsRequest() throws Exception {
      expect(http.submit(new HttpCommand(getRequest))).andReturn(future);
      future.addListener(anyObject(Runnable.class), eq(userThreads));
5
CodeRank
This code example shows how to use the following methods:callWithTimeout
      org.jclouds.Fallback<?> fallback = getFallback(commandName, invocation, command);
 
      logger.debug(">> blocking on %s for %s", invocation, limitNanos);
      try { 
         return timeLimiter
               .callWithTimeout(new InvokeAndTransform(commandName, command), limitNanos, NANOSECONDS, true);
      } catch (Throwable t) {
         try { 
            return fallback.createOrPropagate(t);
         } catch (Exception e) {
            throw propagate(e);
         } 
      } 
   } 
 
   private org.jclouds.Fallback<?> getFallback(String commandName, Invocation invocation, HttpCommand command) {
      HttpRequest request = command.getCurrentRequest();
      org.jclouds.Fallback<?> fallback = config.getFallback(invocation);
      if (fallback instanceof InvocationContext) 
         InvocationContext.class.cast(fallback).setContext(request);
5
CodeRank
This code example shows how to use the following methods:callWithTimeout
      org.jclouds.Fallback<?> fallback = getFallback(commandName, invocation, command);
 
      logger.debug(">> blocking on %s for %s", invocation, limitNanos);
      try { 
         return timeLimiter
               .callWithTimeout(new InvokeAndTransform(commandName, command), limitNanos, NANOSECONDS, true);
      } catch (Throwable t) {
         try { 
            return fallback.createOrPropagate(t);
         } catch (Exception e) {
            throw propagate(e);
         } 
      } 
   } 
 
   private org.jclouds.Fallback<?> getFallback(String commandName, Invocation invocation, HttpCommand command) {
      HttpRequest request = command.getCurrentRequest();
      org.jclouds.Fallback<?> fallback = config.getFallback(invocation);
      if (fallback instanceof InvocationContext) 
         InvocationContext.class.cast(fallback).setContext(request);
5
CodeRank
See Code Examples for Guava TimeLimiter Methods: