Example #1
0
        // -=-=-=-=-=-=-=- MessageListener Interface -=-=-=-=-=-=-=-
        public void receive(GCT.Message msg)
        {
            try
            {
                Object obj = msg.getObject();
                if(obj!=null && (obj is String))
                {
                    String str = (String)obj;
                    String userHandler = "???";
                    int pos = str.IndexOf("|:|");
                    if(pos != -1)
                    {
                        userHandler = str.Substring(0,pos);
                        str = str.Substring((pos+3),str.Length-(pos+3));
                    }
                    if(members.Contains(msg.Source))
                    {
                        members[msg.Source] = userHandler;
                        updateMembers();
                        txtMsgsReceived.AppendText(userHandler + ":   " + (String)str + "\n");

                        txtMsgsReceived.SelectionStart = txtMsgsReceived.TextLength;
                        txtMsgsReceived.Focus();
                        txtMsgsReceived.ScrollToCaret();
                    }
                }

            }
            catch(Exception e)
            {
            }
        }
Example #2
0
        // -=-=-=-=-=-=-=- MembershipListener Interface -=-=-=-=-=-=-=-
        public void viewAccepted(GCT.View new_view)
        {
            members = new Hashtable();
            ArrayList tmpMbrs = new_view.getMembers();

            for (int x = 0; x < tmpMbrs.Count; x++)
            {
                members.Add((Address)tmpMbrs[x], "User" + x);
            }
            updateMembers();
        }
 // -=-=-=-=-=-=-=- MessageListener Interface -=-=-=-=-=-=-=-
 /// <summary>
 /// Message Listener Implementation. Receives messages from the channel and 
 /// updates the hashtable accordingly.
 /// </summary>
 /// <param name="msg">The received message</param>
 public void receive(GCT.Message msg)
 {
     if(msg == null)
         return;
     object obj = msg.getObject();
     if(obj==null) return;
     if(!(obj is HTUpdate)) return;
     HTUpdate update = (HTUpdate)obj;
     switch(update.Type)
     {
         case HTUpdate.ADD:
             if(update.Key!=null && update.Value!=null)
                 _Add(update.Key,update.Value);
             break;
         case HTUpdate.UPDATE:
             if(update.Key!=null && update.Value!=null)
                 _Update(update.Key,update.Value);
             break;
         case HTUpdate.REMOVE:
             if(update.Key!=null)
                 _Remove(update.Key);
             break;
         case HTUpdate.CLEAR:
             _Clear();
             break;
         case HTUpdate.SET_STATE:
             if(update.Value!=null && update.Value is Hashtable)
             {
                 lock(state_mutex)
                 {
                     _State((Hashtable)update.Value);
                     Monitor.Pulse(state_mutex);
                 }
             }
             break;
         case HTUpdate.GET_STATE:
             if(channel.getView().getMembers()[0].Equals(channel.getLocalAddress()))
                 channel.send(new Message(msg.Source,channel.getLocalAddress(),new HTUpdate(HTUpdate.SET_STATE,null,base.Clone())));
             break;
     }
 }