converted to

This commit is contained in:
nathan 2020-08-17 16:48:29 +02:00
parent 77c3209090
commit a214c2b53a
5 changed files with 72 additions and 80 deletions

View File

@ -0,0 +1,24 @@
package dorkbox.network.connection.connectionType
import dorkbox.network.handshake.UpgradeType
/**
* Used in [IpConnectionTypeRule] to decide what kind of connection a matching IP Address should have.
*/
enum class ConnectionProperties(val type: Byte) {
/**
* No compression, no encryption
*/
NOTHING(UpgradeType.NONE),
/**
* Only compression
*/
COMPRESS(UpgradeType.COMPRESS),
/**
* Compression + encryption
*/
COMPRESS_AND_ENCRYPT(UpgradeType.ENCRYPT);
}

View File

@ -13,17 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package dorkbox.network.connection.ping; package dorkbox.network.connection.ping
import java.io.IOException; import java.io.IOException
public object PingCanceledException : IOException() {
class PingCanceledException extends IOException { private const val serialVersionUID = 9045461384091038605L
private static final long serialVersionUID = 9045461384091038605L;
public
PingCanceledException() {
super("Ping request has been canceled.");
}
} }

View File

@ -13,34 +13,20 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package dorkbox.network.connection.ping; package dorkbox.network.connection.ping
import java.util.concurrent.atomic.AtomicInteger; import dorkbox.network.connection.Connection
import dorkbox.network.connection.Ping
import dorkbox.network.connection.Connection; import dorkbox.network.connection.PingListener
import dorkbox.network.connection.Ping; import java.util.concurrent.atomic.AtomicInteger
import dorkbox.network.connection.PingListener;
public
class PingFuture implements Ping {
private static final AtomicInteger pingCounter = new AtomicInteger(0);
// private final Promise<PingTuple<? extends Connection>> promise;
private final int id;
private final long sentTime;
class PingFuture internal constructor() : Ping {
/** /**
* Protected constructor for when we are completely overriding this class. (Used by the "local" connection for instant pings) * @return the ID of this ping future
*/ */
@SuppressWarnings("unused") // private final Promise<PingTuple<? extends Connection>> promise;
PingFuture() { val id: Int
// this(null); private val sentTime: Long
id = -1;
sentTime = -2;
}
// public // public
// PingFuture(Promise<PingTuple<? extends Connection>> promise) { // PingFuture(Promise<PingTuple<? extends Connection>> promise) {
// this.promise = promise; // this.promise = promise;
@ -50,15 +36,20 @@ class PingFuture implements Ping {
// if (this.id == Integer.MAX_VALUE) { // if (this.id == Integer.MAX_VALUE) {
// pingCounter.set(0); // pingCounter.set(0);
// } // }
// }// try {
// PingTuple<? extends Connection> entry = this.promise.syncUninterruptibly()
// .get();
// if (entry != null) {
// return entry.responseTime;
// }
// } catch (InterruptedException e) {
// } catch (ExecutionException e) {
// } // }
/** /**
* Wait for the ping to return, and returns the ping response time in MS or -1 if it failed. * Wait for the ping to return, and returns the ping response time in MS or -1 if it failed.
*/ */
@Override override val response: Int
public get() =// try {
int getResponse() {
// try {
// PingTuple<? extends Connection> entry = this.promise.syncUninterruptibly() // PingTuple<? extends Connection> entry = this.promise.syncUninterruptibly()
// .get(); // .get();
// if (entry != null) { // if (entry != null) {
@ -66,18 +57,14 @@ class PingFuture implements Ping {
// } // }
// } catch (InterruptedException e) { // } catch (InterruptedException e) {
// } catch (ExecutionException e) { // } catch (ExecutionException e) {
// } // }
return -1; -1
}
/** /**
* Adds the specified listener to this future. The specified listener is notified when this future is done. If this future is already * Adds the specified listener to this future. The specified listener is notified when this future is done. If this future is already
* completed, the specified listener is notified immediately. * completed, the specified listener is notified immediately.
*/ */
@Override override fun <C : Connection> add(listener: PingListener<C>) {
@SuppressWarnings({"unchecked", "rawtypes"})
public
<C extends Connection> void add(PingListener<C> listener) {
// this.promise.addListener((GenericFutureListener) listener); // this.promise.addListener((GenericFutureListener) listener);
} }
@ -85,27 +72,21 @@ class PingFuture implements Ping {
* Removes the specified listener from this future. The specified listener is no longer notified when this future is done. If the * Removes the specified listener from this future. The specified listener is no longer notified when this future is done. If the
* specified listener is not associated with this future, this method does nothing and returns silently. * specified listener is not associated with this future, this method does nothing and returns silently.
*/ */
@Override override fun <C : Connection> remove(listener: PingListener<C>) {
@SuppressWarnings({"unchecked", "rawtypes"})
public
<C extends Connection> void remove(PingListener<C> listener) {
// this.promise.removeListener((GenericFutureListener) listener); // this.promise.removeListener((GenericFutureListener) listener);
} }
/** /**
* Cancel this Ping. * Cancel this Ping.
*/ */
@Override override fun cancel() {
public
void cancel() {
// this.promise.tryFailure(new PingCanceledException()); // this.promise.tryFailure(new PingCanceledException());
} }
/** /**
* This is when the endpoint that ORIGINALLY sent the ping, finally receives a response. * This is when the endpoint that ORIGINALLY sent the ping, finally receives a response.
*/ */
public fun <C : Connection?> setSuccess(connection: C, ping: PingMessage?) {
<C extends Connection> void setSuccess(C connection, PingMessage ping) {
// if (ping.id == this.id) { // if (ping.id == this.id) {
// long longTime = System.currentTimeMillis() - this.sentTime; // long longTime = System.currentTimeMillis() - this.sentTime;
// if (longTime < Integer.MAX_VALUE) { // if (longTime < Integer.MAX_VALUE) {
@ -117,17 +98,21 @@ class PingFuture implements Ping {
// } // }
} }
public // return this.promise.isSuccess();
boolean isSuccess() { val isSuccess: Boolean
// return this.promise.isSuccess(); get() =// return this.promise.isSuccess();
return false; false
companion object {
private val pingCounter = AtomicInteger(0)
} }
/** /**
* @return the ID of this ping future * Protected constructor for when we are completely overriding this class. (Used by the "local" connection for instant pings)
*/ */
public init {
int getId() { // this(null);
return this.id; id = -1
sentTime = -2
} }
} }

View File

@ -13,13 +13,12 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package dorkbox.network.connection.ping; package dorkbox.network.connection.ping
/** /**
* Internal message to determine round trip time. * Internal message to determine round trip time.
*/ */
public
class PingMessage { class PingMessage {
public int id; var id = 0
public boolean isReply; var isReply = false
} }

View File

@ -13,17 +13,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package dorkbox.network.connection.ping; package dorkbox.network.connection.ping
import dorkbox.network.connection.Connection
import dorkbox.network.connection.Connection; class PingTuple<C : Connection?>(var connection: C, var responseTime: Int)
public class PingTuple<C extends Connection> {
public C connection;
public int responseTime;
public PingTuple(C connection, int responseTime) {
this.connection = connection;
this.responseTime = responseTime;
}
}