View Javadoc

1   /*
2      Copyright 2008 Ramon Servadei
3   
4      Licensed under the Apache License, Version 2.0 (the "License");
5      you may not use this file except in compliance with the License.
6      You may obtain a copy of the License at
7   
8          http://www.apache.org/licenses/LICENSE-2.0
9   
10     Unless required by applicable law or agreed to in writing, software
11     distributed under the License is distributed on an "AS IS" BASIS,
12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13     See the License for the specific language governing permissions and
14     limitations under the License.
15   */
16  package fulmine.context;
17  
18  import java.util.Map;
19  import java.util.Set;
20  import java.util.concurrent.atomic.AtomicInteger;
21  
22  import fulmine.ILifeCycle;
23  import fulmine.event.listener.IEventListener;
24  import fulmine.model.container.IContainer;
25  import fulmine.model.field.IField;
26  import fulmine.rpc.IRpcDefinition;
27  import fulmine.rpc.IRpcMarker;
28  import fulmine.rpc.IRpcPublicationListener;
29  import fulmine.rpc.IRpcRegistry;
30  import fulmine.rpc.IRpcResult;
31  import fulmine.rpc.IRpcResultHandler;
32  import fulmine.util.collection.MapList;
33  import fulmine.util.collection.MapSet;
34  import fulmine.util.concurrent.ITaskExecutor;
35  import fulmine.util.reference.DualValue;
36  import fulmine.util.reference.IReferenceCounter;
37  import fulmine.util.reference.QuadValue;
38  
39  /**
40   * Interface for the state object of the {@link RpcManager}
41   * 
42   * @author Ramon Servadei
43   */
44  interface IRpcManagerState extends ILifeCycle
45  {
46  
47      /**
48       * Initialise the state
49       * 
50       * @param operations
51       *            the operations reference
52       */
53      void init(IRpcManagerOperations operations);
54  
55      /** The context */
56      IFrameworkContext getContext();
57  
58      /** The RPC registry */
59      IRpcRegistry getRegistry();
60  
61      /**
62       * Holds the {@link IRpcResultHandler} to invoke with the {@link IRpcResult}
63       * for the matching RPC marker ID. The {@link IRpcDefinition} is also held
64       * with the result handler.
65       */
66      Map<Integer, DualValue<IRpcResultHandler, IRpcDefinition>> getResultHandlers();
67  
68      /** Used to generate the marker ID for each successive RPC invocation */
69      AtomicInteger getMarkerCounter();
70  
71      /** Holds RPC invocations for contexts not yet available */
72      MapList<String, QuadValue<String, IField[], IRpcResultHandler, IRpcMarker>> getPendingRpcInvocations();
73  
74      /** Get the result records for the connected remote contexts. */
75      MapSet<String, IContainer> getResultRecords();
76  
77      /** The currently connected contexts */
78      Set<String> getConnectedContexts();
79  
80      /**
81       * Get the name of the result record from the event. The name has the format
82       * 
83       * <pre>
84       *  [remote context identity]:[rpc key]
85       * </pre>
86       * 
87       * @param remoteContextIdentity
88       *            the remote context identity
89       * @param rpcKey
90       *            the rpc key
91       * @return the RPC's result record name for the remote context calling this
92       *         RPC
93       */
94      public String getResultRecordName(String remoteContextIdentity,
95          String rpcKey);
96  
97      /** Get the event handler */
98      IEventListener getEventHandler();
99  
100     /**
101      * Get the {@link IRpcPublicationListener} instances registered against each
102      * remote context.
103      * <p>
104      * Access must be synchronized
105      * 
106      * @return the {@link IRpcPublicationListener} instances registered against
107      *         each remote context
108      */
109     MapSet<String, IRpcPublicationListener> getRpcPublicationListeners();
110 
111     /**
112      * Get the reference counter for currently subscribed result records
113      * 
114      * @return a reference counter of the currently subscribed result records
115      */
116     IReferenceCounter<DualValue<String, String>> getResultRecordSubscriptionCounter();
117 
118     /**
119      * Get a task executor for running invoke and result received events
120      * 
121      * @return a task executor
122      */
123     ITaskExecutor getTaskExecutor();
124 
125     /**
126      * Tracks the collection of observed result records. This is needed so that
127      * an RPC can be invoked; an RPC invocation has to wait until it is known
128      * that the result record is being observed (by the channel that will send
129      * the result to the RPC invoker)
130      * <p>
131      * Access should be synchronised on the collection.
132      * 
133      * @return the collection of observed result records
134      */
135     Set<String> getObservedResultRecords();
136 }