@Override public final void run() { if (owner == currentThread()) { try { process(); } catch (Throwable t) { onError(t); } } else { // the pipeline is executed on the wrong IOThread, so send the // pipeline to the right IO Thread to be executed. addTaskAndWakeup(this); } }
final void unregisterOp(int operation) throws IOException { SelectionKey selectionKey = getSelectionKey(); int interestOps = selectionKey.interestOps(); if ((interestOps & operation) != 0) { selectionKey.interestOps(interestOps & ~operation); } }
@Override public final void run() { if (pipeline.owner() == currentThread()) { // the task is executed by the proper thread try { run0(); } catch (Exception e) { pipeline.onError(e); } } else { // the pipeline is migrating or already has migrated // lets lets reschedule this task on the pipeline so // it will be picked up by the new owner. pipeline.addTaskAndWakeup(this); } }
@Override public void run() { // if there is no change, we are done if (owner == newOwner) { return; } publishMetrics(); try { startMigration(newOwner); } catch (Throwable t) { onError(t); } }
private void processSelectionKey(SelectionKey sk) { NioPipeline pipeline = (NioPipeline) sk.attachment(); try { if (!sk.isValid()) { // if the selectionKey isn't valid, we throw this exception to feedback the situation into the pipeline.onFailure throw new CancelledKeyException(); } // we don't need to check for sk.isReadable/sk.isWritable since the pipeline has only registered // for events it can handle. eventCount.inc(); pipeline.process(); } catch (Throwable t) { pipeline.onError(t); } }
@Override public void run() { try { assert owner == null; owner = newOwner; ownerId = newOwner.id; // we don't need to wakeup since the io thread will see the delayed tasks. restoreTasks(owner, delayedTaskStack.getAndSet(null), false); completedMigrations.inc(); ioBalancer.signalMigrationComplete(); if (!socketChannel.isOpen()) { return; } selectionKey = getSelectionKey(); registerOp(initialOps); } catch (Throwable t) { onError(t); } } }
private void restoreTasks(NioThread owner, TaskNode node, boolean wakeup) { if (node == null) { return; } // we restore in the opposite order so that we get fifo. restoreTasks(owner, node.next, false); if (wakeup) { owner.addTaskAndWakeup(node.task); } else { owner.addTask(node.task); } }
void start() { addTaskAndWakeup(new NioPipelineTask(this) { @Override protected void run0() { try { getSelectionKey(); } catch (Throwable t) { onError(t); } } }); }
@Override protected void run0() { try { getSelectionKey(); } catch (Throwable t) { onError(t); } } });
private void rebuildSelector() { selectorRebuildCount.inc(); Selector newSelector = newSelector(logger); Selector oldSelector = this.selector; // reset each pipeline's selectionKey, cancel the old keys for (SelectionKey key : oldSelector.keys()) { NioPipeline pipeline = (NioPipeline) key.attachment(); SelectableChannel channel = key.channel(); try { int ops = key.interestOps(); SelectionKey newSelectionKey = channel.register(newSelector, ops, pipeline); pipeline.setSelectionKey(newSelectionKey); } catch (ClosedChannelException e) { logger.info("Channel was closed while trying to register with new selector."); } catch (CancelledKeyException e) { // a CancelledKeyException may be thrown in key.interestOps // in this case, since the key is already cancelled, just do nothing ignore(e); } key.cancel(); } // close the old selector and substitute with new one closeSelector(); this.selector = newSelector; logger.warning("Recreated Selector because of possible java/network stack bug."); }
for (ChannelHandler handler : handlers()) { handler.interceptError(error);
@Override public void run() { // if there is no change, we are done if (owner == newOwner) { return; } publishMetrics(); try { startMigration(newOwner); } catch (Throwable t) { onError(t); } }
private void processSelectionKey(SelectionKey sk) { NioPipeline pipeline = (NioPipeline) sk.attachment(); try { if (!sk.isValid()) { // if the selectionKey isn't valid, we throw this exception to feedback the situation into the pipeline.onFailure throw new CancelledKeyException(); } // we don't need to check for sk.isReadable/sk.isWritable since the pipeline has only registered // for events it can handle. eventCount.inc(); pipeline.process(); } catch (Throwable t) { pipeline.onError(t); } }
@Override public void run() { try { assert owner == null; owner = newOwner; ownerId = newOwner.id; // we don't need to wakeup since the io thread will see the delayed tasks. restoreTasks(owner, delayedTaskStack.getAndSet(null), false); completedMigrations.inc(); ioBalancer.signalMigrationComplete(); if (!socketChannel.isOpen()) { return; } selectionKey = getSelectionKey(); registerOp(initialOps); } catch (Throwable t) { onError(t); } } }
private void restoreTasks(NioThread owner, TaskNode node, boolean wakeup) { if (node == null) { return; } // we restore in the opposite order so that we get fifo. restoreTasks(owner, node.next, false); if (wakeup) { owner.addTaskAndWakeup(node.task); } else { owner.addTask(node.task); } }
void start() { addTaskAndWakeup(new NioPipelineTask(this) { @Override protected void run0() { try { getSelectionKey(); } catch (Throwable t) { onError(t); } } }); }
@Override protected void run0() { try { getSelectionKey(); } catch (Throwable t) { onError(t); } } });
private void rebuildSelector() { selectorRebuildCount.inc(); Selector newSelector = newSelector(logger); Selector oldSelector = this.selector; // reset each pipeline's selectionKey, cancel the old keys for (SelectionKey key : oldSelector.keys()) { NioPipeline pipeline = (NioPipeline) key.attachment(); SelectableChannel channel = key.channel(); try { int ops = key.interestOps(); SelectionKey newSelectionKey = channel.register(newSelector, ops, pipeline); pipeline.setSelectionKey(newSelectionKey); } catch (ClosedChannelException e) { logger.info("Channel was closed while trying to register with new selector."); } catch (CancelledKeyException e) { // a CancelledKeyException may be thrown in key.interestOps // in this case, since the key is already cancelled, just do nothing ignore(e); } key.cancel(); } // close the old selector and substitute with new one closeSelector(); this.selector = newSelector; logger.warning("Recreated Selector because of possible java/network stack bug."); }
for (ChannelHandler handler : handlers()) { handler.interceptError(error);
@Override public final void run() { if (owner == currentThread()) { try { process(); } catch (Throwable t) { onError(t); } } else { // the pipeline is executed on the wrong IOThread, so send the // pipeline to the right IO Thread to be executed. addTaskAndWakeup(this); } }