
io.vertx.groovy.core.eventbus.MessageProducer.groovy Maven / Gradle / Ivy
/*
* 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.core.eventbus;
import groovy.transform.CompileStatic
import io.vertx.lang.groovy.InternalHelper
import io.vertx.core.json.JsonObject
import io.vertx.core.eventbus.DeliveryOptions
import io.vertx.groovy.core.streams.WriteStream
import io.vertx.core.AsyncResult
import io.vertx.core.Handler
/**
* Represents a stream of message that can be written to.
*
*/
@CompileStatic
public class MessageProducer implements WriteStream {
private final def io.vertx.core.eventbus.MessageProducer delegate;
public MessageProducer(Object delegate) {
this.delegate = (io.vertx.core.eventbus.MessageProducer) delegate;
}
public Object getDelegate() {
return delegate;
}
/**
* Same as {@link io.vertx.groovy.core.eventbus.MessageProducer#end} but writes some data to the stream before ending.
* @param t
*/
public void end(T t) {
((io.vertx.core.streams.WriteStream) this.delegate).end(InternalHelper.unwrapObject(t));
}
/**
* This will return true
if there are more bytes in the write queue than the value set using {@link io.vertx.groovy.core.eventbus.MessageProducer#setWriteQueueMaxSize}
* @return true if write queue is full
*/
public boolean writeQueueFull() {
def ret = ((io.vertx.core.streams.WriteStream) this.delegate).writeQueueFull();
return ret;
}
/**
* Synonym for {@link io.vertx.groovy.core.eventbus.MessageProducer#write}.
* @param message the message to send
* @return reference to this for fluency
*/
public MessageProducer send(T message) {
def ret= InternalHelper.safeCreate(this.delegate.send(InternalHelper.unwrapObject(message)), io.vertx.groovy.core.eventbus.MessageProducer.class);
return ret;
}
public MessageProducer send(T message, Handler>> replyHandler) {
def ret= InternalHelper.safeCreate(this.delegate.send(InternalHelper.unwrapObject(message), new Handler>>() {
public void handle(AsyncResult> event) {
AsyncResult> f
if (event.succeeded()) {
f = InternalHelper.>result(new Message