Search in sources :

Example 1 with OutboundHandler

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

the class NioOutboundPipeline method updatePipeline.

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

Example 2 with OutboundHandler

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

the class NioOutboundPipeline method process.

// is never called concurrently!
@Override
@SuppressWarnings("unchecked")
public void process() throws Exception {
    processCount.inc();
    OutboundHandler[] localHandlers = handlers;
    HandlerStatus pipelineStatus = CLEAN;
    for (int handlerIndex = 0; handlerIndex < localHandlers.length; handlerIndex++) {
        OutboundHandler handler = localHandlers[handlerIndex];
        HandlerStatus handlerStatus = handler.onWrite();
        if (localHandlers != handlers) {
            // change in the pipeline detected, therefor the loop is restarted.
            localHandlers = handlers;
            pipelineStatus = CLEAN;
            handlerIndex = -1;
        } else if (handlerStatus != CLEAN) {
            pipelineStatus = handlerStatus;
        }
    }
    flushToSocket();
    if (migrationRequested()) {
        startMigration();
        // So we don't need to worry about write-through
        return;
    }
    if (sendBuffer.remaining() > 0) {
        pipelineStatus = DIRTY;
    }
    switch(pipelineStatus) {
        case CLEAN:
            postProcessClean();
            break;
        case DIRTY:
            postProcessDirty();
            break;
        case BLOCKED:
            postProcessBlocked();
            break;
        default:
            throw new IllegalStateException();
    }
}
Also used : HandlerStatus(com.hazelcast.internal.networking.HandlerStatus) OutboundHandler(com.hazelcast.internal.networking.OutboundHandler)

Example 3 with OutboundHandler

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

the class NioOutboundPipeline method addLast.

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

Example 4 with OutboundHandler

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

the class NioOutboundPipeline method replace.

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

Example 5 with OutboundHandler

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

the class MemberChannelInitializer method initChannel.

@Override
public void initChannel(Channel channel) {
    ServerConnection connection = (TcpServerConnection) channel.attributeMap().get(ServerConnection.class);
    OutboundHandler[] outboundHandlers = serverContext.createOutboundHandlers(EndpointQualifier.MEMBER, connection);
    InboundHandler[] inboundHandlers = serverContext.createInboundHandlers(EndpointQualifier.MEMBER, connection);
    SingleProtocolEncoder protocolEncoder = new SingleProtocolEncoder(new MemberProtocolEncoder(outboundHandlers));
    SingleProtocolDecoder protocolDecoder = new SingleProtocolDecoder(ProtocolType.MEMBER, inboundHandlers, protocolEncoder, true);
    channel.outboundPipeline().addLast(protocolEncoder);
    channel.inboundPipeline().addLast(protocolDecoder);
}
Also used : OutboundHandler(com.hazelcast.internal.networking.OutboundHandler) InboundHandler(com.hazelcast.internal.networking.InboundHandler) ServerConnection(com.hazelcast.internal.server.ServerConnection)

Aggregations

OutboundHandler (com.hazelcast.internal.networking.OutboundHandler)6 ServerConnection (com.hazelcast.internal.server.ServerConnection)2 HandlerStatus (com.hazelcast.internal.networking.HandlerStatus)1 InboundHandler (com.hazelcast.internal.networking.InboundHandler)1 ByteBuffer (java.nio.ByteBuffer)1