Exemplo n.º 1
0
        private void UpdateQueueWithFullUpdate(byte[] data)
        {
            if (data == null || data.Length == 0)
            {
                throw new ArgumentException("The specified data cannot be null or empty", "data");
            }

            lock (ProcessQueue)
            {
                ProcessQueue = PrioritisedQueueSerialiser.Deserialise(data);
            }
        }
Exemplo n.º 2
0
 public static SubscribeFn <C> buffer <A, C>(
     IObservable <A> o, int size, IObservableQueue <A, C> queue
     ) =>
 obs => o.subscribe(
     val => {
     queue.addLast(val);
     if (queue.count > size)
     {
         queue.removeFirst();
     }
     obs.push(queue.collection);
 },
     obs.finish
     );
Exemplo n.º 3
0
        private void SendFullQueueUpdate(IPAddress ip)
        {
            if (ip == null)
            {
                throw new ArgumentException("The specified ip is not valid", "ip");
            }

            IObservableQueue <ClientProcess> temp = ProcessQueue;

            var msg = new InterNodeCommunicationMessage {
                Data = PrioritisedQueueSerialiser.Serialise(temp), IsLocalOnly = true, MessageType = InterNodeMessageType.FullQueueUpdateReceived
            };

            SendToNode(ip, InterNodeCommunicationMessageSerialiser.Serialise(msg));
        }
Exemplo n.º 4
0
 public static SubscribeFn <C> timeBuffer <A, C>(
     IObservable <A> o, Duration duration,
     IObservableQueue <Tpl <A, float>, C> queue,
     TimeScale timeScale
     )
 {
     return(obs => o.subscribe(val => {
         queue.addLast(F.t(val, timeScale.now()));
         var lastTime = queue.last._2;
         if (queue.first._2 + duration.seconds <= lastTime)
         {
             // Remove items which are too old.
             while (queue.first._2 + duration.seconds < lastTime)
             {
                 queue.removeFirst();
             }
             obs.push(queue.collection);
         }
     }));
 }
Exemplo n.º 5
0
 public static IObservable <C> timeBuffer <A, C>(
     this IObservable <A> o, Duration duration, IObservableQueue <Tpl <A, float>, C> queue,
     TimeScale timeScale = TimeScale.Realtime
     ) => Observable.a(ObservableOpImpls.timeBuffer(o, duration, queue, timeScale));
Exemplo n.º 6
0
 public static IObservable <C> buffer <A, C>(
     this IObservable <A> o, int size, IObservableQueue <A, C> queue
     ) => Observable.a(ObservableOpImpls.buffer(o, size, queue));
Exemplo n.º 7
0
        public void Start()
        {
            // Resolve all the types
            _clientCommunicationsSocket    = DependancyInjector.Resolve <ISocket>();
            _internodeConnectionSocket     = DependancyInjector.Resolve <ISocket>();
            _internodeListeningSocket      = DependancyInjector.Resolve <ISocket>();
            AutoDiscoveryMessageSerialiser = DependancyInjector.Resolve <ISerialiser <AutoDiscoveryMessage, byte[]> >();
            //CacheSerialiser = DependancyInjector.Resolve<ISerialiser<CacheProvider<String, ClientResultMessage>, byte[]>>();
            ClientMessageSerialiser                 = DependancyInjector.Resolve <ISerialiser <ClientMessage, byte[]> >();
            ClientProcessSerialiser                 = DependancyInjector.Resolve <ISerialiser <ClientProcess, byte[]> >();
            ClientResultMessageSerialiser           = DependancyInjector.Resolve <ISerialiser <ClientResultMessage, byte[]> >();
            InterNodeCommunicationMessageSerialiser = DependancyInjector.Resolve <ISerialiser <InterNodeCommunicationMessage, byte[]> >();
            PrioritisedQueueSerialiser              = DependancyInjector.Resolve <ISerialiser <IObservableQueue <ClientProcess>, byte[]> >();
            ProcessQueue = DependancyInjector.Resolve <IObservableQueue <ClientProcess> >();
            ResultCache  = DependancyInjector.Resolve <CacheProvider <String, ClientResultMessage> >();
            NodeTask     = DependancyInjector.Resolve <INodeTask>();

            if (NodeTask == null)
            {
                Console.WriteLine("ERROR :: NodeTask is not defined.");
            }


            // Setup the auto discovery socket (if applicable)
            if (UseAutoDiscovery)
            {
                if (AutoDiscoveryPort <= 0)
                {
                    AutoDiscoveryPort = 275;
                }
                _autoDiscoverySocket = DependancyInjector.Resolve <IBroadcastSocket>();
                _autoDiscoverySocket.AllowAddressReuse = true;
                _autoDiscoverySocket.UseBroadcasting   = true;
                _autoDiscoverySocket.Port           = AutoDiscoveryPort;
                _autoDiscoverySocket.BindingAddress = IPAddress.Parse(AutoDiscoveryBindingAddress);
            }

            // hook up the events ready
            ResultCache.Subscribe(new ResultCacheObserver(this, LogProvider));
            ProcessQueue.Subscribe(new PrioritisedQueueObserver(this, LogProvider));
            _internodeConnectionSocket.OnClientConnectCompleted += internode_OnClientConnectCompleted;
            _internodeConnectionSocket.OnDataReceived           += internode_OnDataReceived;
            _internodeListeningSocket.OnClientConnectCompleted  += internode_OnClientConnectCompleted;
            _internodeListeningSocket.OnDataReceived            += internode_OnDataReceived;
            _clientCommunicationsSocket.OnDataReceived          += client_OnDataReceived;


            // setup the arguments ready
            if (ClientPort <= 0)
            {
                ClientPort = 270;
            }
            if (InternodePort <= 0)
            {
                InternodePort = 280;
            }

            if (String.IsNullOrEmpty(ClientBindingAddress))
            {
                ClientBindingAddress = "0.0.0.0";
            }
            if (String.IsNullOrEmpty(InternodeBindingAddress))
            {
                InternodeBindingAddress = "0.0.0.0";
            }

            _clientCommunicationsSocket.Port           = ClientPort;
            _clientCommunicationsSocket.BindingAddress = IPAddress.Parse(ClientBindingAddress);

            _internodeConnectionSocket.Port           = InternodePort;
            _internodeConnectionSocket.BindingAddress = IPAddress.Parse(InternodeBindingAddress);

            _internodeListeningSocket.Port           = InternodePort;
            _internodeListeningSocket.BindingAddress = IPAddress.Parse(InternodeBindingAddress);

            _internodeListeningSocket.Start();
            _clientCommunicationsSocket.Start();

            if (UseAutoDiscovery)
            {
                _autoDiscoverySocket.OnDataReceived += autodiscovery_OnDataReceived;
                _autoDiscoverySocket.Start();
                _autoDiscoverySocket.SendBroadcastMessage(BroadcastMessageType.Startup, AutoDiscoveryMessageSerialiser, AutoDiscoveryPort);
            }
        }