
io.vertx.groovy.ext.stomp.StompClient.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vertx-stomp Show documentation
Show all versions of vertx-stomp Show documentation
Stomp support for Vert.x 3
The newest version!
/*
* Copyright 2014 Red Hat, Inc.
*
* Red Hat licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.vertx.groovy.ext.stomp;
import groovy.transform.CompileStatic
import io.vertx.lang.groovy.InternalHelper
import io.vertx.core.json.JsonObject
import io.vertx.ext.stomp.Frame
import io.vertx.groovy.core.Vertx
import io.vertx.core.AsyncResult
import io.vertx.core.Handler
import io.vertx.groovy.core.net.NetClient
import io.vertx.ext.stomp.StompClientOptions
/**
* Defines a STOMP client.
*/
@CompileStatic
public class StompClient {
private final def io.vertx.ext.stomp.StompClient delegate;
public StompClient(Object delegate) {
this.delegate = (io.vertx.ext.stomp.StompClient) delegate;
}
public Object getDelegate() {
return delegate;
}
/**
* Creates a {@link io.vertx.groovy.ext.stomp.StompClient} using the default implementation.
* @param vertx the vert.x instance to use
* @return the created {@link io.vertx.groovy.ext.stomp.StompClient}
*/
public static StompClient create(Vertx vertx) {
def ret = InternalHelper.safeCreate(io.vertx.ext.stomp.StompClient.create(vertx != null ? (io.vertx.core.Vertx)vertx.getDelegate() : null), io.vertx.groovy.ext.stomp.StompClient.class);
return ret;
}
/**
* Creates a {@link io.vertx.groovy.ext.stomp.StompClient} using the default implementation.
* @param vertx the vert.x instance to use
* @param options the options (see StompClientOptions)
* @return the created {@link io.vertx.groovy.ext.stomp.StompClient}
*/
public static StompClient create(Vertx vertx, Map options) {
def ret = InternalHelper.safeCreate(io.vertx.ext.stomp.StompClient.create(vertx != null ? (io.vertx.core.Vertx)vertx.getDelegate() : null, options != null ? new io.vertx.ext.stomp.StompClientOptions(io.vertx.lang.groovy.InternalHelper.toJsonObject(options)) : null), io.vertx.groovy.ext.stomp.StompClient.class);
return ret;
}
/**
* Connects to the server.
* @param port the server port
* @param host the server host
* @param resultHandler handler called with the connection result
* @return the current {@link io.vertx.groovy.ext.stomp.StompClient}
*/
public StompClient connect(int port, String host, Handler> resultHandler) {
delegate.connect(port, host, resultHandler != null ? new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
resultHandler.handle(io.vertx.core.Future.succeededFuture(InternalHelper.safeCreate(ar.result(), io.vertx.groovy.ext.stomp.StompClientConnection.class)));
} else {
resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
} : null);
return this;
}
/**
* Connects to the server.
* @param net the NET client to use
* @param resultHandler handler called with the connection result
* @return the current {@link io.vertx.groovy.ext.stomp.StompClient}
*/
public StompClient connect(NetClient net, Handler> resultHandler) {
delegate.connect(net != null ? (io.vertx.core.net.NetClient)net.getDelegate() : null, resultHandler != null ? new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
resultHandler.handle(io.vertx.core.Future.succeededFuture(InternalHelper.safeCreate(ar.result(), io.vertx.groovy.ext.stomp.StompClientConnection.class)));
} else {
resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
} : null);
return this;
}
/**
* Connects to the server.
* @param port the server port
* @param host the server host
* @param net the NET client to use
* @param resultHandler handler called with the connection result
* @return the current {@link io.vertx.groovy.ext.stomp.StompClient}
*/
public StompClient connect(int port, String host, NetClient net, Handler> resultHandler) {
delegate.connect(port, host, net != null ? (io.vertx.core.net.NetClient)net.getDelegate() : null, resultHandler != null ? new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
resultHandler.handle(io.vertx.core.Future.succeededFuture(InternalHelper.safeCreate(ar.result(), io.vertx.groovy.ext.stomp.StompClientConnection.class)));
} else {
resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
} : null);
return this;
}
/**
* Connects to the server using the host and port configured in the client's options.
* @param resultHandler handler called with the connection result
* @return the current {@link io.vertx.groovy.ext.stomp.StompClient}
*/
public StompClient connect(Handler> resultHandler) {
delegate.connect(resultHandler != null ? new Handler>() {
public void handle(AsyncResult ar) {
if (ar.succeeded()) {
resultHandler.handle(io.vertx.core.Future.succeededFuture(InternalHelper.safeCreate(ar.result(), io.vertx.groovy.ext.stomp.StompClientConnection.class)));
} else {
resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
}
}
} : null);
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.
*
* When a connection is created, the handler is used as
* {@link io.vertx.groovy.ext.stomp.StompClientConnection#receivedFrameHandler}.
* @param handler the handler
* @return the current {@link io.vertx.groovy.ext.stomp.StompClient}
*/
public StompClient receivedFrameHandler(Handler
© 2015 - 2025 Weber Informatics LLC | Privacy Policy