From bb6cacbaee3bbbe06006fcca916e239406bcf3af Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 13 Aug 2020 17:02:41 +0200 Subject: [PATCH] WIP - disabled ping --- src/dorkbox/network/connection/Ping.kt | 4 +- .../network/connection/PingListener.java | 20 +++-- .../network/connection/ping/PingFuture.java | 74 +++++++++---------- 3 files changed, 48 insertions(+), 50 deletions(-) diff --git a/src/dorkbox/network/connection/Ping.kt b/src/dorkbox/network/connection/Ping.kt index 544ad6d6..e42c9f2b 100644 --- a/src/dorkbox/network/connection/Ping.kt +++ b/src/dorkbox/network/connection/Ping.kt @@ -25,13 +25,13 @@ interface Ping { * Adds a ping listener to this future. The listener is notified when this future is done. If this future is already completed, * then the listener is notified immediately. */ - fun add(listener: PingListener?) + fun add(listener: PingListener?) /** * Removes a ping listener from this future. The listener is no longer notified when this future is done. If the listener * was not previously associated with this future, this method does nothing and returns silently. */ - fun remove(listener: PingListener?) + fun remove(listener: PingListener?) /** * Cancel this Ping. diff --git a/src/dorkbox/network/connection/PingListener.java b/src/dorkbox/network/connection/PingListener.java index 8ca74182..e3df1e85 100644 --- a/src/dorkbox/network/connection/PingListener.java +++ b/src/dorkbox/network/connection/PingListener.java @@ -15,25 +15,23 @@ */ package dorkbox.network.connection; -import dorkbox.network.connection.ping.PingTuple; -import io.netty.util.concurrent.Future; -import io.netty.util.concurrent.GenericFutureListener; - // note that we specifically DO NOT implement equals/hashCode, because we cannot create two separate // listeners that are somehow equal to each other. public abstract -class PingListener implements GenericFutureListener>> { +class PingListener + // implements GenericFutureListener>> +{ public PingListener() { } - @Override - public - void operationComplete(Future> future) throws Exception { - PingTuple pingTuple = future.get(); - response(pingTuple.connection, pingTuple.responseTime); - } + // @Override + // public + // void operationComplete(Future> future) throws Exception { + // PingTuple pingTuple = future.get(); + // response(pingTuple.connection, pingTuple.responseTime); + // } /** * Called when the ping response has been received. diff --git a/src/dorkbox/network/connection/ping/PingFuture.java b/src/dorkbox/network/connection/ping/PingFuture.java index d0eb7fab..75bf5072 100644 --- a/src/dorkbox/network/connection/ping/PingFuture.java +++ b/src/dorkbox/network/connection/ping/PingFuture.java @@ -15,21 +15,18 @@ */ package dorkbox.network.connection.ping; -import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicInteger; import dorkbox.network.connection.Connection; import dorkbox.network.connection.Ping; import dorkbox.network.connection.PingListener; -import io.netty.util.concurrent.GenericFutureListener; -import io.netty.util.concurrent.Promise; public class PingFuture implements Ping { private static final AtomicInteger pingCounter = new AtomicInteger(0); - private final Promise> promise; + // private final Promise> promise; private final int id; private final long sentTime; @@ -39,19 +36,21 @@ class PingFuture implements Ping { */ @SuppressWarnings("unused") PingFuture() { - this(null); + // this(null); + id = -1; + sentTime = -2; } - public - PingFuture(Promise> promise) { - this.promise = promise; - this.id = pingCounter.getAndIncrement(); - this.sentTime = System.currentTimeMillis(); - - if (this.id == Integer.MAX_VALUE) { - pingCounter.set(0); - } - } + // public + // PingFuture(Promise> promise) { + // this.promise = promise; + // this.id = pingCounter.getAndIncrement(); + // this.sentTime = System.currentTimeMillis(); + // + // if (this.id == Integer.MAX_VALUE) { + // pingCounter.set(0); + // } + // } /** * Wait for the ping to return, and returns the ping response time in MS or -1 if it failed. @@ -59,15 +58,15 @@ class PingFuture implements Ping { @Override public int getResponse() { - try { - PingTuple entry = this.promise.syncUninterruptibly() - .get(); - if (entry != null) { - return entry.responseTime; - } - } catch (InterruptedException e) { - } catch (ExecutionException e) { - } + // try { + // PingTuple entry = this.promise.syncUninterruptibly() + // .get(); + // if (entry != null) { + // return entry.responseTime; + // } + // } catch (InterruptedException e) { + // } catch (ExecutionException e) { + // } return -1; } @@ -79,7 +78,7 @@ class PingFuture implements Ping { @SuppressWarnings({"unchecked", "rawtypes"}) public void add(PingListener listener) { - this.promise.addListener((GenericFutureListener) listener); + // this.promise.addListener((GenericFutureListener) listener); } /** @@ -90,7 +89,7 @@ class PingFuture implements Ping { @SuppressWarnings({"unchecked", "rawtypes"}) public void remove(PingListener listener) { - this.promise.removeListener((GenericFutureListener) listener); + // this.promise.removeListener((GenericFutureListener) listener); } /** @@ -99,7 +98,7 @@ class PingFuture implements Ping { @Override public void cancel() { - this.promise.tryFailure(new PingCanceledException()); + // this.promise.tryFailure(new PingCanceledException()); } /** @@ -107,20 +106,21 @@ class PingFuture implements Ping { */ public void setSuccess(C connection, PingMessage ping) { - if (ping.id == this.id) { - long longTime = System.currentTimeMillis() - this.sentTime; - if (longTime < Integer.MAX_VALUE) { - this.promise.setSuccess(new PingTuple(connection, (int) longTime)); - } - else { - this.promise.setSuccess(new PingTuple(connection, Integer.MAX_VALUE)); - } - } + // if (ping.id == this.id) { + // long longTime = System.currentTimeMillis() - this.sentTime; + // if (longTime < Integer.MAX_VALUE) { + // this.promise.setSuccess(new PingTuple(connection, (int) longTime)); + // } + // else { + // this.promise.setSuccess(new PingTuple(connection, Integer.MAX_VALUE)); + // } + // } } public boolean isSuccess() { - return this.promise.isSuccess(); + // return this.promise.isSuccess(); + return false; } /**