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 | |||
| @@ -113,6 +113,32 @@ public class IncomingJingleFileTransfer extends JingleFileTransfer implements In | |||
| 113 | } | 113 | } |
| 114 | }); | 114 | }); |
| 115 | } | 115 | } |
| 116 | |||
| 117 | @Override | ||
| 118 | protected void finalize() throws Throwable { | ||
| 119 | try { | ||
| 120 | destroy(); | ||
| 121 | } | ||
| 122 | finally { | ||
| 123 | super.finalize(); | ||
| 124 | } | ||
| 125 | } | ||
| 126 | |||
| 127 | /** | ||
| 128 | * This replaces the C++ destructor. After calling this object should not be used again. | ||
| 129 | * If any methods are called after they behaviour is undefined and they may throw expections. | ||
| 130 | */ | ||
| 131 | public void destroy() { | ||
| 132 | if (waitOnHashTimerTickedConnection != null) { | ||
| 133 | waitOnHashTimerTickedConnection.disconnect(); | ||
| 134 | waitOnHashTimerTickedConnection = null; | ||
| 135 | } | ||
| 136 | if (waitOnHashTimer != null) { | ||
| 137 | waitOnHashTimer.stop(); | ||
| 138 | waitOnHashTimer = null; | ||
| 139 | } | ||
| 140 | hashCalculator = null; | ||
| 141 | } | ||
| 116 | 142 | ||
| 117 | /** | 143 | /** |
| 118 | * IncomingFileTransferMethod. | 144 | * IncomingFileTransferMethod. |
| @@ -494,6 +520,9 @@ public class IncomingJingleFileTransfer extends JingleFileTransfer implements In | |||
| 494 | } | 520 | } |
| 495 | 521 | ||
| 496 | private void handleWaitOnHashTimerTicked() { | 522 | private void handleWaitOnHashTimerTicked() { |
| 523 | if (waitOnHashTimer == null) { | ||
| 524 | return; | ||
| 525 | } | ||
| 497 | logger_.fine("\n"); | 526 | logger_.fine("\n"); |
| 498 | waitOnHashTimer.stop(); | 527 | waitOnHashTimer.stop(); |
| 499 | terminate(JinglePayload.Reason.Type.Success); | 528 | terminate(JinglePayload.Reason.Type.Success); |
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 | |||
| @@ -88,6 +88,16 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou | |||
| 88 | private SignalConnection processedBytesConnection; | 88 | private SignalConnection processedBytesConnection; |
| 89 | private SignalConnection transferFinishedConnection; | 89 | private SignalConnection transferFinishedConnection; |
| 90 | private Logger logger_ = Logger.getLogger(this.getClass().getName()); | 90 | private Logger logger_ = Logger.getLogger(this.getClass().getName()); |
| 91 | |||
| 92 | /** | ||
| 93 | * Connection to {@link Timer#onTick} of {@link #waitForRemoteTermination} | ||
| 94 | */ | ||
| 95 | private final SignalConnection onTickConnection; | ||
| 96 | |||
| 97 | /** | ||
| 98 | * Connection to {@link ReadBytestream#onRead} of {@link #stream} | ||
| 99 | */ | ||
| 100 | private SignalConnection streamReadConnection; | ||
| 91 | 101 | ||
| 92 | public OutgoingJingleFileTransfer( | 102 | public OutgoingJingleFileTransfer( |
| 93 | final JID toJID, | 103 | final JID toJID, |
| @@ -112,20 +122,52 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou | |||
| 112 | 122 | ||
| 113 | // calculate both, MD5 and SHA-1 since we don't know which one the other side supports | 123 | // calculate both, MD5 and SHA-1 since we don't know which one the other side supports |
| 114 | hashCalculator = new IncrementalBytestreamHashCalculator(true, true, crypto); | 124 | hashCalculator = new IncrementalBytestreamHashCalculator(true, true, crypto); |
| 115 | stream.onRead.connect(new Slot1<ByteArray>() { | 125 | streamReadConnection = stream.onRead.connect(new Slot1<ByteArray>() { |
| 116 | @Override | 126 | @Override |
| 117 | public void call(ByteArray b) { | 127 | public void call(ByteArray b) { |
| 128 | if (hashCalculator == null) { | ||
| 129 | return; | ||
| 130 | } | ||
| 118 | hashCalculator.feedData(b); | 131 | hashCalculator.feedData(b); |
| 119 | } | 132 | } |
| 120 | }); | 133 | }); |
| 121 | waitForRemoteTermination = timerFactory.createTimer(5000); | 134 | waitForRemoteTermination = timerFactory.createTimer(5000); |
| 122 | waitForRemoteTermination.onTick.connect(new Slot() { | 135 | onTickConnection = waitForRemoteTermination.onTick.connect(new Slot() { |
| 123 | @Override | 136 | @Override |
| 124 | public void call() { | 137 | public void call() { |
| 125 | handleWaitForRemoteTerminationTimeout(); | 138 | handleWaitForRemoteTerminationTimeout(); |
| 126 | } | 139 | } |
| 127 | }); | 140 | }); |
| 128 | } | 141 | } |
| 142 | |||
| 143 | @Override | ||
| 144 | protected void finalize() throws Throwable { | ||
| 145 | try { | ||
| 146 | destroy(); | ||
| 147 | } | ||
| 148 | finally { | ||
| 149 | super.finalize(); | ||
| 150 | } | ||
| 151 | } | ||
| 152 | |||
| 153 | /** | ||
| 154 | * This replaces the C++ destructor. After calling this object should not be used again. | ||
| 155 | * If any methods are called after they behaviour is undefined and they may throw expections. | ||
| 156 | */ | ||
| 157 | public void destroy() { | ||
| 158 | if (onTickConnection != null) { | ||
| 159 | onTickConnection.disconnect(); | ||
| 160 | } | ||
| 161 | if (waitForRemoteTermination != null) { | ||
| 162 | waitForRemoteTermination.stop(); | ||
| 163 | waitForRemoteTermination = null; | ||
| 164 | } | ||
| 165 | if (streamReadConnection != null) { | ||
| 166 | streamReadConnection.disconnect(); | ||
| 167 | } | ||
| 168 | hashCalculator = null; | ||
| 169 | removeTransporter(); | ||
| 170 | } | ||
| 129 | 171 | ||
| 130 | /** | 172 | /** |
| 131 | * OutgoingFileTransferMethod. | 173 | * OutgoingFileTransferMethod. |
| @@ -383,6 +425,9 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou | |||
| 383 | } | 425 | } |
| 384 | 426 | ||
| 385 | private void handleWaitForRemoteTerminationTimeout() { | 427 | private void handleWaitForRemoteTerminationTimeout() { |
| 428 | if (waitForRemoteTermination == null) { | ||
| 429 | return; | ||
| 430 | } | ||
| 386 | assert(internalState.equals(State.WaitForTermination)); | 431 | assert(internalState.equals(State.WaitForTermination)); |
| 387 | logger_.warning("Other party did not terminate session. Terminate it now.\n"); | 432 | logger_.warning("Other party did not terminate session. Terminate it now.\n"); |
| 388 | waitForRemoteTermination.stop(); | 433 | waitForRemoteTermination.stop(); |
Swift