use of io.netty.buffer.EmptyByteBuf in project activemq-artemis by apache.
the class MQTTPublishManager method sendInternal.
/**
* Sends a message either on behalf of the client or on behalf of the broker (Will Messages)
* @param messageId
* @param topic
* @param qos
* @param payload
* @param retain
* @param internal if true means on behalf of the broker (skips authorisation) and does not return ack.
* @throws Exception
*/
void sendInternal(int messageId, String topic, int qos, ByteBuf payload, boolean retain, boolean internal) throws Exception {
synchronized (lock) {
Message serverMessage = MQTTUtil.createServerMessageFromByteBuf(session, topic, retain, qos, payload);
if (qos > 0) {
serverMessage.setDurable(MQTTUtil.DURABLE_MESSAGES);
}
if (qos < 2 || !state.getPubRec().contains(messageId)) {
if (qos == 2 && !internal)
state.getPubRec().add(messageId);
Transaction tx = session.getServerSession().newTransaction();
try {
if (internal) {
session.getServer().getPostOffice().route(serverMessage, tx, true);
} else {
session.getServerSession().send(tx, serverMessage, true, false);
}
if (retain) {
boolean reset = payload instanceof EmptyByteBuf || payload.capacity() == 0;
session.getRetainMessageManager().handleRetainedMessage(serverMessage, topic, reset, tx);
}
tx.commit();
} catch (Throwable t) {
logger.warn(t.getMessage(), t);
tx.rollback();
throw t;
}
createMessageAck(messageId, qos, internal);
}
}
}
use of io.netty.buffer.EmptyByteBuf in project reactor-netty by reactor.
the class ChannelOperationsHandler method channelRead.
@Override
public final void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg == null || msg == Unpooled.EMPTY_BUFFER || msg instanceof EmptyByteBuf) {
return;
}
try {
ChannelOperations<?, ?> ops = ChannelOperations.get(ctx.channel());
if (ops != null) {
ops.onInboundNext(ctx, msg);
} else {
if (log.isDebugEnabled()) {
String loggingMsg = msg.toString();
if (msg instanceof HttpResponse) {
DecoderResult decoderResult = ((HttpResponse) msg).decoderResult();
if (decoderResult.isFailure()) {
log.debug("Decoding failed: " + msg + " : ", decoderResult.cause());
}
}
if (msg instanceof ByteBufHolder) {
loggingMsg = ((ByteBufHolder) msg).content().toString(Charset.defaultCharset());
}
log.debug("{} No ChannelOperation attached. Dropping: {}", ctx.channel().toString(), loggingMsg);
}
ReferenceCountUtil.release(msg);
}
} catch (Throwable err) {
Exceptions.throwIfFatal(err);
exceptionCaught(ctx, err);
ReferenceCountUtil.safeRelease(msg);
}
}
use of io.netty.buffer.EmptyByteBuf in project grpc-java by grpc.
the class NettyServerStreamTest method abortStreamAfterClientHalfCloseShouldCallClose.
@Test
public void abortStreamAfterClientHalfCloseShouldCallClose() {
Status status = Status.INTERNAL.withCause(new Throwable());
// Client half-closes. Listener gets halfClosed()
stream().transportState().inboundDataReceived(new EmptyByteBuf(UnpooledByteBufAllocator.DEFAULT), true);
verify(serverListener).halfClosed();
// Abort from the transport layer
stream().transportState().transportReportStatus(status);
verify(serverListener).closed(same(status));
assertNull("no message expected", listenerMessageQueue.poll());
}
use of io.netty.buffer.EmptyByteBuf in project thingsboard by thingsboard.
the class MqttTransportHandlerTest method getMqttPublishMessage.
MqttPublishMessage getMqttPublishMessage() {
MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH, true, MqttQoS.AT_LEAST_ONCE, false, 123);
MqttPublishVariableHeader variableHeader = new MqttPublishVariableHeader("v1/gateway/telemetry", packedId.incrementAndGet());
ByteBuf payload = new EmptyByteBuf(new PooledByteBufAllocator());
return new MqttPublishMessage(mqttFixedHeader, variableHeader, payload);
}
Aggregations