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;
}
}
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();
}
}
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;
}
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;
}
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);
}
Aggregations