Files
IM-server-new/broker/src/main/java/io/moquette/interception/HazelcastInterceptHandler.java
T
Luis Barrios 46fcdc0894 Allow InterceptHandler to specify the messages they can intercept. This allows us to improve the performance of the broker interceptor, and will make log traces more clear.
- Add methods to return an unique identifier and the supported message types at the InterceptHandler interface.
- Include a default implementation of the new methods in the AbstractInterceptHandler. By default, all the interceptors will be able to handle any message (same as before).
- Comment verifyNoMoreInteractions() call from the BrokerInterceptorTest.testAddAndRemoveInterceptHandler(). The removeInterceptHandler() method of the broker interceptor
  polls the InterceptHandler, so an interaction will always exist after the call to onSubscribe().
2017-01-10 17:06:13 +01:00

36 lines
1.1 KiB
Java

package io.moquette.interception;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.ITopic;
import io.moquette.interception.messages.InterceptPublishMessage;
import io.moquette.server.Server;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Created by mackristof on 28/05/2016.
*/
public class HazelcastInterceptHandler extends AbstractInterceptHandler {
private static final Logger LOG = LoggerFactory.getLogger(HazelcastInterceptHandler.class);
private final HazelcastInstance hz;
public HazelcastInterceptHandler(Server server){
this.hz = server.getHazelcastInstance();
}
@Override
public String getID() {
return HazelcastInterceptHandler.class.getName() + "@" + hz.getName();
}
@Override
public void onPublish(InterceptPublishMessage msg) {
LOG.info("{} publish on {} message: {}", msg.getClientID(), msg.getTopicName(), new String(msg.getPayload().array()));
ITopic<HazelcastMsg> topic = hz.getTopic("moquette");
HazelcastMsg hazelcastMsg = new HazelcastMsg(msg);
topic.publish(hazelcastMsg);
}
}