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