Exemple #1
0
        public void PostMessage(int actorId, Message message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            _messages.Enqueue(message);
        }
Exemple #2
0
 private static void ReportError(IMainWindow Window, string start, Message message)
 {
     // item 126
     string text;
     Exception ex = message.Payload as Exception;
     // item 128
     if (ex == null) {
     // item 131
     text = start;
     } else {
     // item 127
     text = start + "\n" + ex.Message;
     }
     // item 132
     Window.ReportError(text);
 }
Exemple #3
0
        public void PostMessage(int actorId, Message message)
        {
            IActor actor;
            lock (_lock)
            {
                if (!_actors.TryGetValue(actorId, out actor))
                {
                    return;
                }
            }

            Action toDo = () =>
                {
                    RunMessageHandler(actorId, actor, message);
                };

            _dispatcher(toDo);
        }
Exemple #4
0
 public void OnMessage(IRuntime runtime, int myId, Message message)
 {
     switch (message.Code) {
     case PumpFinished:
         switch (CurrentState) {
             case StateNames.Operational:
                 Operational_PumpFinished(runtime, myId, message);
                 break;
             default:
                 break;
         }
         break;
     case RequestArrived:
         switch (CurrentState) {
             case StateNames.Operational:
                 Operational_RequestArrived(runtime, myId, message);
                 break;
             default:
                 break;
         }
         break;
     default:
         break;
     }
 }
Exemple #5
0
 public void OnMessage(IRuntime runtime, int myActorId, Message message)
 {
     switch (message.Code) {
     case CallResult.Completed:
         History.Add (String.Format ("Completed {0} {1}", myActorId, message.Payload));
         Finished.Set ();
         break;
     case CallResult.Error:
         History.Add (String.Format ("Failure {0}", myActorId));
         Finished.Set ();
         break;
     case CallResult.Cancelled:
         History.Add (String.Format ("Cancelled {0}", myActorId));
         Finished.Set ();
         break;
     case CallResult.Timeout:
         History.Add (String.Format ("Timeout {0}", myActorId));
         Finished.Set ();
         break;
     case Start:
         runtime.SendCall (Target, 666, null, myActorId, TimeSpan.FromSeconds (0.5));
         break;
     default:
         break;
     }
 }
Exemple #6
0
        private void ThreadProcedure()
        {
            _logger.Info("Started dedicated thread " + _name);
            Message pulse = new Message(Codes.Pulse, 0, null, 0);
            while (true)
            {
                bool mustExist = ProcessMessages();
                if (mustExist)
                {
                    break;
                }

                RunMessageHandler(pulse);
            }

            Runtime runtime = (Runtime)_runtime;
            runtime.RemoveThread(_actorId);

            _logger.Info("Finished dedicated thread " + _name);
        }
Exemple #7
0
 private void SendRemaining_CallResult_Cancelled(IRuntime runtime, int myId, Message message)
 {
     // item 397
     CurrentState = StateNames.Deleting;
     runtime.RemoveActor(myId);
 }
Exemple #8
0
            private void ReadSend_CallResult_Completed(IRuntime runtime, int myId, Message message)
            {
                int _sw5030000_ = 0;
                // item 5030000
                _sw5030000_ = message.Id;
                // item 5030001
                if (_sw5030000_ == Read) {
                // item 398
                SaveReceivedCount(this, message);
                // item 333
                CurrentState = StateNames.JustSend;
                } else {
                // item 5030002
                if (_sw5030000_ == Send) {

                } else {
                    // item 5030003
                    throw new InvalidOperationException("Not expected:  " + _sw5030000_.ToString());
                }
                // item 376
                CurrentState = StateNames.JustRead;
                }
            }
Exemple #9
0
 private void JustRead_CallResult_Completed(IRuntime runtime, int myId, Message message)
 {
     // item 344
     SaveReceivedCount(this, message);
     // item 343
     bool finished = SwapBuffers(this);
     // item 411
     StartSend(runtime, this, myId);
     // item 346
     if (finished) {
     // item 348
     CurrentState = StateNames.SendRemaining;
     } else {
     // item 499
     StartRead(runtime, this, myId);
     // item 327
     CurrentState = StateNames.ReadSend;
     }
 }
Exemple #10
0
 public void OnMessage(IRuntime runtime, int myId, Message message)
 {
     switch (message.Code) {
     case CallResult.Cancelled:
         switch (CurrentState) {
             case StateNames.JustRead:
                 JustRead_CallResult_Cancelled(runtime, myId, message);
                 break;
             case StateNames.ReadSend:
                 ReadSend_CallResult_Cancelled(runtime, myId, message);
                 break;
             case StateNames.JustSend:
                 JustSend_CallResult_Cancelled(runtime, myId, message);
                 break;
             case StateNames.SendRemaining:
                 SendRemaining_CallResult_Cancelled(runtime, myId, message);
                 break;
             default:
                 break;
         }
         break;
     case CallResult.Completed:
         switch (CurrentState) {
             case StateNames.JustRead:
                 JustRead_CallResult_Completed(runtime, myId, message);
                 break;
             case StateNames.ReadSend:
                 ReadSend_CallResult_Completed(runtime, myId, message);
                 break;
             case StateNames.JustSend:
                 JustSend_CallResult_Completed(runtime, myId, message);
                 break;
             case StateNames.SendRemaining:
                 SendRemaining_CallResult_Completed(runtime, myId, message);
                 break;
             default:
                 break;
         }
         break;
     case CallResult.Error:
         switch (CurrentState) {
             case StateNames.JustRead:
                 JustRead_CallResult_Error(runtime, myId, message);
                 break;
             case StateNames.ReadSend:
                 ReadSend_CallResult_Error(runtime, myId, message);
                 break;
             case StateNames.JustSend:
                 JustSend_CallResult_Error(runtime, myId, message);
                 break;
             case StateNames.SendRemaining:
                 SendRemaining_CallResult_Error(runtime, myId, message);
                 break;
             default:
                 break;
         }
         break;
     default:
         break;
     }
 }
Exemple #11
0
 private void Init_Codes_Start(IRuntime runtime, int myId, Message message)
 {
     // item 840
     runtime.SendCall(
     FolderReader,
     ReadFolder,
     Folder,
     myId,
     TimeSpan.FromSeconds(1)
     );
     // item 766
     CurrentState = StateNames.WaitingForFolder;
 }
Exemple #12
0
 public void OnMessage(IRuntime runtime, int myId, Message message)
 {
     switch (message.Code) {
     case CallResult.Cancelled:
         switch (CurrentState) {
             case StateNames.Init:
                 break;
             case StateNames.WaitingForFolder:
                 WaitingForFolder_CallResult_Cancelled(runtime, myId, message);
                 break;
             case StateNames.Sending:
                 break;
             default:
                 break;
         }
         break;
     case CallResult.Completed:
         switch (CurrentState) {
             case StateNames.Init:
                 break;
             case StateNames.WaitingForFolder:
                 WaitingForFolder_CallResult_Completed(runtime, myId, message);
                 break;
             case StateNames.Sending:
                 break;
             default:
                 break;
         }
         break;
     case CallResult.Error:
         switch (CurrentState) {
             case StateNames.Init:
                 break;
             case StateNames.WaitingForFolder:
                 WaitingForFolder_CallResult_Error(runtime, myId, message);
                 break;
             case StateNames.Sending:
                 break;
             default:
                 break;
         }
         break;
     case CallResult.Timeout:
         switch (CurrentState) {
             case StateNames.Init:
                 break;
             case StateNames.WaitingForFolder:
                 WaitingForFolder_CallResult_Timeout(runtime, myId, message);
                 break;
             case StateNames.Sending:
                 break;
             default:
                 break;
         }
         break;
     case Codes.Start:
         switch (CurrentState) {
             case StateNames.Init:
                 Init_Codes_Start(runtime, myId, message);
                 break;
             case StateNames.WaitingForFolder:
                 break;
             case StateNames.Sending:
                 break;
             default:
                 break;
         }
         break;
     case PumpFinished:
         switch (CurrentState) {
             case StateNames.Init:
                 break;
             case StateNames.WaitingForFolder:
                 break;
             case StateNames.Sending:
                 Sending_PumpFinished(runtime, myId, message);
                 break;
             default:
                 break;
         }
         break;
     default:
         break;
     }
 }
Exemple #13
0
 private void Working_ReadFolder(IRuntime runtime, int myId, Message message)
 {
     // item 870
     string folder = (string)message.Payload;
     // item 871
     List<string> files = null;
     Exception exception = null;
     try {
     files = Directory
         .EnumerateFiles(folder)
         .ToList();
     } catch (Exception ex) {
     exception = ex;
     runtime.Log.Error(
         "Error reading folder: " + folder,
         ex
     );
     }
     // item 873
     if (files == null) {
     // item 875
     runtime.SendResult(
         message.Sender,
         message.Id,
         CallResult.Error,
         exception,
         myId
     );
     // item 856
     CurrentState = StateNames.Working;
     } else {
     // item 872
     runtime.SendResult(
         message.Sender,
         message.Id,
         CallResult.Completed,
         files,
         myId
     );
     // item 856
     CurrentState = StateNames.Working;
     }
 }
Exemple #14
0
 private void Working_default(IRuntime runtime, int myId, Message message)
 {
     // item 856
     CurrentState = StateNames.Working;
 }
Exemple #15
0
 public void OnMessage(IRuntime runtime, int myId, Message message)
 {
     switch (message.Code) {
     case ReadFolder:
         switch (CurrentState) {
             case StateNames.Working:
                 Working_ReadFolder(runtime, myId, message);
                 break;
             default:
                 break;
         }
         break;
     default:
         break;
     }
 }
Exemple #16
0
 private static void SaveReceivedCount(StreamPump pump, Message message)
 {
     // item 262
     pump.InBuffer.Count = (int)message.Payload;
     pump.SoFar += pump.InBuffer.Count;
 }
Exemple #17
0
 private void SendRemaining_CallResult_Completed(IRuntime runtime, int myId, Message message)
 {
     // item 470
     runtime.Log.Info(String.Format(
     "Pump {0} completed request.",
     myId
     ));
     // item 330
     CurrentState = StateNames.Deleting;
     runtime.RemoveActor(myId);
 }
Exemple #18
0
 private void Operational_PumpFinished(IRuntime runtime, int myId, Message message)
 {
     // item 457
     int actorId = (int)message.Payload;
     // item 454
     if (ActivePumps.ContainsKey(actorId)) {
     // item 464
     runtime.Log.Info("Closing pump: " + actorId);
     // item 458
     HttpListenerResponse response = ActivePumps[actorId].Response;
     ActivePumps.Remove(actorId);
     // item 459
     response.Close();
     // item 425
     CurrentState = StateNames.Operational;
     } else {
     // item 425
     CurrentState = StateNames.Operational;
     }
 }
Exemple #19
0
 private void Operational_RequestArrived(IRuntime runtime, int myId, Message message)
 {
     // item 440
     HttpListenerContext context = (HttpListenerContext)message.Payload;
     // item 474
     string url = context.Request.RawUrl;
     // item 441
     if (ActivePumps.Count < MaxPumps) {
     // item 461
     runtime.Log.Info("Serving request for: " + url);
     // item 452
     int actorId = ProcessRequest(
         runtime,
         myId,
         context,
         Folder,
         url,
         FolderReader
     );
     // item 453
     ActivePumps.Add(actorId, context);
     // item 425
     CurrentState = StateNames.Operational;
     } else {
     // item 460
     runtime.Log.Info("Limit reached. Aborting.");
     // item 443
     context.Response.Abort();
     // item 425
     CurrentState = StateNames.Operational;
     }
 }
Exemple #20
0
 private void Init_default(IRuntime runtime, int myId, Message message)
 {
     // item 783
     CurrentState = StateNames.Init;
 }
Exemple #21
0
 private void JustRead_CallResult_Cancelled(IRuntime runtime, int myId, Message message)
 {
     // item 345
     CurrentState = StateNames.Deleting;
     runtime.RemoveActor(myId);
 }
Exemple #22
0
 private void Sending_default(IRuntime runtime, int myId, Message message)
 {
     // item 819
     CurrentState = StateNames.Sending;
 }
Exemple #23
0
 private void JustSend_CallResult_Completed(IRuntime runtime, int myId, Message message)
 {
     // item 472
     bool finished = SwapBuffers(this);
     // item 523
     StartSend(runtime, this, myId);
     // item 403
     if (finished) {
     // item 405
     CurrentState = StateNames.SendRemaining;
     } else {
     // item 524
     StartRead(runtime, this, myId);
     // item 408
     CurrentState = StateNames.ReadSend;
     }
 }
Exemple #24
0
 private void Sending_PumpFinished(IRuntime runtime, int myId, Message message)
 {
     // item 847
     int actorId = (int)message.Payload;
     // item 817
     if (actorId == PumpId) {
     // item 820
     CurrentState = StateNames.Deleting;
     runtime.RemoveActor(myId);
     } else {
     // item 819
     CurrentState = StateNames.Sending;
     }
 }
Exemple #25
0
 private void ReadSend_CallResult_Error(IRuntime runtime, int myId, Message message)
 {
     // item 365
     CurrentState = StateNames.Deleting;
     runtime.RemoveActor(myId);
 }
Exemple #26
0
 private void WaitingForFolder_CallResult_Completed(IRuntime runtime, int myId, Message message)
 {
     // item 843
     var files = (List<string>)message.Payload;
     // item 846
     string responseText = BuildFolderIndexPage(files);
     byte[] responseData = Encoding.UTF8.GetBytes(
     responseText
     );
     // item 844
     PumpId = CreatePumpFromBytes(
     runtime,
     myId,
     Response,
     responseData,
     200
     );
     // item 772
     CurrentState = StateNames.Sending;
 }
Exemple #27
0
 private void RunMessageHandler(Message message)
 {
     try
     {
         _actor.OnMessage(_runtime, _actorId, message);
     }
     catch (Exception ex)
     {
         _logger.Error("Exception in actor OnMessage", ex);
         IActor newActor = _errorHandler.OnError(_runtime, _actorId, _actor, ex);
         if (newActor != null)
         {
             _logger.Info(String.Format("Replacing actor {0}, type: {1}", _actorId, newActor.GetType().Name));
             _actor = newActor;
         }
     }
 }
Exemple #28
0
 private void WaitingForFolder_CallResult_Timeout(IRuntime runtime, int myId, Message message)
 {
     // item 900
     runtime.Log.Info(
     "Timeout on ReadFolder"
     );
     // item 801
     CurrentState = StateNames.Deleting;
     runtime.RemoveActor(myId);
 }
Exemple #29
0
 private void WaitingForFolder_CallResult_Error(IRuntime runtime, int myId, Message message)
 {
     // item 801
     CurrentState = StateNames.Deleting;
     runtime.RemoveActor(myId);
 }
Exemple #30
0
 public void OnMessage(IRuntime runtime, int myActorId, Message message)
 {
     switch (Result) {
     case CallResult.Completed:
         runtime.SendResult (message.Sender, message.Id, CallResult.Completed, "hi", myActorId);
         break;
     case CallResult.Error:
         runtime.SendResult (message.Sender, message.Id, CallResult.Error, null, myActorId);
         break;
     case CallResult.Cancelled:
         runtime.SendResult (message.Sender, message.Id, CallResult.Cancelled, null, myActorId);
         break;
     case CallResult.Timeout:
         break;
     default:
         break;
     }
 }