Search in sources :

Example 1 with InboundHandler

use of com.hazelcast.internal.networking.InboundHandler in project hazelcast by hazelcast.

the class NioInboundPipeline method updatePipeline.

private void updatePipeline(InboundHandler[] handlers) {
    this.handlers = handlers;
    receiveBuffer = handlers.length == 0 ? null : (ByteBuffer) handlers[0].src();
    InboundHandler prev = null;
    for (InboundHandler handler : handlers) {
        if (prev != null) {
            Object src = handler.src();
            if (src instanceof ByteBuffer) {
                prev.dst(src);
            }
        }
        prev = handler;
    }
}
Also used : InboundHandler(com.hazelcast.internal.networking.InboundHandler) ByteBuffer(java.nio.ByteBuffer)

Example 2 with InboundHandler

use of com.hazelcast.internal.networking.InboundHandler in project hazelcast by hazelcast.

the class NioInboundPipeline method process.

@Override
void process() throws Exception {
    int readBytes = socketChannel.read(receiveBuffer);
    if (readBytes == -1) {
        throw new EOFException("Remote socket closed!");
    }
    if (readBytes > 0) {
        processCount.inc();
        lastReadTime = currentTimeMillis();
        bytesRead.inc(readBytes);
    }
    // currently the whole pipeline is retried when one of the handlers is dirty; but only the dirty handler
    // and the remaining sequence should need to retry.
    InboundHandler[] localHandlers = handlers;
    boolean cleanPipeline;
    boolean unregisterRead;
    do {
        cleanPipeline = true;
        unregisterRead = false;
        for (int handlerIndex = 0; handlerIndex < localHandlers.length; handlerIndex++) {
            InboundHandler handler = localHandlers[handlerIndex];
            HandlerStatus handlerStatus = handler.onRead();
            if (localHandlers != handlers) {
                // change in the pipeline detected, restarting loop
                handlerIndex = -1;
                localHandlers = handlers;
                continue;
            }
            switch(handlerStatus) {
                case CLEAN:
                    break;
                case DIRTY:
                    cleanPipeline = false;
                    break;
                case BLOCKED:
                    // setting cleanPipeline to true keep flushing everything downstream, but not upstream.
                    cleanPipeline = true;
                    unregisterRead = true;
                    break;
                default:
                    throw new IllegalStateException();
            }
        }
    } while (!cleanPipeline);
    if (migrationRequested()) {
        startMigration();
        return;
    }
    if (unregisterRead) {
        unregisterOp(OP_READ);
    }
}
Also used : HandlerStatus(com.hazelcast.internal.networking.HandlerStatus) InboundHandler(com.hazelcast.internal.networking.InboundHandler) EOFException(java.io.EOFException)

Example 3 with InboundHandler

use of com.hazelcast.internal.networking.InboundHandler in project hazelcast by hazelcast.

the class DefaultNodeExtension method createInboundHandlers.

@Override
public InboundHandler[] createInboundHandlers(EndpointQualifier qualifier, ServerConnection connection, ServerContext serverContext) {
    NodeEngineImpl nodeEngine = node.nodeEngine;
    PacketDecoder decoder = new PacketDecoder(connection, nodeEngine.getPacketDispatcher());
    return new InboundHandler[] { decoder };
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) InboundHandler(com.hazelcast.internal.networking.InboundHandler) PacketDecoder(com.hazelcast.internal.server.tcp.PacketDecoder)

Example 4 with InboundHandler

use of com.hazelcast.internal.networking.InboundHandler in project hazelcast by hazelcast.

the class NioInboundPipeline method addLast.

@Override
public InboundPipeline addLast(InboundHandler... addedHandlers) {
    checkNotNull(addedHandlers, "handlers can't be null");
    for (InboundHandler addedHandler : addedHandlers) {
        fixDependencies(addedHandler);
        addedHandler.setChannel(channel).handlerAdded();
    }
    updatePipeline(append(handlers, addedHandlers));
    return this;
}
Also used : InboundHandler(com.hazelcast.internal.networking.InboundHandler)

Example 5 with InboundHandler

use of com.hazelcast.internal.networking.InboundHandler in project hazelcast by hazelcast.

the class NioInboundPipeline method replace.

@Override
public InboundPipeline replace(InboundHandler oldHandler, InboundHandler... addedHandlers) {
    checkNotNull(oldHandler, "oldHandler can't be null");
    checkNotNull(addedHandlers, "addedHandlers can't be null");
    InboundHandler[] newHandlers = replaceFirst(handlers, oldHandler, addedHandlers);
    if (newHandlers == handlers) {
        throw new IllegalArgumentException("handler " + oldHandler + " isn't part of the pipeline");
    }
    for (InboundHandler addedHandler : addedHandlers) {
        fixDependencies(addedHandler);
        addedHandler.setChannel(channel).handlerAdded();
    }
    updatePipeline(newHandlers);
    return this;
}
Also used : InboundHandler(com.hazelcast.internal.networking.InboundHandler)

Aggregations

InboundHandler (com.hazelcast.internal.networking.InboundHandler)7 ServerConnection (com.hazelcast.internal.server.ServerConnection)2 HandlerStatus (com.hazelcast.internal.networking.HandlerStatus)1 OutboundHandler (com.hazelcast.internal.networking.OutboundHandler)1 PacketDecoder (com.hazelcast.internal.server.tcp.PacketDecoder)1 SingleProtocolEncoder (com.hazelcast.internal.server.tcp.SingleProtocolEncoder)1 TcpServerConnection (com.hazelcast.internal.server.tcp.TcpServerConnection)1 TextHandshakeDecoder (com.hazelcast.internal.server.tcp.TextHandshakeDecoder)1 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)1 EOFException (java.io.EOFException)1 ByteBuffer (java.nio.ByteBuffer)1