Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java 8 - Kryo v4 and more... #156

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="**/.svn/*" kind="src" path="src"/>
<classpathentry kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**/.svn/*" kind="src" path="examples"/>
<classpathentry excluding="**/.svn/*" kind="src" path="test"/>
<classpathentry exported="true" kind="lib" path="lib/kryo-2.23.1-SNAPSHOT-all-debug.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="lib" path="build/junit-4.6.jar"/>
<classpathentry kind="lib" path="lib/jsonbeans-0.5.jar"/>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="src" output="target/test-classes" path="test">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ bin/
target/
.idea/
*.iml
/dependency-reduced-pom.xml
8 changes: 7 additions & 1 deletion .project
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
</projectDescription>
4 changes: 4 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
encoding/src=UTF-8
encoding/test=UTF-8
11 changes: 8 additions & 3 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.doc.comment.support=enabled
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
Expand Down Expand Up @@ -79,4 +84,4 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=enab
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=ignore
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=1.7
org.eclipse.jdt.core.compiler.source=1.8
Binary file added build/junit-4.12.jar
Binary file not shown.
Binary file removed build/junit-4.6.jar
Binary file not shown.
Binary file added build/minlog-1.3.0.jar
Binary file not shown.
Binary file removed build/minlog-none-1.2.jar
Binary file not shown.
Binary file added build/objenesis-2.1.jar
Binary file not shown.
Binary file added build/reflectasm-1.10.1-shaded.jar
Binary file not shown.
Binary file removed lib/jsonbeans-0.5.jar
Binary file not shown.
Binary file added lib/jsonbeans-0.7.jar
Binary file not shown.
Binary file removed lib/kryo-2.23.1-SNAPSHOT-all-debug.jar
Binary file not shown.
Binary file added lib/kryo-4.0.2.jar
Binary file not shown.
156 changes: 99 additions & 57 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,68 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>9</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>com.esotericsoftware</groupId>
<artifactId>kryonet</artifactId>
<version>2.22.0-RC1</version>
<packaging>jar</packaging>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryonet</artifactId>
<version>3.0.0</version>
<packaging>jar</packaging>

<name>kryonet</name>
<description>TCP and UDP client/server library for Java</description>
<url>https://github.com/EsotericSoftware/kryonet</url>
<name>kryonet</name>
<description>TCP and UDP client/server library for Java</description>
<url>https://github.com/EsotericSoftware/kryonet</url>

<licenses>
<license>
<name>New BSD License</name>
<url>http://www.opensource.org/licenses/bsd-license.php</url>
<distribution>repo</distribution>
</license>
</licenses>
<licenses>
<license>
<name>New BSD License</name>
<url>http://www.opensource.org/licenses/bsd-license.php</url>
<distribution>repo</distribution>
</license>
</licenses>

<developers>
<developer>
<id>nathan.sweet</id>
<name>Nathan Sweet</name>
<email>[email protected]</email>
</developer>
</developers>
<developers>
<developer>
<id>nathan.sweet</id>
<name>Nathan Sweet</name>
<email>[email protected]</email>
</developer>
</developers>

<scm>
<url>https://github.com/EsotericSoftware/kryonet</url>
<connection>scm:git:https://github.com/EsotericSoftware/kryonet.git</connection>
<developerConnection>scm:git:https://github.com/EsotericSoftware/kryonet.git</developerConnection>
<tag>HEAD</tag>
</scm>
<scm>
<url>https://github.com/EsotericSoftware/kryonet</url>
<connection>scm:git:https://github.com/EsotericSoftware/kryonet.git</connection>
<developerConnection>scm:git:https://github.com/EsotericSoftware/kryonet.git</developerConnection>
<tag>HEAD</tag>
</scm>

<build>
<!-- Set nonstandard source and test source dirs -->
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<build>
<!-- Set nonstandard source and test source dirs -->
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>

</build>
<resources>
<resource>
<directory>${basedir}/src</directory>
<includes>
<include>**/*.java</include>
</includes>
</resource>
</resources>

<dependencies>
<dependency>
<groupId>com.esotericsoftware.kryo</groupId>
<artifactId>kryo</artifactId>
<version>2.24.0</version>
</dependency>
<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>jsonbeans</artifactId>
<version>0.7</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>12</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<!-- put your configurations here -->
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo</artifactId>
<version>4.0.2</version>
</dependency>
<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>jsonbeans</artifactId>
<version>0.7</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
</project>
16 changes: 8 additions & 8 deletions src/com/esotericsoftware/kryonet/Client.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* Copyright (c) 2008, Nathan Sweet
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
* conditions are met:
*
*
* - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with the distribution.
* - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Expand Down Expand Up @@ -100,7 +100,8 @@ public Client (int writeBufferSize, int objectBufferSize, Serialization serializ

this.serialization = serialization;

this.discoveryHandler = ClientDiscoveryHandler.DEFAULT;
this.discoveryHandler = new ClientDiscoveryHandler() {
};

initialize(serialization, writeBufferSize, objectBufferSize);

Expand All @@ -120,7 +121,7 @@ public Serialization getSerialization () {
}

public Kryo getKryo () {
return serialization instanceof KryoSerialization ? ((KryoSerialization)serialization).getKryo() : null;
return ((KryoSerialization)serialization).getKryo();
}

/** Opens a TCP only client.
Expand Down Expand Up @@ -472,8 +473,7 @@ private void broadcast (int udpPort, DatagramSocket socket) throws IOException {
if (DEBUG) debug("kryonet", "Broadcasted host discovery on port: " + udpPort);
}

/** Broadcasts a UDP message on the LAN to discover any running servers. The address of the first server to respond is
* returned.
/** Broadcasts a UDP message on the LAN to discover any running servers. The address of the first server to respond is returned.
* @param udpPort The UDP port of the server.
* @param timeoutMillis The number of milliseconds to wait for a response.
* @return the first server found, or null if no server responded. */
Expand Down Expand Up @@ -532,4 +532,4 @@ public List<InetAddress> discoverHosts (int udpPort, int timeoutMillis) {
discoveryHandler.onFinally();
}
}
}
}
65 changes: 35 additions & 30 deletions src/com/esotericsoftware/kryonet/ClientDiscoveryHandler.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* Copyright (c) 2008, Nathan Sweet
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
* conditions are met:
*
*
* - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with the distribution.
* - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Expand All @@ -25,32 +25,37 @@
import com.esotericsoftware.kryo.io.Input;

public interface ClientDiscoveryHandler {
/** This implementation of the {@link ClientDiscoveryHandler} is responsible for providing the {@link Client} with it's default
* behavior. */
public static final ClientDiscoveryHandler DEFAULT = new ClientDiscoveryHandler() {
public DatagramPacket onRequestNewDatagramPacket () {
return new DatagramPacket(new byte[0], 0);
}

public void onDiscoveredHost (DatagramPacket datagramPacket, Kryo kryo) {
}

public void onFinally () {
}

/**
* Implementations of this method should return a new {@link DatagramPacket}
* that the {@link Client} will use to fill with the incoming packet data
* sent by the {@link ServerDiscoveryHandler}.
*
* @return a new {@link DatagramPacket}
*/
public default DatagramPacket onRequestNewDatagramPacket() {
return new DatagramPacket(new byte[0], 0);
};

/**
* Called when the {@link Client} discovers a host.
*
* @param datagramPacket
* the same {@link DatagramPacket} from
* {@link #onRequestNewDatagramPacket()}, after being filled with
* the incoming packet data.
* @param kryo
* the {@link Kryo} instance
*/
public default void onDiscoveredHost(DatagramPacket datagramPacket, Kryo kryo) {
};

/**
* Called right before the {@link Client#discoverHost(int, int)} or
* {@link Client#discoverHosts(int, int)} method exits. This allows the
* implementation to clean up any resources used, i.e. an {@link Input}.
*/
public default void onFinally() {
};

/** Implementations of this method should return a new {@link DatagramPacket} that the {@link Client} will use to fill with the
* incoming packet data sent by the {@link ServerDiscoveryHandler}.
* @return a new {@link DatagramPacket} */
public DatagramPacket onRequestNewDatagramPacket ();

/** Called when the {@link Client} discovers a host.
* @param datagramPacket the same {@link DatagramPacket} from {@link #onRequestNewDatagramPacket()}, after being filled with
* the incoming packet data.
* @param kryo the {@link Kryo} instance, or null. */
public void onDiscoveredHost (DatagramPacket datagramPacket, Kryo kryo);

/** Called right before the {@link Client#discoverHost(int, int)} or {@link Client#discoverHosts(int, int)} method exits. This
* allows the implementation to clean up any resources used, i.e. an {@link Input}. */
public void onFinally ();
}
}
Loading