/** * @return the client's options. */ public StompClientOptions options() { StompClientOptions ret = delegate.options(); return ret; }
/** * Closes the client. */ public void close() { delegate.close(); }
/** * A general error frame handler. It can be used to catch <code>ERROR</code> frame emitted during the connection process * (wrong authentication). This error handler will be pass to all {@link io.vertx.rxjava.ext.stomp.StompClientConnection} created from this * client. Obviously, the client can override it when the connection is established. * @param handler the handler * @return the current {@link io.vertx.rxjava.ext.stomp.StompClient} */ public io.vertx.rxjava.ext.stomp.StompClient errorFrameHandler(Handler<Frame> handler) { delegate.errorFrameHandler(handler); return this; }
/** * Creates a {@link StompClient} using the default implementation. * * @param vertx the vert.x instance to use * @return the created {@link StompClient} */ static StompClient create(Vertx vertx) { return create(vertx, new StompClientOptions()); }
Frame.Heartbeat.create(client.options().getHeartbeat()), Frame.Heartbeat.parse(frame.getHeader(Frame.HEARTBEAT))); long pong = Frame.Heartbeat.computePongPeriod( Frame.Heartbeat.create(client.options().getHeartbeat()), Frame.Heartbeat.parse(frame.getHeader(Frame.HEARTBEAT))); pinger = client.vertx().setPeriodic(ping, l -> pingHandler.handle(this)); ponger = client.vertx().setPeriodic(pong, l -> { long delta = System.nanoTime() - lastServerActivity; final long deltaInMs = TimeUnit.MILLISECONDS.convert(delta, TimeUnit.NANOSECONDS); if (deltaInMs > pong * 2) { LOGGER.error("Disconnecting client " + client + " - no server activity detected in the last " + deltaInMs + " ms."); client.vertx().cancelTimer(ponger);
@Override public synchronized void close() { closed = true; connected = false; if (closeHandler != null) { context.runOnContext(v -> closeHandler.handle(this)); } if (pinger != -1) { client.vertx().cancelTimer(pinger); pinger = -1; } if (ponger != -1) { client.vertx().cancelTimer(ponger); ponger = -1; } socket.close(); client.close(); pendingReceipts.clear(); subscriptions.clear(); server = null; sessionId = null; version = null; }
/** * @return whether or not the client is connected to the server. */ public boolean isClosed() { boolean ret = delegate.isClosed(); return ret; }
/** * Configures a writing handler that gets notified when a STOMP frame is written on the wire. * This handler can be used for logging, debugging or ad-hoc behavior. The frame can still be modified at the time. * <p> * When a connection is created, the handler is used as * {@link io.vertx.rxjava.ext.stomp.StompClientConnection#writingFrameHandler}. * @param handler the handler * @return the current {@link io.vertx.rxjava.ext.stomp.StompClient} */ public io.vertx.rxjava.ext.stomp.StompClient writingFrameHandler(Handler<Frame> handler) { delegate.writingFrameHandler(handler); return this; }
/** * Configures a received handler that gets notified when a STOMP frame is received by the client. * This handler can be used for logging, debugging or ad-hoc behavior. The frame can still be modified at the time. * <p> * When a connection is created, the handler is used as * {@link io.vertx.rxjava.ext.stomp.StompClientConnection#receivedFrameHandler}. * @param handler the handler * @return the current {@link io.vertx.rxjava.ext.stomp.StompClient} */ public io.vertx.rxjava.ext.stomp.StompClient receivedFrameHandler(Handler<Frame> handler) { delegate.receivedFrameHandler(handler); return this; }
/** * @return the vert.x instance used by the client. */ public io.vertx.rxjava.core.Vertx vertx() { io.vertx.rxjava.core.Vertx ret = io.vertx.rxjava.core.Vertx.newInstance(delegate.vertx()); return ret; }
/** * Connects to the server using the host and port configured in the client's options. * @param resultHandler handler called with the connection result. A failure will be sent to the handler if a TCP level issue happen before the `CONNECTED` frame is received. Afterwards, the {@link io.vertx.rxjava.ext.stomp.StompClient#exceptionHandler} is called. * @return the current {@link io.vertx.rxjava.ext.stomp.StompClient} */ public io.vertx.rxjava.ext.stomp.StompClient connect(Handler<AsyncResult<io.vertx.rxjava.ext.stomp.StompClientConnection>> resultHandler) { delegate.connect(new Handler<AsyncResult<io.vertx.ext.stomp.StompClientConnection>>() { public void handle(AsyncResult<io.vertx.ext.stomp.StompClientConnection> ar) { if (ar.succeeded()) { resultHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.stomp.StompClientConnection.newInstance(ar.result()))); } else { resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); return this; }
/** * Creates a {@link io.vertx.rxjava.ext.stomp.StompClient} using the default implementation. * @param vertx the vert.x instance to use * @return the created {@link io.vertx.rxjava.ext.stomp.StompClient} */ public static io.vertx.rxjava.ext.stomp.StompClient create(io.vertx.rxjava.core.Vertx vertx) { io.vertx.rxjava.ext.stomp.StompClient ret = io.vertx.rxjava.ext.stomp.StompClient.newInstance(io.vertx.ext.stomp.StompClient.create(vertx.getDelegate())); return ret; }
/** * @return whether or not the client is connected to the server. */ public boolean isClosed() { boolean ret = delegate.isClosed(); return ret; }
/** * Configures a writing handler that gets notified when a STOMP frame is written on the wire. * This handler can be used for logging, debugging or ad-hoc behavior. The frame can still be modified at the time. * <p> * When a connection is created, the handler is used as * {@link io.vertx.rxjava.ext.stomp.StompClientConnection#writingFrameHandler}. * @param handler the handler * @return the current {@link io.vertx.rxjava.ext.stomp.StompClient} */ public io.vertx.rxjava.ext.stomp.StompClient writingFrameHandler(Handler<Frame> handler) { delegate.writingFrameHandler(handler); return this; }
/** * Configures a received handler that gets notified when a STOMP frame is received by the client. * This handler can be used for logging, debugging or ad-hoc behavior. The frame can still be modified at the time. * <p> * When a connection is created, the handler is used as * {@link io.vertx.rxjava.ext.stomp.StompClientConnection#receivedFrameHandler}. * @param handler the handler * @return the current {@link io.vertx.rxjava.ext.stomp.StompClient} */ public io.vertx.rxjava.ext.stomp.StompClient receivedFrameHandler(Handler<Frame> handler) { delegate.receivedFrameHandler(handler); return this; }
/** * @return the vert.x instance used by the client. */ public io.vertx.rxjava.core.Vertx vertx() { io.vertx.rxjava.core.Vertx ret = io.vertx.rxjava.core.Vertx.newInstance(delegate.vertx()); return ret; }
/** * Connects to the server using the host and port configured in the client's options. * @param resultHandler handler called with the connection result. A failure will be sent to the handler if a TCP level issue happen before the `CONNECTED` frame is received. Afterwards, the {@link io.vertx.rxjava.ext.stomp.StompClient#exceptionHandler} is called. * @return the current {@link io.vertx.rxjava.ext.stomp.StompClient} */ public io.vertx.rxjava.ext.stomp.StompClient connect(Handler<AsyncResult<io.vertx.rxjava.ext.stomp.StompClientConnection>> resultHandler) { delegate.connect(new Handler<AsyncResult<io.vertx.ext.stomp.StompClientConnection>>() { public void handle(AsyncResult<io.vertx.ext.stomp.StompClientConnection> ar) { if (ar.succeeded()) { resultHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.stomp.StompClientConnection.newInstance(ar.result()))); } else { resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); return this; }
/** * Creates a {@link io.vertx.rxjava.ext.stomp.StompClient} using the default implementation. * @param vertx the vert.x instance to use * @param options the options * @return the created {@link io.vertx.rxjava.ext.stomp.StompClient} */ public static io.vertx.rxjava.ext.stomp.StompClient create(io.vertx.rxjava.core.Vertx vertx, StompClientOptions options) { io.vertx.rxjava.ext.stomp.StompClient ret = io.vertx.rxjava.ext.stomp.StompClient.newInstance(io.vertx.ext.stomp.StompClient.create(vertx.getDelegate(), options)); return ret; }
/** * @return the client's options. */ public StompClientOptions options() { StompClientOptions ret = delegate.options(); return ret; }
/** * Creates a {@link StompClientConnectionImpl} instance * * @param vertx the vert.x instance * @param socket the underlying TCP socket * @param client the stomp client managing this connection * @param resultHandler the result handler to invoke then the connection has been established */ public StompClientConnectionImpl(Vertx vertx, NetSocket socket, StompClient client, Handler<AsyncResult<StompClientConnection>> resultHandler) { this.socket = socket; this.client = client; this.resultHandler = resultHandler; this.context = vertx.getOrCreateContext(); FrameParser parser = new FrameParser(); parser.handler(this); socket.handler(buffer -> { lastServerActivity = System.nanoTime(); parser.handle(buffer); }) .closeHandler(v -> { if (!closed && !client.isClosed()) { close(); if (droppedHandler != null) { droppedHandler.handle(this); } } }); }