wsky / top-link

embedded duplex multi-channel endpoint and connection management for c#/java/...
6 stars 1 forks source link

sendAndWait in IO-Thread course Timeout #50

Closed wsky closed 11 years ago

wsky commented 11 years ago
public void onMessage(EndpointContext context) throws Exception {
    server.getEndpoint(context.getMessageFrom()).sendAndWait(msg,1000);
}

always timeout if onMessage raised in io-thread

channelHandler.setScheduler(new Scheduler<Identity>());

after enable scheduler that onMessage called in business thread, it works.

wsky commented 11 years ago

as NIO Selector is readable when processbuffer, in the same io-thread just can read and pend message to sendbuffer

for (SelectionKey key : selector.selectedKeys()) {
                                if (key.isValid() && key.isWritable() && upstreamQueue.peek() != null) {
                                    SocketChannel channel = (SocketChannel) key
                                            .channel();
                                    channel.write(upstreamQueue.poll());
                                    socket.register(selector, OP_READ);
                                } else if (key.isValid() && key.isReadable()) {
                                    read(socket, downstreamBuffer); // read
                                    // response
                                    switch (state) {
                                    case HANDSHAKE: // CONNECTED -> HANDSHAKE
                                        pipeline.sendHandshakeDownstream(WebSocketBase.this, downstreamBuffer);
                                        if (getHandshake().isDone()){
                                            processBuffer(downstreamBuffer);
                                            handshakeLatch.countDown();
                                        }
                                        break;
                                    case WAIT: // read frames
                                    case CLOSING:
                                        processBuffer(downstreamBuffer);
                                        break;
                                    default:
                                        break;
                                    }
                                }