示例#1
0
文件: promise.cs 项目: bowen-xu/TCE
 /**
  * repeate do current OnNext Action
  */
 public void again(RpcAsyncContext ctx)
 {
     if (_currentNext != null)
     {
         _currentNext(ctx);
     }
 }
示例#2
0
文件: promise.cs 项目: bowen-xu/TCE
        /**
         * onNext()
         * promise下一个处理
         * 同一个promise中 step1 -> step2
         * 下一个promise 跳转到上级 promise
         */
        public void onNext(RpcAsyncContext ctx, RpcPromise from = null)
        {
            if (true)
            {
                if (from != null && from._lastPoint != null)
                {
                    int index = _sucesslist.IndexOf(from._lastPoint);
                    _sucesslist.RemoveRange(0, index + 1);
                }

                if (_sucesslist.Count == 0)
                {
                    onFinally(ctx);
                    return;
                }
                OnNext next = null;
                next = _sucesslist[0];
                _sucesslist.RemoveAt(0);
                _currentNext = next;
                if (next != null)
                {
                    next(ctx);
                }
            }
        }
示例#3
0
文件: promise.cs 项目: bowen-xu/TCE
 private void onFinally(RpcAsyncContext ctx)
 {
     _currentNext = _finally;
     if (_finally != null)
     {
         _finally(ctx);
     }
     if (_nextPromise != null)
     {
         _nextPromise.onNext(ctx, this);
     }
 }
示例#4
0
        protected virtual void doReturnMsg(RpcMessage m2)
        {
            RpcMessage m1 = null;

            // count+=1;

            m1 = RpcCommunicator.instance().dequeueMessage(m2.sequence);

            if (m1 != null)
            {
                if (m1.async != null)
                {
                    // it will raise exception in user callback function
                    try {
                        if (m2.errcode != RpcException.RPCERROR_SUCC)
                        {
                            // remote exception
                            //m1.async.ctx.exception = new RpcException(m2.errcode);
                            if (m1.async.promise != null)
                            {
                                RpcAsyncContext ctx = new RpcAsyncContext();
                                ctx.promise   = m1.async.promise;
                                ctx.exception = new RpcException(m2.errcode);
                                m1.async.promise.onError(ctx);
                            }
                            else
                            {
                                m1.async.onError(m2.errcode);
                            }
                        }
                        else
                        {
                            m1.async.callReturn(m1, m2);
                        }
                    }
                    catch (Exception e) {
                        RpcCommunicator.instance().logger.error("User CallBack failed: m1.async.callReturn ." + e.ToString());
                    }
                }
                else
                {
                    lock (m1){
                        m1.result = m2;                     // assing to init-caller
                        //m1.notify();
                        m1.ev.Set();
                    }
                }
            }
        }
示例#5
0
        protected override bool connect()
        {
            IPAddress  addr = IPAddress.Parse(_ep.host);
            IPEndPoint ep   = new IPEndPoint(addr, _ep.port);

            _status = ConnectStatus.CONNECTING;
            _sock   = newSocket();
            _sock.BeginConnect(ep, delegate(IAsyncResult ar) {
                RpcConnectionAsyncSocket s = (RpcConnectionAsyncSocket)ar.AsyncState;
                try {
                    s.handler.EndConnect(ar);
                    if (s.handler.Connected == true)
                    {
                        s.onConnected();
                        //s._thread = new Thread(run);
                        //s._thread.Start();  // launch one thread for data recieving .
                    }
                }
                catch (Exception e) {
                    // connect failed
                    //s.onDisconnected();
                    RpcCommunicator.instance().logger.error("connect to host failed!");
                }
                //connect failed, trigger event to user as Promise
                if (s.handler.Connected == false)
                {
                    foreach (RpcMessage m in _unsent_msglist)
                    {
                        RpcAsyncContext ctx = m.async.ctx;
                        ctx.exception       = new RpcException(RpcException.RPCERROR_CONNECT_FAILED);
                        m.async.promise.onError(ctx);
                    }
                    _unsent_msglist.Clear();
                }
                s._status = ConnectStatus.STOPPED;
            }, this);

            return(true);
        }
示例#6
0
        protected void _timerCheckHealth(object source, System.Timers.ElapsedEventArgs e)
        {
            //RpcCommunicator.instance().logger.debug("Communicator:: health checking..");
            List <RpcMessage> removeList = new List <RpcMessage>();

            lock (_cachedMsgList){
                long       cursec         = Utility.unixTimestamp(DateTime.Now);
                List <int> deprecatedlist = new List <int>();
                foreach (KeyValuePair <int, RpcMessage> kv in _cachedMsgList)
                {
                    if ((cursec - kv.Value.issuetime) * 1000 > _settings.callwait)
                    {
                        deprecatedlist.Add(kv.Key);
                    }
                }
                foreach (int seq in deprecatedlist)
                {
                    removeList.Add(_cachedMsgList[seq]);
                    _cachedMsgList.Remove(seq);
                    RpcCommunicator.instance().logger.error(String.Format("message({0}) be dropped for timeout", seq));
                }
            }
            //
            foreach (RpcMessage message in removeList)
            {
                if (message.async.promise == null)
                {
                    message.async.onError(RpcException.RPCERROR_TIMEOUT);
                }
                else
                {
                    RpcAsyncContext ctx = new RpcAsyncContext();
                    ctx.promise   = message.async.promise;
                    ctx.exception = new RpcException(RpcException.RPCERROR_TIMEOUT);
                    message.async.promise.onError(ctx);
                }
            }
        }
示例#7
0
文件: promise.cs 项目: bowen-xu/TCE
        public void onError(RpcAsyncContext ctx)
        {
            if (_errorlist.Count == 0)
            {
                onFinally(ctx);
                return;
            }
            // pick out one fork-promise
            KeyValuePair <RpcPromise, OnNext> kv = _errorlist[0];
            OnNext     succ = kv.Value;
            RpcPromise next = kv.Key;

            _errorlist.RemoveAt(0);
            // scan list and remove all nodes which's depth of node is less than promise.
            int index = _sucesslist.IndexOf(succ);

            _sucesslist.RemoveRange(0, index + 1);

            if (next != null)
            {
                ctx.promise = next;
                next.onNext(ctx);
            }
        }
示例#8
0
 protected void _timerCheckHealth(object source, System.Timers.ElapsedEventArgs e)
 {
     //RpcCommunicator.instance().logger.debug("Communicator:: health checking..");
     List<RpcMessage> removeList = new List<RpcMessage>();
     lock (_cachedMsgList){
         long cursec = Utility.unixTimestamp(DateTime.Now);
         List<int> deprecatedlist=new List<int>();
         foreach (KeyValuePair<int, RpcMessage> kv in _cachedMsgList) {
             if ( (cursec - kv.Value.issuetime)*1000 > _settings.callwait) {
                 deprecatedlist.Add( kv.Key);
             }
         }
         foreach (int seq in deprecatedlist) {
             removeList.Add( _cachedMsgList[seq]);
             _cachedMsgList.Remove(seq);
             RpcCommunicator.instance().logger.error(String.Format("message({0}) be dropped for timeout", seq));
         }
     }
     //
     foreach (RpcMessage message in removeList) {
         if (message.async.promise == null) {
             message.async.onError(RpcException.RPCERROR_TIMEOUT);
         }
         else {
             RpcAsyncContext ctx = new RpcAsyncContext();
             ctx.promise = message.async.promise;
             ctx.exception = new RpcException(RpcException.RPCERROR_TIMEOUT);
             message.async.promise.onError(ctx);
         }
     }
 }
示例#9
0
文件: promise.cs 项目: adoggie/TCE
 /**
  * repeate do current OnNext Action
  */
 public void again(RpcAsyncContext ctx)
 {
     if (_currentNext != null) {
         _currentNext(ctx);
     }
 }
示例#10
0
文件: promise.cs 项目: adoggie/TCE
 private void onFinally(RpcAsyncContext ctx)
 {
     _currentNext = _finally;
     if (_finally != null) {
         _finally(ctx);
     }
     if (_nextPromise != null) {
         _nextPromise.onNext(ctx,this);
     }
 }
示例#11
0
文件: promise.cs 项目: adoggie/TCE
        /**
         * onNext()
         * promise下一个处理
         * 同一个promise中 step1 -> step2
         * 下一个promise 跳转到上级 promise
         */
        public void onNext(RpcAsyncContext ctx,RpcPromise from = null)
        {
            if (true) {
                if (from != null && from._lastPoint != null)
                {
                    int index = _sucesslist.IndexOf(from._lastPoint);
                    _sucesslist.RemoveRange(0,index+1);
                }

                if (_sucesslist.Count == 0) {
                    onFinally(ctx);
                    return;
                }
                OnNext next = null;
                next = _sucesslist[0];
                _sucesslist.RemoveAt(0);
                _currentNext = next;
                if ( next != null) {
                    next( ctx );
                }
            }
        }
示例#12
0
文件: promise.cs 项目: adoggie/TCE
        public void onError(RpcAsyncContext ctx)
        {
            if (_errorlist.Count == 0)
            {
                onFinally(ctx);
                return;
            }
            // pick out one fork-promise
            KeyValuePair<RpcPromise, OnNext> kv = _errorlist[0];
            OnNext succ = kv.Value;
            RpcPromise next = kv.Key;
            _errorlist.RemoveAt(0);
            // scan list and remove all nodes which's depth of node is less than promise.
            int index = _sucesslist.IndexOf(succ);
            _sucesslist.RemoveRange(0, index + 1);

            if (next != null) {
                ctx.promise = next;
                next.onNext(ctx);
            }
        }
示例#13
0
文件: connection.cs 项目: adoggie/TCE
        protected virtual void doReturnMsg(RpcMessage m2)
        {
            RpcMessage m1 = null;
               // count+=1;

            m1 = RpcCommunicator.instance().dequeueMessage(m2.sequence);

            if(m1!=null){
                if(m1.async !=null){
                    // it will raise exception in user callback function
                    try {
                        if (m2.errcode != RpcException.RPCERROR_SUCC) {
                            // remote exception
                            //m1.async.ctx.exception = new RpcException(m2.errcode);
                            if (m1.async.promise != null) {
                                RpcAsyncContext ctx = new RpcAsyncContext();
                                ctx.promise = m1.async.promise;
                                ctx.exception = new RpcException(m2.errcode);
                                m1.async.promise.onError( ctx );
                            }
                            else {
                                m1.async.onError(m2.errcode);
                            }
                        }
                        else {
                            m1.async.callReturn(m1, m2);
                        }
                    }
                    catch (Exception e) {
                        RpcCommunicator.instance().logger.error("User CallBack failed: m1.async.callReturn ." + e.ToString());
                    }
                }else{
                    lock(m1){
                        m1.result = m2; // assing to init-caller
                        //m1.notify();
                        m1.ev.Set();
                    }
                }
            }
        }