Esempio n. 1
0
 internal void DetachProcessor()
 {
     if (OperationProxy.timeReportEnabled)
     {
         this.timer.Stop();
         this.timerresult     = (double)(this.timer.ElapsedTicks * 1000L) / (double)Stopwatch.Frequency;
         this.recentprocessor = this.processor;
     }
     if (this.thread != Thread.CurrentThread.ManagedThreadId)
     {
         Log <OperationProxy> .Logger.FatalFormat("Thread Unsafe code DetachProcessor : [{0} != {1} ({2})]", this.thread, Thread.CurrentThread.ManagedThreadId, this.Processor);
     }
     if (this.processor != null)
     {
         OperationProcessor operationProcessor = this.processor;
         this.processor = null;
         if (this.timeOutSchedule != 0L)
         {
             Scheduler.Cancel(this.timeOutSchedule);
             this.timeOutSchedule = 0L;
         }
         operationProcessor.Dispose();
         if (this.ProcessorDisposed != null)
         {
             try
             {
                 this.ProcessorDisposed(this);
             }
             catch (Exception ex)
             {
                 Log <OperationProxy> .Logger.Error("Error in ProcessorDisposed event", ex);
             }
         }
     }
 }
Esempio n. 2
0
        public void ProcessMessage(object msg)
        {
            if (this.thread != Thread.CurrentThread.ManagedThreadId)
            {
                Log <OperationProxy> .Logger.FatalFormat("Thread Unsafe code ProcessMessage : [{0} != {1} ({2})]", this.thread, Thread.CurrentThread.ManagedThreadId, this.Processor);
            }
            if (this.disposed)
            {
                if (msg is FunctionSync)
                {
                    FunctionSync functionSync = msg as FunctionSync;
                    Log <OperationProxy> .Logger.ErrorFormat("Try to access disposed object in ProcessMessage [(processing {0})]", functionSync.Name);
                }
                else
                {
                    Log <OperationProxy> .Logger.ErrorFormat("Try to access disposed object in ProcessMessage [(processing {0})]", msg.GetType().ToString());
                }
                throw new ObjectDisposedException("OperationProxy");
            }
            try
            {
                OperationProxy.currentProxy = this;
                if (msg is Operation)
                {
                    OperationProcessor operationProcessor = this.MakeProcessor(msg as Operation);
                    if (OperationPerformance.GatherPerformance)
                    {
                        operationProcessor.GatherPerformance = true;
                    }
                    if ((operationProcessor == null || !this.AttachProcessor(operationProcessor)) && this.Sending != null)
                    {
                        this.Sending(new FailMessage(string.Format("[ProcessMessage] !AttachProcessor [0]", operationProcessor))
                        {
                            Reason = FailMessage.ReasonCode.NotSupportedOperation
                        });
                    }
                }
                else
                {
                    this.processor.ProcessFeedback(msg);
                }
                this.CheckFinish();
            }
            catch (Exception ex)
            {
                Log <OperationProxy> .Logger.ErrorFormat("Error in ProcessMessage [(processing {0}) {1}]", msg.GetType().ToString(), ex.ToString());

                this.CheckFinish();
            }
            finally
            {
                OperationProxy.currentProxy = null;
            }
        }
Esempio n. 3
0
 private void OnTimeOut(OperationProcessor op)
 {
     if (this.processor != null && op == this.processor && !this.processor.Finished)
     {
         this.timeOutSchedule = 0L;
         this.ProcessMessage(new FailMessage(string.Format("[OnTimeOut] {0}", op))
         {
             Reason = FailMessage.ReasonCode.TimeOut
         });
         Log <OperationProxy> .Logger.ErrorFormat("Operation Time Out : [{0} on {1}]", op.Operation, op);
     }
 }
Esempio n. 4
0
        private bool AttachProcessor(OperationProcessor newProcessor)
        {
            if (this.thread != Thread.CurrentThread.ManagedThreadId)
            {
                Log <OperationProxy> .Logger.FatalFormat("Thread Unsafe code AttachProcessor : [{0} != {1} ({2})]", this.thread, Thread.CurrentThread.ManagedThreadId, this.Processor);
            }
            if (this.processor != null)
            {
                Log <OperationProxy> .Logger.ErrorFormat("duplicate processor : [{0} on {1}]", newProcessor, this.processor);

                this.DetachProcessor();
                return(false);
            }
            this.processor = newProcessor;
            if (this.processor == null)
            {
                return(true);
            }
            Log <OperationProxy> .Logger.DebugFormat("Attach {0}({1})", newProcessor.GetType().Name, newProcessor.Operation.GetType().Name);

            JobProcessor loop = JobProcessor.Current;

            this.processor.OnSend += delegate(object msg)
            {
                if (msg is ISynchronizable)
                {
                    ISynchronizable synchronizable = (ISynchronizable)msg;
                    synchronizable.OnFinished += this.OnSynchronizableFinished;
                    synchronizable.OnSync();
                    return;
                }
                if (this.Sending != null)
                {
                    this.Sending(msg);
                }
            };
            if (OperationProxy.timeReportEnabled)
            {
                this.timer = Stopwatch.StartNew();
            }
            if (this.processor.Operation.TimeOut != 0)
            {
                this.timeOutSchedule = Scheduler.Schedule(loop, Job.Create <OperationProcessor>(new Action <OperationProcessor>(this.OnTimeOut), this.processor), this.processor.Operation.TimeOut);
            }
            if (this.ProcessorAttached != null)
            {
                try
                {
                    this.ProcessorAttached(this, this.processor);
                }
                catch (Exception ex)
                {
                    Log <OperationProxy> .Logger.Error("ProcessorAttached", ex);

                    this.DetachProcessor();
                    return(false);
                }
            }
            this.processor.Start();
            return(true);
        }