Integrated by hand part of the pull request #13 'fix pom and clean deprecated class and add bat file to windows'

This commit is contained in:
andrea
2015-03-04 22:40:56 +01:00
parent 443682f24f
commit 4baf407657
10 changed files with 69 additions and 21 deletions
@@ -34,9 +34,9 @@ public class NettyChannel implements ServerChannel {
private Map<Object, AttributeKey<Object>> m_attributesKeys = new HashMap<Object, AttributeKey<Object>>(); private Map<Object, AttributeKey<Object>> m_attributesKeys = new HashMap<Object, AttributeKey<Object>>();
private static final AttributeKey<Object> ATTR_KEY_KEEPALIVE = new AttributeKey<Object>(Constants.KEEP_ALIVE); private static final AttributeKey<Object> ATTR_KEY_KEEPALIVE = AttributeKey.valueOf(Constants.KEEP_ALIVE);
private static final AttributeKey<Object> ATTR_KEY_CLEANSESSION = new AttributeKey<Object>(Constants.CLEAN_SESSION); private static final AttributeKey<Object> ATTR_KEY_CLEANSESSION = AttributeKey.valueOf(Constants.CLEAN_SESSION);
private static final AttributeKey<Object> ATTR_KEY_CLIENTID = new AttributeKey<Object>(Constants.ATTR_CLIENTID); private static final AttributeKey<Object> ATTR_KEY_CLIENTID = AttributeKey.valueOf(Constants.ATTR_CLIENTID);
NettyChannel(ChannelHandlerContext ctx) { NettyChannel(ChannelHandlerContext ctx) {
m_channel = ctx; m_channel = ctx;
@@ -24,7 +24,7 @@ import io.netty.util.AttributeKey;
public class BytesMetricsHandler extends ChannelDuplexHandler { public class BytesMetricsHandler extends ChannelDuplexHandler {
private static final AttributeKey<BytesMetrics> ATTR_KEY_METRICS = new AttributeKey<BytesMetrics>("BytesMetrics"); private static final AttributeKey<BytesMetrics> ATTR_KEY_METRICS = AttributeKey.valueOf("BytesMetrics");
private BytesMetricsCollector m_collector; private BytesMetricsCollector m_collector;
@@ -23,7 +23,7 @@ import io.netty.util.AttributeKey;
public class MessageMetricsHandler extends ChannelDuplexHandler { public class MessageMetricsHandler extends ChannelDuplexHandler {
private static final AttributeKey<MessageMetrics> ATTR_KEY_METRICS = new AttributeKey<MessageMetrics>("MessageMetrics"); private static final AttributeKey<MessageMetrics> ATTR_KEY_METRICS = AttributeKey.valueOf("MessageMetrics");
private MessageMetricsCollector m_collector; private MessageMetricsCollector m_collector;
@@ -85,7 +85,7 @@ public class SimpleMessaging implements IMessaging, EventHandler<ValueEvent> {
public void init(Properties configProps) { public void init(Properties configProps) {
subscriptions = new SubscriptionsStore(); subscriptions = new SubscriptionsStore();
m_executor = Executors.newFixedThreadPool(1); m_executor = Executors.newFixedThreadPool(1);
m_disruptor = new Disruptor<ValueEvent>(ValueEvent.EVENT_FACTORY, 1024 * 32, m_executor); m_disruptor = new Disruptor<>(ValueEvent.EVENT_FACTORY, 1024 * 32, m_executor);
/*Disruptor<ValueEvent> m_disruptor = new Disruptor<ValueEvent>(ValueEvent.EVENT_FACTORY, 1024 * 32, m_executor, /*Disruptor<ValueEvent> m_disruptor = new Disruptor<ValueEvent>(ValueEvent.EVENT_FACTORY, 1024 * 32, m_executor,
ProducerType.MULTI, new BusySpinWaitStrategy());*/ ProducerType.MULTI, new BusySpinWaitStrategy());*/
m_disruptor.handleEventsWith(this); m_disruptor.handleEventsWith(this);
@@ -200,7 +200,7 @@ public class SubscriptionsStore {
} catch (ParseException ex) { } catch (ParseException ex) {
//TODO handle the parse exception //TODO handle the parse exception
LOG.error(null, ex); LOG.error(null, ex);
return Collections.EMPTY_LIST; return Collections.emptyList();
} }
Queue<Token> tokenQueue = new LinkedBlockingDeque<Token>(tokens); Queue<Token> tokenQueue = new LinkedBlockingDeque<Token>(tokens);
@@ -274,7 +274,7 @@ public class SubscriptionsStore {
} }
protected static List<Token> parseTopic(String topic) throws ParseException { protected static List<Token> parseTopic(String topic) throws ParseException {
List res = new ArrayList<Token>(); List<Token> res = new ArrayList<>();
String[] splitted = topic.split("/"); String[] splitted = topic.split("/");
if (splitted.length == 0) { if (splitted.length == 0) {
@@ -46,7 +46,7 @@ public class SubscriptionsStoreTest {
@Test @Test
public void testParseTopic() throws ParseException { public void testParseTopic() throws ParseException {
List tokens = store.parseTopic("finance/stock/ibm"); List<Token> tokens = store.parseTopic("finance/stock/ibm");
assertEqualsSeq(asArray("finance", "stock", "ibm"), tokens); assertEqualsSeq(asArray("finance", "stock", "ibm"), tokens);
tokens = store.parseTopic("/finance/stock/ibm"); tokens = store.parseTopic("/finance/stock/ibm");
@@ -63,7 +63,7 @@ public class SubscriptionsStoreTest {
@Test @Test
public void testParseTopicMultiValid() throws ParseException { public void testParseTopicMultiValid() throws ParseException {
List tokens = store.parseTopic("finance/stock/#"); List<Token> tokens = store.parseTopic("finance/stock/#");
assertEqualsSeq(asArray("finance", "stock", Token.MULTI), tokens); assertEqualsSeq(asArray("finance", "stock", Token.MULTI), tokens);
tokens = store.parseTopic("#"); tokens = store.parseTopic("#");
@@ -82,7 +82,7 @@ public class SubscriptionsStoreTest {
@Test @Test
public void testParseTopicSingleValid() throws ParseException { public void testParseTopicSingleValid() throws ParseException {
List tokens = store.parseTopic("finance/stock/+"); List<Token> tokens = store.parseTopic("finance/stock/+");
assertEqualsSeq(asArray("finance", "stock", Token.SINGLE), tokens); assertEqualsSeq(asArray("finance", "stock", Token.SINGLE), tokens);
tokens = store.parseTopic("+"); tokens = store.parseTopic("+");
@@ -15,6 +15,11 @@
<outputDirectory>bin</outputDirectory> <outputDirectory>bin</outputDirectory>
<fileMode>0755</fileMode> <fileMode>0755</fileMode>
</file> </file>
<file>
<source>src/main/scripts/moquette.bat</source>
<outputDirectory>bin</outputDirectory>
</file>
<file> <file>
<source>src/main/resources/log4j.properties</source> <source>src/main/resources/log4j.properties</source>
@@ -0,0 +1,43 @@
@ECHO OFF
rem #
rem # Copyright (c) 2012-2015 Igor Yova
rem #
echo " "
echo " ___ ___ _ _ ___ ________ _____ _____ "
echo " | \/ | | | | | | \/ | _ |_ _|_ _| "
echo " | . . | ___ __ _ _ _ ___| |_| |_ ___ | . . | | | | | | | | "
echo " | |\/| |/ _ \ / _\ | | | |/ _ \ __| __/ _ \ | |\/| | | | | | | | | "
echo " | | | | (_) | (_| | |_| | __/ |_| || __/ | | | \ \/' / | | | | "
echo " \_| |_/\___/ \__, |\__,_|\___|\__|\__\___| \_| |_/\_/\_\ \_/ \_/ "
echo " | | "
echo " |_| "
echo " "
set "CURRENT_DIR=%cd%"
if not "%MOQUETTE_HOME%" == "" goto gotHome
set "MOQUETTE_HOME=%CURRENT_DIR%"
if exist "%MOQUETTE_HOME%\bin\moquette.bat" goto okHome
cd ..
set "MOQUETTE_HOME=%cd%"
cd "%CURRENT_DIR%"
:gotHome
if exist "%MOQUETTE_HOME%\bin\moquette.bat" goto okHome
echo The MOQUETTE_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
goto end
:okHome
rem Set JavaHome if it exists
if exist { "%JAVA_HOME%\bin\java" } (
set "JAVA="%JAVA_HOME%\bin\java""
)
echo Using JAVA_HOME: "%JAVA_HOME%"
echo Using MOQUETTE_HOME: "%MOQUETTE_HOME%"
rem set LOG_CONSOLE_LEVEL=info
rem set LOG_FILE_LEVEL=fine
set JAVA_OPTS=
set JAVA_OPTS_SCRIPT=-XX:+HeapDumpOnOutOfMemoryError -Djava.awt.headless=true
%JAVA% -server %JAVA_OPTS% %JAVA_OPTS_SCRIPT% -Dlog4j.configuration=file:%LOG_FILE% -Dmoquette.path=%MOQUETTE_PATH% -cp %MOQUETTE_HOME%\lib\moquette-broker-0.7-SNAPSHOT.jar;%MOQUETTE_HOME%\lib\* org.eclipse.moquette.server.Server
@@ -32,8 +32,8 @@ import org.eclipse.moquette.proto.messages.ConnectMessage;
* @author andrea * @author andrea
*/ */
public class ConnectDecoder extends DemuxDecoder { public class ConnectDecoder extends DemuxDecoder {
static final AttributeKey<Boolean> CONNECT_STATUS = new AttributeKey<Boolean>("connected"); static final AttributeKey<Boolean> CONNECT_STATUS = AttributeKey.valueOf("connected");
@Override @Override
void decode(AttributeMap ctx, ByteBuf in, List<Object> out) throws UnsupportedEncodingException { void decode(AttributeMap ctx, ByteBuf in, List<Object> out) throws UnsupportedEncodingException {
@@ -119,17 +119,17 @@ public class ConnectDecoder extends DemuxDecoder {
throw new CorruptedFrameException("Received a CONNECT with connectionFlags[0(bit)] != 0"); throw new CorruptedFrameException("Received a CONNECT with connectionFlags[0(bit)] != 0");
} }
} }
boolean cleanSession = ((connFlags & 0x02) >> 1) == 1 ? true : false; boolean cleanSession = ((connFlags & 0x02) >> 1) == 1;
boolean willFlag = ((connFlags & 0x04) >> 2) == 1 ? true : false; boolean willFlag = ((connFlags & 0x04) >> 2) == 1;
byte willQos = (byte) ((connFlags & 0x18) >> 3); byte willQos = (byte) ((connFlags & 0x18) >> 3);
if (willQos > 2) { if (willQos > 2) {
in.resetReaderIndex(); in.resetReaderIndex();
throw new CorruptedFrameException("Expected will QoS in range 0..2 but found: " + willQos); throw new CorruptedFrameException("Expected will QoS in range 0..2 but found: " + willQos);
} }
boolean willRetain = ((connFlags & 0x20) >> 5) == 1 ? true : false; boolean willRetain = ((connFlags & 0x20) >> 5) == 1;
boolean passwordFlag = ((connFlags & 0x40) >> 6) == 1 ? true : false; boolean passwordFlag = ((connFlags & 0x40) >> 6) == 1;
boolean userFlag = ((connFlags & 0x80) >> 7) == 1 ? true : false; boolean userFlag = ((connFlags & 0x80) >> 7) == 1;
//a password is true iff user is true. //a password is true iff user is true.
if (!userFlag && passwordFlag) { if (!userFlag && passwordFlag) {
in.resetReaderIndex(); in.resetReaderIndex();
@@ -32,9 +32,9 @@ import org.eclipse.moquette.proto.messages.AbstractMessage;
public class MQTTDecoder extends ByteToMessageDecoder { public class MQTTDecoder extends ByteToMessageDecoder {
//3 = 3.1, 4 = 3.1.1 //3 = 3.1, 4 = 3.1.1
static final AttributeKey<Integer> PROTOCOL_VERSION = new AttributeKey<Integer>("version"); static final AttributeKey<Integer> PROTOCOL_VERSION = AttributeKey.valueOf("version");
private final Map<Byte, DemuxDecoder> m_decoderMap = new HashMap<Byte, DemuxDecoder>(); private final Map<Byte, DemuxDecoder> m_decoderMap = new HashMap<>();
public MQTTDecoder() { public MQTTDecoder() {
m_decoderMap.put(AbstractMessage.CONNECT, new ConnectDecoder()); m_decoderMap.put(AbstractMessage.CONNECT, new ConnectDecoder());