예제 #1
0
        public ServerApiSmr(string id, string url, int minDelay, int maxDelay, List <string> serversUrls)
        {
            BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();

            this.Id = id;
            Hashtable props = new Hashtable();
            int       port  = DU.ExtractPortFromUrl(url);

            props["port"]    = port;
            props["timeout"] = 1000;
            Channel          = new TcpChannel(props, null, provider);
            Nodes            = new List <Node>();

            ChannelServices.RegisterChannel(Channel, false);

            foreach (string serverUrl in serversUrls)
            {
                if (port != DU.ExtractPortFromUrl(serverUrl))
                {
                    Nodes.Add((Node)Activator.GetObject(typeof(Node), serverUrl));
                }
            }

            Node node = new Node(id, url, Nodes, minDelay, maxDelay);

            RemotingServices.Marshal(node, DU.ExtractObjectNameFromUrl(url));
        }
예제 #2
0
        public ServerApi(string id, string url, int minDelay, int maxDelay, List <String> urls)
        {
            int        port    = DU.ExtractPortFromUrl(url);
            TcpChannel Channel = new TcpChannel(DU.ExtractPortFromUrl(url));

            ChannelServices.RegisterChannel(Channel, false);

            Dictionary <string, Pingable> TupleSpaces = new Dictionary <string, Pingable>();
            string selfURL = "";

            foreach (string serverUrl in urls)
            {
                if (port != DU.ExtractPortFromUrl(serverUrl))
                {
                    Console.WriteLine(serverUrl);
                    TupleSpaces.Add(serverUrl, (TupleSpace)Activator.GetObject(typeof(TupleSpace), serverUrl));
                }
                else
                {
                    selfURL = serverUrl;
                }
            }

            TupleSpace tupleSpace = new TupleSpace(selfURL, minDelay, maxDelay, TupleSpaces);

            RemotingServices.Marshal(tupleSpace, DU.ExtractObjectNameFromUrl(url));
            tupleSpace.Stopped = true;
            List <TupleSpace> tupleSpaces = new List <TupleSpace>();

            foreach (var entry in TupleSpaces)
            {
                tupleSpaces.Add((TupleSpace)entry.Value);
            }
            tupleSpace.Update();
            tupleSpace.Stopped = false;
            Console.WriteLine("Enter to exit");
            Console.ReadLine();
        }