static void checkParser(GmqPathHelper.PathComponents pc, String path, PublishableStateMessageHeader.MsgType msgType)
        {
            GmqPathHelper.PathComponents result = new GmqPathHelper.PathComponents();
            result.type = msgType;
            Assert.True(GmqPathHelper.parse(path, result));

            Assert.AreEqual(pc, result);
        }
Example #2
0
        public void onMessage(IPublishableParser parser)
        {
            PublishableStateMessageHeader mh = new PublishableStateMessageHeader();
            GMQueue.helperParsePublishableStateMessageBegin(parser, ref mh);
            switch (mh.type)
            {
                case PublishableStateMessageHeader.MsgType.connectionRequest:
                    {
                        GmqPathHelper.PathComponents pc = new GmqPathHelper.PathComponents();
                        pc.type = PublishableStateMessageHeader.MsgType.connectionRequest;
                        bool pathOK = GmqPathHelper.parse(mh.path, pc);
                        if (!pathOK)
                            throw new Exception(); // TODO: ... (bad path)

                        //auto f = connFactories.find(pc.statePublisherOrConnectionType);
                        //if (f == connFactories.end())
                        //	throw std::exception(); // TODO:  ... (no factory for conn name)
                        //auto & connFactory = *f->second;
                        IConnectionFactory connFactory = connFactories[pc.statePublisherOrConnectionType];

                        ServerConnection sc = new ServerConnection();
                        sc.connection = connFactory.create();
                        sc.ref_id_at_client = mh.ref_id_at_subscriber;
                        sc.ref_id_at_server = ++connIdxBase;
                        //sc.connection->pool = this;
                        //sc.connection->connID = sc.ref_id_at_server;
                        //sc.connection->status = ConnectionT::Status::connected;
                        sc.connection.setServerConnected(this, sc.ref_id_at_server);
                        /*auto ins = */
                        connections.Add(sc.ref_id_at_server, sc);
                        //assert(ins.second);

                        PublishableStateMessageHeader hdrBack = new PublishableStateMessageHeader();
                        hdrBack.type = PublishableStateMessageHeader.MsgType.connectionAccepted;
                        hdrBack.state_type_id_or_direction = (ulong)PublishableStateMessageHeader.ConnMsgDirection.toClient;
                        hdrBack.priority = mh.priority; // TODO: source?
                        hdrBack.ref_id_at_subscriber = mh.ref_id_at_subscriber;
                        hdrBack.ref_id_at_publisher = sc.ref_id_at_server;

                        BufferT msgBack = platform.makeBuffer();
                        IPublishableComposer composer = platform.makePublishableComposer(msgBack);
                        GMQueue.helperComposePublishableStateMessageBegin(composer, hdrBack);
                        GMQueue.helperComposePublishableStateMessageEnd(composer);
                        //assert(transport != nullptr);
                        transport.postMessage(msgBack);

                        break;
                    }
                case PublishableStateMessageHeader.MsgType.connectionMessage:
                    {
                        Debug.Assert(mh.state_type_id_or_direction == (ulong)PublishableStateMessageHeader.ConnMsgDirection.toServer);
                        //auto f = connections.find(mh.ref_id_at_publisher);
                        //if (f == connections.end())
                        //	throw std::exception();
                        //auto & conn = f->second;
                        ServerConnection conn = connections[mh.ref_id_at_publisher];
                        Debug.Assert(conn.ref_id_at_server == mh.ref_id_at_publisher); // self-consistency
                                                                                       //auto riter = parser.getIterator();
                        conn.connection.onMessage(parser.getIterator());
                        //parser = riter;
                        break;
                    }
                default:
                    throw new Exception(); // TODO: ... (unknown msg type)
            }
            GMQueue.helperParsePublishableStateMessageEnd(parser);
        }