/** * Find the {@link NetChannel} for the given IO channel object. * * @param ioChannel * The channel object. * @param <C> * The type of the channel object. * * @return The {@link NetChannel} associated with the given channel. */ protected <C> NetChannel<IN, OUT> select(@Nonnull C ioChannel) { Assert.notNull(ioChannel, "Channel cannot be null."); Iterator<Registration<? extends NetChannel<IN, OUT>>> channs = netChannels.select(ioChannel).iterator(); if (channs.hasNext()) { return channs.next().getObject(); } else { NetChannel<IN, OUT> conn = createChannel(ioChannel); register(ioChannel, conn); notifyOpen(conn); return conn; } }
public void close(@Nullable final Consumer<Boolean> onClose) { for (Registration<? extends NetChannel<IN, OUT>> reg : getChannels()) { if (!reg.isCancelled()) { doCloseChannel(reg.getObject()); } } if (null != onClose) { reactor.schedule(onClose, true); } }
/** * Subclasses should implement this method to perform the actual IO channel close. * * @param onClose */ protected void doClose(@Nullable Consumer<Boolean> onClose) { getReactor().schedule(onClose, true); }
public Promise<Boolean> close() { Deferred<Boolean, Promise<Boolean>> d = Promises.defer(env, reactor.getDispatcher()); close(d); return d.compose(); }
/** * Close the given channel. * * @param channel * The channel object. * @param <C> * The type of the channel object. */ protected <C> void close(@Nonnull C channel) { Assert.notNull(channel, "Channel cannot be null"); for (Registration<? extends NetChannel<IN, OUT>> reg : netChannels.select(channel)) { NetChannel<IN, OUT> chann = reg.getObject(); reg.cancel(); notifyClose(chann); } }
public Iterator<NetChannel<IN, OUT>> iterator() { FastList<NetChannel<IN, OUT>> channels = FastList.newList(); for (Registration<? extends NetChannel<IN, OUT>> reg : getChannels()) { channels.add(reg.getObject()); } return channels.iterator(); }
/** * Notify this server's consumers that the server has started. */ protected void notifyStart(final Runnable started) { getReactor().notify(start.getObject(), selfEvent); if (null != started) { getReactor().schedule(new Consumer<Runnable>() { @Override public void accept(Runnable r) { r.run(); } }, started); } }
/** * Notify this server's consumers that the server has stopped. */ protected void notifyShutdown() { getReactor().notify(shutdown.getObject(), selfEvent); }