mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-11 10:09:38 +02:00
Use static threadPool and start working on async file transfer method
This commit is contained in:
parent
71486ab68e
commit
f26f3bb503
7 changed files with 65 additions and 6 deletions
|
@ -25,6 +25,7 @@ import org.jivesoftware.smack.XMPPConnection;
|
|||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||
import org.jivesoftware.smackx.jingle.JingleTransportMethodManager;
|
||||
import org.jivesoftware.smackx.jingle.Role;
|
||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||
|
@ -162,7 +163,7 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement
|
|||
public void onSessionInitiated(BytestreamSession bytestreamSession) {
|
||||
LOGGER.log(Level.INFO, "Bytestream initiated. Start receiving.");
|
||||
receivingThread = new ReceiveTask(bytestreamSession, file, target);
|
||||
queued.add(threadPool.submit(receivingThread));
|
||||
queued.add(JingleManager.getThreadPool().submit(receivingThread));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.util.logging.Logger;
|
|||
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.SmackFuture;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
|
@ -82,6 +83,12 @@ public final class JingleFileTransferManager extends Manager implements JingleHa
|
|||
offer.send(file);
|
||||
}
|
||||
|
||||
public SmackFuture<?> asyncSendFile(FullJid recipient, File file) {
|
||||
OutgoingJingleFileOffer offer = new OutgoingJingleFileOffer(connection(), recipient);
|
||||
JingleManager.getInstanceFor(connection()).registerJingleSessionHandler(recipient, offer.getSessionId(), offer);
|
||||
return offer.sendAsync(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQ handleJingleRequest(Jingle jingle) {
|
||||
FullJid fullJid = jingle.getFrom().asFullJidOrThrow();
|
||||
|
|
|
@ -21,9 +21,11 @@ import java.util.logging.Level;
|
|||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.SmackFuture;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||
import org.jivesoftware.smackx.jingle.JingleTransportMethodManager;
|
||||
|
@ -75,6 +77,13 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
|
|||
initiateFileOffer(transfer, JingleContent.Creator.initiator, contentName);
|
||||
}
|
||||
|
||||
public SmackFuture<?> sendAsync(File file) {
|
||||
source = file;
|
||||
String contentName = "jft-" + StringUtils.randomString(20);
|
||||
JingleFileTransfer transfer = JingleFileTransferManager.fileTransferFromFile(file);
|
||||
return null; //TODO
|
||||
}
|
||||
|
||||
public void initiateFileOffer(JingleFileTransfer file, JingleContent.Creator creator, String name) throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException {
|
||||
if (state != State.fresh) {
|
||||
throw new IllegalStateException("This session is not fresh.");
|
||||
|
@ -113,7 +122,7 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
|
|||
@Override
|
||||
public void onSessionInitiated(final BytestreamSession session) {
|
||||
sendingThread = new SendTask(session, source);
|
||||
queued.add(threadPool.submit(sendingThread));
|
||||
queued.add(JingleManager.getThreadPool().submit(sendingThread));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -138,7 +147,7 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
|
|||
final JingleTransportManager<?> replacementManager = JingleTransportMethodManager.getInstanceFor(connection)
|
||||
.getTransportManager(transportReplace);
|
||||
|
||||
queued.add(threadPool.submit(new Runnable() {
|
||||
queued.add(JingleManager.getThreadPool().submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue