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.distribution; 17 18 import java.util.Map; 19 import java.util.Set; 20 21 import fulmine.ILifeCycle; 22 import fulmine.context.IFrameworkContext; 23 import fulmine.distribution.channel.IChannel; 24 import fulmine.distribution.channel.IChannelFactory; 25 import fulmine.distribution.connection.IConnectionParameters; 26 import fulmine.event.listener.IEventListener; 27 import fulmine.event.listener.ILifeCycleEventListener; 28 import fulmine.event.subscription.ISubscriptionManager; 29 import fulmine.event.subscription.ISubscriptionParameters; 30 import fulmine.protocol.specification.IFrameReader; 31 import fulmine.protocol.specification.IFrameWriter; 32 import fulmine.util.reference.DualValue; 33 import fulmine.util.reference.IAutoCreatingStore; 34 import fulmine.util.reference.IReferenceCounter; 35 36 /** 37 * Interface for the shared state object of the {@link DistributionManager}. 38 * 39 * @author Ramon Servadei 40 */ 41 public interface IDistributionState extends ILifeCycle 42 { 43 /** 44 * Initialise the state 45 */ 46 void init(); 47 48 /** Create the channel factory to use */ 49 IChannelFactory createChannelFactory(); 50 51 /** Constructs the channels */ 52 IChannelFactory getChannelFactory(); 53 54 /** Get the event handler */ 55 ILifeCycleEventListener getEventHandler(); 56 57 /** 58 * The channels in use, keyed on remote context identity. This uses 59 * copy-on-write concurrency. 60 */ 61 Map<String, IChannel> getChannels(); 62 63 /** 64 * The discovered contexts, keyed on remote context identity. 65 * <p> 66 * Access to this must be synchronised on the {@link IDistributionState}. 67 */ 68 Map<String, IConnectionParameters> getDiscoveredContexts(); 69 70 /** Handles the subscriptions for local containers */ 71 ISubscriptionManager getSubscriptionManager(); 72 73 /** 74 * Tracks all the subscriptions per remote context. These are persisted for 75 * the duration of this context so that re-subscription can occur in the 76 * event of a remote context re-connecting. 77 * <p> 78 * Access to this must be synchronised on the {@link IDistributionState}. 79 */ 80 IAutoCreatingStore<String, Set<DualValue<ISubscriptionParameters, IEventListener>>> getRemoteSubscriptions(); 81 82 /** 83 * Tracks number of connections to other remote contexts. Used to ensure 84 * there are no duplicate connections to a single remote context. 85 * <p> 86 * Access to this must be synchronised on the {@link IDistributionState}. 87 */ 88 IReferenceCounter<String> getConnectedContexts(); 89 90 /** 91 * Tracks whether this context is CONNECTING to a remote context (identified 92 * by the {@link IConnectionParameters#getRemoteContextIdentity()}). This 93 * ensures that the CONNECTING operation to a remote context is idempotent. 94 * <p> 95 * Access to this must be synchronised on the {@link IDistributionState} 96 */ 97 IReferenceCounter<String> getCONNECTINGContexts(); 98 99 /** The context */ 100 IFrameworkContext getContext(); 101 102 /** The frame reader */ 103 IFrameReader getFrameReader(); 104 105 /** The frame writer */ 106 IFrameWriter getFrameWriter(); 107 108 /** 109 * Set the channels. 110 * <p> 111 * Access to this must be synchronised on the {@link IDistributionState}. 112 * Uses the <a 113 * href="http://www.ibm.com/developerworks/java/library/j-jtp06197.html" 114 * >'cheap read-write lock'</a> 115 */ 116 void setChannels(Map<String, IChannel> channels); 117 118 /** 119 * Get the {@link IRemoteUpdateInvoker} to use for updating remote 120 * containers 121 * 122 * @param remoteContextIdentity 123 * the remote context the invoker handles 124 * 125 * @return the {@link IRemoteUpdateInvoker} 126 */ 127 IRemoteUpdateInvoker getRemoteUpdateInvoker(String remoteContextIdentity); 128 }