Refactoring, dropped unuseful ServerChannel abstraction in favor on Netty's Channel

This commit is contained in:
andsel
2016-01-24 19:21:24 +01:00
parent beb556c73c
commit 7b1db3e1db
13 changed files with 164 additions and 256 deletions
@@ -1,35 +0,0 @@
/*
* Copyright (c) 2012-2015 The original author or authors
* ------------------------------------------------------
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* The Apache License v2.0 is available at
* http://www.opensource.org/licenses/apache2.0.php
*
* You may elect to redistribute this code under either of these licenses.
*/
package io.moquette.server;
import io.netty.util.AttributeKey;
/**
*
* @author andrea
*/
public interface ServerChannel {
Object getAttribute(AttributeKey<Object> key);
void setAttribute(AttributeKey<Object> key, Object value);
void setIdleTime(int idleTime);
void close(boolean immediately);
void write(Object value);
}
@@ -20,13 +20,12 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.timeout.IdleStateHandler;
import io.netty.util.Attribute;
import io.netty.util.AttributeKey;
import io.moquette.server.ServerChannel;
/**
*
* @author andrea
*/
public class NettyChannel implements ServerChannel {
public class NettyChannel {
private ChannelHandlerContext m_channel;
@@ -52,28 +52,28 @@ public class NettyMQTTHandler extends ChannelInboundHandlerAdapter {
m_processor.processConnect(ctx.channel(), (ConnectMessage) msg);
break;
case SUBSCRIBE:
m_processor.processSubscribe(new NettyChannel(ctx), (SubscribeMessage) msg);
m_processor.processSubscribe(ctx.channel(), (SubscribeMessage) msg);
break;
case UNSUBSCRIBE:
m_processor.processUnsubscribe(new NettyChannel(ctx), (UnsubscribeMessage) msg);
m_processor.processUnsubscribe(ctx.channel(), (UnsubscribeMessage) msg);
break;
case PUBLISH:
m_processor.processPublish(new NettyChannel(ctx), (PublishMessage) msg);
m_processor.processPublish(ctx.channel(), (PublishMessage) msg);
break;
case PUBREC:
m_processor.processPubRec(new NettyChannel(ctx), (PubRecMessage) msg);
m_processor.processPubRec(ctx.channel(), (PubRecMessage) msg);
break;
case PUBCOMP:
m_processor.processPubComp(new NettyChannel(ctx), (PubCompMessage) msg);
m_processor.processPubComp(ctx.channel(), (PubCompMessage) msg);
break;
case PUBREL:
m_processor.processPubRel(new NettyChannel(ctx), (PubRelMessage) msg);
m_processor.processPubRel(ctx.channel(), (PubRelMessage) msg);
break;
case DISCONNECT:
m_processor.processDisconnect(new NettyChannel(ctx));
m_processor.processDisconnect(ctx.channel());
break;
case PUBACK:
m_processor.processPubAck(new NettyChannel(ctx), (PubAckMessage) msg);
m_processor.processPubAck(ctx.channel(), (PubAckMessage) msg);
break;
case PINGREQ:
PingRespMessage pingResp = new PingRespMessage();
@@ -27,13 +27,13 @@ import io.netty.util.AttributeKey;
*/
public class NettyUtils {
public static Object getAttribute(ChannelHandlerContext channel, AttributeKey<Object> key) {
Attribute<Object> attr = channel.attr(key);
public static Object getAttribute(ChannelHandlerContext ctx, AttributeKey<Object> key) {
Attribute<Object> attr = ctx.channel().attr(key);
return attr.get();
}
public static void setAttribute(ChannelHandlerContext channel, AttributeKey<Object> key, Object value) {
Attribute<Object> attr = channel.attr(key);
public static void setAttribute(ChannelHandlerContext ctx, AttributeKey<Object> key, Object value) {
Attribute<Object> attr = ctx.channel().attr(key);
attr.set(value);
}