Exemplo n.º 1
0
    static void DequeueFromServer(CAsyncQueue sq)
    {
        uint messages_dequeued = 0;

        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
        CAsyncQueue.DDequeue         d  = (aq, messageCount, fileSize, messages, bytes) => {
            if (messageCount > 0)
            {
                //there are more messages left at server queue, we re-send a request to dequeue
                aq.Dequeue(TEST_QUEUE_KEY, sq.LastDequeueCallback);
            }
            else
            {
                //set dequeue callback to null and stop dequeuing
                aq.LastDequeueCallback = null;
            }
        };
        CAsyncServiceHandler.DOnResultReturned rr = (sender, reqId, q) => {
            bool processed = false;
            switch (reqId)
            {
            case idMessage:
            {
                byte[] utf8 = q.IntenalBuffer;
                string s    = CUQueue.ToString(utf8, (int)q.GetSize());
                ++messages_dequeued;
            }
                processed = true;
                break;

            default:
                break;
            }
            return(processed);
        };

        sq.ResultReturned += rr;
        Console.WriteLine("Going to dequeue message ......");
        sw.Start();
        bool ok = sq.Dequeue(TEST_QUEUE_KEY, d);

        //optionally, add one or two extra to improve processing concurrency at both client and server sides for better performance and throughput
        ok = sq.Dequeue(TEST_QUEUE_KEY, d);
        ok = sq.Dequeue(TEST_QUEUE_KEY, d);
        sq.WaitAll();
        sq.ResultReturned -= rr;
        sw.Stop();
        Console.WriteLine(messages_dequeued + " messages dequeued from server within " + sw.ElapsedMilliseconds + " ms");
    }
Exemplo n.º 2
0
        void Push_OnPublish(ClientSide.CClientSocket sender, ClientSide.CMessageSender messageSender, uint[] group, object msg)
        {
            if (group[0] == UDB.DB_CONSTS.CACHE_UPDATE_CHAT_GROUP_ID)
            {
#if WINCE
#else
                if (m_bMidTier)
                {
                    ServerSide.CSocketProServer.PushManager.Publish(msg, UDB.DB_CONSTS.CACHE_UPDATE_CHAT_GROUP_ID);
                }
#endif
                SetInitialCache();
                return;
            }
#if WINCE
#else
            if (m_bMidTier)
            {
                //push message onto front clients which may be interested in the message
                ServerSide.CSocketProServer.PushManager.Publish(msg, UDB.DB_CONSTS.STREAMING_SQL_CHAT_GROUP_ID);
            }
#endif
            //vData[0] == event type; vData[1] == host; vData[2] = database user; vData[3] == db name; vData[4] == table name
            object[]           vData     = (object[])msg;
            UDB.tagUpdateEvent eventType = (UDB.tagUpdateEvent)((int)vData[0]);
            if (m_MasterCache.DBServerName == null || m_MasterCache.DBServerName.Length == 0)
            {
                if (vData[1] is sbyte[])
                {
                    m_MasterCache.DBServerName = CUQueue.ToString((sbyte[])vData[1]);
                }
                else if (vData[1] is string)
                {
                    m_MasterCache.DBServerName = (string)vData[1];
                }
            }

            if (vData[2] is sbyte[])
            {
                m_MasterCache.Updater = CUQueue.ToString((sbyte[])vData[2]);
            }
            else if (vData[2] is string)
            {
                m_MasterCache.Updater = (string)vData[2];
            }
            else
            {
                m_MasterCache.Updater = "";
            }

            string dbName = "";
            if (vData[3] is sbyte[])
            {
                dbName = CUQueue.ToString((sbyte[])vData[3]);
            }
            else if (vData[3] is string)
            {
                dbName = (string)vData[3];
            }
            string tblName = "";
            if (vData[4] is sbyte[])
            {
                tblName = CUQueue.ToString((sbyte[])vData[4]);
            }
            else if (vData[4] is string)
            {
                tblName = (string)vData[4];
            }
            uint ret = 0;
            switch (eventType)
            {
            case UDB.tagUpdateEvent.ueDelete:
            {
                List <Object> v = new List <object>();
                for (int n = 5; n < vData.Length; ++n)
                {
                    v.Add(vData[n]);
                }
                ret = m_MasterCache.DeleteARow(dbName, tblName, v.ToArray());
            }
            break;

            case UDB.tagUpdateEvent.ueInsert:
            {
                List <Object> v = new List <object>();
                for (int n = 5; n < vData.Length; ++n)
                {
                    v.Add(vData[n]);
                }
                ret = m_MasterCache.AddRows(dbName, tblName, v);
            }
            break;

            case UDB.tagUpdateEvent.ueUpdate:
            {
                List <Object> v = new List <object>();
                for (int n = 5; n < vData.Length; ++n)
                {
                    v.Add(vData[n]);
                }
                ret = m_MasterCache.UpdateARow(dbName, tblName, v.ToArray());
            }
            break;

            default:
                break;
            }
        }
Exemplo n.º 3
0
            private void OnReqArrive(ulong hSocket, ushort usRequestID, uint len)
            {
                CSocketPeer sp = Seek(hSocket);

                if (sp == null)
                {
                    return;
                }
                sp.m_CurrReqID = usRequestID;
                CUQueue q = sp.m_qBuffer;

                q.SetSize(0);
                if (len > q.MaxBufferSize)
                {
                    q.Realloc(len);
                }
                if (len > 0)
                {
                    uint res;
                    unsafe
                    {
                        fixed(byte *buffer = q.m_bytes)
                        {
                            if (m_nMainThreads <= 1)
                            {
                                CUQueue.CopyMemory(buffer, (void *)ServerCoreLoader.GetRequestBuffer(hSocket), len);
                                res = len;
                            }
                            else
                            {
                                res = ServerCoreLoader.RetrieveBuffer(hSocket, len, buffer, false);
                            }
                        }
                    }
                    System.Diagnostics.Debug.Assert(res == len);
                    q.SetSize(res);
                }
                if (m_svsId != BaseServiceID.sidHTTP)
                {
                    q.OS     = sp.m_os;
                    q.Endian = sp.m_endian;
                    if ((tagBaseRequestID)usRequestID == tagBaseRequestID.idInterrupt)
                    {
                        CClientPeer cp = (CClientPeer)sp;
                        ulong       options;
                        q.Load(out options);
                        cp.OnIntNotified(options);
                        return;
                    }
                }
                else
                {
                    CHttpPeerBase hp = (CHttpPeerBase)sp;
                    hp.m_WebRequestName = null;
                    hp.m_vArg.Clear();
                    if (usRequestID == (ushort)tagHttpRequestID.idUserRequest)
                    {
                        uint    count;
                        sbyte[] reqName;
                        q.Load(out reqName);
                        hp.m_WebRequestName = CUQueue.ToString(reqName);
                        q.Load(out count);
                        for (uint n = 0; n < count; ++n)
                        {
                            object arg;
                            q.Load(out arg);
                            hp.m_vArg.Add(arg);
                        }
                    }
                }
                sp.OnRArrive(usRequestID, len);
            }