Switched the default connector from MINA to Netty
This commit is contained in:
@@ -1,82 +1,82 @@
|
|||||||
package org.dna.mqtt.moquette.server;
|
package org.dna.mqtt.moquette.server;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.dna.mqtt.moquette.messaging.spi.impl.SimpleMessaging;
|
import org.dna.mqtt.moquette.messaging.spi.impl.SimpleMessaging;
|
||||||
import org.dna.mqtt.moquette.server.mina.MinaAcceptor;
|
import org.dna.mqtt.moquette.server.mina.MinaAcceptor;
|
||||||
import org.dna.mqtt.moquette.server.netty.NettyAcceptor;
|
import org.dna.mqtt.moquette.server.netty.NettyAcceptor;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
/**
|
/**
|
||||||
* Launch a configured version of the server.
|
* Launch a configured version of the server.
|
||||||
* @author andrea
|
* @author andrea
|
||||||
*/
|
*/
|
||||||
public class Server {
|
public class Server {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(Server.class);
|
private static final Logger LOG = LoggerFactory.getLogger(Server.class);
|
||||||
|
|
||||||
public static final String STORAGE_FILE_PATH = System.getProperty("user.home") +
|
public static final String STORAGE_FILE_PATH = System.getProperty("user.home") +
|
||||||
File.separator + "moquette_store.hawtdb";
|
File.separator + "moquette_store.hawtdb";
|
||||||
public static String NETTY_NIO_FRAMEWORK = "netty";
|
public static String NETTY_NIO_FRAMEWORK = "netty";
|
||||||
public static String MINA_NIO_FRAMEWORK = "mina";
|
public static String MINA_NIO_FRAMEWORK = "mina";
|
||||||
public static String DEFAULT_NIO_FRAMEWORK = MINA_NIO_FRAMEWORK;
|
public static String DEFAULT_NIO_FRAMEWORK = NETTY_NIO_FRAMEWORK;
|
||||||
|
|
||||||
private ServerAcceptor m_acceptor;
|
private ServerAcceptor m_acceptor;
|
||||||
SimpleMessaging messaging;
|
SimpleMessaging messaging;
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
String nioFrameworkType = DEFAULT_NIO_FRAMEWORK;
|
String nioFrameworkType = DEFAULT_NIO_FRAMEWORK;
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
//TODO check the typing and in case print usge message
|
//TODO check the typing and in case print usge message
|
||||||
nioFrameworkType = args[1];
|
nioFrameworkType = args[1];
|
||||||
if (!(nioFrameworkType.equals(DEFAULT_NIO_FRAMEWORK) ||
|
if (!(nioFrameworkType.equals(DEFAULT_NIO_FRAMEWORK) ||
|
||||||
nioFrameworkType.equals(DEFAULT_NIO_FRAMEWORK))) {
|
nioFrameworkType.equals(DEFAULT_NIO_FRAMEWORK))) {
|
||||||
printUsage(nioFrameworkType);
|
printUsage(nioFrameworkType);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final Server server = new Server();
|
final Server server = new Server();
|
||||||
server.startServer(nioFrameworkType);
|
server.startServer(nioFrameworkType);
|
||||||
//Bind a shutdown hook
|
//Bind a shutdown hook
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
server.stopServer();
|
server.stopServer();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startServer() throws IOException {
|
public void startServer() throws IOException {
|
||||||
startServer(DEFAULT_NIO_FRAMEWORK);
|
startServer(DEFAULT_NIO_FRAMEWORK);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startServer(String nioFrameworkType) throws IOException {
|
public void startServer(String nioFrameworkType) throws IOException {
|
||||||
LOG.info("Starting server with " + nioFrameworkType + " connectors");
|
LOG.info("Starting server with " + nioFrameworkType + " connectors");
|
||||||
messaging = SimpleMessaging.getInstance();
|
messaging = SimpleMessaging.getInstance();
|
||||||
messaging.init();
|
messaging.init();
|
||||||
|
|
||||||
if (nioFrameworkType.equals(MINA_NIO_FRAMEWORK)) {
|
if (nioFrameworkType.equals(MINA_NIO_FRAMEWORK)) {
|
||||||
m_acceptor = new MinaAcceptor();
|
m_acceptor = new MinaAcceptor();
|
||||||
} else if (nioFrameworkType.equals(NETTY_NIO_FRAMEWORK)) {
|
} else if (nioFrameworkType.equals(NETTY_NIO_FRAMEWORK)) {
|
||||||
m_acceptor = new NettyAcceptor();
|
m_acceptor = new NettyAcceptor();
|
||||||
}
|
}
|
||||||
m_acceptor.initialize(messaging);
|
m_acceptor.initialize(messaging);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopServer() {
|
public void stopServer() {
|
||||||
LOG.info("Server stopping...");
|
LOG.info("Server stopping...");
|
||||||
messaging.stop();
|
messaging.stop();
|
||||||
m_acceptor.close();
|
m_acceptor.close();
|
||||||
LOG.info("Server stopped");
|
LOG.info("Server stopped");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void printUsage(String nioFrameworkType) {
|
private static void printUsage(String nioFrameworkType) {
|
||||||
System.out.println("The broker should be invoked with the following command line: \n");
|
System.out.println("The broker should be invoked with the following command line: \n");
|
||||||
System.out.println("> java -jar <broker.jar> [mina|netty]\n");
|
System.out.println("> java -jar <broker.jar> [mina|netty]\n");
|
||||||
System.out.println("while was invoked with type: " + nioFrameworkType);
|
System.out.println("while was invoked with type: " + nioFrameworkType);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user