Search in sources :

Example 1 with PacketDecoder

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) {
    }
}
Also used : MQTTConnection(com.swiftmq.impl.mqtt.connection.MQTTConnection) PacketDecoder(com.swiftmq.impl.mqtt.v311.PacketDecoder) SwiftletException(com.swiftmq.swiftlet.SwiftletException) ConnectionVetoException(com.swiftmq.swiftlet.net.ConnectionVetoException)

Example 2 with PacketDecoder

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);
    }
}
Also used : ByteBuf(com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf) IOException(java.io.IOException)

Example 3 with PacketDecoder

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;
}
Also used : MqttMessageType(com.swiftmq.impl.mqtt.v311.netty.handler.codec.mqtt.MqttMessageType)

Aggregations

MQTTConnection (com.swiftmq.impl.mqtt.connection.MQTTConnection)1 PacketDecoder (com.swiftmq.impl.mqtt.v311.PacketDecoder)1 ByteBuf (com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf)1 MqttMessageType (com.swiftmq.impl.mqtt.v311.netty.handler.codec.mqtt.MqttMessageType)1 SwiftletException (com.swiftmq.swiftlet.SwiftletException)1 ConnectionVetoException (com.swiftmq.swiftlet.net.ConnectionVetoException)1 IOException (java.io.IOException)1