Search in sources :

Example 1 with MQTTConnection

use of com.swiftmq.impl.mqtt.connection.MQTTConnection 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 MQTTConnection

use of com.swiftmq.impl.mqtt.connection.MQTTConnection in project swiftmq-ce by iitsoftware.

the class MQTTSwiftlet method doDisconnect.

private void doDisconnect(Connection connection) {
    // It may happen during shutdown that the Network Swiftlet calls this method and ctx becomes null
    SwiftletContext myCtx = ctx;
    if (myCtx == null)
        return;
    if (myCtx.traceSpace.enabled)
        myCtx.traceSpace.trace(getName(), "doDisconnect: " + connection);
    MQTTConnection mqttConnection = (MQTTConnection) connection.getUserObject();
    if (mqttConnection != null) {
        myCtx.usageListConnections.removeDynamicEntity(connection);
        mqttConnection.close();
        connections.remove(connection);
        if (shutdownSem != null && connections.size() == 0)
            shutdownSem.notifySingleWaiter();
    }
    if (myCtx.traceSpace.enabled)
        myCtx.traceSpace.trace(getName(), "doDisconnect: " + connection + ", DONE.");
}
Also used : MQTTConnection(com.swiftmq.impl.mqtt.connection.MQTTConnection)

Example 3 with MQTTConnection

use of com.swiftmq.impl.mqtt.connection.MQTTConnection in project swiftmq-ce by iitsoftware.

the class MQTTSwiftlet method performTimeAction.

public void performTimeAction() {
    Connection[] c = (Connection[]) connections.toArray(new Connection[connections.size()]);
    for (int i = 0; i < c.length; i++) {
        MQTTConnection vc = (MQTTConnection) c[i].getUserObject();
        vc.collect(lastCollect);
    }
    lastCollect = System.currentTimeMillis();
}
Also used : MQTTConnection(com.swiftmq.impl.mqtt.connection.MQTTConnection) MQTTConnection(com.swiftmq.impl.mqtt.connection.MQTTConnection) Connection(com.swiftmq.swiftlet.net.Connection)

Example 4 with MQTTConnection

use of com.swiftmq.impl.mqtt.connection.MQTTConnection in project swiftmq-ce by iitsoftware.

the class SessionRegistry method associateSession.

public synchronized void associateSession(String clientId, AssociateSessionCallback callback) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", associateSession, clientId=" + clientId + " ...");
    MQTTConnection connection = callback.getMqttConnection();
    MQTTSession session = sessions.get(clientId);
    if (session == null) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", associateSession, clientId=" + clientId + " no session found, create a new one");
        session = new MQTTSession(ctx, clientId, true);
        sessions.put(clientId, session);
        createUsage(clientId, session);
        session.associate(connection);
        callback.associated(session);
    } else if (session.getMqttConnection() != null) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", associateSession, clientId=" + clientId + " session found, associated with another connection, initiate close");
        session.setWasPresent(true);
        callbacks.put(clientId, callback);
        ctx.networkSwiftlet.getConnectionManager().removeConnection(session.getMqttConnection().getConnection());
    } else {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", associateSession, clientId=" + clientId + " session found, not associated with another connection, invoke callback");
        session.setWasPresent(true);
        session.associate(connection);
        callback.associated(session);
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", associateSession, clientId=" + clientId + " done");
}
Also used : MQTTConnection(com.swiftmq.impl.mqtt.connection.MQTTConnection)

Aggregations

MQTTConnection (com.swiftmq.impl.mqtt.connection.MQTTConnection)4 PacketDecoder (com.swiftmq.impl.mqtt.v311.PacketDecoder)1 SwiftletException (com.swiftmq.swiftlet.SwiftletException)1 Connection (com.swiftmq.swiftlet.net.Connection)1 ConnectionVetoException (com.swiftmq.swiftlet.net.ConnectionVetoException)1