public void onMessage(IPublishableParser parser) { PublishableStateMessageHeader mh = new PublishableStateMessageHeader(); GMQueue.helperParsePublishableStateMessageBegin(parser, ref mh); switch (mh.type) { case PublishableStateMessageHeader.MsgType.connectionAccepted: { //auto f = connections.find(mh.ref_id_at_subscriber); //if (f == connections.end()) // throw std::exception(); //auto & conn = f->second; ClientConnection conn = connections[mh.ref_id_at_subscriber]; Debug.Assert(conn.ref_id_at_client == mh.ref_id_at_subscriber); // self-consistency conn.ref_id_at_server = mh.ref_id_at_publisher; //if (conn.connection->status != ConnectionT::Status::connRequestSent) // throw std::exception(); // well, we have not requested connection yet //conn.connection->status = ConnectionT::Status::connected; conn.connection.setConnected(); conn.connection.onConnectionAccepted(); break; } case PublishableStateMessageHeader.MsgType.connectionMessage: { Debug.Assert(mh.state_type_id_or_direction == (ulong)PublishableStateMessageHeader.ConnMsgDirection.toClient); //auto f = connections.find(mh.ref_id_at_subscriber); //if (f == connections.end()) // throw std::exception(); //auto & conn = f->second; ClientConnection conn = connections[mh.ref_id_at_subscriber]; if (!conn.connection.isConnected()) throw new Exception(); // TODO: revise Debug.Assert(conn.ref_id_at_server == mh.ref_id_at_publisher); // self-consistency //ReadIteratorT riter = parser.getIterator(); conn.connection.onMessage(parser.getIterator()); //parser = riter; break; } default: throw new Exception(); // TODO: ... (unknown msg type) } GMQueue.helperParsePublishableStateMessageEnd(parser); }
void onMessage(IPublishableParser parser) { ReadIteratorT riter = parser.getIterator().shallowClone(); IPublishableParser parser1 = platform.makePublishableParser(riter); PublishableStateMessageHeader mh = new PublishableStateMessageHeader(); GMQueue.helperParsePublishableStateMessageBegin(parser1, ref mh); switch (mh.type) { case PublishableStateMessageHeader.MsgType.subscriptionResponse: case PublishableStateMessageHeader.MsgType.stateUpdate: subPool.onMessage(parser); break; case PublishableStateMessageHeader.MsgType.subscriptionRequest: pubPool.onMessage(parser); break; case PublishableStateMessageHeader.MsgType.connectionRequest: srvPool.onMessage(parser); break; case PublishableStateMessageHeader.MsgType.connectionAccepted: cliPool.onMessage(parser); break; case PublishableStateMessageHeader.MsgType.connectionMessage: switch ((PublishableStateMessageHeader.ConnMsgDirection)mh.state_type_id_or_direction) { case PublishableStateMessageHeader.ConnMsgDirection.toClient: cliPool.onMessage(parser); break; case PublishableStateMessageHeader.ConnMsgDirection.toServer: srvPool.onMessage(parser); break; default: throw new Exception(); // TODO: ... (unknown msg type) } break; default: throw new Exception(); // TODO: ... (unknown msg type) } }
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); }