diff options
| author | Alex Clayton <alex.clayton@isode.com> | 2016-03-15 15:46:56 (GMT) |
|---|---|---|
| committer | Alex Clayton <alex.clayton@isode.com> | 2016-03-16 10:04:37 (GMT) |
| commit | 1a0b79956729aefe3a10093c58b508ac651e4d0c (patch) | |
| tree | 89ace2db57d8c6a2b7ef402bff0cd6703987bf6a | |
| parent | 1eddc7b6041678c47ae3e2e8e632419ae3b5e150 (diff) | |
| download | stroke-1a0b79956729aefe3a10093c58b508ac651e4d0c.zip stroke-1a0b79956729aefe3a10093c58b508ac651e4d0c.tar.bz2 | |
Add destroy methods to IncomingJingleFileTransfer and OutgoingJingleFileTransfer.
Add destroy methods to IncomingJingleFileTransfer and
OutgoingJingeFlieTranser to match the destructors of the swiften code
(as of patch 'Add missing Timer related cleanup code' -
52e685379436794cc0e4c2687c35f5e69a2f09a7).
Test-information: Unit tests ran ok.
Change-Id: Ie86c5fc74f66d9c62095045475eb6d9447c7699e
| -rw-r--r-- | src/com/isode/stroke/filetransfer/IncomingJingleFileTransfer.java | 29 | ||||
| -rw-r--r-- | src/com/isode/stroke/filetransfer/OutgoingJingleFileTransfer.java | 49 |
2 files changed, 76 insertions, 2 deletions
diff --git a/src/com/isode/stroke/filetransfer/IncomingJingleFileTransfer.java b/src/com/isode/stroke/filetransfer/IncomingJingleFileTransfer.java index 60cde19..1c67014 100644 --- a/src/com/isode/stroke/filetransfer/IncomingJingleFileTransfer.java +++ b/src/com/isode/stroke/filetransfer/IncomingJingleFileTransfer.java @@ -115,2 +115,28 @@ public class IncomingJingleFileTransfer extends JingleFileTransfer implements In } + + @Override + protected void finalize() throws Throwable { + try { + destroy(); + } + finally { + super.finalize(); + } + } + + /** + * This replaces the C++ destructor. After calling this object should not be used again. + * If any methods are called after they behaviour is undefined and they may throw expections. + */ + public void destroy() { + if (waitOnHashTimerTickedConnection != null) { + waitOnHashTimerTickedConnection.disconnect(); + waitOnHashTimerTickedConnection = null; + } + if (waitOnHashTimer != null) { + waitOnHashTimer.stop(); + waitOnHashTimer = null; + } + hashCalculator = null; + } @@ -496,2 +522,5 @@ public class IncomingJingleFileTransfer extends JingleFileTransfer implements In private void handleWaitOnHashTimerTicked() { + if (waitOnHashTimer == null) { + return; + } logger_.fine("\n"); diff --git a/src/com/isode/stroke/filetransfer/OutgoingJingleFileTransfer.java b/src/com/isode/stroke/filetransfer/OutgoingJingleFileTransfer.java index f32821b..aa38022 100644 --- a/src/com/isode/stroke/filetransfer/OutgoingJingleFileTransfer.java +++ b/src/com/isode/stroke/filetransfer/OutgoingJingleFileTransfer.java @@ -90,2 +90,12 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou private Logger logger_ = Logger.getLogger(this.getClass().getName()); + + /** + * Connection to {@link Timer#onTick} of {@link #waitForRemoteTermination} + */ + private final SignalConnection onTickConnection; + + /** + * Connection to {@link ReadBytestream#onRead} of {@link #stream} + */ + private SignalConnection streamReadConnection; @@ -114,5 +124,8 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou hashCalculator = new IncrementalBytestreamHashCalculator(true, true, crypto); - stream.onRead.connect(new Slot1<ByteArray>() { + streamReadConnection = stream.onRead.connect(new Slot1<ByteArray>() { @Override public void call(ByteArray b) { + if (hashCalculator == null) { + return; + } hashCalculator.feedData(b); @@ -121,3 +134,3 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou waitForRemoteTermination = timerFactory.createTimer(5000); - waitForRemoteTermination.onTick.connect(new Slot() { + onTickConnection = waitForRemoteTermination.onTick.connect(new Slot() { @Override @@ -128,2 +141,31 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou } + + @Override + protected void finalize() throws Throwable { + try { + destroy(); + } + finally { + super.finalize(); + } + } + + /** + * This replaces the C++ destructor. After calling this object should not be used again. + * If any methods are called after they behaviour is undefined and they may throw expections. + */ + public void destroy() { + if (onTickConnection != null) { + onTickConnection.disconnect(); + } + if (waitForRemoteTermination != null) { + waitForRemoteTermination.stop(); + waitForRemoteTermination = null; + } + if (streamReadConnection != null) { + streamReadConnection.disconnect(); + } + hashCalculator = null; + removeTransporter(); + } @@ -385,2 +427,5 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou private void handleWaitForRemoteTerminationTimeout() { + if (waitForRemoteTermination == null) { + return; + } assert(internalState.equals(State.WaitForTermination)); |
Swift