Skip to content
Merged
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
25 changes: 10 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,44 +76,39 @@ public final class TestSimpleServer {

@EventHandler
public static class ConnectionEstablishedHandler extends AbstractHandler
implements EventConnectionEstablishedResult {
implements EventConnectionEstablishedResult<ZeroMap> {

@Override
public void handle(Session session, DataCollection message,
ConnectionEstablishedResult result) {
public void handle(Session session, ZeroMap message, ConnectionEstablishedResult result) {
if (result == ConnectionEstablishedResult.SUCCESS) {
var request = (ZeroMap) message;

api().login(request.getString(SharedEventKey.KEY_PLAYER_LOGIN), session);
api().login(message.getString(SharedEventKey.KEY_PLAYER_LOGIN), session);
}
}
}

@EventHandler
public static class PlayerLoggedInHandler extends AbstractHandler
implements EventPlayerLoggedinResult<Player> {
implements EventPlayerLogin<Player> {

@Override
public void handle(Player player, PlayerLoggedInResult result) {
if (result == PlayerLoggedInResult.SUCCESS) {
var parcel = map().putString(SharedEventKey.KEY_PLAYER_LOGIN,
public void handle(Player player) {
var parcel = map().putString(SharedEventKey.KEY_PLAYER_LOGIN,
String.format("Welcome to server: %s", player.getName()));

response().setContent(parcel.toBinary()).setRecipientPlayer(player).write();
}
response().setContent(parcel.toBinary()).setRecipientPlayer(player).write();
}
}

@EventHandler
public static class ReceivedMessageFromPlayerHandler extends AbstractHandler
implements EventReceivedMessageFromPlayer<Player> {
implements EventReceivedMessageFromPlayer<Player, ZeroMap> {

@Override
public void handle(Player player, DataCollection message) {
public void handle(Player player, ZeroMap message) {
var parcel =
map().putString(SharedEventKey.KEY_CLIENT_SERVER_ECHO, String.format("Echo(%s): %s",
player.getName(),
((ZeroMap) message).getString(SharedEventKey.KEY_CLIENT_SERVER_ECHO)));
message.getString(SharedEventKey.KEY_CLIENT_SERVER_ECHO)));

response().setContent(parcel.toBinary()).setRecipientPlayer(player).write();
}
Expand Down
1 change: 1 addition & 0 deletions examples/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions examples/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,7 @@
## 0.6.6 2025-09-01 Feature release
- Upgraded dependencies
- Removed unnecessary wrapper methods

## 0.6.7 2025-09-02 Feature release
- Upgraded dependencies
- Adapted new APIs
31 changes: 13 additions & 18 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ This project contains a collection of examples that show you how to manipulate t

## Dependencies
```txt
- tenio-core 0.6.6
- tenio-engine 0.6.4
- tenio-core 0.6.7
- tenio-engine 0.6.5
```

## Requirements
Expand Down Expand Up @@ -85,44 +85,39 @@ public final class TestSimpleServer {

@EventHandler
public static class ConnectionEstablishedHandler extends AbstractHandler
implements EventConnectionEstablishedResult {
implements EventConnectionEstablishedResult<ZeroMap> {

@Override
public void handle(Session session, DataCollection message,
ConnectionEstablishedResult result) {
public void handle(Session session, ZeroMap message, ConnectionEstablishedResult result) {
if (result == ConnectionEstablishedResult.SUCCESS) {
var request = (ZeroMap) message;

api().login(request.getString(SharedEventKey.KEY_PLAYER_LOGIN), session);
api().login(message.getString(SharedEventKey.KEY_PLAYER_LOGIN), session);
}
}
}

@EventHandler
public static class PlayerLoggedInHandler extends AbstractHandler
implements EventPlayerLoggedinResult<Player> {
implements EventPlayerLogin<Player> {

@Override
public void handle(Player player, PlayerLoggedInResult result) {
if (result == PlayerLoggedInResult.SUCCESS) {
var parcel = map().putString(SharedEventKey.KEY_PLAYER_LOGIN,
String.format("Welcome to server: %s", player.getName()));
public void handle(Player player) {
var parcel = map().putString(SharedEventKey.KEY_PLAYER_LOGIN,
String.format("Welcome to server: %s", player.getName()));

response().setContent(parcel.toBinary()).setRecipientPlayer(player).write();
}
response().setContent(parcel.toBinary()).setRecipientPlayer(player).write();
}
}

@EventHandler
public static class ReceivedMessageFromPlayerHandler extends AbstractHandler
implements EventReceivedMessageFromPlayer<Player> {
implements EventReceivedMessageFromPlayer<Player, ZeroMap> {

@Override
public void handle(Player player, DataCollection message) {
public void handle(Player player, ZeroMap message) {
var parcel =
map().putString(SharedEventKey.KEY_CLIENT_SERVER_ECHO, String.format("Echo(%s): %s",
player.getName(),
((ZeroMap) message).getString(SharedEventKey.KEY_CLIENT_SERVER_ECHO)));
message.getString(SharedEventKey.KEY_CLIENT_SERVER_ECHO)));

response().setContent(parcel.toBinary()).setRecipientPlayer(player).write();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20250901.0.6.6
20250902.0.6.7
1 change: 0 additions & 1 deletion examples/configuration.example0.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
<Task name="system-monitoring-interval">60</Task> <!-- Unit: Seconds -->
</Schedules>
<Properties>
<Property name="data-serialization">zero</Property>
<Property name="max-request-queue-size">100</Property>
<Property name="max-response-queue-size-per-session">100</Property>
<!-- When the server get disconnection of one client, can be hold its
Expand Down
1 change: 0 additions & 1 deletion examples/configuration.example1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
<Task name="system-monitoring-interval">60</Task> <!-- Unit: Seconds -->
</Schedules>
<Properties>
<Property name="data-serialization">msgpack</Property>
<Property name="max-request-queue-size">100</Property>
<Property name="max-response-queue-size-per-session">100</Property>
<!-- When the server get disconnection of one client, can be hold its
Expand Down
1 change: 0 additions & 1 deletion examples/configuration.example10.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
<Task name="system-monitoring-interval">60</Task> <!-- Unit: Seconds -->
</Schedules>
<Properties>
<Property name="data-serialization">msgpack</Property>
<Property name="max-request-queue-size">100</Property>
<Property name="max-response-queue-size-per-session">100</Property>
<!-- When the server get disconnection of one client, can be hold its
Expand Down
1 change: 0 additions & 1 deletion examples/configuration.example11.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
<Task name="system-monitoring-interval">60</Task> <!-- Unit: Seconds -->
</Schedules>
<Properties>
<Property name="data-serialization">zero</Property>
<Property name="max-request-queue-size">100</Property>
<Property name="max-response-queue-size-per-session">100</Property>
<!-- When the server get disconnection of one client, can be hold its
Expand Down
1 change: 0 additions & 1 deletion examples/configuration.example3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
<Task name="system-monitoring-interval">60</Task> <!-- Unit: Seconds -->
</Schedules>
<Properties>
<Property name="data-serialization">zero</Property>
<Property name="max-request-queue-size">100</Property>
<Property name="max-response-queue-size-per-session">100</Property>
<!-- When the server get disconnection of one client, can be hold its
Expand Down
1 change: 0 additions & 1 deletion examples/configuration.example4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
<Task name="system-monitoring-interval">60</Task> <!-- Unit: Seconds -->
</Schedules>
<Properties>
<Property name="data-serialization">zero</Property>
<Property name="max-request-queue-size">0</Property>
<Property name="max-response-queue-size-per-session">300</Property>
<!-- When the server get disconnection of one client, can be hold its
Expand Down
1 change: 0 additions & 1 deletion examples/configuration.example6.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
<Task name="system-monitoring-interval">60</Task> <!-- Unit: Seconds -->
</Schedules>
<Properties>
<Property name="data-serialization">zero</Property>
<Property name="max-request-queue-size">0</Property>
<Property name="max-response-queue-size-per-session">5000</Property>
<!-- When the server get disconnection of one client, can be hold its
Expand Down
1 change: 0 additions & 1 deletion examples/configuration.example7.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
<Task name="system-monitoring-interval">60</Task> <!-- Unit: Seconds -->
</Schedules>
<Properties>
<Property name="data-serialization">msgpack</Property>
<Property name="max-request-queue-size">100</Property>
<Property name="max-response-queue-size-per-session">100</Property>
<!-- When the server get disconnection of one client, can be hold its
Expand Down
1 change: 0 additions & 1 deletion examples/configuration.example8.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
<Task name="system-monitoring-interval">60</Task> <!-- Unit: Seconds -->
</Schedules>
<Properties>
<Property name="data-serialization">zero</Property>
<Property name="max-request-queue-size">100</Property>
<Property name="max-response-queue-size-per-session">100</Property>
<!-- When the server get disconnection of one client, can be hold its
Expand Down
1 change: 0 additions & 1 deletion examples/configuration.example9.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
<Task name="system-monitoring-interval">60</Task> <!-- Unit: Seconds -->
</Schedules>
<Properties>
<Property name="data-serialization">zero</Property>
<Property name="max-request-queue-size">100</Property>
<Property name="max-response-queue-size-per-session">100</Property>
<!-- When the server get disconnection of one client, can be hold its
Expand Down
8 changes: 4 additions & 4 deletions examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>io.github.congcoi123</groupId>
<artifactId>tenio-examples</artifactId>
<version>0.6.6</version>
<version>0.6.7</version>

<name>${project.groupId}:${project.artifactId}</name>
<description>
Expand Down Expand Up @@ -38,9 +38,9 @@
<jdk.release>17</jdk.release>
<jdk.vendor>oracle</jdk.vendor>

<io.github.congcoi123.tenio.core.version>0.6.6</io.github.congcoi123.tenio.core.version>
<io.github.congcoi123.tenio.engine.version>0.6.4</io.github.congcoi123.tenio.engine.version>
<org.apache.commons.version>3.17.0</org.apache.commons.version>
<io.github.congcoi123.tenio.core.version>0.6.7</io.github.congcoi123.tenio.core.version>
<io.github.congcoi123.tenio.engine.version>0.6.5</io.github.congcoi123.tenio.engine.version>
<org.apache.commons.version>3.18.0</org.apache.commons.version>

<maven.compiler.plugin.version>3.8.0</maven.compiler.plugin.version>
<maven.compiler.target>17</maven.compiler.target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ of this software and associated documentation files (the "Software"), to deal
THE SOFTWARE.
*/

package com.tenio.core.entity.define.result;
package com.tenio.examples.client;

import static org.junit.jupiter.api.Assertions.assertEquals;
import com.tenio.core.network.entity.session.implement.SessionImpl;

import org.junit.jupiter.api.Test;
/**
* The customized session implementation.
*/
public final class CustomSession extends SessionImpl {

class PlayerLoginResultTest {
@Test
void testValueOf() {
assertEquals("SUCCESS", PlayerLoginResult.valueOf("SUCCESS").toString());
public CustomSession() {
super();
createPacketSocketHandler();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ of this software and associated documentation files (the "Software"), to deal

package com.tenio.examples.client;

import com.tenio.common.data.DataCollection;

/**
* This interface helps you listen to all messages these came from the server's
* UDP port.
*/
public interface DatagramListener {
public interface DatagramListener<D extends DataCollection> {

/**
* Listens for upcoming packets.
*
* @param binary an array of {@code byte} data
* @param message the received {@link D} message
*/
void onReceivedUDP(byte[] binary);
void onReceivedUDP(D message);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ of this software and associated documentation files (the "Software"), to deal

package com.tenio.examples.client;

import com.tenio.core.network.zero.codec.compression.BinaryPacketCompressor;
import com.tenio.core.network.codec.compression.BinaryPacketCompressor;

/**
* The default implementation of the binary packet compressor.
Expand All @@ -34,12 +34,12 @@ of this software and associated documentation files (the "Software"), to deal
public final class DefaultBinaryPacketCompressor implements BinaryPacketCompressor {

@Override
public byte[] compress(byte[] binary) {
return binary;
public byte[] compress(byte[] binaries) {
return binaries;
}

@Override
public byte[] uncompress(byte[] binary) {
return binary;
public byte[] uncompress(byte[] binaries) {
return binaries;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ of this software and associated documentation files (the "Software"), to deal

package com.tenio.examples.client;

import com.tenio.core.network.zero.codec.encryption.BinaryPacketEncryptor;
import com.tenio.core.network.codec.encryption.BinaryPacketEncryptor;

/**
* The default implementation for the binary packet encryption.
Expand All @@ -34,12 +34,12 @@ of this software and associated documentation files (the "Software"), to deal
public final class DefaultBinaryPacketEncryptor implements BinaryPacketEncryptor {

@Override
public byte[] decrypt(byte[] binary) {
return binary;
public byte[] decrypt(byte[] binaries) {
return binaries;
}

@Override
public byte[] encrypt(byte[] binary) {
return binary;
public byte[] encrypt(byte[] binaries) {
return binaries;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ of this software and associated documentation files (the "Software"), to deal

package com.tenio.examples.client;

import com.tenio.core.entity.data.ServerMessage;
import com.tenio.common.data.DataCollection;

/**
* This interface helps you listen to all messages these came from the server's
* TCP port.
*/
public interface SocketListener {
public interface SocketListener<D extends DataCollection> {

/**
* Listen for a new message.
* Listen to a new message.
*
* @param message the received message
* @param message the received {@link D} message
*/
void onReceivedTCP(ServerMessage message);
void onReceivedTCP(D message);
}
Loading