Add simple connection management capabilities to the broker. An external codebase will now be able to monitor and close the opened connections.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package io.moquette.connections;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* This interface will be used by an external codebase to retrieve and close
|
||||
* physical connections.
|
||||
*
|
||||
* @author lbarrios
|
||||
*
|
||||
*/
|
||||
public interface IConnectionsManager {
|
||||
/**
|
||||
* Returns the number of physical connections
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getActiveConnectionsNo();
|
||||
|
||||
/**
|
||||
* Determines wether a MQTT client is connected to the broker.
|
||||
*
|
||||
* @param clientID
|
||||
* @return
|
||||
*/
|
||||
public boolean isConnected(String clientID);
|
||||
|
||||
/**
|
||||
* Returns the identifiers of the MQTT clients that are connected to the
|
||||
* broker.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Collection<String> getConnectedClientIds();
|
||||
|
||||
/**
|
||||
* Closes a physical connection.
|
||||
*
|
||||
* @param clientID
|
||||
* @param closeImmediately
|
||||
* If false, the connection will be flushed before it is closed.
|
||||
* @return
|
||||
*/
|
||||
public boolean closeConnection(String clientID, boolean closeImmediately);
|
||||
|
||||
/**
|
||||
* Returns the state of the session of a given client.
|
||||
* @param clientID
|
||||
* @return
|
||||
*/
|
||||
public MqttSession getSessionStatus(String clientID);
|
||||
|
||||
/**
|
||||
* Returns the state of all the sessions
|
||||
* @return
|
||||
*/
|
||||
public Collection<MqttSession> getSessions();
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package io.moquette.connections;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* A class that represents the overall connection status of a MQTT session. Its
|
||||
* instances will be used by an external codebase when the broker is configured
|
||||
* in embedded mode.
|
||||
*
|
||||
* @author lbarrios
|
||||
*
|
||||
*/
|
||||
public class MqttSession {
|
||||
|
||||
private boolean connectionEstablished;
|
||||
private boolean cleanSession;
|
||||
private int inflightMessages;
|
||||
private int pendingPublishMessagesNo;
|
||||
private int secondPhaseAckPendingMessages;
|
||||
private Collection<MqttSubscription> activeSubscriptions;
|
||||
|
||||
public boolean isConnectionEstablished() {
|
||||
return connectionEstablished;
|
||||
}
|
||||
|
||||
public void setConnectionEstablished(boolean connectionEstablished) {
|
||||
this.connectionEstablished = connectionEstablished;
|
||||
}
|
||||
|
||||
public boolean isCleanSession() {
|
||||
return cleanSession;
|
||||
}
|
||||
|
||||
public void setCleanSession(boolean cleanSession) {
|
||||
this.cleanSession = cleanSession;
|
||||
}
|
||||
|
||||
public int getPendingPublishMessagesNo() {
|
||||
return pendingPublishMessagesNo;
|
||||
}
|
||||
|
||||
public void setPendingPublishMessagesNo(int pendingPublishMessagesNo) {
|
||||
this.pendingPublishMessagesNo = pendingPublishMessagesNo;
|
||||
}
|
||||
|
||||
public int getInflightMessages() {
|
||||
return inflightMessages;
|
||||
}
|
||||
|
||||
public void setInflightMessages(int inflightMessages) {
|
||||
this.inflightMessages = inflightMessages;
|
||||
}
|
||||
|
||||
public int getSecondPhaseAckPendingMessages() {
|
||||
return secondPhaseAckPendingMessages;
|
||||
}
|
||||
|
||||
public void setSecondPhaseAckPendingMessages(int secondPhaseAckPendingMessages) {
|
||||
this.secondPhaseAckPendingMessages = secondPhaseAckPendingMessages;
|
||||
}
|
||||
|
||||
public Collection<MqttSubscription> getActiveSubscriptions() {
|
||||
return activeSubscriptions;
|
||||
}
|
||||
|
||||
public void setActiveSubscriptions(Collection<MqttSubscription> activeSubscriptions) {
|
||||
this.activeSubscriptions = activeSubscriptions;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package io.moquette.connections;
|
||||
|
||||
/**
|
||||
* A class that represents a MQTT subscription.
|
||||
*
|
||||
* @author lbarrios
|
||||
*
|
||||
*/
|
||||
public class MqttSubscription {
|
||||
private final String requestedQos;
|
||||
private final String clientId;
|
||||
private final String topicFilter;
|
||||
private final boolean active;
|
||||
|
||||
public MqttSubscription(String requestedQos, String clientId, String topicFilter, boolean active) {
|
||||
this.requestedQos = requestedQos;
|
||||
this.clientId = clientId;
|
||||
this.topicFilter = topicFilter;
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public String getRequestedQos() {
|
||||
return requestedQos;
|
||||
}
|
||||
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public String getTopicFilter() {
|
||||
return topicFilter;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user