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

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

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

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

 @Override
 public Boolean call() throws Exception {
  return ServletScopes.transferRequest(FALSE_CALLABLE).call();
 }
};
origin: com.google.inject.extensions/guice-servlet

/**
 * Wraps the given callable in a contextual callable that "transfers" the request to another
 * thread. This acts as a way of transporting request context data from the current thread to a
 * future thread.
 *
 * <p>As opposed to {@link #continueRequest}, this method propagates all existing scoped objects.
 * The primary use case is in server implementations where you can detach the request processing
 * thread while waiting for data, and reattach to a different thread to finish processing at a
 * later time.
 *
 * <p>Because request-scoped objects are not typically thread-safe, the callable returned by this
 * method must not be run on a different thread until the current request scope has terminated.
 * The returned callable will block until the current thread has released the request scope.
 *
 * @param callable code to be executed in another thread, which depends on the request scope.
 * @return a callable that will invoke the given callable, making the request context available to
 *     it.
 * @throws OutOfScopeException if this method is called from a non-request thread, or if the
 *     request has completed.
 * @since 4.0
 */
public static <T> Callable<T> transferRequest(Callable<T> callable) {
 return wrap(callable, transferRequest());
}
origin: com.google.inject.extensions/guice-servlet

 @Override
 public Callable<Boolean> call() {
  final Object original = injector.getInstance(Object.class);
  return ServletScopes.transferRequest(
    new Callable<Boolean>() {
     @Override
     public Boolean call() {
      return original == injector.getInstance(Object.class);
     }
    });
 }
};
origin: com.google.inject.extensions/guice-servlet

 @Override
 public Data call() {
  Data data = new Data();
  data.object = injector.getInstance(Object.class);
  data.scoper = ServletScopes.transferRequest();
  return data;
 }
};
origin: com.google.inject.extensions/guice-servlet

 @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();
  }
 }
};
origin: com.google.inject.extensions/guice-servlet

public void testTransferHttp_outOfScope() {
 try {
  ServletScopes.transferRequest(FALSE_CALLABLE);
  fail();
 } catch (OutOfScopeException expected) {
 }
}
origin: com.google.inject.extensions/guice-servlet

public void testTransferNonHttp_outOfScope() {
 try {
  ServletScopes.transferRequest(FALSE_CALLABLE);
  fail();
 } catch (OutOfScopeException expected) {
 }
}
origin: com.google.inject.extensions/guice-servlet

public void testTransferNonHttp_outOfScope_closeable() {
 try {
  ServletScopes.transferRequest();
  fail();
 } catch (OutOfScopeException expected) {
 }
}
origin: com.google.inject.extensions/guice-servlet

 @Override
 public Boolean call() throws Exception {
  final RequestScoper scoper = ServletScopes.transferRequest();
  ExecutorService executor = Executors.newSingleThreadExecutor();
  try {
   Future<Boolean> future =
     executor.submit(
       new Callable<Boolean>() {
        @Override
        public Boolean call() {
         RequestScoper.CloseableScope scope = scoper.open();
         try {
          return false;
         } finally {
          scope.close();
         }
        }
       });
   try {
    return future.get(100, TimeUnit.MILLISECONDS);
   } catch (TimeoutException e) {
    return true;
   }
  } finally {
   executor.shutdownNow();
  }
 }
};
origin: com.google.inject.extensions/guice-servlet

 @Override
 public Boolean call() throws Exception {
  RequestScoper.CloseableScope scope = ServletScopes.transferRequest().open();
  try {
   return false;
  } finally {
   scope.close();
  }
 }
};
origin: org.sonatype.sisu.inject/guice-servlet

/**
 * Wraps the given callable in a contextual callable that "transfers" the request to another
 * thread. This acts as a way of transporting request context data from the current thread to a
 * future thread.
 *
 * <p>As opposed to {@link #continueRequest}, this method propagates all existing scoped objects.
 * The primary use case is in server implementations where you can detach the request processing
 * thread while waiting for data, and reattach to a different thread to finish processing at a
 * later time.
 *
 * <p>Because request-scoped objects are not typically thread-safe, the callable returned by this
 * method must not be run on a different thread until the current request scope has terminated.
 * The returned callable will block until the current thread has released the request scope.
 *
 * @param callable code to be executed in another thread, which depends on the request scope.
 * @return a callable that will invoke the given callable, making the request context available to
 *     it.
 * @throws OutOfScopeException if this method is called from a non-request thread, or if the
 *     request has completed.
 * @since 4.0
 */
public static <T> Callable<T> transferRequest(Callable<T> callable) {
 return wrap(callable, transferRequest());
}
origin: com.jwebmp.inject.extensions/guice-servlet

/**
 * Wraps the given callable in a contextual callable that "transfers" the request to another
 * thread. This acts as a way of transporting request context data from the current thread to a
 * future thread.
 *
 * <p>As opposed to {@link #continueRequest}, this method propagates all existing scoped objects.
 * The primary use case is in server implementations where you can detach the request processing
 * thread while waiting for data, and reattach to a different thread to finish processing at a
 * later time.
 *
 * <p>Because request-scoped objects are not typically thread-safe, the callable returned by this
 * method must not be run on a different thread until the current request scope has terminated.
 * The returned callable will block until the current thread has released the request scope.
 *
 * @param callable code to be executed in another thread, which depends on the request scope.
 * @return a callable that will invoke the given callable, making the request context available to
 *     it.
 * @throws OutOfScopeException if this method is called from a non-request thread, or if the
 *     request has completed.
 * @since 4.0
 */
public static <T> Callable<T> transferRequest(Callable<T> callable) {
 return wrap(callable, transferRequest());
}
origin: org.sonatype.nexus/nexus-extdirect

public ExtDirectJsonRequestProcessorThread() {
 Subject subject = SecurityUtils.getSubject();
 checkState(subject != null, "Subject is not set");
 // create the thread state by this moment as this is created in the master (web container) thread
 threadState = new SubjectThreadState(subject);
 final String baseUrl = BaseUrlHolder.get();
 processRequest = ServletScopes.transferRequest(new Callable<String>()
 {
  @Override
  public String call() {
   threadState.bind();
   UserIdMdcHelper.set();
   try {
    // apply base-url from the original thread
    BaseUrlHolder.set(baseUrl);
    return ExtDirectJsonRequestProcessorThread.super.processRequest();
   }
   finally {
    UserIdMdcHelper.unset();
    threadState.restore();
   }
  }
 });
}
com.google.inject.servletServletScopestransferRequest

Javadoc

Returns an object that "transfers" the request to another thread. This acts as a way of transporting request context data from the current thread to a future thread. The transferred scope is the one active for the thread that calls this method. A later call to open()activates the transferred the scope, including propagating any objects scoped at that time.

As opposed to #continueRequest, this method propagates all existing scoped objects. The primary use case is in server implementations where you can detach the request processing thread while waiting for data, and reattach to a different thread to finish processing at a later time.

Because request-scoped objects are not typically thread-safe, it is important to avoid applying the same request scope concurrently. The returned Scoper will block on open until the current thread has released the request scope.

Popular methods of ServletScopes

  • scopeRequest
    Scopes the given callable inside a request scope. This is not the same as the HTTP request scope, bu
  • continueRequest
    Wraps the given callable in a contextual callable that "continues" the HTTP request in another threa
  • 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

  • Parsing JSON documents to java classes using gson
  • onRequestPermissionsResult (Fragment)
  • setContentView (Activity)
  • addToBackStack (FragmentTransaction)
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • LinkedList (java.util)
    Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list oper
  • ConcurrentHashMap (java.util.concurrent)
    A plug-in replacement for JDK1.5 java.util.concurrent.ConcurrentHashMap. This version is based on or
  • CountDownLatch (java.util.concurrent)
    A synchronization aid that allows one or more threads to wait until a set of operations being perfor
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
  • StringUtils (org.apache.commons.lang)
    Operations on java.lang.String that arenull safe. * IsEmpty/IsBlank - checks if a String contains
  • Top 12 Jupyter Notebook extensions
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