mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-07-08 23:07:46 +07:00
Modified generics with API - endpoint should work with any Object as QoS param
This commit is contained in:
@ -2,7 +2,7 @@ package com.riiablo.net;
|
|||||||
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
|
||||||
public interface Endpoint<T, Q> extends PacketSender<Q> {
|
public interface Endpoint<T> extends PacketSender<Object> {
|
||||||
void reset();
|
void reset();
|
||||||
void update(float delta);
|
void update(float delta);
|
||||||
void messageReceived(ChannelHandlerContext ctx, T msg);
|
void messageReceived(ChannelHandlerContext ctx, T msg);
|
||||||
|
@ -15,7 +15,7 @@ import java.net.SocketAddress;
|
|||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
|
|
||||||
public class EndpointedChannelHandler<T, Q> implements ChannelHandler, ChannelInboundHandler, ChannelOutboundHandler {
|
public class EndpointedChannelHandler<T> implements ChannelHandler, ChannelInboundHandler, ChannelOutboundHandler {
|
||||||
private static final String TAG = "EndpointedChannelHandler";
|
private static final String TAG = "EndpointedChannelHandler";
|
||||||
|
|
||||||
private static final boolean DEBUG = true;
|
private static final boolean DEBUG = true;
|
||||||
@ -24,9 +24,9 @@ public class EndpointedChannelHandler<T, Q> implements ChannelHandler, ChannelIn
|
|||||||
private static final boolean DEBUG_OUTBOUND = DEBUG && true;
|
private static final boolean DEBUG_OUTBOUND = DEBUG && true;
|
||||||
|
|
||||||
private final TypeParameterMatcher matcher;
|
private final TypeParameterMatcher matcher;
|
||||||
private final Endpoint<T, Q> endpoint;
|
private final Endpoint<T> endpoint;
|
||||||
|
|
||||||
public EndpointedChannelHandler(Class<T> packetType, Endpoint<T, Q> endpoint) {
|
public EndpointedChannelHandler(Class<T> packetType, Endpoint<T> endpoint) {
|
||||||
this.endpoint = endpoint;
|
this.endpoint = endpoint;
|
||||||
matcher = TypeParameterMatcher.get(packetType);
|
matcher = TypeParameterMatcher.get(packetType);
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ import com.riiablo.net.reliable.channel.UnreliableMessageChannel;
|
|||||||
import com.riiablo.net.reliable.channel.UnreliableOrderedMessageChannel;
|
import com.riiablo.net.reliable.channel.UnreliableOrderedMessageChannel;
|
||||||
import com.riiablo.util.EnumIntMap;
|
import com.riiablo.util.EnumIntMap;
|
||||||
|
|
||||||
public class ReliableEndpoint implements Endpoint<DatagramPacket, QoS>, MessageChannel.PacketTransceiver {
|
public class ReliableEndpoint implements Endpoint<DatagramPacket>, MessageChannel.PacketTransceiver {
|
||||||
private static final String TAG = "ReliableEndpoint";
|
private static final String TAG = "ReliableEndpoint";
|
||||||
|
|
||||||
private static final boolean DEBUG = true;
|
private static final boolean DEBUG = true;
|
||||||
@ -69,10 +69,11 @@ public class ReliableEndpoint implements Endpoint<DatagramPacket, QoS>, MessageC
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(QoS qos, ByteBuffer bb) {
|
public void sendMessage(Object qos, ByteBuffer bb) {
|
||||||
if (DEBUG_SEND) Log.debug(TAG, "sendMessage");
|
if (DEBUG_SEND) Log.debug(TAG, "sendMessage");
|
||||||
if (DEBUG_QOS) Log.debug(TAG, "sending message with %s QoS (0x%02x)", qos, qos.ordinal());
|
assert qos instanceof QoS;
|
||||||
int channelId = defaultChannels.get(qos);
|
if (DEBUG_QOS) Log.debug(TAG, "sending message with %s QoS (0x%02x)", qos, ((QoS) qos).ordinal());
|
||||||
|
int channelId = defaultChannels.get((QoS) qos);
|
||||||
sendMessage(channelId, bb);
|
sendMessage(channelId, bb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ public class TestClient extends ApplicationAdapter implements PacketProcessor {
|
|||||||
new HeadlessApplication(new TestClient(), config);
|
new HeadlessApplication(new TestClient(), config);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Endpoint<DatagramPacket, QoS> endpoint;
|
private Endpoint<?> endpoint;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create() {
|
public void create() {
|
||||||
@ -51,7 +51,8 @@ public class TestClient extends ApplicationAdapter implements PacketProcessor {
|
|||||||
.handler(new ChannelInitializer<DatagramChannel>() {
|
.handler(new ChannelInitializer<DatagramChannel>() {
|
||||||
@Override
|
@Override
|
||||||
protected void initChannel(DatagramChannel ch) {
|
protected void initChannel(DatagramChannel ch) {
|
||||||
endpoint = new ReliableEndpoint(ch, TestClient.this);
|
Endpoint<DatagramPacket> endpoint = new ReliableEndpoint(ch, TestClient.this);
|
||||||
|
TestClient.this.endpoint = endpoint;
|
||||||
ch.pipeline()
|
ch.pipeline()
|
||||||
.addLast(new EndpointedChannelHandler<>(DatagramPacket.class, endpoint))
|
.addLast(new EndpointedChannelHandler<>(DatagramPacket.class, endpoint))
|
||||||
;
|
;
|
||||||
@ -65,6 +66,7 @@ public class TestClient extends ApplicationAdapter implements PacketProcessor {
|
|||||||
Gdx.app.error(TAG, t.getMessage(), t);
|
Gdx.app.error(TAG, t.getMessage(), t);
|
||||||
} finally {
|
} finally {
|
||||||
group.shutdownGracefully();
|
group.shutdownGracefully();
|
||||||
|
Gdx.app.exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ public class TestServer extends ApplicationAdapter implements PacketProcessor {
|
|||||||
new HeadlessApplication(new TestServer(), config);
|
new HeadlessApplication(new TestServer(), config);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Endpoint<DatagramPacket, QoS> endpoint;
|
private Endpoint<?> endpoint;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create() {
|
public void create() {
|
||||||
@ -52,7 +52,8 @@ public class TestServer extends ApplicationAdapter implements PacketProcessor {
|
|||||||
.handler(new ChannelInitializer<DatagramChannel>() {
|
.handler(new ChannelInitializer<DatagramChannel>() {
|
||||||
@Override
|
@Override
|
||||||
protected void initChannel(DatagramChannel ch) {
|
protected void initChannel(DatagramChannel ch) {
|
||||||
endpoint = new ReliableEndpoint(ch, TestServer.this);
|
ReliableEndpoint endpoint = new ReliableEndpoint(ch, TestServer.this);
|
||||||
|
TestServer.this.endpoint = endpoint;
|
||||||
ch.pipeline()
|
ch.pipeline()
|
||||||
.addLast(new EndpointedChannelHandler<>(DatagramPacket.class, endpoint))
|
.addLast(new EndpointedChannelHandler<>(DatagramPacket.class, endpoint))
|
||||||
;
|
;
|
||||||
@ -66,6 +67,7 @@ public class TestServer extends ApplicationAdapter implements PacketProcessor {
|
|||||||
Gdx.app.error(TAG, t.getMessage(), t);
|
Gdx.app.error(TAG, t.getMessage(), t);
|
||||||
} finally {
|
} finally {
|
||||||
group.shutdownGracefully();
|
group.shutdownGracefully();
|
||||||
|
Gdx.app.exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ import com.badlogic.gdx.Gdx;
|
|||||||
import com.riiablo.net.Endpoint;
|
import com.riiablo.net.Endpoint;
|
||||||
import com.riiablo.net.PacketProcessor;
|
import com.riiablo.net.PacketProcessor;
|
||||||
|
|
||||||
public class TcpEndpoint implements Endpoint<ByteBuf, Object> {
|
public class TcpEndpoint implements Endpoint<ByteBuf> {
|
||||||
private static final String TAG = "TcpEndpoint";
|
private static final String TAG = "TcpEndpoint";
|
||||||
|
|
||||||
private static final boolean DEBUG = true;
|
private static final boolean DEBUG = true;
|
||||||
|
@ -38,7 +38,7 @@ public class TestClient extends ApplicationAdapter implements PacketProcessor {
|
|||||||
new HeadlessApplication(new TestClient(), config);
|
new HeadlessApplication(new TestClient(), config);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Endpoint<ByteBuf, Object> endpoint;
|
private Endpoint<?> endpoint;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create() {
|
public void create() {
|
||||||
@ -53,7 +53,8 @@ public class TestClient extends ApplicationAdapter implements PacketProcessor {
|
|||||||
.handler(new ChannelInitializer<SocketChannel>() {
|
.handler(new ChannelInitializer<SocketChannel>() {
|
||||||
@Override
|
@Override
|
||||||
protected void initChannel(SocketChannel ch) {
|
protected void initChannel(SocketChannel ch) {
|
||||||
endpoint = new TcpEndpoint(ch, TestClient.this);
|
Endpoint<ByteBuf> endpoint = new TcpEndpoint(ch, TestClient.this);
|
||||||
|
TestClient.this.endpoint = endpoint;
|
||||||
ch.pipeline()
|
ch.pipeline()
|
||||||
.addLast(new EndpointedChannelHandler<>(ByteBuf.class, endpoint))
|
.addLast(new EndpointedChannelHandler<>(ByteBuf.class, endpoint))
|
||||||
;
|
;
|
||||||
|
@ -33,7 +33,7 @@ public class TestServer extends ApplicationAdapter implements PacketProcessor {
|
|||||||
new HeadlessApplication(new TestServer(), config);
|
new HeadlessApplication(new TestServer(), config);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Endpoint<ByteBuf, Object> endpoint;
|
private Endpoint<?> endpoint;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create() {
|
public void create() {
|
||||||
@ -48,7 +48,8 @@ public class TestServer extends ApplicationAdapter implements PacketProcessor {
|
|||||||
.childHandler(new ChannelInitializer<SocketChannel>() {
|
.childHandler(new ChannelInitializer<SocketChannel>() {
|
||||||
@Override
|
@Override
|
||||||
protected void initChannel(SocketChannel ch) {
|
protected void initChannel(SocketChannel ch) {
|
||||||
endpoint = new TcpEndpoint(ch, TestServer.this);
|
TcpEndpoint endpoint = new TcpEndpoint(ch, TestServer.this);
|
||||||
|
TestServer.this.endpoint = endpoint;
|
||||||
ch.pipeline()
|
ch.pipeline()
|
||||||
.addLast(new EndpointedChannelHandler<>(ByteBuf.class, endpoint))
|
.addLast(new EndpointedChannelHandler<>(ByteBuf.class, endpoint))
|
||||||
;
|
;
|
||||||
|
Reference in New Issue
Block a user