1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-27 22:42:06 +01:00
This commit is contained in:
vanitasvitae 2017-06-23 23:41:40 +02:00
parent 136af25342
commit c4ef2c9552
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
6 changed files with 19 additions and 30 deletions

View file

@ -42,7 +42,7 @@ import org.jxmpp.jid.FullJid;
public class IncomingJingleFileOffer extends JingleFileTransferSession implements IncomingFileOfferCallback { public class IncomingJingleFileOffer extends JingleFileTransferSession implements IncomingFileOfferCallback {
private static final Logger LOGGER = Logger.getLogger(IncomingJingleFileOffer.class.getName()); private static final Logger LOGGER = Logger.getLogger(IncomingJingleFileOffer.class.getName());
private Jingle pendingSessionInitiate = null; private Jingle pendingSessionInitiate = null;
private ReceivingThread receivingThread; private ReceiveTask receivingThread;
public enum State { public enum State {
fresh, fresh,
@ -143,8 +143,8 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement
transportSession.initiateIncomingSession(new JingleTransportInitiationCallback() { transportSession.initiateIncomingSession(new JingleTransportInitiationCallback() {
@Override @Override
public void onSessionInitiated(BytestreamSession bytestreamSession) { public void onSessionInitiated(BytestreamSession bytestreamSession) {
receivingThread = new ReceivingThread(bytestreamSession, file, target); receivingThread = new ReceiveTask(bytestreamSession, file, target);
receivingThread.start(); queued.add(threadPool.submit(receivingThread));
} }
@Override @Override

View file

@ -51,7 +51,7 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
terminated terminated
} }
private Thread sendingThread; private Runnable sendingThread;
private File source; private File source;
private State state; private State state;
@ -110,8 +110,8 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
@Override @Override
public void onSessionInitiated(final BytestreamSession session) { public void onSessionInitiated(final BytestreamSession session) {
LOGGER.log(Level.INFO, "BytestreamSession initiated. Start transfer."); LOGGER.log(Level.INFO, "BytestreamSession initiated. Start transfer.");
sendingThread = new SendingThread(session, source); sendingThread = new SendTask(session, source);
sendingThread.start(); queued.add(threadPool.submit(sendingThread));
} }
@Override @Override
@ -129,11 +129,6 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
public IQ handleSessionTerminate(Jingle sessionTerminate) { public IQ handleSessionTerminate(Jingle sessionTerminate) {
LOGGER.log(Level.INFO, "Received session-terminate: " + sessionTerminate.getReason().asEnum()); LOGGER.log(Level.INFO, "Received session-terminate: " + sessionTerminate.getReason().asEnum());
if (sendingThread != null && !sendingThread.isInterrupted()) {
LOGGER.log(Level.INFO, "Interrupt sending thread.");
sendingThread.interrupt();
}
state = State.terminated; state = State.terminated;
return jutil.createAck(sessionTerminate); return jutil.createAck(sessionTerminate);
} }

View file

@ -30,14 +30,14 @@ import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChi
/** /**
* Thread for receiving data. * Thread for receiving data.
*/ */
public class ReceivingThread extends Thread { public class ReceiveTask implements Runnable {
private static final Logger LOGGER = Logger.getLogger(ReceivingThread.class.getName()); private static final Logger LOGGER = Logger.getLogger(ReceiveTask.class.getName());
private final BytestreamSession session; private final BytestreamSession session;
private final JingleFileTransfer fileTransfer; private final JingleFileTransfer fileTransfer;
private final File target; private final File target;
public ReceivingThread(BytestreamSession session, JingleFileTransfer fileTransfer, File target) { public ReceiveTask(BytestreamSession session, JingleFileTransfer fileTransfer, File target) {
this.session = session; this.session = session;
this.fileTransfer = fileTransfer; this.fileTransfer = fileTransfer;
this.target = target; this.target = target;

View file

@ -29,13 +29,13 @@ import org.jivesoftware.smackx.bytestreams.BytestreamSession;
/** /**
* Created by vanitas on 21.06.17. * Created by vanitas on 21.06.17.
*/ */
public class SendingThread extends Thread { public class SendTask implements Runnable {
private static final Logger LOGGER = Logger.getLogger(SendingThread.class.getName()); private static final Logger LOGGER = Logger.getLogger(SendTask.class.getName());
private final BytestreamSession session; private final BytestreamSession session;
private final File source; private final File source;
public SendingThread(BytestreamSession session, File source) { public SendTask(BytestreamSession session, File source) {
this.session = session; this.session = session;
this.source = source; this.source = source;
} }
@ -69,14 +69,4 @@ public class SendingThread extends Thread {
} }
} }
} }
@Override
public void interrupt() {
try {
session.close();
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Could not close session.", e);
}
super.interrupt();
}
} }

View file

@ -34,7 +34,6 @@ import org.jivesoftware.smackx.jingle.element.JingleAction;
import org.jivesoftware.smackx.jingle.element.JingleContent; import org.jivesoftware.smackx.jingle.element.JingleContent;
import org.jivesoftware.smackx.jingle.element.JingleContentDescription; import org.jivesoftware.smackx.jingle.element.JingleContentDescription;
import org.jivesoftware.smackx.jingle.transports.jingle_ibb.JingleIBBTransportManager; import org.jivesoftware.smackx.jingle.transports.jingle_ibb.JingleIBBTransportManager;
import org.jivesoftware.smackx.jingle.transports.jingle_s5b.JingleS5BTransportManager;
import org.jxmpp.jid.FullJid; import org.jxmpp.jid.FullJid;
@ -103,7 +102,7 @@ public final class JingleManager extends Manager {
//Register transports. //Register transports.
JingleTransportMethodManager transportMethodManager = JingleTransportMethodManager.getInstanceFor(connection); JingleTransportMethodManager transportMethodManager = JingleTransportMethodManager.getInstanceFor(connection);
transportMethodManager.registerTransportManager(JingleIBBTransportManager.getInstanceFor(connection)); transportMethodManager.registerTransportManager(JingleIBBTransportManager.getInstanceFor(connection));
transportMethodManager.registerTransportManager(JingleS5BTransportManager.getInstanceFor(connection)); //transportMethodManager.registerTransportManager(JingleS5BTransportManager.getInstanceFor(connection));
} }
public JingleHandler registerDescriptionHandler(String namespace, JingleHandler handler) { public JingleHandler registerDescriptionHandler(String namespace, JingleHandler handler) {

View file

@ -16,6 +16,9 @@
*/ */
package org.jivesoftware.smackx.jingle.transports.jingle_ibb; package org.jivesoftware.smackx.jingle.transports.jingle_ibb;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
@ -31,6 +34,7 @@ import org.jivesoftware.smackx.jingle.transports.JingleTransportSession;
import org.jivesoftware.smackx.jingle.transports.jingle_ibb.element.JingleIBBTransport; import org.jivesoftware.smackx.jingle.transports.jingle_ibb.element.JingleIBBTransport;
public class JingleIBBTransportSession extends JingleTransportSession<JingleIBBTransport> { public class JingleIBBTransportSession extends JingleTransportSession<JingleIBBTransport> {
private static final Logger LOGGER = Logger.getLogger(JingleIBBTransportSession.class.getName());
private final JingleIBBTransportManager transportManager; private final JingleIBBTransportManager transportManager;
@ -53,6 +57,7 @@ public class JingleIBBTransportSession extends JingleTransportSession<JingleIBBT
@Override @Override
public void initiateOutgoingSession(JingleTransportInitiationCallback callback) { public void initiateOutgoingSession(JingleTransportInitiationCallback callback) {
LOGGER.log(Level.INFO, "Initiate Jingle InBandBytestream session.");
if (jingleSession.get() == null) { if (jingleSession.get() == null) {
callback.onException(new NullPointerException("Lost reference to JingleSession.")); callback.onException(new NullPointerException("Lost reference to JingleSession."));
return; return;
@ -72,7 +77,7 @@ public class JingleIBBTransportSession extends JingleTransportSession<JingleIBBT
@Override @Override
public void initiateIncomingSession(final JingleTransportInitiationCallback callback) { public void initiateIncomingSession(final JingleTransportInitiationCallback callback) {
LOGGER.log(Level.INFO, "Await Jingle InBandBytestream session.");
if (jingleSession.get() == null) { if (jingleSession.get() == null) {
callback.onException(new NullPointerException("Lost reference to JingleSession.")); callback.onException(new NullPointerException("Lost reference to JingleSession."));
} }