public ISession newSession(IAssociateSession s)
        {
            // create session
            AESession ses = null;

            lock (_sessionsLock)
            {
                ulong sid = ++_sessionIDSeed;
                ses = new AESession(s, sid);

                _sessionsByID[sid] = ses;
            }

            // add to listener
            _listeners[(int)s.type].addSession(ses);

            return(ses);
        }
Пример #2
0
        public int addSession(ISession s)
        {
            IAssociateSession ases = s.getAssociateSession(this.type);

            if (ases == null)
            {
                Debug.logger.log(LogType.LOG_ERR, "AEServer AEListener addSession session[" + AESession.dumpSessionInfo(s) + "] without associate session type[" + this.type + "]");
                return(0);
            }

            int ret = 0;

            lock (_sessionsLock)
            {
                _sessionsByOrgID[(OrgSessionIDType)ases.orgSessionID] = s;
                ret = _sessionsByOrgID.Count;
            }

            return(ret);
        }
        protected ITask _queueSessionTask(ISession session, ITask t)
        {
            IService svr = _getSessionService(session);

            if (svr == null)
            {
                session.lastErrorCode = AEErrorCode.ERR_SERVICE_NOT_FOUND;
                session.lastErrorMsg  = "AEServer session manager queueSessionTask session[" + AESession.dumpSessionInfo(session) + "] without service";
                Debug.logger.log(LogType.LOG_ERR, session.lastErrorMsg);
                return(null);
            }

            return(svr.queueTask(session, t));
        }
        // return : =0 if failed, otherwise return service queued task count
        public ITask queueSessionTask(ISession session, ITask t)
        {
            if (session.isClosed || session.isClosing)
            {
                // session is closing or closed, discard message
                session.lastErrorCode = AEErrorCode.ERR_SESSION_QUEUE_TASK_ERROR;
                session.lastErrorMsg  = "AEServer session manager queueSessionTask session[" + AESession.dumpSessionInfo(session) + "] is closing or closed";
                Debug.logger.log(LogType.LOG_ERR, session.lastErrorMsg);
                return(null);
            }

            if (session.isChangingService && !(t is AESessionAddTask))
            {
                session.lastErrorCode = AEErrorCode.ERR_SESSION_QUEUE_TASK_ERROR;
                session.lastErrorMsg  = "AEServer session manager queueSessionTask session[" + AESession.dumpSessionInfo(session) + "] is changing service";
                Debug.logger.log(LogType.LOG_WARNNING, session.lastErrorMsg);
                // when session is changing service, only session add task is accept, any other task will be discard
                return(null);
            }

            return(_queueSessionTask(session, t));
        }