Skip to content

Commit

Permalink
squash: One thread pool and xmpp and xmppSend queues per instance.
Browse files Browse the repository at this point in the history
  • Loading branch information
damencho committed Oct 31, 2024
1 parent 15523bf commit ba1d89d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
34 changes: 31 additions & 3 deletions src/main/java/org/jitsi/jigasi/JvbConference.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.concurrent.*;

import static net.java.sip.communicator.service.protocol.event.LocalUserChatRoomPresenceChangeEvent.*;
import static org.jivesoftware.smack.packet.StanzaError.Condition.*;
Expand Down Expand Up @@ -185,6 +186,8 @@ public class JvbConference
*/
private String meetingId;

private static ExecutorService threadPool = Util.createNewThreadPool("xmpp-executor-pool");

/**
* A queue used to offload xmpp execution in a new thread to avoid blocking xmpp threads,
* by executing the tasks in new thread
Expand All @@ -208,7 +211,32 @@ public class JvbConference
return false;
}
},
Util.createNewThreadPool("xmpp-executor-pool")
threadPool
);

/**
* A queue used for sending xmpp messages.
*/
public final PacketQueue<Runnable> xmppSendQueue = new PacketQueue<>(
Integer.MAX_VALUE,
false,
"xmpp-send-queue",
r -> {
// do process and try
try
{
r.run();

return true;
}
catch (Throwable e)
{
logger.error("Error processing xmpp queue item", e);

return false;
}
},
threadPool
);

/**
Expand Down Expand Up @@ -2306,7 +2334,7 @@ private void processVisitorsJson(String json)
*/
public void sendMessageToRoom(String messageString)
{
xmppInvokeQueue.add(() -> sendMessageToRoomInternal(messageString));
xmppSendQueue.add(() -> sendMessageToRoomInternal(messageString));
}

public void sendMessageToRoomInternal(String messageString)
Expand Down Expand Up @@ -2338,7 +2366,7 @@ public void sendMessageToRoomInternal(String messageString)
*/
public void sendJsonMessage(JSONObject jsonMessage)
{
xmppInvokeQueue.add(() -> sendJsonMessageInternal(jsonMessage));
xmppSendQueue.add(() -> sendJsonMessageInternal(jsonMessage));
}

private void sendJsonMessageInternal(JSONObject jsonMessage)
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jitsi/jigasi/lobby/Lobby.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ protected void leaveRoom()
@Override
public void invitationReceived(ChatRoomInvitationReceivedEvent evt)
{
JvbConference.xmppInvokeQueue.add(() -> invitationReceivedInternal(evt));
this.jvbConference.xmppInvokeQueue.add(() -> invitationReceivedInternal(evt));
}

private void invitationReceivedInternal(ChatRoomInvitationReceivedEvent chatRoomInvitationReceivedEvent)
Expand Down Expand Up @@ -255,7 +255,7 @@ private void notifyAccessGranted()
@Override
public void localUserPresenceChanged(LocalUserChatRoomPresenceChangeEvent evt)
{
JvbConference.xmppInvokeQueue.add(() -> localUserPresenceChangedInternal(evt));
this.jvbConference.xmppInvokeQueue.add(() -> localUserPresenceChangedInternal(evt));
}

private void localUserPresenceChangedInternal(LocalUserChatRoomPresenceChangeEvent evt)
Expand Down

0 comments on commit ba1d89d

Please sign in to comment.