Added sample publish InterceptHandler implementation to EmbeddedLauncher (#104 publish listner part)
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2015 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package io.moquette.interception;
|
||||
|
||||
import io.moquette.interception.messages.*;
|
||||
|
||||
/**
|
||||
* Basic abstract class usefull to avoid empty methods creation in subclasses.
|
||||
*
|
||||
* Created by andrea on 08/12/15.
|
||||
*/
|
||||
public abstract class AbstractInterceptHandler implements InterceptHandler {
|
||||
|
||||
@Override
|
||||
public void onConnect(InterceptConnectMessage msg) {}
|
||||
|
||||
@Override
|
||||
public void onDisconnect(InterceptDisconnectMessage msg) {}
|
||||
|
||||
@Override
|
||||
public void onPublish(InterceptPublishMessage msg) {}
|
||||
|
||||
@Override
|
||||
public void onSubscribe(InterceptSubscribeMessage msg) {}
|
||||
|
||||
@Override
|
||||
public void onUnsubscribe(InterceptUnsubscribeMessage msg) {}
|
||||
}
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2015 The original author or authors
|
||||
* ------------------------------------------------------
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Apache License v2.0 which accompanies this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* The Apache License v2.0 is available at
|
||||
* http://www.opensource.org/licenses/apache2.0.php
|
||||
*
|
||||
* You may elect to redistribute this code under either of these licenses.
|
||||
*/
|
||||
package io.moquette.interception.messages;
|
||||
|
||||
import io.moquette.proto.messages.AbstractMessage;
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package io.moquette.server;
|
||||
|
||||
import io.moquette.interception.InterceptHandler;
|
||||
import io.moquette.server.config.MemoryConfig;
|
||||
import io.moquette.spi.impl.SimpleMessaging;
|
||||
import io.moquette.server.config.FilesystemConfig;
|
||||
@@ -26,6 +27,9 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
@@ -87,12 +91,23 @@ public class Server {
|
||||
* Starts Moquette bringing the configuration files from the given Config implementation.
|
||||
*/
|
||||
public void startServer(IConfig config) throws IOException {
|
||||
startServer(config, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts Moquette with config provided by an implementation of IConfig class and with the set of InterceptHandler
|
||||
* */
|
||||
public void startServer(IConfig config, List<? extends InterceptHandler> handlers) throws IOException {
|
||||
if (handlers == null) {
|
||||
handlers = Collections.emptyList();
|
||||
}
|
||||
|
||||
final String handlerProp = System.getProperty("intercept.handler");
|
||||
if (handlerProp != null) {
|
||||
config.setProperty("intercept.handler", handlerProp);
|
||||
}
|
||||
LOG.info("Persistent store file: " + config.getProperty(io.moquette.commons.Constants.PERSISTENT_STORE_PROPERTY_NAME));
|
||||
final ProtocolProcessor processor = SimpleMessaging.getInstance().init(config);
|
||||
final ProtocolProcessor processor = SimpleMessaging.getInstance().init(config, handlers);
|
||||
|
||||
m_acceptor = new NettyAcceptor();
|
||||
m_acceptor.initialize(processor, config);
|
||||
|
||||
@@ -39,7 +39,7 @@ public class ClasspathConfig implements IConfig {
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
InputStream is = classLoader.getResourceAsStream("config/moquette.conf");
|
||||
if (is == null) {
|
||||
throw new RuntimeException("Can't locate the resourse \"config/moquette.conf\"");
|
||||
throw new RuntimeException("Can't locate the resource \"config/moquette.conf\"");
|
||||
}
|
||||
Reader configReader = new InputStreamReader(is);
|
||||
ConfigurationParser confParser = new ConfigurationParser();
|
||||
|
||||
@@ -66,7 +66,7 @@ public class SimpleMessaging {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public ProtocolProcessor init(IConfig props) {
|
||||
public ProtocolProcessor init(IConfig props, List<? extends InterceptHandler> embeddedObservers) {
|
||||
subscriptions = new SubscriptionsStore();
|
||||
|
||||
m_mapStorage = new MapDBPersistentStore(props);
|
||||
@@ -74,7 +74,7 @@ public class SimpleMessaging {
|
||||
IMessagesStore messagesStore = m_mapStorage.messagesStore();
|
||||
ISessionsStore sessionsStore = m_mapStorage.sessionsStore(messagesStore);
|
||||
|
||||
List<InterceptHandler> observers = new ArrayList<>();
|
||||
List<InterceptHandler> observers = new ArrayList<>(embeddedObservers);
|
||||
String interceptorClassName = props.getProperty("intercept.handler");
|
||||
if (interceptorClassName != null && !interceptorClassName.isEmpty()) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user