public void Receive(ReceiveMessageEventArgs eventargs) { // TODO: Change to connect ACK type or something DebugLogic ("Got {0} ACK", eventargs.m_message.GetMessageType ()); m_oSignalEvent.Set (); }
public void Receive(ReceiveMessageEventArgs eventargs) { Message m = eventargs.m_message; string type = m.PopString (); if (String.Compare (type, "connect", true) == 0) { DebugInfo ("Puppet Master says: Start Server"); if (m_server.Unpause ()) { SendInfoMsgToPuppetMaster ("Resumed main communication channel"); } else { DebugLogic ("Failed to resume main communication channel"); } } else if (String.Compare (type, "disconnect", true) == 0) { DebugInfo ("Puppet Master says: Stop Server"); if (m_server.Pause ()) { SendInfoMsgToPuppetMaster ("Paused main communication channel"); } else { DebugLogic ("Failed to pause main communication channel"); } } }
public void Receive(ReceiveMessageEventArgs eventargs) { Message m = eventargs.m_message; m_sequenceNumberToReturn = Int32.Parse (m.PopString ()); oSignalEvent.Set (); }
public void Receive(ReceiveMessageEventArgs eventargs) { Message message = eventargs.m_message; if (!m_server.m_replicationService.IsMaster) { // TODO: reply, in future: redirect question? DebugInfo ("Got request intended for master."); m_server.m_replicationService.SendImNotMasterMessage (message); return; } // All we need from the request is the source // uri. DebugInfo ("Server {0} got request for sequence number from {1}", m_server.UserName, message.GetSourceUserName ()); // Create response to the requester Message response = new Message (); response.SetSourceUri (m_server.UserName); response.SetDestinationUsers (message.GetSourceUserName ()); response.SetMessageType ("sequencenumber"); long nextSequenceNumber = GetSequenceNumber (); response.PushString (nextSequenceNumber.ToString ()); // this is implictly a blocking call m_server.m_replicationService.ReplicateSequenceNumber (nextSequenceNumber); m_server.m_sendReceiveMiddleLayer.Send (response); }
public void Receive(ReceiveMessageEventArgs eventargs) { Message m = eventargs.m_message; // Update response string and manually // reset the waiting Lookup() thread m_lookupResponse = m.PopString (); m_oSignalEvent.Set (); }
public void ReceiveFailure(ReceiveMessageEventArgs eventargs) { Message m = eventargs.m_message; // Update response string and manually // reset the waiting Lookup() thread m_client.RotateMaster (); m_client.m_sendReceiveMiddleLayer.Send (m, m_client.CurrentMasterServer, "SERVER"); }
public void Receive(ReceiveMessageEventArgs eventargs) { Message m = eventargs.m_message; string type = m.PopString (); DebugUncond ("Got {0} from puppetmaster", type); if (String.Compare (type, "connect", true) == 0) { DebugInfo ("Puppet Master says: Connect"); if (m_client.Connect ()) { SendInfoMsgToPuppetMaster ("{0} connected", m_client.UserName); } } else if (String.Compare (type, "disconnect", true) == 0) { DebugInfo ("Puppet Master says: Disconnect"); if (m_client.Disconnect ()) { SendInfoMsgToPuppetMaster ("{0} disconnected", m_client.UserName); } } else if (String.Compare (type, "reservation", true) == 0) { string description = m.PopString (); string userstringlist = m.PopString (); string slotstringlist = m.PopString (); List<string> userlist = BuildList (userstringlist); List<string> slotlist = BuildList (slotstringlist); List<int> slots = ConvertToInts(slotlist); DebugInfo ("Puppet Master says: Reserve (Description: {0} Users: {1} Slots: {2})", description, userstringlist, slotstringlist); m_client.Reserve (description, userlist, slots); } else if (String.Compare (type, "read_calendar", true) == 0) { DebugInfo ("Puppet Master says: ReadCalendar"); string ret = m_client.ReadCalendar (); DebugInfo ("ReadCalendar: {0}", ret); SendInfoMsgToPuppetMaster (ret); } }
public void Receive(ReceiveMessageEventArgs eventargs) { // parse message and call appropriate action Message m = eventargs.m_message; string message_source = m.GetSourceUserName (); string request_type = m.GetMessageType (); string message_source_uri = m.GetSourceUri (); if (request_type.Equals ("lookup")) { // Client has requested a username lookup, // respond with the URI string for the // user string user_request = m.PopString (); string uri = GetUriForUser (user_request); DebugInfo ("Answering lookup for {0} with {1}", user_request, uri); Message response = new Message (); response.SetMessageType ("lookup"); response.SetDestinationUsers (message_source); response.SetSourceUserName (m_server.UserName); response.PushString (uri); SendReply(response); } else if (request_type.Equals ("connect")) { if (!m_server.m_replicationService.IsMaster) { // TODO: reply, in future: redirect question? DebugInfo ("Got request intended for master."); m_server.m_replicationService.SendImNotMasterMessage (m); return; } // add user to DB UserConnect (message_source, message_source_uri); // Send an ACK or the client starves to death Message ack_message = new Message (); ack_message.SetMessageType ("connect"); ack_message.SetDestinationUsers (message_source); ack_message.SetSourceUserName (m_server.UserName); // replicate message (implicit block) m_server.m_replicationService.ReplicateUserConnect (message_source, message_source_uri); SendReply (ack_message); } else if (request_type.Equals ("disconnect")) { if (!m_server.m_replicationService.IsMaster) { // TODO: reply, in future: redirect question? DebugInfo ("Got request intended for master."); m_server.m_replicationService.SendImNotMasterMessage (m); return; } // remove from replicas (implicit block until 1 ack is received) m_server.m_replicationService.ReplicateUserDisconnect (message_source); UserDisconnect (message_source); // TODO: Find a way to get an ACK across // for a disconnect message } return; }
public void Receive(ReceiveMessageEventArgs e) { Message m = e.m_message; if (m.GetMessageType ().Equals ("replicate")) { string subtype = m.PopString (); #region replicate if (subtype.Equals ("sequencenumber")) { DebugLogic ("Got sequence number replication request from {0}", m.GetSourceUserName ()); HandleSequenceNumberReplication (m.PopString (), m.GetSourceUserName ()); } else if (subtype.Equals ("sequencenumber_ack")) { DebugLogic ("ACK replication request: SequenceNumber"); m_oSignalEvent.Set (); } else if (subtype.Equals ("user_connect")) { DebugLogic ("Got user_connect replication request for {0}", m.GetSourceUserName ()); string username = m.PopString (); string uri = m.PopString (); HandleUserConnectReplication (username, uri, m.GetSourceUserName ()); } else if (subtype.Equals ("user_connect_ack")) { DebugLogic ("ACK replication request: UserConnect"); m_oSignalEvent.Set (); } else if (subtype.Equals ("user_disconnect")) { DebugLogic ("Got user_disconnect replication request for {0}", m.GetSourceUserName ()); string username = m.PopString (); HandleUserDisconnectReplication (username, m.GetSourceUserName ()); } else if (subtype.Equals ("user_disconnect_ack")) { DebugLogic ("ACK replication request: UserDisconnect"); m_oSignalEvent.Set (); } #endregion } else if (m.GetMessageType ().Equals ("whoismaster")) { string reply; Message ack = new Message (); m.SetMessageType ("whoismaster_ack"); m.SetDestinationUsers (m.GetSourceUserName ()); m.SetSourceUserName (m_server.UserName); // TODO: only reply if we've bootstrapped if (String.IsNullOrEmpty (CurrentMaster)) { m.PushString ("empty"); reply = "empty"; } else { m.PushString (CurrentMaster); reply = CurrentMaster; } m_server.m_sendReceiveMiddleLayer.Send (m); DebugInfo ("Got question: Who is master? Replying: {0}", reply); } else if (m.GetMessageType ().Equals ("whoismaster_ack")) { m_masterReplyBuffer = m.PopString (); if (m_masterReplyBuffer.Equals ("empty")) { DebugFatal ("There are other servers alive, but I could not determine who is master.\n" + "Try starting me again."); } m_oSignalEvent.Set (); } else if (m.GetMessageType ().Equals ("sync_usertable")) { if (IsMaster) { DebugLogic ("Got sync request from {0}", m.GetSourceUserName ()); // TODO: need to lock usertable and pause replying to connect/disconnect requests Message reply = PackUserTable(); reply.SetMessageType ("sync_usertable_ack"); reply.SetDestinationUsers (m.GetSourceUserName ()); reply.SetSourceUserName (m_server.UserName); m_server.m_sendReceiveMiddleLayer.Send (reply); } } else if (m.GetMessageType ().Equals ("sync_usertable_ack")) { UnPackUserTable (m); DebugLogic ("Installing usertable from current master."); m_oSignalEvent.Set (); } }
public void Receive(ReceiveMessageEventArgs eventargs) { lock (this) { /* Message format for any calendar message (stack part) starts as follows: * * - SubType TODO: Later register more types up there. * - ReservationSequenceNumber * - Message Sub Type * * This remains common for all kinds of messages. */ // Unpack message Message m = eventargs.m_message; string src = m.GetSourceUserName (); // source user name List<string> userlist = m.GetDestinationUsers (); // list of users string messageSubType = m.PopString (); // message sub type int reservationSequenceNumber = Int32.Parse (m.PopString ()); // seq no DebugLogic ("Message of subtype {0} received", messageSubType); if (messageSubType.Equals ("reservationrequest")) { ReceiveReservationRequest (m, src, userlist, reservationSequenceNumber, messageSubType); } else if (messageSubType.Equals ("reservationack") || messageSubType.Equals ("reservationnack")) { ReceiveReservationAckNack (m, src, userlist, reservationSequenceNumber, messageSubType); } else if (messageSubType.Equals ("precommit")) { ReceiveReservationPreCommit (m, src, userlist, reservationSequenceNumber, messageSubType); } else if (messageSubType.Equals ("yes")) { ReceiveReservationYes (m, src, userlist, reservationSequenceNumber, messageSubType); } else if (messageSubType.Equals ("docommit")) { ReceiveReservationDoCommit(m, src, userlist, reservationSequenceNumber, messageSubType); } else if (messageSubType.Equals ("abort")) { ReceiveReservationAbort(m, src, userlist, reservationSequenceNumber, messageSubType); } } // Lock end }
public void ResendToAnotherNode(ReceiveMessageEventArgs eventargs) { DebugLogic ("Resending to another node"); Message m = eventargs.m_message; string uri = m.PopString (); m_rotateMasterCallback (); Send (m.MessageForResending, uri, "SERVER"); }
public void Receive(ReceiveMessageEventArgs eventargs) { Message m = eventargs.m_message; if (m.GetMessageType ().Equals ("puppet_register")) { string msg = String.Format ("REGISTERED {0} for remote control.", m.GetSourceUserName ()); m_puppetMaster.NotifySubscribers (msg, m.GetSourceUserName ()); HandleClientRegistration (m.GetSourceUserName (), m.GetSourceUri ()); } else if (m.GetMessageType ().Equals ("puppet_info")) { string msg = String.Format ("[{0}] {1}", m.GetSourceUserName (), m.PopString ()); m_puppetMaster.NotifySubscribers (msg, m.GetSourceUserName ()); } else { DebugLogic ("Received unknown message."); } }