Пример #1
0
        /// <summary>
        /// Opens a host to accept incoming connections. Connects to a registration server.
        /// </summary>
        /// <param name="registrationServerNameOrAddress">Name or address of the registration server.</param>
        /// <param name="registrationServerPort">The port number to the registration server.</param>
        /// <param name="listenerPort">The port that this node accepts connections on.</param>
        private void OpenAndConnectToRegistrationServer(string registrationServerNameOrAddress, int registrationServerPort, int listenerPort)
        {
            if (_host == null)
            {
                try
                {
                    //Open a connection to the registration server
                    IPEndPoint registrationServerEndPoint = new IPEndPoint(Dns.GetHostEntry(registrationServerNameOrAddress).AddressList[0], registrationServerPort);
                    _registrationServerProxy = ProxyFactory.CreateProxy <IRegistrationServer>(registrationServerEndPoint);

                    //get the nodes that are already registered
                    List <IPEndPoint> remoteNodeEndPoints = _registrationServerProxy.GetAllNodeEndPoints();
                    _remoteNodes.Clear();
                    foreach (IPEndPoint endpoint in remoteNodeEndPoints)
                    {
                        INode remoteNode = new RemoteNodeProxy(endpoint);
                        _remoteNodes.Add(remoteNode.GetId(), remoteNode);
                    }

                    //open the host that contains this node
                    _host = new ServiceHost(this, listenerPort);
                    _host.Open();

                    //Register the host with the registration server. This causes all other registered nodes to connect to this one
                    _registrationServerProxy.RegisterNode(_host.EndPoint);
                }
                catch (Exception ex)
                {
                    string msg = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                    Log.Error("Could not connect to registration server. Message reads : {0}", msg);
                }
            }
        }
Пример #2
0
 public void NodeRegistered(IPEndPoint nodeEndPoint)
 {
     lock (_remoteNodes)
     {
         INode  node   = new RemoteNodeProxy(nodeEndPoint);
         ushort nodeId = node.GetId();
         _remoteNodes.Add(nodeId, node);
         //notify all local workers that a new remote node has entered the grid
         lock (_localWorkers)
         {
             foreach (Worker worker in _localWorkers.Values)
             {
                 worker.OnRemoteNodeRegistered(nodeId);
             }
         }
     }
 }