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