Hello, i'm picking up on an old project and it's using Netty 3.2.4, I was 
wondering I could get some help or someone to point me in the right 
direction with this. (I've checked the what's new and noteworthy in 4.0 
already).

Basically I'm using netty for inter-channel communication between servers. 
The center server is the main one, it interconnects with a login and world 
server.

My remote listener is something like this: 

    public RemoteServerListener(String password, boolean useNio) {
        this.interServerPassword = password;
        ChannelFactory chFactory;
        if (useNio) {
            chFactory = new NioServerSocketChannelFactory(
                    Executors.newSingleThreadExecutor(),
                    Executors.newCachedThreadPool()
            );
        } else {
            chFactory = new OioServerSocketChannelFactory(
                    Executors.newSingleThreadExecutor(),
                    Executors.newCachedThreadPool()
            );
        }
        this.bootstrap = new ServerBootstrap(chFactory);
        this.bootstrap.setPipelineFactory(() -> {
            ChannelPipeline pipeline = Channels.pipeline();
            pipeline.addLast("decoder", new InterServerPacketDecoder());
            pipeline.addLast("encoder", new InterServerPacketEncoder());
            pipeline.addLast("handler", new CenterServerHandler());
            return pipeline;
        });
        bootstrap.setOption("child.bufferFactory", new 
HeapChannelBufferFactory(ByteOrder.LITTLE_ENDIAN));
    }

    public boolean bind(int port) {
        try {
            bootstrap.bind(new InetSocketAddress(port));
            LOG.log(Level.INFO, "Listening on port {0}", port);
            return true;
        } catch (ChannelException ex) {
            LOG.log(Level.SEVERE, "Could not bind on port " + port, ex);
            return false;
        }
    }

So I know that Netty 4 no longer uses OIO so I could get rid of that and 
what not. But the way I initiate this is in my main center server class 
like this:

 public void init() { 
      listener = new RemoteServerListener(authKey, useNio);
if (listener.bind(port))
LOG.log(Level.INFO, "Center Server is online.");
 }


I noticed that in Netty 4, they have the shutdown and bind hooks directly 
in the Server/Client. How would I still achieve this?

Another thing i'm confused about is in my netty 3 I have this:

 public static final ChannelLocal<CenterRemoteSession> sessions = new 
ChannelLocal<CenterRemoteSession>();

Followed my by CenterServerHandler :

   private class CenterServerHandler extends SimpleChannelUpstreamHandler {

        @Override
        public void channelOpen(ChannelHandlerContext ctx, 
ChannelStateEvent e) throws Exception {
            LOG.log(Level.FINEST, "Trying to accept remote server from 
{0}", e.getChannel().getRemoteAddress());
        }

        @Override
        public void channelConnected(ChannelHandlerContext ctx, 
ChannelStateEvent e) throws Exception {
            LOG.log(Level.FINE, "Remote server connected from {0}", 
e.getChannel().getRemoteAddress());
            sessions.set(e.getChannel(), new 
CenterRemoteSession(e.getChannel(), interServerPassword));
        }

        @Override
        public void channelDisconnected(ChannelHandlerContext ctx, 
ChannelStateEvent e) throws Exception {
            LOG.log(Level.FINE, "Remote server from {0} disconnected", 
e.getChannel().getRemoteAddress());
            sessions.get(e.getChannel()).disconnected();
        }

        @Override
        public void channelClosed(ChannelHandlerContext ctx, 
ChannelStateEvent e) throws Exception {
            LOG.log(Level.FINEST, "Removing remote server from {0}", 
e.getChannel().getRemoteAddress());
            sessions.remove(e.getChannel());
        }

        @Override
        public void messageReceived(ChannelHandlerContext ctx, MessageEvent 
e) {
            sessions.get(e.getChannel()).process((byte[]) e.getMessage());
        }

        @Override
        public void exceptionCaught(ChannelHandlerContext ctx, 
ExceptionEvent e) {
            LOG.log(Level.FINE, "Exception raised in internal network 
facing code (remote server " + e.getChannel().getRemoteAddress() + ")", 
e.getCause());
        }
    }

In Netty 4 there is no ChannelLocal, so how would I go about doing this?

I also know that in netty 4, that channelDisconnected and channelClosed has 
been merged into one. so which method would I use since my above 2 methods 
for closed and disconnected do 2 different things.

Also one of my game server handler has this: 
 private class GameServerHandler extends 
IdleStateAwareChannelUpstreamHandler {

 } 






-- 
You received this message because you are subscribed to the Google Groups 
"Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netty+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/netty/a3ae7fc1-4126-4851-8b99-66d6114a6714%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to