예제 #1
0
        protected void Timeout(SSContext context, long timeout, TimeoutCallback callback)
        {
            long timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();

            if (timeout <= 0)
            {
                callback(context, timestamp);
            }
            else
            {
                if (m_totalServiceSession >= Int32.MaxValue)
                {
                    m_totalServiceSession = 0;
                }

                SSTimerNode timerNode = new SSTimerNode();
                timerNode.Opaque           = m_serviceAddress;
                timerNode.Session          = ++m_totalServiceSession;
                timerNode.TimeoutTimestamp = timestamp + timeout;

                SSTimer.GetInstance().Add(timerNode);

                TimeoutContext timeoutContext = new TimeoutContext();
                timeoutContext.Callback = callback;
                timeoutContext.Context  = context;
                m_timeoutCallbacks.Add(timerNode.Session, timeoutContext);
            }
        }
예제 #2
0
        private void Boot(BootServices customBoot)
        {
            // create global instance first
            m_globalMQ     = GlobalMQ.GetInstance();
            m_serviceSlots = ServiceSlots.GetInstance();
            m_netpackQueue = NetworkPacketQueue.GetInstance();
            m_timer        = SSTimer.GetInstance();

            NetProtocol.GetInstance();

            // create logger service second
            Logger_Init loggerInit = new Logger_Init();

            if (m_bootConfig.ContainsKey("Logger"))
            {
                if (Directory.Exists(m_bootConfig["Logger"].ToString()))
                {
                    loggerInit.logger_path = Path.GetFullPath(m_bootConfig["Logger"].ToString());
                }
                else
                {
                    DirectoryInfo di = Directory.CreateDirectory(m_bootConfig["Logger"].ToString());
                    if (di.Exists)
                    {
                        loggerInit.logger_path = Path.GetFullPath(m_bootConfig["Logger"].ToString());
                    }
                    else
                    {
                        loggerInit.logger_path = "../";
                    }
                }
            }
            else
            {
                loggerInit.logger_path = "../";
            }
            SparkServerUtility.NewService("SparkServer.Framework.Service.Logger.LoggerService", "logger", loggerInit.encode());

            m_tcpObjectContainer = new TCPObjectContainer();
            if (m_bootConfig.ContainsKey("ClusterConfig"))
            {
                InitCluster();
            }

            if (m_bootConfig.ContainsKey("Gateway"))
            {
                InitGateway();
            }

            customBoot();

            LoggerHelper.Info(0, "Start SparkServer Server...");

            for (int i = 0; i < m_workerNum; i++)
            {
                Thread thread = new Thread(new ThreadStart(ThreadWorker));
                thread.Start();
            }

            Thread timerThread = new Thread(new ThreadStart(ThreadTimer));

            timerThread.Start();
        }