Beispiel #1
0
        public long LogCommand(EventCommand command)
        {
            lock (_filelock)
              {
            CommandSN++;
            if (Configuration.EnableJournaling)
              if (OpenLogFile())
              {
            // Writing the journal
            _writer.Write('K');
            _writer.Write(CommandSN);
            _writer.Write(command.CommandMarker ?? string.Empty);
            _writer.Write('D');
            _writer.Write((int)command.Command.Length);
            _writer.Write(command.Command);
            //_logfile.Flush();

            if (_logfile.Length - _logfile.Position < MByte)
            {
              IncreaseFileSize();
            }
              }
              }
              return CommandSN;
        }
Beispiel #2
0
        internal static void ExecuteEvent(string database, EventCommand waitingevent )
        {
            var store = new ObjectStoreWrapper(database);

              foreach (var ge in _globaleventhandlers)
              {
            try
            {
              if (ge != null) ge(store, waitingevent);
            }
            catch (Exception ex)
            {
              Debug.WriteLine(ex.Message);
            }
              }

              Action<ObjectStoreWrapper, BSonDoc> method = FindEventHandler(waitingevent.Command.Deserialize());
              try
              {
            if (method != null)
              method(store, waitingevent.Command.Deserialize());
              }
              catch (Exception ex)
              {
            Debug.WriteLine(ex.Message);
              }
        }
Beispiel #3
0
        internal static void ExecuteCommandEvent(string database, EventCommand waitingevent)
        {
            var store = new ObjectStoreWrapper(database);

              #region Execute inline global event handlers
              foreach (var ge in _globaleventhandlers)
              {
            try
            {
              if (ge != null) ge(store, waitingevent);
            }
            catch (Exception ex)
            {
              Debug.WriteLine(ex.Message);
            }
              }
              #endregion

              var command = waitingevent.Command.Deserialize();

              var currenthandlers = ChechHandlers(command);
              if (currenthandlers != null)
            foreach (var hh in currenthandlers)
            {
              try
              {
            hh.HandleCommand(store, command);
              }
              catch (Exception ex)
              {
            Debug.WriteLine(ex.Message);
              }
            }
        }
Beispiel #4
0
        public void GlobalEvent(EventMessage message)
        {
            var store = StoreManager.GetEventStore(message.Database);

              EventCommand cmd = new EventCommand() { Command = message.Command, CommandMarker = message.CommandMarker };
              cmd.SetMarker(P2PConfiguration.NoRedispatch);

              store.Enqueue(cmd);
        }
Beispiel #5
0
        public long Enqueue(EventCommand command)
        {
            var csn = _journal.LogCommand(command);
              command.CommandSN = csn;
              lock (_waitingevents)
            _waitingevents.Enqueue(command);

              CommandsReady.Set();

              return csn;
        }
Beispiel #6
0
 public long Enqueue(byte[] command)
 {
     var cmd = new EventCommand() { Command = command };
       return Enqueue(cmd);
 }
Beispiel #7
0
 internal static void WriteCommand(BinaryWriter bw, EventCommand command)
 {
     bw.Write('K');
       bw.Write(command.CommandSN);
       bw.Write(command.CommandMarker ?? string.Empty);
       bw.Write('D');
       bw.Write(command.Command.Length);
       bw.Write(command.Command);
 }