重构
This commit is contained in:
@@ -37,11 +37,11 @@ public class ServerAPIHelper {
|
||||
Executor getResponseExecutor();
|
||||
}
|
||||
|
||||
public static void sendRequest(String fromUser, String clientId, String request, byte[] message, String target, TargetEntry.Type type, Callback callback, boolean isAdmin) {
|
||||
sendRequest(fromUser, clientId, request, message, target, type, callback, isAdmin, false);
|
||||
public static void sendRequest(String fromUser, String clientId, String request, byte[] message, Callback callback, boolean isAdmin) {
|
||||
sendRequest(fromUser, clientId, request, message, callback, isAdmin, false);
|
||||
}
|
||||
|
||||
public static void sendRequest(String fromUser, String clientId, String request, byte[] message, String target, TargetEntry.Type type, Callback callback, boolean isAdmin, boolean isRobotOrChannel) {
|
||||
public static void sendRequest(String fromUser, String clientId, String request, byte[] message, Callback callback, boolean isAdmin, boolean isRobotOrChannel) {
|
||||
int requestId = 0;
|
||||
|
||||
if (callback != null) {
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <[email protected]>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package io.moquette.persistence;
|
||||
|
||||
public class TargetEntry {
|
||||
public TargetEntry(Type type, String target) {
|
||||
this.type = type;
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
TARGET_TYPE_USER,
|
||||
TARGET_TYPE_CHATROOM,
|
||||
TARGET_TYPE_MASTER_NODE,
|
||||
}
|
||||
public Type type;
|
||||
public String target;
|
||||
}
|
||||
@@ -27,7 +27,6 @@ import io.moquette.persistence.ServerAPIHelper;
|
||||
import io.moquette.interception.InterceptHandler;
|
||||
import io.moquette.interception.messages.InterceptAcknowledgedMessage;
|
||||
import io.moquette.persistence.MemorySessionStore;
|
||||
import io.moquette.persistence.TargetEntry;
|
||||
import io.moquette.server.ConnectionDescriptor;
|
||||
import io.moquette.server.ConnectionDescriptorStore;
|
||||
import io.moquette.server.Server;
|
||||
@@ -98,10 +97,9 @@ public class ProtocolProcessor {
|
||||
});
|
||||
}
|
||||
|
||||
private void handleTargetRemovedFromCurrentNode(TargetEntry target) {
|
||||
System.out.println("kickof user " + target);
|
||||
if (target.type == TargetEntry.Type.TARGET_TYPE_USER) {
|
||||
Collection<MemorySessionStore.Session> sessions = m_sessionsStore.sessionForUser(target.target);
|
||||
private void kickoffUserOffline(String userId) {
|
||||
System.out.println("kickoff user " + userId);
|
||||
Collection<MemorySessionStore.Session> sessions = m_sessionsStore.sessionForUser(userId);
|
||||
for (MemorySessionStore.Session session : sessions) {
|
||||
ConnectionDescriptor descriptor = connectionDescriptors.getConnection(session.getClientID());
|
||||
try {
|
||||
@@ -113,9 +111,6 @@ public class ProtocolProcessor {
|
||||
Utility.printExecption(LOG, e);
|
||||
}
|
||||
}
|
||||
} else if(target.type == TargetEntry.Type.TARGET_TYPE_CHATROOM) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -704,7 +699,7 @@ public class ProtocolProcessor {
|
||||
public void onApiMessage(String fromUser, String clientId, byte[] message, int messageId, String from, String request, boolean isAdmin, boolean isRobotOrChannel) {
|
||||
if(request.equals(ServerAPIHelper.KICKOFF_USER_REQUEST)) {
|
||||
String userId = new String(message);
|
||||
mServer.getImBusinessScheduler().execute(()->handleTargetRemovedFromCurrentNode(new TargetEntry(TargetEntry.Type.TARGET_TYPE_USER, userId)));
|
||||
mServer.getImBusinessScheduler().execute(()-> kickoffUserOffline(userId));
|
||||
return;
|
||||
}
|
||||
qos1PublishHandler.onApiMessage(fromUser, clientId, message, messageId, from, request, isAdmin, isRobotOrChannel);
|
||||
|
||||
Reference in New Issue
Block a user