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 * Gets all beans of a given type
11 *
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 *
20 * @param callback The callback class to execute
21 * @return Optional result of the operation. May be null
22 * @throws RuntimeException if anything went wrong. The caller will be responsible for rolling back.
23 */
24 <T> T doInTransaction(HostTransactionCallback<T> callback);
25
26 /**
27 * The interface to implement for code that needs to be ran inside a host transaction
28 * <p>
29 * Use {@link java.lang.Void} for <code>void</code> returns.
30 */
31 public static interface HostTransactionCallback<T> {
32 /**
33 * Runs an action in a transaction and returns a optional value.
34 *
35 * @return Optional result of the operation. May be null
36 * @throws RuntimeException if anything went wrong. The caller will be responsible for rolling back.
37 */
38 T doInTransaction();
39 }
40 }