mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-22 12:02:05 +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 primaryNegotiator;
|
||||||
private final StreamNegotiator secondaryNegotiator;
|
private final StreamNegotiator secondaryNegotiator;
|
||||||
private final XMPPConnection connection;
|
|
||||||
|
|
||||||
public FaultTolerantNegotiator(XMPPConnection connection, StreamNegotiator primary,
|
public FaultTolerantNegotiator(XMPPConnection connection, StreamNegotiator primary,
|
||||||
StreamNegotiator secondary) {
|
StreamNegotiator secondary) {
|
||||||
|
super(connection);
|
||||||
this.primaryNegotiator = primary;
|
this.primaryNegotiator = primary;
|
||||||
this.secondaryNegotiator = secondary;
|
this.secondaryNegotiator = secondary;
|
||||||
this.connection = connection;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -64,7 +63,7 @@ public class FaultTolerantNegotiator extends StreamNegotiator {
|
||||||
@Override
|
@Override
|
||||||
public InputStream createIncomingStream(final StreamInitiation initiation) throws SmackException, XMPPErrorException, InterruptedException {
|
public InputStream createIncomingStream(final StreamInitiation initiation) throws SmackException, XMPPErrorException, InterruptedException {
|
||||||
// This could be either an xep47 ibb 'open' iq or an xep65 streamhost iq
|
// 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);
|
StreamNegotiator streamNegotiator = determineNegotiator(initationSet);
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,6 @@ import org.jxmpp.jid.Jid;
|
||||||
*/
|
*/
|
||||||
public class IBBTransferNegotiator extends StreamNegotiator {
|
public class IBBTransferNegotiator extends StreamNegotiator {
|
||||||
|
|
||||||
private XMPPConnection connection;
|
|
||||||
|
|
||||||
private InBandBytestreamManager manager;
|
private InBandBytestreamManager manager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,7 +52,7 @@ public class IBBTransferNegotiator extends StreamNegotiator {
|
||||||
* @param connection The connection which this negotiator works on.
|
* @param connection The connection which this negotiator works on.
|
||||||
*/
|
*/
|
||||||
protected IBBTransferNegotiator(XMPPConnection connection) {
|
protected IBBTransferNegotiator(XMPPConnection connection) {
|
||||||
this.connection = connection;
|
super(connection);
|
||||||
this.manager = InBandBytestreamManager.getByteStreamManager(connection);
|
this.manager = InBandBytestreamManager.getByteStreamManager(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +73,7 @@ public class IBBTransferNegotiator extends StreamNegotiator {
|
||||||
*/
|
*/
|
||||||
this.manager.ignoreBytestreamRequestOnce(initiation.getSessionID());
|
this.manager.ignoreBytestreamRequestOnce(initiation.getSessionID());
|
||||||
|
|
||||||
Stanza streamInitiation = initiateIncomingStream(this.connection, initiation);
|
Stanza streamInitiation = initiateIncomingStream(connection(), initiation);
|
||||||
return negotiateIncomingStream(streamInitiation);
|
return negotiateIncomingStream(streamInitiation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,13 +43,11 @@ import org.jxmpp.jid.Jid;
|
||||||
*/
|
*/
|
||||||
public class Socks5TransferNegotiator extends StreamNegotiator {
|
public class Socks5TransferNegotiator extends StreamNegotiator {
|
||||||
|
|
||||||
private XMPPConnection connection;
|
|
||||||
|
|
||||||
private Socks5BytestreamManager manager;
|
private Socks5BytestreamManager manager;
|
||||||
|
|
||||||
Socks5TransferNegotiator(XMPPConnection connection) {
|
Socks5TransferNegotiator(XMPPConnection connection) {
|
||||||
this.connection = connection;
|
super(connection);
|
||||||
this.manager = Socks5BytestreamManager.getBytestreamManager(this.connection);
|
this.manager = Socks5BytestreamManager.getBytestreamManager(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -75,7 +73,7 @@ public class Socks5TransferNegotiator extends StreamNegotiator {
|
||||||
*/
|
*/
|
||||||
this.manager.ignoreBytestreamRequestOnce(initiation.getSessionID());
|
this.manager.ignoreBytestreamRequestOnce(initiation.getSessionID());
|
||||||
|
|
||||||
Stanza streamInitiation = initiateIncomingStream(this.connection, initiation);
|
Stanza streamInitiation = initiateIncomingStream(connection(), initiation);
|
||||||
return negotiateIncomingStream(streamInitiation);
|
return negotiateIncomingStream(streamInitiation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.filetransfer;
|
package org.jivesoftware.smackx.filetransfer;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.Manager;
|
||||||
import org.jivesoftware.smack.SmackException;
|
import org.jivesoftware.smack.SmackException;
|
||||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||||
|
@ -42,7 +43,11 @@ import java.io.OutputStream;
|
||||||
*
|
*
|
||||||
* @author Alexander Wenckus
|
* @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.
|
* A event manager for stream initiation requests send to us.
|
||||||
|
|
Loading…
Reference in a new issue