2016-06-28 17:27:35 +02:00
|
|
|
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;
|
2017-01-28 10:06:30 +01:00
|
|
|
import io.netty.buffer.ByteBuf;
|
2016-06-28 17:27:35 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
2017-01-28 10:06:30 +01:00
|
|
|
import static io.moquette.spi.impl.Utils.readBytesAndRewind;
|
|
|
|
|
|
2016-06-28 17:27:35 +02:00
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
|
2016-09-12 17:49:40 +02:00
|
|
|
public HazelcastInterceptHandler(Server server){
|
2016-06-28 17:27:35 +02:00
|
|
|
this.hz = server.getHazelcastInstance();
|
|
|
|
|
}
|
2017-01-10 17:06:13 +01:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getID() {
|
|
|
|
|
return HazelcastInterceptHandler.class.getName() + "@" + hz.getName();
|
|
|
|
|
}
|
2016-06-28 17:27:35 +02:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onPublish(InterceptPublishMessage msg) {
|
2017-01-28 10:06:30 +01:00
|
|
|
//TODO ugly, too much array copy
|
|
|
|
|
ByteBuf payload = msg.getPayload();
|
|
|
|
|
byte[] payloadContent = readBytesAndRewind(payload);
|
|
|
|
|
|
|
|
|
|
LOG.info("{} publish on {} message: {}", msg.getClientID(), msg.getTopicName(), new String(payloadContent));
|
2016-06-28 17:27:35 +02:00
|
|
|
ITopic<HazelcastMsg> topic = hz.getTopic("moquette");
|
2016-07-22 13:19:16 +02:00
|
|
|
HazelcastMsg hazelcastMsg = new HazelcastMsg(msg);
|
2016-06-28 17:27:35 +02:00
|
|
|
topic.publish(hazelcastMsg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|