Example #1
0
        public override void StartYarn(Yarn yarn, Task task)
        {
            YarnOfThread yarnOfThread = ((YarnOfThread)yarn);

            yarnOfThread.Thread.Task = task;
            task.OnBeforeRun        += yarnOfThread.TaskBeforeRun;
            yarnOfThread.Thread.Start();
        }
Example #2
0
 public virtual void ReleaseYarn(Yarn yarn)
 {
     mActiveYarns.AcquireWriterLock();
     try {
         mActiveYarns.Remove(yarn);
     } finally {
         mActiveYarns.ReleaseWriterLock();
     }
 }
Example #3
0
        public override void TerminateYarn(Yarn yarn)
        {
            YarnOfThread LYarn = (YarnOfThread)yarn;

            if (LYarn.Thread.TheThread == null)
            {
                this.ReleaseYarn(yarn);
                return;
            }
            if (LYarn.Thread.TheThread.ThreadState != ThreadState.Unstarted)
            {
                LYarn.Thread.Stop();
            }
        }
Example #4
0
        private void ListenThreadExecute()
        {
            bool LAbort = false;
            Yarn LYarn  = null;
            TcpConnection <TReplyCode, TReply> LPeer = null;
            Socket   LSocket = null;
            TContext LContext;

            while (!LAbort)
            {
                try {
                    LYarn   = mScheduler.AcquireYarn();
                    LSocket = mServerSocket.Accept();
                    if (LSocket == null)
                    {
                        LAbort = true;
                        return;
                    }
                    LPeer               = new TcpConnection <TReplyCode, TReply>();
                    LPeer.Socket        = LSocket;
                    LPeer.ManagedSocket = true;

                    // add support for MaxConnections

                    LContext               = new TContext();
                    LContext.Yarn          = LYarn;
                    LContext.TcpConnection = LPeer;
                    LContext.OnBeforeRun  += ContextConnected;
                    LContext.OnAfterRun   += ContextDisconnected;
                    LContext.OnRun        += DoExecute;
                    LContext.OnException  += DoContextException;
                    ContextCreated(LContext);
                    Scheduler.StartYarn(LYarn, LContext);

                    /*
                     *      except
                     *              on E: Exception do begin
                     *                      Sys.FreeAndNil(LContext);
                     *                      Sys.FreeAndNil(LPeer);
                     *                      // Must terminate - likely has not started yet
                     *                      if LYarn <> nil then begin
                     *                              Server.Scheduler.TerminateYarn(LYarn);
                     *                      end;
                     *                      // EAbort is used to kick out above and destroy yarns and other, but
                     *                      // we dont want to show the user
                     *                      if not (E is EAbort) then begin
                     *                              Server.DoListenException(Self, E);
                     *                      end;
                     *              end;
                     *      end;
                     *
                     */
                } catch (Exception E) {
                    LContext = null;
                    LPeer    = null;
                    LSocket  = null;
                    if (LYarn != null)
                    {
                        Scheduler.TerminateYarn(LYarn);
                        LYarn = null;
                    }
                    if (!(E is ThreadAbortException))
                    {
                        DoListenException(E);
                    }
                }
            }
        }
Example #5
0
 public abstract void TerminateYarn(Yarn yarn);
Example #6
0
 public abstract void StartYarn(Yarn yarn, Task task);