private bool SendMasterMessage(EndpointAddress master)
 {
     var socket = AssertConnection(master);
     var msg = new Message("master", String.Empty);
     using(var writer = msg.GetContentWriter())
     {
         _config.MasterConfiguration.WriteTo(writer);
     }
     return SendMessageAndWaitForAck(socket,msg);
 }
 public override Message AsMessage()
 {
     const string header = "spu";
     var args = String.Join(" ", StoreId, JobId, PrevTxnId);
     var msg = new Message(header, args);
     using(var writer = msg.GetContentWriter())
     {
         if (!String.IsNullOrEmpty(Expression))
         {
             writer.WriteLine(Expression);
         }
     }
     return msg;
 }
Esempio n. 3
0
 private bool SendMasterMessage(NodeConfiguration master)
 {
     var socket = AssertConnection(master);
     if (socket == null) return false;
     var msg = new Message("master", String.Empty);
     using(var writer = msg.GetContentWriter())
     {
         _config.MasterConfiguration.WriteTo(writer);
     }
     bool masterIsSet = SendMessageAndWaitForAck(socket,msg);
     if (masterIsSet)
     {
         _master = master;
     }
     return masterIsSet;
 }
 public override Message AsMessage()
 {
     const string header = "txn";
     var args = String.Join(" ", StoreId, JobId, PrevTxnId);
     var msg = new Message(header, args);
     using(var writer = msg.GetContentWriter())
     {
         if (!String.IsNullOrEmpty(Preconditions))
         {
             writer.WriteLine(Preconditions);
         }
         writer.WriteLine("||");
         if (!String.IsNullOrEmpty(Deletes))
         {
             writer.WriteLine(Deletes);
         }
         writer.WriteLine("||");
         if (!String.IsNullOrEmpty(Inserts))
         {
             writer.WriteLine(Inserts);
         }
     }
     return msg;
 }
Esempio n. 5
0
        /// <summary>
        /// Construct a sync message that lists all the stores we have and the last commited transaction id for each one
        /// then start a reader to process the updates the master will send to us
        /// </summary>
        /// <param name="masterAddress"></param>
        /// <param name="lastTxn"></param>
        public void SendSyncToMaster(EndpointAddress masterAddress, Dictionary<string, string> lastTxn)
        {
            var msg = new Message("sync", String.Empty);
            using(var writer = msg.GetContentWriter())
            {
                foreach (var entry in lastTxn)
                {
                    writer.WriteLine("{0}|{1}", entry.Key, entry.Value);
                }
            }

            var socket = new TcpClient(masterAddress.Uri.Host, masterAddress.Uri.Port);
            var socketStream = socket.GetStream();

            msg.WriteTo(socketStream);
            socketStream.Flush();

            var messageReader = new MessageReader(socket, HandleSyncMessage);
            messageReader.Start();
        }