use of com.swiftmq.impl.mqtt.v311.PacketDecoder in project swiftmq-ce by iitsoftware.
the class MQTTSwiftlet method doConnect.
private void doConnect(Connection connection, Entity connectionTemplate) {
Entity ce = ctx.usageListConnections.createEntity();
MQTTConnection mqttConnection = new MQTTConnection(ctx, connection, ce, connectionTemplate);
PacketDecoder packetDecoder = new PacketDecoder(mqttConnection, ctx.protSpace, ((Integer) connectionTemplate.getProperty("max-message-size").getValue()).intValue());
connection.setInboundHandler(packetDecoder);
connection.setUserObject(mqttConnection);
connections.add(connection);
try {
ce.setName(connection.toString());
ce.getProperty("connect-time").setValue(new Date().toString());
ce.setDynamicObject(connection);
ce.createCommands();
ctx.usageListConnections.addEntity(ce);
} catch (Exception ignored) {
}
}
use of com.swiftmq.impl.mqtt.v311.PacketDecoder in project swiftmq-ce by iitsoftware.
the class PacketDecoder method finishPacket.
private void finishPacket(Connection connection) throws IOException {
if (traceSpace.enabled)
trace("PacketDecoder/finishPacket");
if (available() >= packetSize) {
ByteBuf byteBuf = new ByteBuf(packetSize);
byteBuf.writeBytes(buffer, readPos, packetSize);
byteBuf.reset();
try {
mqttDecoder.decode(byteBuf, decoded);
mqttListener.onMessage(decoded);
decoded.clear();
} catch (Exception e) {
if (traceSpace.enabled)
trace("PacketDecoder/finishPacket: exception=" + e);
mqttListener.onException(e);
}
readPos += packetSize;
packetCompleted(connection);
}
}
use of com.swiftmq.impl.mqtt.v311.PacketDecoder in project swiftmq-ce by iitsoftware.
the class PacketDecoder method getFixedHeaderSize.
private int getFixedHeaderSize(int messageType) {
int size;
MqttMessageType type = MqttMessageType.valueOf(messageType);
switch(type) {
case PINGREQ:
case PINGRESP:
case DISCONNECT:
case PUBACK:
case PUBCOMP:
case PUBREL:
case PUBREC:
case UNSUBACK:
size = 2;
break;
default:
size = MAX_FHEADERS_SIZE;
}
if (traceSpace.enabled)
trace("PacketDecoder/getFixedHeaderSize: messageType=" + messageType);
return size;
}
Aggregations