21
21
import net .java .sip .communicator .service .protocol .*;
22
22
import net .java .sip .communicator .service .protocol .Message ;
23
23
import org .jitsi .jigasi .*;
24
+ import org .jitsi .jigasi .util .Util ;
24
25
import org .jitsi .service .libjitsi .*;
25
26
import org .jitsi .service .neomedia .*;
26
27
import org .jitsi .service .neomedia .device .*;
27
28
import org .jitsi .service .neomedia .recording .*;
28
29
import org .jitsi .utils .logging .*;
30
+ import org .jitsi .utils .queue .*;
29
31
30
32
import java .io .*;
31
33
import java .nio .charset .*;
@@ -157,14 +159,29 @@ public abstract class AbstractTranscriptPublisher<T>
157
159
= Logger .getLogger (AbstractTranscriptPublisher .class );
158
160
159
161
/**
160
- * Aspect for successful upload of transcript
162
+ * A queue used to offload xmpp message sending in a new thread to avoid blocking.
161
163
*/
162
- private static final String DD_ASPECT_SUCCESS = "upload_success" ;
164
+ private static final PacketQueue <Runnable > xmppInvokeQueue = new PacketQueue <>(
165
+ Integer .MAX_VALUE ,
166
+ false ,
167
+ "xmpp-transcript-publisher" ,
168
+ r -> {
169
+ // do process and try
170
+ try
171
+ {
172
+ r .run ();
163
173
164
- /**
165
- * Aspect for failed upload of transcript
166
- */
167
- private static final String DD_ASPECT_FAIL = "upload_fail" ;
174
+ return true ;
175
+ }
176
+ catch (Throwable e )
177
+ {
178
+ logger .error ("Error processing xmpp queue item" , e );
179
+
180
+ return false ;
181
+ }
182
+ },
183
+ Util .createNewThreadPool ("transcript-publisher-executor-pool" )
184
+ );
168
185
169
186
/**
170
187
* Get a string which contains a time stamp and a random UUID, with an
@@ -194,13 +211,27 @@ protected static String generateHardToGuessTimeString(String prefix,
194
211
* @param message the message to send
195
212
*/
196
213
protected void sendMessage (ChatRoom chatRoom , T message )
214
+ {
215
+ xmppInvokeQueue .add (() -> sendMessageInternal (chatRoom , message ));
216
+ }
217
+
218
+ private void sendMessageInternal (ChatRoom chatRoom , T message )
197
219
{
198
220
if (chatRoom == null )
199
221
{
200
222
logger .error ("Cannot send message as chatRoom is null" );
201
223
return ;
202
224
}
203
225
226
+ if (!chatRoom .isJoined ())
227
+ {
228
+ if (logger .isDebugEnabled ())
229
+ {
230
+ logger .debug ("Skip sending message to room which we left!" );
231
+ }
232
+ return ;
233
+ }
234
+
204
235
String messageString = message .toString ();
205
236
Message chatRoomMessage = chatRoom .createMessage (messageString );
206
237
try
@@ -222,6 +253,11 @@ protected void sendMessage(ChatRoom chatRoom, T message)
222
253
* @param jsonMessage the json message to send
223
254
*/
224
255
protected void sendJsonMessage (ChatRoom chatRoom , T jsonMessage )
256
+ {
257
+ xmppInvokeQueue .add (() -> sendJsonMessageInternal (chatRoom , jsonMessage ));
258
+ }
259
+
260
+ private void sendJsonMessageInternal (ChatRoom chatRoom , T jsonMessage )
225
261
{
226
262
if (chatRoom == null )
227
263
{
0 commit comments