View Javadoc

1   package com.atlassian.sal.spi;
2   
3   import java.util.Map;
4   
5   /**
6    * Interface for accessing host information, meant to be exposed as a host component
7    */
8   public interface HostContextAccessor
9   {
10      /**
11       * Gets all beans of a given type
12       * @param iface The interface to use
13       * @return A map of String keys and object instances
14       */
15      <T> Map<String, T> getComponentsOfType(Class<T> iface);
16  
17      /**
18       * Runs an action in a transaction and returns a optional value.
19       * @param callback The callback class to execute
20       * @return Optional result of the operation. May be null
21       * @throws RuntimeException if anything went wrong.  The caller will be responsible for rolling back.
22       */
23      <T> T doInTransaction(HostTransactionCallback<T> callback);
24  
25      /**
26       * The interface to implement for code that needs to be ran inside a host transaction
27       * <p>
28       * Use {@link java.lang.Void} for <code>void</code> returns.
29       */
30      public static interface HostTransactionCallback<T>
31      {
32          /**
33           * Runs an action in a transaction and returns a optional value.
34           * @return Optional result of the operation. May be null
35           * @throws RuntimeException if anything went wrong.  The caller will be responsible for rolling back.
36           */
37          T doInTransaction();
38      }
39  }