mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-11 01:59:38 +02:00
IBB sending works using worker thread
This commit is contained in:
parent
5dc37ab239
commit
cb3583e510
9 changed files with 149 additions and 52 deletions
|
@ -19,6 +19,7 @@ package org.jivesoftware.smackx.jingle;
|
|||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.Manager;
|
||||
|
@ -33,7 +34,6 @@ import org.jivesoftware.smackx.jingle.element.JingleAction;
|
|||
import org.jivesoftware.smackx.jingle.element.JingleContent;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescription;
|
||||
import org.jivesoftware.smackx.jingle.transports.jingle_ibb.JingleIBBTransportManager;
|
||||
import org.jivesoftware.smackx.jingle.transports.jingle_s5b.JingleS5BTransportManager;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
|
||||
|
@ -88,19 +88,21 @@ public final class JingleManager extends Manager {
|
|||
|
||||
if (jingleDescriptionHandler == null) {
|
||||
//Unsupported Application
|
||||
LOGGER.log(Level.WARNING, "Unsupported Jingle application.");
|
||||
return jutil.createSessionTerminateUnsupportedApplications(fullFrom, sid);
|
||||
}
|
||||
return jingleDescriptionHandler.handleJingleRequest(jingle);
|
||||
}
|
||||
|
||||
//Unknown session
|
||||
LOGGER.log(Level.WARNING, "Unknown session.");
|
||||
return jutil.createErrorUnknownSession(jingle);
|
||||
}
|
||||
});
|
||||
//Register transports.
|
||||
JingleTransportMethodManager transportMethodManager = JingleTransportMethodManager.getInstanceFor(connection);
|
||||
transportMethodManager.registerTransportManager(JingleIBBTransportManager.getInstanceFor(connection));
|
||||
transportMethodManager.registerTransportManager(JingleS5BTransportManager.getInstanceFor(connection));
|
||||
//transportMethodManager.registerTransportManager(JingleS5BTransportManager.getInstanceFor(connection));
|
||||
}
|
||||
|
||||
public JingleHandler registerDescriptionHandler(String namespace, JingleHandler handler) {
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.jingle;
|
||||
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
|
@ -24,6 +28,7 @@ import org.jivesoftware.smackx.jingle.element.Jingle;
|
|||
import org.jxmpp.jid.FullJid;
|
||||
|
||||
public abstract class JingleSession implements JingleSessionHandler {
|
||||
private static final Logger LOGGER = Logger.getLogger(JingleSession.class.getName());
|
||||
|
||||
protected final FullJid local;
|
||||
|
||||
|
@ -33,6 +38,39 @@ public abstract class JingleSession implements JingleSessionHandler {
|
|||
|
||||
protected final String sid;
|
||||
|
||||
protected final ConcurrentLinkedQueue<Runnable> tasks = new ConcurrentLinkedQueue<Runnable>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public boolean add(Runnable runnable) {
|
||||
synchronized (tasks) {
|
||||
LOGGER.log(Level.INFO, "Add task.");
|
||||
boolean b = super.add(runnable);
|
||||
tasks.notify();
|
||||
return b;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final Thread worker = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (tasks) {
|
||||
while (true) {
|
||||
try {
|
||||
tasks.wait();
|
||||
while (!tasks.isEmpty()) {
|
||||
LOGGER.log(Level.INFO, "Run task.");
|
||||
tasks.poll().run();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.log(Level.WARNING, "Interrupted.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public JingleSession(FullJid initiator, FullJid responder, Role role, String sid) {
|
||||
if (role == Role.initiator) {
|
||||
this.local = initiator;
|
||||
|
@ -43,6 +81,7 @@ public abstract class JingleSession implements JingleSessionHandler {
|
|||
}
|
||||
this.sid = sid;
|
||||
this.role = role;
|
||||
worker.start();
|
||||
}
|
||||
|
||||
public FullJid getInitiator() {
|
||||
|
|
|
@ -105,7 +105,7 @@ public class JingleUtil {
|
|||
Jingle jingle = createSessionInitiate(recipient, sessionId, contentCreator, contentName, contentSenders,
|
||||
description, transport);
|
||||
|
||||
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
|
||||
return connection.createStanzaCollectorAndSend(jingle).nextResult();
|
||||
}
|
||||
|
||||
public Jingle createSessionAccept(FullJid recipient,
|
||||
|
@ -148,7 +148,7 @@ public class JingleUtil {
|
|||
Jingle jingle = createSessionAccept(recipient, sessionId, contentCreator, contentName, contentSenders,
|
||||
description, transport);
|
||||
|
||||
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
|
||||
return connection.createStanzaCollectorAndSend(jingle).nextResult();
|
||||
}
|
||||
|
||||
public Jingle createSessionTerminate(FullJid recipient, String sessionId, JingleReason reason) {
|
||||
|
|
|
@ -122,6 +122,10 @@ public final class Jingle extends IQ {
|
|||
return action;
|
||||
}
|
||||
|
||||
public JingleReason getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a List of the contents.
|
||||
*
|
||||
|
|
|
@ -124,6 +124,10 @@ public class JingleReason implements NamedElement {
|
|||
return xml;
|
||||
}
|
||||
|
||||
public Reason asEnum() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
|
||||
public static class AlternativeSession extends JingleReason {
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue