summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/com/isode/stroke/streamstack/WhitespacePingLayer.java38
1 files changed, 36 insertions, 2 deletions
diff --git a/src/com/isode/stroke/streamstack/WhitespacePingLayer.java b/src/com/isode/stroke/streamstack/WhitespacePingLayer.java
index 3a1805c..95da051 100644
--- a/src/com/isode/stroke/streamstack/WhitespacePingLayer.java
+++ b/src/com/isode/stroke/streamstack/WhitespacePingLayer.java
@@ -6,3 +6,3 @@
/*
- * Copyright (c) 2011, Isode Limited, London, England.
+ * Copyright (c) 2011-2016, Isode Limited, London, England.
* All rights reserved.
@@ -11,2 +11,4 @@ package com.isode.stroke.streamstack;
+import java.util.logging.Logger;
+
import com.isode.stroke.base.SafeByteArray;
@@ -14,2 +16,3 @@ import com.isode.stroke.network.Timer;
import com.isode.stroke.network.TimerFactory;
+import com.isode.stroke.signals.SignalConnection;
import com.isode.stroke.signals.Slot;
@@ -19,2 +22,4 @@ public class WhitespacePingLayer extends StreamLayer {
private static final int TIMEOUT_MILLISECONDS = 60000;
+
+ private final Logger logger = Logger.getLogger(this.getClass().getName());
@@ -23,3 +28,3 @@ public class WhitespacePingLayer extends StreamLayer {
timer = timerFactory.createTimer(TIMEOUT_MILLISECONDS);
- timer.onTick.connect(new Slot() {
+ onTickConnection = timer.onTick.connect(new Slot() {
public void call() {
@@ -29,2 +34,26 @@ public class WhitespacePingLayer extends StreamLayer {
}
+
+ @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 may throw {@link NullPointerException}
+ */
+ public void destroy() {
+ if (isActive && timer != null) {
+ logger.finer("WhitespacePingLayer still active at destruction");
+ timer.stop();
+ }
+ onTickConnection.disconnect();
+ timer = null;
+ isActive = false;
+ }
@@ -39,2 +68,5 @@ public class WhitespacePingLayer extends StreamLayer {
private void handleTimerTick() {
+ if (timer == null) {
+ return;
+ }
timer.stop();
@@ -60,2 +92,4 @@ public class WhitespacePingLayer extends StreamLayer {
private Timer timer;
+
+ private final SignalConnection onTickConnection;
}