Interface Executor

  • All Superinterfaces:
    org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.Aware
    All Known Implementing Classes:
    Executor.Impl

    public interface Executor
    extends org.springframework.context.ApplicationContextAware
    Simple execution/work interface which can be used for internal tasks which need to have a full working implementation. The execute(Principal, Work) method ensures that SecuritySystem.login(Principal) is called before the task, that a TransactionCallback and a HibernateCallback surround the call, and that subsequently SecuritySystem.logout() is called.
    Since:
    3.0-Beta3
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      <T> T execute​(java.util.Map<java.lang.String,​java.lang.String> callContext, ome.system.Principal p, Executor.Work<T> work)
      Executes a Executor.Work instance wrapped in two layers of AOP.
      <T> T execute​(ome.system.Principal p, Executor.Work<T> work)
      Call execute(Map, Principal, Work) with a null call context.
      java.lang.Object executeSql​(Executor.SqlWork work)
      Executes a Executor.SqlWork wrapped with a transaction.
      <T> T get​(java.util.concurrent.Future<T> future)
      Helper method to perform Future.get() and properly unwrap the exceptions.
      ome.system.OmeroContext getContext()
      Provides access to the context for Work-API consumers who need to publish events, etc.
      java.util.concurrent.ExecutorService getService()
      Returns the ExecutorService assigned to this instance.
      ome.system.Principal principal()
      Returns a Principal representing your current session or null, if none is active.
      <T> java.util.concurrent.Future<T> submit​(java.util.concurrent.Callable<T> callable)
      Call submit(Map, Callable) with a null callContext.
      <T> java.util.concurrent.Future<T> submit​(java.util.Map<java.lang.String,​java.lang.String> callContext, java.util.concurrent.Callable<T> callable)
      Simple submission method which can be used in conjunction with a call to execute(Principal, Work) to overcome the no-multiple-login rule.
      <T> java.util.concurrent.Future<T> submit​(Executor.Priority prio, java.util.concurrent.Callable<T> callable)
      Simple submission method with a Executor.Priority.
      <T> java.util.concurrent.Future<T> submit​(Executor.Priority prio, java.util.Map<java.lang.String,​java.lang.String> callContext, java.util.concurrent.Callable<T> callable)
      Like submit(Map, Callable) but provide info to which priority queue should be used.
      • Methods inherited from interface org.springframework.context.ApplicationContextAware

        setApplicationContext
    • Method Detail

      • getContext

        ome.system.OmeroContext getContext()
        Provides access to the context for Work-API consumers who need to publish events, etc.
      • principal

        ome.system.Principal principal()
        Returns a Principal representing your current session or null, if none is active.
      • execute

        <T> T execute​(java.util.Map<java.lang.String,​java.lang.String> callContext,
                      ome.system.Principal p,
                      Executor.Work<T> work)
        Executes a Executor.Work instance wrapped in two layers of AOP. The first is intended to acquire the proper arguments for Executor.Work.doWork(Session, ServiceFactory) from the OmeroContext, and the second performs all the standard service actions for any normal method call. If the Map argument is not null, then additionally, setContext will be called in a try/finally block. The first login within this thread will then pick up this delayed context. If the Principal argument is not null, then additionally, a login/logout sequence will be performed in a try/finally block. Executor.Work implementation must be annotated with Transactional in order to properly specify isolation, read-only status, etc.
        Parameters:
        callContext - Possibly null.
        p - Possibly null.
        work - Not null.
        Returns:
        See above.
      • submit

        <T> java.util.concurrent.Future<T> submit​(java.util.concurrent.Callable<T> callable)
        Call submit(Map, Callable) with a null callContext.
        Parameters:
        callable -
        Returns:
        See above.
      • submit

        <T> java.util.concurrent.Future<T> submit​(java.util.Map<java.lang.String,​java.lang.String> callContext,
                                                  java.util.concurrent.Callable<T> callable)
        Simple submission method which can be used in conjunction with a call to execute(Principal, Work) to overcome the no-multiple-login rule.
        Type Parameters:
        T -
        Parameters:
        callContext - Possibly null. See CurrentDetails.setContext(Map)
        callable - Not null. Action to be taken.
        Returns:
        See above.
      • submit

        <T> java.util.concurrent.Future<T> submit​(Executor.Priority prio,
                                                  java.util.Map<java.lang.String,​java.lang.String> callContext,
                                                  java.util.concurrent.Callable<T> callable)
        Like submit(Map, Callable) but provide info to which priority queue should be used.
        Parameters:
        prio - Possibly null. Priority for execution. Default: Executor.Priority.USER
        callContext - Possibly null. See CurrentDetails.setContext(Map)
        callable - Not null. Action to be taken.
        Returns:
        See above.
      • get

        <T> T get​(java.util.concurrent.Future<T> future)
        Helper method to perform Future.get() and properly unwrap the exceptions. Any RuntimeException which was thrown during execution will be rethrown. All other exceptions will be wrapped in an InternalException.
      • getService

        java.util.concurrent.ExecutorService getService()
        Returns the ExecutorService assigned to this instance. Used by submit(Callable) and get(Future).
      • executeSql

        java.lang.Object executeSql​(Executor.SqlWork work)
        Executes a Executor.SqlWork wrapped with a transaction. Since StatelessSession does not return proxies, there is less concern about returned values, but this method completely overrides OMERO security, and should be used very carefully. As with execute(Principal, Work) the Executor.SqlWork instance must be properly marked with an Transactional annotation.
        Parameters:
        work - Non-null.
        Returns:
        See above.