/** * Notify this server's consumers that the server has stopped. */ protected void notifyShutdown() { reactor.notify(shutdown.getT2(), selfEvent); }
/** * Notify this server's consumers that the given connection has been opened. * * @param conn The {@link TcpConnection} that was opened. */ protected void notifyOpen(@Nonnull TcpConnection<IN, OUT> conn) { reactor.notify(open.getT2(), Event.wrap(conn)); }
/** * Notify this client's consumers that the connection has been opened. * * @param conn * The {@link TcpConnection} that was opened. */ protected void notifyOpen(@Nonnull TcpConnection<IN, OUT> conn) { reactor.notify(open.getT2(), Event.wrap(conn)); }
/** * Notify this clients's consumers that the connection has been closed. * * @param conn * The {@link TcpConnection} that was closed. */ protected void notifyClose(@Nonnull TcpConnection<IN, OUT> conn) { reactor.notify(close.getT2(), Event.wrap(conn)); }
/** * Notify this server's consumers that the given connection has been closed. * * @param conn The {@link TcpConnection} that was closed. */ protected void notifyClose(@Nonnull TcpConnection<IN, OUT> conn) { reactor.notify(close.getT2(), Event.wrap(conn)); }
void notifyRead(Object obj) { eventsReactor.notify(read.getT2(), (Event.class.isInstance(obj) ? (Event)obj : Event.wrap(obj))); }
/** * Notify this server's consumers that the server has started. * * @param started An optional callback to invoke. */ protected void notifyStart(@Nullable final Consumer<Void> started) { if (null != started) { reactor.on(start.getT1(), new Consumer<Event<Void>>() { @Override public void accept(Event<Void> ev) { started.accept(null); } }); } reactor.notify(start.getT2(), selfEvent); }
@SuppressWarnings("unchecked") @Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (Tuple2.class.isInstance(msg)) { Tuple2<Object, Boolean> tup = (Tuple2<Object, Boolean>) msg; if (null != tup.getT1()) { super.write(ctx, tup.getT1(), promise); } if (tup.getT2()) { ctx.flush(); } } else { super.write(ctx, msg, promise); ctx.flush(); } } }
protected <U> Composable(@Nullable Observable observable, @Nullable Composable<U> parent, @Nullable Tuple2<Selector, Object> acceptSelectorTuple, @Nullable Environment environment) { Assert.state(observable != null || parent != null, "One of 'observable' or 'parent' cannot be null."); this.parent = parent; this.environment = environment; this.events = parent == null ? observable : parent.events; if (null == acceptSelectorTuple) { this.acceptSelector = Selectors.anonymous(); this.acceptKey = acceptSelector.getObject(); } else { this.acceptKey = acceptSelectorTuple.getT1(); this.acceptSelector = new ObjectSelector<Object>(acceptSelectorTuple.getT2()); } }
long delay = tup.getT2();
/** * Perfoming necessary decoding on the data and notify the internal {@link Reactor} of any results. * * @param data * The data to decode. * * @return {@literal true} if any more data is remaining to be consumed in the given {@link Buffer}, {@literal false} * otherwise. */ public boolean read(Buffer data) { if(null != decoder && null != data.byteBuffer()) { decoder.apply(data); } else { eventsReactor.notify(read.getT2(), Event.wrap(data)); } return data.remaining() > 0; }
@Override public Promise<IN> sendAndReceive(OUT data) { final Deferred<IN, Promise<IN>> d = Promises.defer(env, eventsReactor.getDispatcher()); Tuple2<Selector, Object> tup = $(); eventsReactor.on(tup.getT1(), new EventConsumer<IN>(d)).cancelAfterUse(); replyToKeys.add(tup.getT2()); send(data, null); return d.compose(); }
protected AbstractTcpConnection(Environment env, Codec<Buffer, IN, OUT> codec, Dispatcher ioDispatcher, Dispatcher eventsDispatcher) { this.env = env; this.ioDispatcher = ioDispatcher; this.ioReactor = Reactors.reactor(env, ioDispatcher); this.eventsReactor = Reactors.reactor(env, eventsDispatcher); if(null != codec) { this.decoder = codec.decoder(new NotifyConsumer<IN>(read.getT2(), eventsReactor)); this.encoder = codec.encoder(); } else { this.decoder = null; this.encoder = null; } this.replyToKeys = BlockingQueueFactory.createQueue(); consume(new Consumer<IN>() { @Override public void accept(IN in) { try { AbstractTcpConnection.this.eventsReactor.notify(replyToKeys.remove(), Event.wrap(in)); } catch(NoSuchElementException ignored) { } } }); }