Fixed Hazelcast itnegration tests, removing unusefull thread sleeps, but more important permitting the co existence of 2 Brokers in the same JVM
This commit is contained in:
@@ -22,13 +22,12 @@ public class HazelcastListener implements MessageListener<HazelcastMsg> {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onMessage(Message<HazelcastMsg> msg) {
|
||||
try {
|
||||
if (!msg.getPublishingMember().equals(server.getHazelcastInstance().getCluster().getLocalMember())) {
|
||||
LOG.info(String.format("%s received from hazelcast for topic %s message : %s\n", msg.getMessageObject().getClientId(), msg.getMessageObject().getTopic(), msg.getMessageObject().getPayload()));
|
||||
LOG.info("{} received from hazelcast for topic {} message: {}", msg.getMessageObject().getClientId(),
|
||||
msg.getMessageObject().getTopic(), msg.getMessageObject().getPayload());
|
||||
PublishMessage publishMessage = new PublishMessage();
|
||||
publishMessage.setTopicName(msg.getMessageObject().getTopic());
|
||||
publishMessage.setQos(AbstractMessage.QOSType.valueOf(msg.getMessageObject().getQos()));
|
||||
@@ -36,10 +35,9 @@ public class HazelcastListener implements MessageListener<HazelcastMsg> {
|
||||
publishMessage.setLocal(false);
|
||||
publishMessage.setClientId(msg.getMessageObject().getClientId());
|
||||
server.internalPublish(publishMessage);
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("error while wait for polling hazelcast msg queue",e);
|
||||
} catch (Exception ex) {
|
||||
LOG.error("error polling hazelcast msg queue", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,10 +31,8 @@ import io.moquette.server.config.MemoryConfig;
|
||||
import io.moquette.spi.impl.SimpleMessaging;
|
||||
import io.moquette.server.config.FilesystemConfig;
|
||||
import io.moquette.server.config.IConfig;
|
||||
import io.moquette.server.config.MemoryConfig;
|
||||
import io.moquette.server.netty.NettyAcceptor;
|
||||
import io.moquette.spi.impl.ProtocolProcessor;
|
||||
import io.moquette.spi.impl.SimpleMessaging;
|
||||
import io.moquette.spi.security.IAuthenticator;
|
||||
import io.moquette.spi.security.IAuthorizator;
|
||||
import io.moquette.spi.security.ISslContextCreator;
|
||||
@@ -63,6 +61,8 @@ public class Server {
|
||||
|
||||
private HazelcastInstance hazelcastInstance;
|
||||
|
||||
private SimpleMessaging m_messaging;
|
||||
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
final Server server = new Server();
|
||||
@@ -131,9 +131,9 @@ public class Server {
|
||||
handlers = Collections.emptyList();
|
||||
}
|
||||
|
||||
final String handlerProp = System.getProperty("intercept.handler");
|
||||
final String handlerProp = System.getProperty(BrokerConstants.INTERCEPT_HANDLER_PROPERTY_NAME);
|
||||
if (handlerProp != null) {
|
||||
config.setProperty("intercept.handler", handlerProp);
|
||||
config.setProperty(BrokerConstants.INTERCEPT_HANDLER_PROPERTY_NAME, handlerProp);
|
||||
}
|
||||
LOG.info("Persistent store file: " + config.getProperty(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME));
|
||||
if (config.getProperty(BrokerConstants.INTERCEPT_HANDLER_PROPERTY_NAME) !=null && config.getProperty(BrokerConstants.INTERCEPT_HANDLER_PROPERTY_NAME).equals(HazelcastInterceptHandler.class.getCanonicalName())) {
|
||||
@@ -152,7 +152,8 @@ public class Server {
|
||||
}
|
||||
listenOnHazelCastMsg();
|
||||
}
|
||||
final ProtocolProcessor processor = SimpleMessaging.getInstance().init(config, handlers, authenticator, authorizator, this);
|
||||
m_messaging = SimpleMessaging.getInstance();
|
||||
final ProtocolProcessor processor = m_messaging.init(config, handlers, authenticator, authorizator, this);
|
||||
|
||||
if (sslCtxCreator == null) {
|
||||
sslCtxCreator = new DefaultMoquetteSslContextCreator(config);
|
||||
@@ -162,8 +163,6 @@ public class Server {
|
||||
m_acceptor.initialize(processor, config, sslCtxCreator);
|
||||
m_processor = processor;
|
||||
m_initialized = true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void listenOnHazelCastMsg() {
|
||||
@@ -193,15 +192,14 @@ public class Server {
|
||||
public void stopServer() {
|
||||
LOG.info("Server stopping...");
|
||||
m_acceptor.close();
|
||||
SimpleMessaging.getInstance().shutdown();
|
||||
m_messaging.shutdown();
|
||||
m_initialized = false;
|
||||
if (hazelcastInstance != null ){
|
||||
if (hazelcastInstance != null) {
|
||||
try {
|
||||
hazelcastInstance.shutdown();
|
||||
} catch (HazelcastInstanceNotActiveException e){
|
||||
LOG.info("hazelcast allready shutdown");
|
||||
} catch (HazelcastInstanceNotActiveException e) {
|
||||
LOG.info("hazelcast already shutdown");
|
||||
}
|
||||
|
||||
}
|
||||
LOG.info("Server stopped");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user