public ReaderWriter(INode creator, IMessageHub messageHub, IEnumerable <IConfiguration> configMap, IMessageSerializer serializer) { var configurations = configMap.ToDictionary(c => c.Key, c => c); this.serializer = serializer; op = new CurrentOperation { Phase = new ObservableAtomicValue <OperationPhase>(OperationPhase.Idle), Type = new ObservableAtomicValue <OperationType>(OperationType.Idle), Accepted = new ObservableConcurrentDictionary <int, INode>(Enumerable.Empty <KeyValuePair <int, INode> >()), ConfigurationMap = new ObservableConcurrentDictionary <IConfigurationIndex, IConfiguration>(configurations) }; gc = new GarbageCollectionOperation { Phase = new ObservableAtomicValue <OperationPhase>(OperationPhase.Idle) }; this.creator = creator; this.configMap = new ObservableConcurrentDictionary <IConfigurationIndex, IConfiguration>(configurations); this.messageHub = messageHub; value = new ObjectValue { Value = 0 }; tag = new Tag(creator); localPhase = new PhaseNumber(); operationQueue = new BlockingCollection <OperationRequest>(new ConcurrentQueue <OperationRequest>()); eventHandlers = new EventHandlerList(); status = new ObservableAtomicValue <NodeStatus>(NodeStatus.Idle); world = new ObservableConcurrentDictionary <int, INode>(); phaseVector = new ObservableConcurrentDictionary <INode, IPhaseNumber>(); preJoinAck = new ObservableCondition(() => status.Get() == NodeStatus.Active, new[] { status }); preOutSend = new ObservableCondition(() => status.Get() == NodeStatus.Active, new[] { status }); preQueryFix = new ObservableCondition(QueryFixCondition, new IChangeNotifiable[] { status, op.Type, op.Phase, op.Accepted, op.ConfigurationMap }); prePropagationFix = new ObservableCondition(PropagationFixCondition, new IChangeNotifiable[] { status, op.Type, op.Phase, op.Accepted, op.ConfigurationMap }); preReadAck = new ObservableCondition(() => status.Get() == NodeStatus.Active && op.Type.Get() == OperationType.Read && op.Phase.Get() == OperationPhase.Done, new IChangeNotifiable[] { status, op.Type, op.Phase }); preWriteAck = new ObservableCondition(() => status.Get() == NodeStatus.Active && op.Type.Get() == OperationType.Write && op.Phase.Get() == OperationPhase.Done, new IChangeNotifiable[] { status, op.Type, op.Phase }); new Thread(ProcessReadWriteRequests).Start(); new Thread(OutJoinAck).Start(); new Thread(OutSend).Start(); new Thread(IntQueryFix).Start(); new Thread(IntPropagationFix).Start(); new Thread(OutReadAck).Start(); new Thread(OutWriteAck).Start(); var listener = messageHub.Subscribe(creator); listener.Where(m => m.Body.MessageType.ToMessageType() == MessageTypes.JoinRw) .Subscribe(new MessageStreamListener(OnJoinReceived)); listener.Where(m => m.Body.MessageType.ToMessageType() == MessageTypes.Gossip) .Subscribe(new MessageStreamListener(OnGossipReceived)); }
public Joiner(INode i, IReaderWriter readerWriter, IRecon recon, IMessageHub messageHub) { this.i = i; this.messageHub = messageHub; eventHandlers = new EventHandlerList(); status = new ObservableAtomicValue <NodeStatus>(NodeStatus.Idle); reconStatus = new ObservableAtomicValue <NodeStatus>(NodeStatus.Idle); rwStatus = new ObservableAtomicValue <NodeStatus>(NodeStatus.Idle); hints = new ObservableAtomicValue <IEnumerable <INode> >(Enumerable.Empty <INode>()); preJoinRw = new ObservableCondition(() => status.Get() == NodeStatus.Joining && rwStatus.Get() == NodeStatus.Idle, new[] { status, rwStatus }); preJoinRecon = new ObservableCondition(() => status.Get() == NodeStatus.Joining && reconStatus.Get() == NodeStatus.Idle, new[] { status, reconStatus }); preJoin = new ObservableCondition(() => status.Get() == NodeStatus.Joining, new[] { status }); preJoinAck = new ObservableCondition(() => status.Get() == NodeStatus.Joining && rwStatus.Get() == NodeStatus.Active && reconStatus.Get() == NodeStatus.Active, new[] { status, rwStatus, reconStatus }); this.recon = recon; this.recon.JoinAck += JoinAckReaderWriter; this.readerWriter = readerWriter; this.readerWriter.JoinAck += JoinAckRecon; new Thread(OutJoinRw).Start(); new Thread(OutJoinRecon).Start(); new Thread(OutSend).Start(); new Thread(OutJoinAck).Start(); }
public Recon() { status = new ObservableAtomicValue <NodeStatus>(NodeStatus.Idle); }