Tabnine Logo
ServletScopes.scopeRequest
Code IndexAdd Tabnine to your IDE (free)

How to use
scopeRequest
method
in
com.google.inject.servlet.ServletScopes

Best Java code snippets using com.google.inject.servlet.ServletScopes.scopeRequest (Showing top 14 results out of 315)

origin: com.google.inject.extensions/guice-servlet

/**
 * Scopes the given callable inside a request scope. This is not the same as the HTTP request
 * scope, but is used if no HTTP request scope is in progress. In this way, keys can be scoped
 * as @RequestScoped and exist in non-HTTP requests (for example: RPC requests) as well as in HTTP
 * request threads.
 *
 * <p>The returned callable will throw a {@link ScopingException} when called if there is a
 * request scope already active on the current thread.
 *
 * @param callable code to be executed which depends on the request scope. Typically in another
 *     thread, but not necessarily so.
 * @param seedMap the initial set of scoped instances for Guice to seed the request scope with. To
 *     seed a key with null, use {@code null} as the value.
 * @return a callable that when called will run inside the a request scope that exposes the
 *     instances in the {@code seedMap} as scoped keys.
 * @since 3.0
 */
public static <T> Callable<T> scopeRequest(Callable<T> callable, Map<Key<?>, Object> seedMap) {
 return wrap(callable, scopeRequest(seedMap));
}
origin: com.google.inject.extensions/guice-servlet

public void testTransferNonHttpRequest_concurrentUseSameThreadOk() throws Exception {
 Callable<Boolean> callable =
   new Callable<Boolean>() {
    @Override
    public Boolean call() throws Exception {
     return ServletScopes.transferRequest(FALSE_CALLABLE).call();
    }
   };
 ImmutableMap<Key<?>, Object> seedMap = ImmutableMap.of();
 assertFalse(ServletScopes.scopeRequest(callable, seedMap).call());
}
origin: com.google.inject.extensions/guice-servlet

 public void testTransferNonHttpRequest_concurrentUseSameThreadOk_closeable() throws Exception {
  Callable<Boolean> callable =
    new Callable<Boolean>() {
     @Override
     public Boolean call() throws Exception {
      RequestScoper.CloseableScope scope = ServletScopes.transferRequest().open();
      try {
       return false;
      } finally {
       scope.close();
      }
     }
    };

  ImmutableMap<Key<?>, Object> seedMap = ImmutableMap.of();
  assertFalse(ServletScopes.scopeRequest(callable, seedMap).call());
 }
}
origin: com.google.inject.extensions/guice-servlet

public void testTransferNonHttpRequest_concurrentUseBlocks() throws Exception {
 Callable<Boolean> callable =
   new Callable<Boolean>() {
    @Override
    public Boolean call() throws Exception {
     ExecutorService executor = Executors.newSingleThreadExecutor();
     try {
      Future<Boolean> future =
        executor.submit(ServletScopes.transferRequest(FALSE_CALLABLE));
      try {
       return future.get(100, TimeUnit.MILLISECONDS);
      } catch (TimeoutException e) {
       return true;
      }
     } finally {
      executor.shutdownNow();
     }
    }
   };
 ImmutableMap<Key<?>, Object> seedMap = ImmutableMap.of();
 assertTrue(ServletScopes.scopeRequest(callable, seedMap).call());
}
origin: com.google.inject.extensions/guice-servlet

assertTrue(ServletScopes.scopeRequest(callable, seedMap).call());
origin: com.google.inject.extensions/guice-servlet

public final void testWrongValueClasses() throws Exception {
 Injector injector =
   Guice.createInjector(
     new ServletModule() {
      @Override
      protected void configureServlets() {
       bindConstant().annotatedWith(Names.named(SomeObject.INVALID)).to(SHOULDNEVERBESEEN);
       bind(SomeObject.class).in(RequestScoped.class);
      }
     });
 OffRequestCallable offRequestCallable = injector.getInstance(OffRequestCallable.class);
 try {
  ServletScopes.scopeRequest(
    offRequestCallable, ImmutableMap.<Key<?>, Object>of(Key.get(SomeObject.class), "Boo!"));
  fail();
 } catch (IllegalArgumentException iae) {
  assertEquals(
    "Value[Boo!] of type[java.lang.String] is not compatible with key["
      + Key.get(SomeObject.class)
      + "]",
    iae.getMessage());
 }
}
origin: com.google.inject.extensions/guice-servlet

Callable<Boolean> transfer = ServletScopes.scopeRequest(callable, seedMap).call();
origin: com.google.inject.extensions/guice-servlet

Data data = ServletScopes.scopeRequest(callable, seedMap).call();
origin: com.google.inject.extensions/guice-servlet

public final void testNullReplacement() throws Exception {
 Injector injector =
   Guice.createInjector(
     new ServletModule() {
      @Override
      protected void configureServlets() {
       bindConstant().annotatedWith(Names.named(SomeObject.INVALID)).to(SHOULDNEVERBESEEN);
       bind(SomeObject.class).in(RequestScoped.class);
      }
     });
 Callable<SomeObject> callable = injector.getInstance(Caller.class);
 try {
  assertNotNull(callable.call());
  fail();
 } catch (ProvisionException pe) {
  assertTrue(pe.getCause() instanceof OutOfScopeException);
 }
 // Validate that an actual null entry in the map results in a null injected object.
 Map<Key<?>, Object> map = Maps.newHashMap();
 map.put(Key.get(SomeObject.class), null);
 callable = ServletScopes.scopeRequest(injector.getInstance(Caller.class), map);
 assertNull(callable.call());
}
origin: com.google.inject.extensions/guice-servlet

executor
  .submit(
    ServletScopes.scopeRequest(
      offRequestCallable,
      ImmutableMap.<Key<?>, Object>of(Key.get(SomeObject.class), someObject)))
executor
  .submit(
    ServletScopes.scopeRequest(
      offRequestCallable,
      ImmutableMap.<Key<?>, Object>of(Key.get(SomeObject.class), someObject)))
origin: org.atteo/evo-tests

  @Override
  public void evaluate() throws Throwable {
    ServletScopes.scopeRequest(new Callable<Object>() {
      @Override
      public Object call() throws Exception {
        try {
          base.evaluate();
        } catch (Throwable e) {
          throw new RuntimeException(e);
        }
        return null;
      }
    }, new HashMap<Key<?>, Object>()).call();
  }
};
origin: org.atteo.moonshine/container-test-utils

  @Override
  public void evaluate() throws Throwable {
    ServletScopes.scopeRequest(new Callable<Object>() {
      @Override
      public Object call() throws Exception {
        try {
          base.evaluate();
        } catch (RuntimeException | Error e) {
          // don't wrap RuntimeExceptions
          // don't wrap Errors either, JUnit throws this
          throw e;
        } catch (Throwable e) {
          throw new RuntimeException(e);
        }
        return null;
      }
    }, new HashMap<Key<?>, Object>()).call();
  }
};
origin: com.jwebmp.inject.extensions/guice-servlet

/**
 * Scopes the given callable inside a request scope. This is not the same as the HTTP request
 * scope, but is used if no HTTP request scope is in progress. In this way, keys can be scoped
 * as @RequestScoped and exist in non-HTTP requests (for example: RPC requests) as well as in HTTP
 * request threads.
 *
 * <p>The returned callable will throw a {@link ScopingException} when called if there is a
 * request scope already active on the current thread.
 *
 * @param callable code to be executed which depends on the request scope. Typically in another
 *     thread, but not necessarily so.
 * @param seedMap the initial set of scoped instances for Guice to seed the request scope with. To
 *     seed a key with null, use {@code null} as the value.
 * @return a callable that when called will run inside the a request scope that exposes the
 *     instances in the {@code seedMap} as scoped keys.
 * @since 3.0
 */
public static <T> Callable<T> scopeRequest(Callable<T> callable, Map<Key<?>, Object> seedMap) {
 return wrap(callable, scopeRequest(seedMap));
}
origin: org.sonatype.sisu.inject/guice-servlet

/**
 * Scopes the given callable inside a request scope. This is not the same as the HTTP request
 * scope, but is used if no HTTP request scope is in progress. In this way, keys can be scoped
 * as @RequestScoped and exist in non-HTTP requests (for example: RPC requests) as well as in HTTP
 * request threads.
 *
 * <p>The returned callable will throw a {@link ScopingException} when called if there is a
 * request scope already active on the current thread.
 *
 * @param callable code to be executed which depends on the request scope. Typically in another
 *     thread, but not necessarily so.
 * @param seedMap the initial set of scoped instances for Guice to seed the request scope with. To
 *     seed a key with null, use {@code null} as the value.
 * @return a callable that when called will run inside the a request scope that exposes the
 *     instances in the {@code seedMap} as scoped keys.
 * @since 3.0
 */
public static <T> Callable<T> scopeRequest(Callable<T> callable, Map<Key<?>, Object> seedMap) {
 return wrap(callable, scopeRequest(seedMap));
}
com.google.inject.servletServletScopesscopeRequest

Javadoc

Returns an object that will apply request scope to a block of code. This is not the same as the HTTP request scope, but is used if no HTTP request scope is in progress. In this way, keys can be scoped as @RequestScoped and exist in non-HTTP requests (for example: RPC requests) as well as in HTTP request threads.

The returned object will throw a ScopingException when opened if there is a request scope already active on the current thread.

Popular methods of ServletScopes

  • continueRequest
    Wraps the given callable in a contextual callable that "continues" the HTTP request in another threa
  • transferRequest
    Wraps the given callable in a contextual callable that "transfers" the request to another thread. Th
  • validateAndCanonicalizeValue
    Validates the key and object, ensuring the value matches the key type, and canonicalizing null objec
  • transferHttpRequest
  • transferNonHttpRequest
  • wrap
  • isRequestScoped
    Returns true if binding is request-scoped. If the binding is a com.google.inject.spi.LinkedKeyBindin
  • isSingletonBinding

Popular in Java

  • Making http requests using okhttp
  • findViewById (Activity)
  • getSystemService (Context)
  • notifyDataSetChanged (ArrayAdapter)
  • Color (java.awt)
    The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • Format (java.text)
    The base class for all formats. This is an abstract base class which specifies the protocol for clas
  • GregorianCalendar (java.util)
    GregorianCalendar is a concrete subclass of Calendarand provides the standard calendar used by most
  • Set (java.util)
    A Set is a data structure which does not allow duplicate elements.
  • BlockingQueue (java.util.concurrent)
    A java.util.Queue that additionally supports operations that wait for the queue to become non-empty
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now