Removed never used and unsufull no-op interceptor, forced usage of BrokerInterceptor, changed BrokerInterceptor to work on a list of InterceptHandler

This commit is contained in:
andrea
2015-08-08 18:37:32 +02:00
parent 9daff2b738
commit dc55ff4078
7 changed files with 94 additions and 86 deletions
@@ -23,8 +23,7 @@ import org.eclipse.moquette.spi.impl.subscriptions.Subscription;
* This interface is to be used internally by the broker components. * This interface is to be used internally by the broker components.
* <p> * <p>
* An interface is used instead of a class to allow more flexibility in changing * An interface is used instead of a class to allow more flexibility in changing
* an implementation. For instance, this interface provide a lightweight * an implementation.
* no-handler interceptor.
* <p> * <p>
* Interceptor implementations forward notifications to a <code>InterceptHandler</code>, * Interceptor implementations forward notifications to a <code>InterceptHandler</code>,
* that is normally a field. So, the implementations should act as a proxy to a custom * that is normally a field. So, the implementations should act as a proxy to a custom
@@ -34,9 +33,6 @@ import org.eclipse.moquette.spi.impl.subscriptions.Subscription;
* @author Wagner Macedo * @author Wagner Macedo
*/ */
public interface Interceptor { public interface Interceptor {
/**
* When no custom handler is provided, this interceptor should be used.
*/
void notifyClientConnected(ConnectMessage msg); void notifyClientConnected(ConnectMessage msg);
@@ -21,6 +21,7 @@ import org.eclipse.moquette.proto.messages.ConnectMessage;
import org.eclipse.moquette.proto.messages.PublishMessage; import org.eclipse.moquette.proto.messages.PublishMessage;
import org.eclipse.moquette.spi.impl.subscriptions.Subscription; import org.eclipse.moquette.spi.impl.subscriptions.Subscription;
import java.util.List;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@@ -30,11 +31,11 @@ import java.util.concurrent.Executors;
* @author Wagner Macedo * @author Wagner Macedo
*/ */
final class BrokerInterceptor implements Interceptor { final class BrokerInterceptor implements Interceptor {
private final InterceptHandler handler; private final List<InterceptHandler> handlers;
private final ExecutorService executor; private final ExecutorService executor;
BrokerInterceptor(InterceptHandler handler) { BrokerInterceptor(List<InterceptHandler> handlers) {
this.handler = handler; this.handlers = handlers;
executor = Executors.newFixedThreadPool(1); executor = Executors.newFixedThreadPool(1);
} }
@@ -47,51 +48,61 @@ final class BrokerInterceptor implements Interceptor {
@Override @Override
public void notifyClientConnected(final ConnectMessage msg) { public void notifyClientConnected(final ConnectMessage msg) {
executor.execute(new Runnable() { for (final InterceptHandler handler : this.handlers) {
@Override executor.execute(new Runnable() {
public void run() { @Override
handler.onConnect(msg.readOnlyClone()); public void run() {
} handler.onConnect(msg.readOnlyClone());
}); }
});
}
} }
@Override @Override
public void notifyClientDisconnected(final String clientID) { public void notifyClientDisconnected(final String clientID) {
executor.execute(new Runnable() { for (final InterceptHandler handler : this.handlers) {
@Override executor.execute(new Runnable() {
public void run() { @Override
handler.onDisconnect(clientID); public void run() {
} handler.onDisconnect(clientID);
}); }
});
}
} }
@Override @Override
public void notifyTopicPublished(final PublishMessage msg) { public void notifyTopicPublished(final PublishMessage msg) {
executor.execute(new Runnable() { for (final InterceptHandler handler : this.handlers) {
@Override executor.execute(new Runnable() {
public void run() { @Override
handler.onPublish(msg.readOnlyClone()); public void run() {
} handler.onPublish(msg.readOnlyClone());
}); }
});
}
} }
@Override @Override
public void notifyTopicSubscribed(final Subscription sub) { public void notifyTopicSubscribed(final Subscription sub) {
executor.execute(new Runnable() { for (final InterceptHandler handler : this.handlers) {
@Override executor.execute(new Runnable() {
public void run() { @Override
handler.onSubscribe(sub.clone()); public void run() {
} handler.onSubscribe(sub);
}); }
});
}
} }
@Override @Override
public void notifyTopicUnsubscribed(final String sub) { public void notifyTopicUnsubscribed(final String sub) {
executor.execute(new Runnable() { for (final InterceptHandler handler : this.handlers) {
@Override executor.execute(new Runnable() {
public void run() { @Override
handler.onUnsubscribe(sub); public void run() {
} handler.onUnsubscribe(sub);
}); }
});
}
} }
} }
@@ -23,9 +23,6 @@ import java.util.*;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import io.netty.util.internal.StringUtil;
import org.apache.commons.codec.binary.StringUtils;
import org.eclipse.moquette.interception.Interceptor;
import org.eclipse.moquette.server.netty.NettyChannel; import org.eclipse.moquette.server.netty.NettyChannel;
import org.eclipse.moquette.spi.IMatchingCondition; import org.eclipse.moquette.spi.IMatchingCondition;
import org.eclipse.moquette.spi.IMessagesStore; import org.eclipse.moquette.spi.IMessagesStore;
@@ -106,7 +103,7 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
private IMessagesStore m_messagesStore; private IMessagesStore m_messagesStore;
private ISessionsStore m_sessionsStore; private ISessionsStore m_sessionsStore;
private IAuthenticator m_authenticator; private IAuthenticator m_authenticator;
private Interceptor interceptor = null; private BrokerInterceptor m_interceptor;
//maps clientID to Will testament, if specified on CONNECT //maps clientID to Will testament, if specified on CONNECT
private Map<String, WillMessage> m_willStore = new HashMap<>(); private Map<String, WillMessage> m_willStore = new HashMap<>();
@@ -116,13 +113,6 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
ProtocolProcessor() {} ProtocolProcessor() {}
void init(SubscriptionsStore subscriptions, IMessagesStore storageService,
ISessionsStore sessionsStore,
IAuthenticator authenticator,
boolean allowAnonymous, IAuthorizator authorizator) {
init(subscriptions, storageService, sessionsStore, authenticator, allowAnonymous, authorizator, null);
}
/** /**
* @param subscriptions the subscription store where are stored all the existing * @param subscriptions the subscription store where are stored all the existing
* clients subscriptions. * clients subscriptions.
@@ -137,11 +127,9 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
void init(SubscriptionsStore subscriptions, IMessagesStore storageService, void init(SubscriptionsStore subscriptions, IMessagesStore storageService,
ISessionsStore sessionsStore, ISessionsStore sessionsStore,
IAuthenticator authenticator, IAuthenticator authenticator,
boolean allowAnonymous, IAuthorizator authorizator, Interceptor interceptor) { boolean allowAnonymous, IAuthorizator authorizator, BrokerInterceptor interceptor) {
//m_clientIDs = clientIDs; //m_clientIDs = clientIDs;
if (interceptor != null) { this.m_interceptor = interceptor;
this.interceptor = interceptor;
}
this.subscriptions = subscriptions; this.subscriptions = subscriptions;
this.allowAnonymous = allowAnonymous; this.allowAnonymous = allowAnonymous;
m_authorizator = authorizator; m_authorizator = authorizator;
@@ -177,7 +165,7 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
ConnAckMessage okResp = new ConnAckMessage(); ConnAckMessage okResp = new ConnAckMessage();
okResp.setReturnCode(ConnAckMessage.IDENTIFIER_REJECTED); okResp.setReturnCode(ConnAckMessage.IDENTIFIER_REJECTED);
session.write(okResp); session.write(okResp);
interceptor.notifyClientConnected(msg); m_interceptor.notifyClientConnected(msg);
return; return;
} }
@@ -233,7 +221,7 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
AbstractMessage.QOSType willQos = AbstractMessage.QOSType.values()[msg.getWillQos()]; AbstractMessage.QOSType willQos = AbstractMessage.QOSType.values()[msg.getWillQos()];
byte[] willPayload = msg.getWillMessage().getBytes(); byte[] willPayload = msg.getWillMessage().getBytes();
ByteBuffer bb = (ByteBuffer) ByteBuffer.allocate(willPayload.length).put(willPayload).flip(); ByteBuffer bb = (ByteBuffer) ByteBuffer.allocate(willPayload.length).put(willPayload).flip();
//save the will testment in the clientID store //save the will testament in the clientID store
WillMessage will = new WillMessage(msg.getWillTopic(), bb, msg.isWillRetain(),willQos ); WillMessage will = new WillMessage(msg.getWillTopic(), bb, msg.isWillRetain(),willQos );
m_willStore.put(msg.getClientID(), will); m_willStore.put(msg.getClientID(), will);
} }
@@ -253,7 +241,7 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
okResp.setSessionPresent(true); okResp.setSessionPresent(true);
} }
session.write(okResp); session.write(okResp);
interceptor.notifyClientConnected(msg); m_interceptor.notifyClientConnected(msg);
LOG.info("Create persistent session for clientID <{}>", msg.getClientID()); LOG.info("Create persistent session for clientID <{}>", msg.getClientID());
m_sessionsStore.addNewSubscription(Subscription.createEmptySubscription(msg.getClientID(), true)); //null means EmptySubscription m_sessionsStore.addNewSubscription(Subscription.createEmptySubscription(msg.getClientID(), true)); //null means EmptySubscription
@@ -317,7 +305,7 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
String user = (String) session.getAttribute(NettyChannel.ATTR_KEY_USERNAME); String user = (String) session.getAttribute(NettyChannel.ATTR_KEY_USERNAME);
if (m_authorizator.canWrite(topic, user, clientID)) { if (m_authorizator.canWrite(topic, user, clientID)) {
executePublish(clientID, msg); executePublish(clientID, msg);
interceptor.notifyTopicPublished(msg); m_interceptor.notifyTopicPublished(msg);
} else { } else {
LOG.debug("topic {} doesn't have write credentials", topic); LOG.debug("topic {} doesn't have write credentials", topic);
} }
@@ -576,7 +564,7 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
m_willStore.remove(clientID); m_willStore.remove(clientID);
LOG.info("DISCONNECT client <{}> with clean session {}", clientID, cleanSession); LOG.info("DISCONNECT client <{}> with clean session {}", clientID, cleanSession);
interceptor.notifyClientDisconnected(clientID); m_interceptor.notifyClientDisconnected(clientID);
} }
void processConnectionLost(LostConnectionEvent evt) { void processConnectionLost(LostConnectionEvent evt) {
@@ -610,7 +598,7 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
for (String topic : topics) { for (String topic : topics) {
subscriptions.removeSubscription(topic, clientID); subscriptions.removeSubscription(topic, clientID);
m_sessionsStore.removeSubscription(topic, clientID); m_sessionsStore.removeSubscription(topic, clientID);
interceptor.notifyTopicUnsubscribed(topic); m_interceptor.notifyTopicUnsubscribed(topic);
} }
//ack the client //ack the client
@@ -655,7 +643,7 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
subscriptions.add(newSubscription); subscriptions.add(newSubscription);
//notify the Observables //notify the Observables
interceptor.notifyTopicSubscribed(newSubscription); m_interceptor.notifyTopicSubscribed(newSubscription);
//scans retained messages to be published to the new subscription //scans retained messages to be published to the new subscription
Collection<IMessagesStore.StoredMessage> messages = m_messagesStore.searchMatching(new IMatchingCondition() { Collection<IMessagesStore.StoredMessage> messages = m_messagesStore.searchMatching(new IMatchingCondition() {
@@ -18,9 +18,9 @@ package org.eclipse.moquette.spi.impl;
import com.lmax.disruptor.EventHandler; import com.lmax.disruptor.EventHandler;
import com.lmax.disruptor.RingBuffer; import com.lmax.disruptor.RingBuffer;
import com.lmax.disruptor.dsl.Disruptor; import com.lmax.disruptor.dsl.Disruptor;
import io.netty.util.internal.StringUtil;
import org.HdrHistogram.Histogram; import org.HdrHistogram.Histogram;
import org.eclipse.moquette.interception.InterceptHandler; import org.eclipse.moquette.interception.InterceptHandler;
import org.eclipse.moquette.interception.Interceptor;
import org.eclipse.moquette.proto.messages.AbstractMessage; import org.eclipse.moquette.proto.messages.AbstractMessage;
import org.eclipse.moquette.spi.impl.security.*; import org.eclipse.moquette.spi.impl.security.*;
import org.eclipse.moquette.server.ServerChannel; import org.eclipse.moquette.server.ServerChannel;
@@ -40,6 +40,8 @@ import java.io.File;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.text.ParseException; import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@@ -75,7 +77,7 @@ public class SimpleMessaging implements IMessaging, EventHandler<ValueEvent> {
private ExecutorService m_executor; private ExecutorService m_executor;
private Disruptor<ValueEvent> m_disruptor; private Disruptor<ValueEvent> m_disruptor;
private Interceptor interceptor; private BrokerInterceptor m_interceptor;
private static SimpleMessaging INSTANCE; private static SimpleMessaging INSTANCE;
@@ -194,14 +196,18 @@ public class SimpleMessaging implements IMessaging, EventHandler<ValueEvent> {
m_sessionsStore = mapStorage; m_sessionsStore = mapStorage;
m_storageService.initStore(); m_storageService.initStore();
try { List<InterceptHandler> observers = new ArrayList<>();
final InterceptHandler handler = Class.forName(props.getProperty("intercept.handler")) String interceptorClassName = props.getProperty("intercept.handler");
.asSubclass(InterceptHandler.class).newInstance(); if (interceptorClassName != null && !interceptorClassName.isEmpty()) {
interceptor = new BrokerInterceptor(handler); try {
} catch (Throwable ex) { InterceptHandler handler = Class.forName(interceptorClassName).asSubclass(InterceptHandler.class).newInstance();
LOG.error("Can't load the intercept handler {}", ex); observers.add(handler);
} catch (Throwable ex) {
LOG.error("Can't load the intercept handler {}", ex);
}
} }
m_interceptor = new BrokerInterceptor(observers);
//List<Subscription> storedSubscriptions = m_sessionsStore.listAllSubscriptions(); //List<Subscription> storedSubscriptions = m_sessionsStore.listAllSubscriptions();
//subscriptions.init(storedSubscriptions); //subscriptions.init(storedSubscriptions);
@@ -251,7 +257,7 @@ public class SimpleMessaging implements IMessaging, EventHandler<ValueEvent> {
} }
boolean allowAnonymous = Boolean.parseBoolean(props.getProperty(ALLOW_ANONYMOUS_PROPERTY_NAME, "true")); boolean allowAnonymous = Boolean.parseBoolean(props.getProperty(ALLOW_ANONYMOUS_PROPERTY_NAME, "true"));
m_processor.init(subscriptions, m_storageService, m_sessionsStore, authenticator, allowAnonymous, authorizator, interceptor); m_processor.init(subscriptions, m_storageService, m_sessionsStore, authenticator, allowAnonymous, authorizator, m_interceptor);
} }
private Object loadClass(String className, Class<?> cls) { private Object loadClass(String className, Class<?> cls) {
@@ -291,8 +297,8 @@ public class SimpleMessaging implements IMessaging, EventHandler<ValueEvent> {
private void processStop() { private void processStop() {
LOG.debug("processStop invoked"); LOG.debug("processStop invoked");
if (interceptor != null) { if (m_interceptor != null) {
((BrokerInterceptor) interceptor).stop(); this.m_interceptor.stop();
} }
m_storageService.close(); m_storageService.close();
LOG.debug("subscription tree {}", subscriptions.dumpTree()); LOG.debug("subscription tree {}", subscriptions.dumpTree());
@@ -19,7 +19,6 @@ import java.text.ParseException;
import java.util.*; import java.util.*;
import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.LinkedBlockingDeque;
import org.eclipse.moquette.interception.Interceptor;
import org.eclipse.moquette.spi.ISessionsStore; import org.eclipse.moquette.spi.ISessionsStore;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -24,6 +24,7 @@ import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@@ -36,7 +37,7 @@ public class BrokerInterceptorTest {
private static final AtomicInteger n = new AtomicInteger(0); private static final AtomicInteger n = new AtomicInteger(0);
// Interceptor loaded with a custom InterceptHandler special for the tests // Interceptor loaded with a custom InterceptHandler special for the tests
private static final BrokerInterceptor interceptor = new BrokerInterceptor(new InterceptHandler() { private static final class MockObserver implements InterceptHandler {
@Override @Override
public void onConnect(ConnectMessage msg) { public void onConnect(ConnectMessage msg) {
n.set(40); n.set(40);
@@ -61,7 +62,9 @@ public class BrokerInterceptorTest {
public void onUnsubscribe(String topic) { public void onUnsubscribe(String topic) {
n.set(80); n.set(80);
} }
}); }
private static final BrokerInterceptor interceptor = new BrokerInterceptor(Arrays.<InterceptHandler>asList(new MockObserver()));
@BeforeClass @BeforeClass
public static void beforeAllTests() { public static void beforeAllTests() {
@@ -21,6 +21,7 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import io.netty.util.AttributeKey; import io.netty.util.AttributeKey;
import org.eclipse.moquette.interception.InterceptHandler;
import org.eclipse.moquette.server.netty.NettyChannel; import org.eclipse.moquette.server.netty.NettyChannel;
import org.eclipse.moquette.spi.IMatchingCondition; import org.eclipse.moquette.spi.IMatchingCondition;
import org.eclipse.moquette.spi.IMessagesStore; import org.eclipse.moquette.spi.IMessagesStore;
@@ -59,6 +60,9 @@ public class ProtocolProcessorTest {
final static String TEST_PWD = "fakepwd"; final static String TEST_PWD = "fakepwd";
final static String EVIL_TEST_USER = "eviluser"; final static String EVIL_TEST_USER = "eviluser";
final static String EVIL_TEST_PWD = "unsecret"; final static String EVIL_TEST_PWD = "unsecret";
final static List<InterceptHandler> EMPTY_OBSERVERS = Collections.emptyList();
final static BrokerInterceptor NO_OBSERVERS_INTERCEPTOR = new BrokerInterceptor(EMPTY_OBSERVERS);
DummyChannel m_session; DummyChannel m_session;
byte m_returnCode; byte m_returnCode;
@@ -172,7 +176,8 @@ public class ProtocolProcessorTest {
subscriptions = new SubscriptionsStore(); subscriptions = new SubscriptionsStore();
subscriptions.init(new MemoryStorageService()); subscriptions.init(new MemoryStorageService());
m_processor = new ProtocolProcessor(); m_processor = new ProtocolProcessor();
m_processor.init(subscriptions, m_storageService, m_sessionStore, m_mockAuthenticator, true, new PermitAllAuthorizator()); m_processor.init(subscriptions, m_storageService, m_sessionStore, m_mockAuthenticator, true,
new PermitAllAuthorizator(), NO_OBSERVERS_INTERCEPTOR);
} }
@Test @Test
@@ -263,7 +268,7 @@ public class ProtocolProcessorTest {
@Test @Test
public void prohibitAnonymousClient() { public void prohibitAnonymousClient() {
connMsg.setClientID("123"); connMsg.setClientID("123");
m_processor.init(subscriptions, m_storageService, m_sessionStore, m_mockAuthenticator, false, new PermitAllAuthorizator()); m_processor.init(subscriptions, m_storageService, m_sessionStore, m_mockAuthenticator, false, new PermitAllAuthorizator(), NO_OBSERVERS_INTERCEPTOR);
//Exercise //Exercise
m_processor.processConnect(m_session, connMsg); m_processor.processConnect(m_session, connMsg);
@@ -277,7 +282,7 @@ public class ProtocolProcessorTest {
connMsg.setClientID("123"); connMsg.setClientID("123");
connMsg.setUserFlag(true); connMsg.setUserFlag(true);
connMsg.setUsername(TEST_USER + "_fake"); connMsg.setUsername(TEST_USER + "_fake");
m_processor.init(subscriptions, m_storageService, m_sessionStore, m_mockAuthenticator, false, new PermitAllAuthorizator()); m_processor.init(subscriptions, m_storageService, m_sessionStore, m_mockAuthenticator, false, new PermitAllAuthorizator(), NO_OBSERVERS_INTERCEPTOR);
//Exercise //Exercise
m_processor.processConnect(m_session, connMsg); m_processor.processConnect(m_session, connMsg);
@@ -289,7 +294,7 @@ public class ProtocolProcessorTest {
@Test @Test
public void acceptAnonymousClient() { public void acceptAnonymousClient() {
connMsg.setClientID("123"); connMsg.setClientID("123");
m_processor.init(subscriptions, m_storageService, m_sessionStore, m_mockAuthenticator, true, new PermitAllAuthorizator()); m_processor.init(subscriptions, m_storageService, m_sessionStore, m_mockAuthenticator, true, new PermitAllAuthorizator(), NO_OBSERVERS_INTERCEPTOR);
//Exercise //Exercise
m_processor.processConnect(m_session, connMsg); m_processor.processConnect(m_session, connMsg);
@@ -376,7 +381,7 @@ public class ProtocolProcessorTest {
//simulate a connect that register a clientID to an IoSession //simulate a connect that register a clientID to an IoSession
subs.init(new MemoryStorageService()); subs.init(new MemoryStorageService());
m_processor.init(subs, m_storageService, m_sessionStore, null, true, new PermitAllAuthorizator()); m_processor.init(subs, m_storageService, m_sessionStore, null, true, new PermitAllAuthorizator(), NO_OBSERVERS_INTERCEPTOR);
ConnectMessage connectMessage = new ConnectMessage(); ConnectMessage connectMessage = new ConnectMessage();
connectMessage.setProcotolVersion((byte)3); connectMessage.setProcotolVersion((byte)3);
connectMessage.setClientID(FAKE_CLIENT_ID); connectMessage.setClientID(FAKE_CLIENT_ID);
@@ -420,7 +425,7 @@ public class ProtocolProcessorTest {
//simulate a connect that register a clientID to an IoSession //simulate a connect that register a clientID to an IoSession
subs.init(new MemoryStorageService()); subs.init(new MemoryStorageService());
m_processor.init(subs, m_storageService, m_sessionStore, null, true, new PermitAllAuthorizator()); m_processor.init(subs, m_storageService, m_sessionStore, null, true, new PermitAllAuthorizator(), NO_OBSERVERS_INTERCEPTOR);
MockReceiverChannel firstReceiverSession = new MockReceiverChannel(); MockReceiverChannel firstReceiverSession = new MockReceiverChannel();
ConnectMessage connectMessage = new ConnectMessage(); ConnectMessage connectMessage = new ConnectMessage();
@@ -559,7 +564,7 @@ public class ProtocolProcessorTest {
subs.init(new MemoryStorageService()); subs.init(new MemoryStorageService());
//simulate a connect that register a clientID to an IoSession //simulate a connect that register a clientID to an IoSession
m_processor.init(subs, m_storageService, m_sessionStore, null, true, new PermitAllAuthorizator()); m_processor.init(subs, m_storageService, m_sessionStore, null, true, new PermitAllAuthorizator(), NO_OBSERVERS_INTERCEPTOR);
ConnectMessage connectMessage = new ConnectMessage(); ConnectMessage connectMessage = new ConnectMessage();
connectMessage.setClientID(FAKE_PUBLISHER_ID); connectMessage.setClientID(FAKE_PUBLISHER_ID);
connectMessage.setProcotolVersion((byte)3); connectMessage.setProcotolVersion((byte)3);
@@ -598,7 +603,7 @@ public class ProtocolProcessorTest {
ByteBuffer.wrap("Hello".getBytes()), true, FAKE_PUBLISHER_ID, 120); ByteBuffer.wrap("Hello".getBytes()), true, FAKE_PUBLISHER_ID, 120);
m_storageService.storePublishForFuture(retainedMessage); m_storageService.storePublishForFuture(retainedMessage);
m_processor.init(subs, m_storageService, m_sessionStore, null, true, new PermitAllAuthorizator()); m_processor.init(subs, m_storageService, m_sessionStore, null, true, new PermitAllAuthorizator(), NO_OBSERVERS_INTERCEPTOR);
ConnectMessage connectMessage = new ConnectMessage(); ConnectMessage connectMessage = new ConnectMessage();
connectMessage.setClientID(FAKE_PUBLISHER_ID); connectMessage.setClientID(FAKE_PUBLISHER_ID);
connectMessage.setProcotolVersion((byte)3); connectMessage.setProcotolVersion((byte)3);
@@ -617,7 +622,7 @@ public class ProtocolProcessorTest {
List<Subscription> inactiveSubscriptions = Arrays.asList(inactiveSub); List<Subscription> inactiveSubscriptions = Arrays.asList(inactiveSub);
when(mockedSubscriptions.matches(eq("/topic"))).thenReturn(inactiveSubscriptions); when(mockedSubscriptions.matches(eq("/topic"))).thenReturn(inactiveSubscriptions);
m_processor = new ProtocolProcessor(); m_processor = new ProtocolProcessor();
m_processor.init(mockedSubscriptions, m_storageService, m_sessionStore, null, true, new PermitAllAuthorizator()); m_processor.init(mockedSubscriptions, m_storageService, m_sessionStore, null, true, new PermitAllAuthorizator(), NO_OBSERVERS_INTERCEPTOR);
//Exercise //Exercise
ByteBuffer buffer = ByteBuffer.allocate(5).put("Hello".getBytes()); ByteBuffer buffer = ByteBuffer.allocate(5).put("Hello".getBytes());
@@ -642,7 +647,7 @@ public class ProtocolProcessorTest {
List<Subscription> inactiveSubscriptions = Arrays.asList(inactiveSub); List<Subscription> inactiveSubscriptions = Arrays.asList(inactiveSub);
when(mockedSubscriptions.matches(eq("/topic"))).thenReturn(inactiveSubscriptions); when(mockedSubscriptions.matches(eq("/topic"))).thenReturn(inactiveSubscriptions);
m_processor = new ProtocolProcessor(); m_processor = new ProtocolProcessor();
m_processor.init(mockedSubscriptions, m_storageService, m_sessionStore, null, true, new PermitAllAuthorizator()); m_processor.init(mockedSubscriptions, m_storageService, m_sessionStore, null, true, new PermitAllAuthorizator(), NO_OBSERVERS_INTERCEPTOR);
//Exercise //Exercise
ByteBuffer buffer = ByteBuffer.allocate(5).put("Hello".getBytes()); ByteBuffer buffer = ByteBuffer.allocate(5).put("Hello".getBytes());
@@ -718,7 +723,7 @@ public class ProtocolProcessorTest {
publishedForwarded.add(new PublishEvent(topic, qos, message, retained, clientId, messageID)); publishedForwarded.add(new PublishEvent(topic, qos, message, retained, clientId, messageID));
} }
}; };
processor.init(subscriptions, memoryMessageStore, null, null, true, null); processor.init(subscriptions, memoryMessageStore, null, null, true, null, NO_OBSERVERS_INTERCEPTOR);
//Exercise //Exercise
processor.forward2Subscribers(forwardPublish); processor.forward2Subscribers(forwardPublish);