Code polish
This commit is contained in:
parent
72068e07e2
commit
404e54bff8
@ -17,8 +17,6 @@ package dorkbox.network.connection.registration.local;
|
|||||||
|
|
||||||
import static dorkbox.network.connection.EndPointBase.maxShutdownWaitTimeInMilliSeconds;
|
import static dorkbox.network.connection.EndPointBase.maxShutdownWaitTimeInMilliSeconds;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
import dorkbox.network.connection.Connection;
|
import dorkbox.network.connection.Connection;
|
||||||
import dorkbox.network.connection.RegistrationWrapper;
|
import dorkbox.network.connection.RegistrationWrapper;
|
||||||
import dorkbox.network.connection.registration.MetaChannel;
|
import dorkbox.network.connection.registration.MetaChannel;
|
||||||
@ -50,14 +48,11 @@ class RegistrationLocalHandler<C extends Connection> extends RegistrationHandler
|
|||||||
MetaChannel metaChannel = new MetaChannel();
|
MetaChannel metaChannel = new MetaChannel();
|
||||||
metaChannel.localChannel = channel;
|
metaChannel.localChannel = channel;
|
||||||
|
|
||||||
this.registrationWrapper.addChannel(channel.hashCode(), metaChannel);
|
registrationWrapper.addChannel(channel.hashCode(), metaChannel);
|
||||||
|
|
||||||
Logger logger2 = this.logger;
|
logger.trace("New LOCAL connection.");
|
||||||
if (logger2.isTraceEnabled()) {
|
|
||||||
logger2.trace("New LOCAL connection.");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.registrationWrapper.connection0(metaChannel);
|
registrationWrapper.connection0(metaChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -65,10 +60,10 @@ class RegistrationLocalHandler<C extends Connection> extends RegistrationHandler
|
|||||||
void exceptionCaught(ChannelHandlerContext context, Throwable cause) throws Exception {
|
void exceptionCaught(ChannelHandlerContext context, Throwable cause) throws Exception {
|
||||||
Channel channel = context.channel();
|
Channel channel = context.channel();
|
||||||
|
|
||||||
this.logger.error(
|
logger.error("Unexpected exception while trying to receive data on LOCAL channel. ({})" + System.getProperty("line.separator"),
|
||||||
"Unexpected exception while trying to receive data on LOCAL channel. ({})" + System.getProperty("line.separator"),
|
channel.remoteAddress(),
|
||||||
channel.remoteAddress(),
|
cause);
|
||||||
cause);
|
|
||||||
if (channel.isOpen()) {
|
if (channel.isOpen()) {
|
||||||
channel.close();
|
channel.close();
|
||||||
}
|
}
|
||||||
@ -86,7 +81,7 @@ class RegistrationLocalHandler<C extends Connection> extends RegistrationHandler
|
|||||||
void channelInactive(ChannelHandlerContext context) throws Exception {
|
void channelInactive(ChannelHandlerContext context) throws Exception {
|
||||||
Channel channel = context.channel();
|
Channel channel = context.channel();
|
||||||
|
|
||||||
this.logger.info("Closed LOCAL connection: {}", channel.remoteAddress());
|
logger.info("Closed LOCAL connection: {}", channel.remoteAddress());
|
||||||
|
|
||||||
// also, once we notify, we unregister this.
|
// also, once we notify, we unregister this.
|
||||||
registrationWrapper.closeChannel(channel, maxShutdownWaitTimeInMilliSeconds);
|
registrationWrapper.closeChannel(channel, maxShutdownWaitTimeInMilliSeconds);
|
||||||
|
@ -50,10 +50,10 @@ class RegistrationLocalHandlerClient<C extends Connection> extends RegistrationL
|
|||||||
super.channelActive(context);
|
super.channelActive(context);
|
||||||
|
|
||||||
Channel channel = context.channel();
|
Channel channel = context.channel();
|
||||||
this.logger.info("Connected to LOCAL connection. [{} ==> {}]",
|
logger.info("Connected to LOCAL connection. [{} ==> {}]",
|
||||||
context.channel()
|
context.channel()
|
||||||
.localAddress(),
|
.localAddress(),
|
||||||
channel.remoteAddress());
|
channel.remoteAddress());
|
||||||
|
|
||||||
// client starts the registration process
|
// client starts the registration process
|
||||||
channel.writeAndFlush(new Registration());
|
channel.writeAndFlush(new Registration());
|
||||||
|
@ -23,7 +23,6 @@ import io.netty.channel.Channel;
|
|||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelPipeline;
|
import io.netty.channel.ChannelPipeline;
|
||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
public
|
public
|
||||||
class RegistrationLocalHandlerServer<C extends Connection> extends RegistrationLocalHandler<C> {
|
class RegistrationLocalHandlerServer<C extends Connection> extends RegistrationLocalHandler<C> {
|
||||||
@ -48,10 +47,10 @@ class RegistrationLocalHandlerServer<C extends Connection> extends RegistrationL
|
|||||||
public
|
public
|
||||||
void channelActive(ChannelHandlerContext context) throws Exception {
|
void channelActive(ChannelHandlerContext context) throws Exception {
|
||||||
Channel channel = context.channel();
|
Channel channel = context.channel();
|
||||||
this.logger.info("Connected to LOCAL connection. [{} <== {}]",
|
logger.info("Connected to LOCAL connection. [{} <== {}]",
|
||||||
context.channel()
|
context.channel()
|
||||||
.localAddress(),
|
.localAddress(),
|
||||||
channel.remoteAddress());
|
channel.remoteAddress());
|
||||||
|
|
||||||
|
|
||||||
super.channelActive(context);
|
super.channelActive(context);
|
||||||
@ -70,13 +69,10 @@ class RegistrationLocalHandlerServer<C extends Connection> extends RegistrationL
|
|||||||
channel.writeAndFlush(message);
|
channel.writeAndFlush(message);
|
||||||
|
|
||||||
ReferenceCountUtil.release(message);
|
ReferenceCountUtil.release(message);
|
||||||
Logger logger2 = this.logger;
|
logger.trace("Sent registration");
|
||||||
if (logger2.isTraceEnabled()) {
|
|
||||||
logger2.trace("Sent registration");
|
|
||||||
}
|
|
||||||
|
|
||||||
ConnectionImpl connection = null;
|
ConnectionImpl connection = null;
|
||||||
MetaChannel metaChannel = this.registrationWrapper.removeChannel(channel.hashCode());
|
MetaChannel metaChannel = registrationWrapper.removeChannel(channel.hashCode());
|
||||||
if (metaChannel != null) {
|
if (metaChannel != null) {
|
||||||
connection = metaChannel.connection;
|
connection = metaChannel.connection;
|
||||||
}
|
}
|
||||||
@ -99,7 +95,7 @@ class RegistrationLocalHandlerServer<C extends Connection> extends RegistrationL
|
|||||||
// have to setup connection handler
|
// have to setup connection handler
|
||||||
pipeline.addLast(CONNECTION_HANDLER, connection);
|
pipeline.addLast(CONNECTION_HANDLER, connection);
|
||||||
|
|
||||||
this.registrationWrapper.connectionConnected0(connection);
|
registrationWrapper.connectionConnected0(connection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user