示例#1
0
        static void Main(string[] args)
        {
            /*
            Hashtable ht = new Hashtable();
            ht.Add("string1","value1");
            ht.Add("string2","value2");
            ht.Add("string3","value3");

            Console.WriteLine("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
            Console.WriteLine("Initial Hashtable");
            Console.WriteLine("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
            foreach(DictionaryEntry e in ht)
            {
                Console.WriteLine("Key: " + e.Key.ToString() + "		Value:" + e.Key.ToString() );
            }
            Console.WriteLine("");
            Console.WriteLine("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
            Console.WriteLine("Modified Hashtable");
            Console.WriteLine("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
            ICollection vals = ht.Values;
            IEnumerator enu = vals.GetEnumerator();
            */
            string props = "UDP(mcast_addr=228.1.2.3;mcast_port=45566;ip_ttl=32):" +
            "PING(timeout=3000;num_initial_members=6):" +
            //"FD(timeout=3000):" +
            //"Basic Chat|OtherNamespace.FD2(timeout=3000):" +
            //"VERIFY_SUSPECT(timeout=1500):" +
            "STABLE(desired_avg_gossip=10000):" +
            "DISCARD(up=0.4;excludeItself=true):" +
            "NAKACK(gc_lag=10;retransmit_timeout=3000):" +
            "UNICAST(timeout=2000):" +
            "GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;print_local_addr=true)";

            Channel chan = new GroupChannel(props);
            DistributedHashtable ht = new DistributedHashtable(chan,"testGroup", null);
            ht.Add(RandomTester.getRandom5Digit(),RandomTester.getRandom5Digit());
        }
示例#2
0
        static void Main(string[] args)
        {
            int testSize = 1000;
            int count = 0;
            int[] values = new int[1000+10];
            string received = "Received: ";
            string props = "UDP(mcast_addr=228.1.2.3;mcast_port=45566;ip_ttl=32):" +
                "PING(timeout=3000;num_initial_members=6):" +
                //"FD(timeout=3000):" +
                //"VERIFY_SUSPECT(timeout=1500):" +
                "STABLE(desired_avg_gossip=10000):" +
                "DISCARD(up=0.2;excludeItself=true):" +
                "NAKACK(gc_lag=10;retransmit_timeout=3000):" +
                "UNICAST(timeout=2000):" +
                "GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;print_local_addr=true)";

            if(args.Length == 3 && args[2].Equals("C"))
                props += ":CAUSAL";

            String time = DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss.ff");
            //Debug.Listeners.Add(new TextWriterTraceListener("CLIENT LOG (" + time + ").txt"));
            System.Diagnostics.Trace.Listeners.Add(new TextWriterTraceListener("CAUSAL LOG (" + time + ").txt"));
            Debug.AutoFlush = true;
            GCT.Trace.trace = true;

            Channel chan = new GroupChannel(props);
            Console.WriteLine("Connecting: " + DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss.ff"));
            chan.connect("Causal");
            Thread.Sleep(10000);
            bool started = false;
            int currentPosition = 0;
            int mod = Convert.ToInt32(args[1]);
            Console.WriteLine("Connected!	Members=" + chan.getView().getMembers().Count + "	:" + DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss.ff"));

            while(true)
            {
                if(args[0].Equals("start") && started == false)
                {
                    Console.WriteLine("Sending start message");
                    chan.send(new Message(null,null,new CausalMessage(count.ToString(),(Address)chan.getView().getMembers()[0])));
                }
                started = true;
                Event obj = chan.receive(-1);
                if (obj.Type == Event.MSG)
                {
                    Message msg = (Message)obj.Arg;
                    if(msg.getObject()==null)
                    {
                        String strHeaders = "";
                        if(strHeaders.Length > 0)
                        {
                            foreach(DictionaryEntry d in msg.Headers)
                            {
                                strHeaders += (String)d.Key + ":";
                            }
                            strHeaders = strHeaders.Substring(0,(strHeaders.Length-1));
                        }
                        if(GCT.Trace.trace)
                            GCT.Trace.info("UDP.handleIncomingUdpPacket()","Headers = " + strHeaders);

                        Console.WriteLine("Received NULL: Frm-->" + msg.Source + " Headers: " + strHeaders);
                        continue;
                    }
                    int recObj=  Convert.ToInt32(((CausalMessage)msg.getObject()).message);
                    received += recObj + ",";
                    Console.WriteLine(received);
                    System.Diagnostics.Trace.WriteLine("Recevied = " + count);
                    count = recObj+1;
                    values[currentPosition] = count-1;
                    currentPosition++;
                    bool error = false;
                    for(int i = 0;i<count;i++)
                    {
                        if(values[i]!=i && values[i]!=0)
                        {
                            Console.WriteLine("Position: " + i + " = " + values[i]);
                            error = true;
                        }
                    }
                    if(error)
                        break;

                    if(((CausalMessage)msg.getObject()).member.Equals(chan.getLocalAddress()))
                    {
                        Random r  = new Random();
                        ArrayList members =chan.getView().getMembers();
                        int nextTarget = r.Next(members.Count);

                        //chose someone other than yourself
                        while (nextTarget == members.IndexOf(chan.getLocalAddress()))
                        {
                            nextTarget = r.Next(members.Count);
                        }
                        Address next = (Address)members[nextTarget];
                        //String nextChar = getNext(receivedLetter);

                        Console.WriteLine("Sending = " + count + "	NextResponder--> " + next);
                        chan.send(new Message(null, null, new CausalMessage(count.ToString(), next)));
                    }

                    /*
                    if(count%2 == mod)
                    {
                        Console.WriteLine("Sending Message: " + count);
                        System.Diagnostics.Trace.WriteLine("Sending = " + count);
                        chan.send(new Message(null,null,count));
                    }
                    */
                }
                if(count==testSize)
                    break;
            }
            Console.WriteLine("Finished2!!!");
            chan.disconnect();
        }
示例#3
0
        static void Main(string[] args)
        {
            DateTime dt = DateTime.Now;
            String time = dt.ToString("yyyy-MM-dd HH.mm.ss.ff");

            Debug.Listeners.Add(new TextWriterTraceListener("CLIENT LOG (" + time + ").txt")); //Console.out
            Debug.AutoFlush = true;

            Debug.WriteLine(DateTime.Now.ToString("HH.mm.ss.ff") + " [Client.Main]");

            GroupChannel chan = new GroupChannel();
            chan.ResponseChooser = new TimeChooser();

            Debug.WriteLine(DateTime.Now.ToString("HH.mm.ss.ff") + "[i] - Registering the channel");
            ChannelServices.RegisterChannel(chan);

            chan.setOpt("receive_local_msgs",true);

            TimeServer currentTime = null;

            String input = "";
            while(input != "Exit" && input != "exit" && input != "e")
            {
                System.Threading.Thread.Sleep(250);
                Console.WriteLine("********* What do you want to do? (Press ? for help)");
                input = Console.ReadLine();
                switch (input)
                {
                    case("c"):
                        Console.WriteLine("Enter group to join: ");
                        String groupname = Console.ReadLine();
                        chan.connect(groupname);
                        break;
                    case("d"):
                        chan.disconnect();
                        break;
                    case("s"):
                        for(int i = 0;i<5;i++)
                            Console.WriteLine("");
                        break;
                    case("r"):
                        RemotingConfiguration.RegisterWellKnownServiceType(new TimeServer().GetType(), "TimeServer", WellKnownObjectMode.SingleCall);
                        break;
                    case("t"):
                        Debug.WriteLine(DateTime.Now.ToString("HH.mm.ss.ff") + "Getting a reference to the TaskRunner Object");
                        if (currentTime==null)
                            currentTime = (TimeServer)Activator.GetObject(typeof(TimeServer), "C#Groups://null:8090/TimeServer");

                        DateTime responseTime = currentTime.getCurrentTime();

                        Console.WriteLine("Current Time is: " + DateTime.Now.ToString("HH:mm:ss:ff"));
                        Console.WriteLine("TimeServer says: " + responseTime.ToString("HH:mm:ss:ff"));
                        Debug.WriteLine("");
                        break;
                    case("?"):
                        Console.WriteLine("Commands Are:\n");
                        Console.WriteLine("		c: Connect to Group");
                        Console.WriteLine("		d: Disconnect from Group");
                        Console.WriteLine("		r: Register TimeServer");
                        Console.WriteLine("		t: Get Current Time From Servers");
                        Console.WriteLine("		e: Exit");
                        break;
                }
            }
            Console.WriteLine("Exiting.....");
            chan.close();
        }