Code polish

This commit is contained in:
nathan 2018-01-14 18:22:02 +01:00
parent 72068e07e2
commit 404e54bff8
3 changed files with 19 additions and 28 deletions

View File

@ -17,8 +17,6 @@ package dorkbox.network.connection.registration.local;
import static dorkbox.network.connection.EndPointBase.maxShutdownWaitTimeInMilliSeconds;
import org.slf4j.Logger;
import dorkbox.network.connection.Connection;
import dorkbox.network.connection.RegistrationWrapper;
import dorkbox.network.connection.registration.MetaChannel;
@ -50,14 +48,11 @@ class RegistrationLocalHandler<C extends Connection> extends RegistrationHandler
MetaChannel metaChannel = new MetaChannel();
metaChannel.localChannel = channel;
this.registrationWrapper.addChannel(channel.hashCode(), metaChannel);
registrationWrapper.addChannel(channel.hashCode(), metaChannel);
Logger logger2 = this.logger;
if (logger2.isTraceEnabled()) {
logger2.trace("New LOCAL connection.");
}
logger.trace("New LOCAL connection.");
this.registrationWrapper.connection0(metaChannel);
registrationWrapper.connection0(metaChannel);
}
@Override
@ -65,10 +60,10 @@ class RegistrationLocalHandler<C extends Connection> extends RegistrationHandler
void exceptionCaught(ChannelHandlerContext context, Throwable cause) throws Exception {
Channel channel = context.channel();
this.logger.error(
"Unexpected exception while trying to receive data on LOCAL channel. ({})" + System.getProperty("line.separator"),
channel.remoteAddress(),
cause);
logger.error("Unexpected exception while trying to receive data on LOCAL channel. ({})" + System.getProperty("line.separator"),
channel.remoteAddress(),
cause);
if (channel.isOpen()) {
channel.close();
}
@ -86,7 +81,7 @@ class RegistrationLocalHandler<C extends Connection> extends RegistrationHandler
void channelInactive(ChannelHandlerContext context) throws Exception {
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.
registrationWrapper.closeChannel(channel, maxShutdownWaitTimeInMilliSeconds);

View File

@ -50,10 +50,10 @@ class RegistrationLocalHandlerClient<C extends Connection> extends RegistrationL
super.channelActive(context);
Channel channel = context.channel();
this.logger.info("Connected to LOCAL connection. [{} ==> {}]",
context.channel()
.localAddress(),
channel.remoteAddress());
logger.info("Connected to LOCAL connection. [{} ==> {}]",
context.channel()
.localAddress(),
channel.remoteAddress());
// client starts the registration process
channel.writeAndFlush(new Registration());

View File

@ -23,7 +23,6 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.util.ReferenceCountUtil;
import org.slf4j.Logger;
public
class RegistrationLocalHandlerServer<C extends Connection> extends RegistrationLocalHandler<C> {
@ -48,10 +47,10 @@ class RegistrationLocalHandlerServer<C extends Connection> extends RegistrationL
public
void channelActive(ChannelHandlerContext context) throws Exception {
Channel channel = context.channel();
this.logger.info("Connected to LOCAL connection. [{} <== {}]",
context.channel()
.localAddress(),
channel.remoteAddress());
logger.info("Connected to LOCAL connection. [{} <== {}]",
context.channel()
.localAddress(),
channel.remoteAddress());
super.channelActive(context);
@ -70,13 +69,10 @@ class RegistrationLocalHandlerServer<C extends Connection> extends RegistrationL
channel.writeAndFlush(message);
ReferenceCountUtil.release(message);
Logger logger2 = this.logger;
if (logger2.isTraceEnabled()) {
logger2.trace("Sent registration");
}
logger.trace("Sent registration");
ConnectionImpl connection = null;
MetaChannel metaChannel = this.registrationWrapper.removeChannel(channel.hashCode());
MetaChannel metaChannel = registrationWrapper.removeChannel(channel.hashCode());
if (metaChannel != null) {
connection = metaChannel.connection;
}
@ -99,7 +95,7 @@ class RegistrationLocalHandlerServer<C extends Connection> extends RegistrationL
// have to setup connection handler
pipeline.addLast(CONNECTION_HANDLER, connection);
this.registrationWrapper.connectionConnected0(connection);
registrationWrapper.connectionConnected0(connection);
}
}
}