mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-12-22 20:47:57 +01:00
Make StreamNegotiator weakly reference XMPPConnection
by extending Manager. Because FileTransferNegotiator will hold a strong reference to the StreamNegotiators, which will eventually prevent XMPPConnection from being GC'ed if no weak references in StreamNegotiator are used. Thanks to Werner Glanzer for pointing this out.
This commit is contained in:
parent
a592a12229
commit
0a6843f41f
4 changed files with 13 additions and 13 deletions
|
@ -40,13 +40,12 @@ public class FaultTolerantNegotiator extends StreamNegotiator {
|
|||
|
||||
private final StreamNegotiator primaryNegotiator;
|
||||
private final StreamNegotiator secondaryNegotiator;
|
||||
private final XMPPConnection connection;
|
||||
|
||||
public FaultTolerantNegotiator(XMPPConnection connection, StreamNegotiator primary,
|
||||
StreamNegotiator secondary) {
|
||||
super(connection);
|
||||
this.primaryNegotiator = primary;
|
||||
this.secondaryNegotiator = secondary;
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -64,7 +63,7 @@ public class FaultTolerantNegotiator extends StreamNegotiator {
|
|||
@Override
|
||||
public InputStream createIncomingStream(final StreamInitiation initiation) throws SmackException, XMPPErrorException, InterruptedException {
|
||||
// This could be either an xep47 ibb 'open' iq or an xep65 streamhost iq
|
||||
IQ initationSet = initiateIncomingStream(connection, initiation);
|
||||
IQ initationSet = initiateIncomingStream(connection(), initiation);
|
||||
|
||||
StreamNegotiator streamNegotiator = determineNegotiator(initationSet);
|
||||
|
||||
|
|
|
@ -44,8 +44,6 @@ import org.jxmpp.jid.Jid;
|
|||
*/
|
||||
public class IBBTransferNegotiator extends StreamNegotiator {
|
||||
|
||||
private XMPPConnection connection;
|
||||
|
||||
private InBandBytestreamManager manager;
|
||||
|
||||
/**
|
||||
|
@ -54,7 +52,7 @@ public class IBBTransferNegotiator extends StreamNegotiator {
|
|||
* @param connection The connection which this negotiator works on.
|
||||
*/
|
||||
protected IBBTransferNegotiator(XMPPConnection connection) {
|
||||
this.connection = connection;
|
||||
super(connection);
|
||||
this.manager = InBandBytestreamManager.getByteStreamManager(connection);
|
||||
}
|
||||
|
||||
|
@ -75,7 +73,7 @@ public class IBBTransferNegotiator extends StreamNegotiator {
|
|||
*/
|
||||
this.manager.ignoreBytestreamRequestOnce(initiation.getSessionID());
|
||||
|
||||
Stanza streamInitiation = initiateIncomingStream(this.connection, initiation);
|
||||
Stanza streamInitiation = initiateIncomingStream(connection(), initiation);
|
||||
return negotiateIncomingStream(streamInitiation);
|
||||
}
|
||||
|
||||
|
|
|
@ -43,13 +43,11 @@ import org.jxmpp.jid.Jid;
|
|||
*/
|
||||
public class Socks5TransferNegotiator extends StreamNegotiator {
|
||||
|
||||
private XMPPConnection connection;
|
||||
|
||||
private Socks5BytestreamManager manager;
|
||||
|
||||
Socks5TransferNegotiator(XMPPConnection connection) {
|
||||
this.connection = connection;
|
||||
this.manager = Socks5BytestreamManager.getBytestreamManager(this.connection);
|
||||
super(connection);
|
||||
this.manager = Socks5BytestreamManager.getBytestreamManager(connection);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -75,7 +73,7 @@ public class Socks5TransferNegotiator extends StreamNegotiator {
|
|||
*/
|
||||
this.manager.ignoreBytestreamRequestOnce(initiation.getSessionID());
|
||||
|
||||
Stanza streamInitiation = initiateIncomingStream(this.connection, initiation);
|
||||
Stanza streamInitiation = initiateIncomingStream(connection(), initiation);
|
||||
return negotiateIncomingStream(streamInitiation);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.filetransfer;
|
||||
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
|
@ -42,7 +43,11 @@ import java.io.OutputStream;
|
|||
*
|
||||
* @author Alexander Wenckus
|
||||
*/
|
||||
public abstract class StreamNegotiator {
|
||||
public abstract class StreamNegotiator extends Manager {
|
||||
|
||||
protected StreamNegotiator(XMPPConnection connection) {
|
||||
super(connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* A event manager for stream initiation requests send to us.
|
||||
|
|
Loading…
Reference in a new issue