示例#1
0
 void worker_OnWorkerNotifyEvent(BasicWorker worker, object data)
 {
     if (OnServerNodeNotifyEvent != null) OnServerNodeNotifyEvent(worker, data);
 }
示例#2
0
 /// <summary>
 /// Adds a worker to the Node, the ServerNode will add this worker to the scan.
 /// </summary>
 /// <param name="worker">Any type derived from BasicWorker.</param>
 public void AddWorker(BasicWorker worker)
 {
     qNodeOpeations.Enqueue(new NodeOperation(NodeOperationEnum.AddWorker, worker));
 }
示例#3
0
 protected void RaiseWorkerNotification(BasicWorker worker, object data)
 {
     if (OnWorkerNotifyEvent != null) OnWorkerNotifyEvent(worker, data);
 }
示例#4
0
 void ServerNode_OnWorkerLatencyChanged(BasicWorker worker, TimeSpan oldLatency)
 {
     //if the latnecy of the worker have changed send the worker to node reassignment.
     qNodeOpeations.Enqueue(new NodeOperation(NodeOperationEnum.RemoveWorker, worker));
     if (OnServerNodeWorkerLatencyChanged != null) OnServerNodeWorkerLatencyChanged(worker, oldLatency);
 }
示例#5
0
 protected void RaiseWorkerLatencyChanged(BasicWorker worker, TimeSpan oldLatency)
 {
     if (OnWorkerLatencyChanged != null) OnWorkerLatencyChanged(worker, oldLatency);
 }
示例#6
0
 void NewNode_OnServerNodeWorkerLatencyChanged(BasicWorker worker, TimeSpan oldLatency)
 {
     AddWorker(worker);
     if (OnServerNotifyEvent != null) OnServerNotifyEvent.BeginInvoke(worker,
         new WorkerLatencyInformationChanged(oldLatency), null, null);
 }
示例#7
0
 void NewNode_OnServerNodeNotifyEvent(BasicWorker worker, object data)
 {
     if (worker == null) //this means the node is reporting, node id is in the data object.
     {
         lock (oServerNodesLocker)
         {
             for(int iScan=0;iScan<serverNodes.Count;iScan++)
             {
                 if(((Guid)data).CompareTo(serverNodes[iScan].NodeId)==0)
                 {
                     if (serverNodes[iScan].Idle)
                     {
                         serverNodes[iScan].Stop();
                         serverNodes[iScan].OnServerNodeNotifyEvent -=
                             new ServerNode.DelegateServerNodeNotification(
                             NewNode_OnServerNodeNotifyEvent);
                         serverNodes[iScan].OnServerNodeWorkerLatencyChanged -=
                             new ServerNode.DelegateServerNodeWorkerLatencyChanged(
                             NewNode_OnServerNodeWorkerLatencyChanged);
                         serverNodes.RemoveAt(iScan);
                     }
                     break;
                 }
             }
         }
     }
     else if (OnServerNotifyEvent != null) OnServerNotifyEvent.BeginInvoke(worker, data, null, null);
 }
示例#8
0
 /// <summary>
 /// Adds a worker to a node from the nodeslist or open a new node for the worker.
 /// The action taken depends on the required latnecy of the worker and the current nodes latencies.
 /// </summary>
 /// <param name="worker">The worker to add.</param>
 private void AddWorker(BasicWorker worker)
 {
     int iBestNodeIndex = 0;
     lock (oServerNodesLocker)
     {
         TimeSpan lowestNodeLatency = TimeSpan.MaxValue;
         for (int iScan = 0; iScan < serverNodes.Count; iScan++)
             if (serverNodes[iScan].Latency < lowestNodeLatency)
             {
                 iBestNodeIndex = iScan;
                 lowestNodeLatency = serverNodes[iBestNodeIndex].Latency;
             }
         if (lowestNodeLatency > worker.RequiredLatency)
         {   //Create a new node.
             ServerNode NewNode = new ServerNode();
             NewNode.OnServerNodeNotifyEvent += //Hook to the node events.
                 new ServerNode.DelegateServerNodeNotification(
                 NewNode_OnServerNodeNotifyEvent);
             NewNode.OnServerNodeWorkerLatencyChanged +=
                 new ServerNode.DelegateServerNodeWorkerLatencyChanged(
                 NewNode_OnServerNodeWorkerLatencyChanged);
             serverNodes.Add(NewNode); //Add the new node to the list.
             iBestNodeIndex = serverNodes.Count - 1;
             if (bServerStarted && !bServerPaused) NewNode.Start();
         }
         serverNodes[iBestNodeIndex].AddWorker(worker);
     }
 }
 /// <summary>
 /// The listeners, accepters and connecters events are routed to this method.
 /// </summary>
 /// <param name="worker">The worker that raised an event.</param>
 /// <param name="data">relvant event data</param>
 void BasicServers_OnServerNotifyEvent(BasicWorker worker, object data)
 {
     NetworkServerClientWorker.NetworkClientNotification incommingEvent = null;
     if (data.GetType() == typeof(NetworkServerClientWorker.NetworkClientNotification))
     {
         incommingEvent = (NetworkServerClientWorker.NetworkClientNotification)data;
         switch (incommingEvent.EventType)
         {
             case NetworkClientBase.ClientEventTypeEnum.None:
                 break;
             case NetworkClientBase.ClientEventTypeEnum.Connected:
                 break;
             case NetworkClientBase.ClientEventTypeEnum.Accepted:
                 NetworkServerClientAccepter accepter =
                     (NetworkServerClientAccepter)incommingEvent.EventData;
                 accepter.RequiredLatency = newAcceptersLatency;
                 accepters.Workers.Add(accepter);
                 break;
             case NetworkClientBase.ClientEventTypeEnum.MessageSent:
                 break;
             case NetworkClientBase.ClientEventTypeEnum.RawDataRecieved:
                 break;
             case NetworkClientBase.ClientEventTypeEnum.MessageRecieved:
                 break;
             case NetworkClientBase.ClientEventTypeEnum.Disconnected:
                 switch (worker.GetType().Name)
                 {
                     case "NetworkServerClientListener": //Controlled by user of this class.
                         break;
                     case "NetworkServerClientAccepter": //This class add it so it should remove it.
                         accepters.Workers.Remove(worker);
                         break;
                     case "NetworkServerClientConnecter"://Controlled by user of this class.
                         break;
                 }
                 break;
             case NetworkClientBase.ClientEventTypeEnum.Error:
                 break;
         }
     }
     OnServerNotify((NetworkServerClientWorker)worker, incommingEvent);
 }