Search in sources :

Example 1 with MqttSink

use of edu.snu.mist.core.sinks.MqttSink in project mist by snuspl.

the class PhysicalObjectGenerator method newSink.

/**
 * Get a new sink.
 * @param conf configuration
 * @param classLoader external class loader
 * @return new sink
 */
@SuppressWarnings("unchecked")
public <T> Sink<T> newSink(final Map<String, String> conf, final ClassLoader classLoader) throws IOException {
    final String type = conf.get(ConfKeys.SinkConf.SINK_TYPE.name());
    if (type.equals(ConfValues.SinkType.NETTY.name())) {
        final String serverAddress = conf.get(ConfKeys.NettySink.SINK_ADDRESS.name());
        final int serverPort = Integer.valueOf(conf.get(ConfKeys.NettySink.SINK_PORT.name()));
        return (Sink<T>) new NettyTextSink(serverAddress, serverPort, nettySharedResource, identifierFactory);
    } else if (type.equals(ConfValues.SinkType.MQTT.name())) {
        final String brokerURI = conf.get(ConfKeys.MqttSink.MQTT_SINK_BROKER_URI.name());
        final String topic = conf.get(ConfKeys.MqttSink.MQTT_SINK_TOPIC.name());
        try {
            return (Sink<T>) new MqttSink(brokerURI, topic, mqttSharedResource);
        } catch (final MqttException e) {
            e.printStackTrace();
            throw new IOException(e);
        }
    } else {
        throw new RuntimeException("Invalid sink type: " + type);
    }
}
Also used : MqttSink(edu.snu.mist.core.sinks.MqttSink) NettyTextSink(edu.snu.mist.core.sinks.NettyTextSink) Sink(edu.snu.mist.core.sinks.Sink) MqttSink(edu.snu.mist.core.sinks.MqttSink) MqttException(org.eclipse.paho.client.mqttv3.MqttException) NettyTextSink(edu.snu.mist.core.sinks.NettyTextSink) IOException(java.io.IOException)

Example 2 with MqttSink

use of edu.snu.mist.core.sinks.MqttSink in project mist by snuspl.

the class PhysicalObjectGeneratorTest method testSuccessOfMqttSink.

/**
 * Test if the mqtt sink is created successfully.
 */
@Test
public void testSuccessOfMqttSink() throws IOException, InjectionException {
    final Server mqttBroker = MqttUtils.createMqttBroker();
    final String topic = "mqttTest";
    final Map<String, String> conf = new HashMap<String, String>() {

        {
            put(ConfKeys.SinkConf.SINK_TYPE.name(), ConfValues.SinkType.MQTT.name());
            put(ConfKeys.MqttSink.MQTT_SINK_BROKER_URI.name(), MqttUtils.BROKER_URI);
            put(ConfKeys.MqttSink.MQTT_SINK_TOPIC.name(), topic);
        }
    };
    final Sink sink = generator.newSink(conf, classLoader);
    Assert.assertTrue(sink instanceof MqttSink);
    mqttBroker.stopServer();
}
Also used : MqttSink(edu.snu.mist.core.sinks.MqttSink) Server(io.moquette.server.Server) NettyTextSink(edu.snu.mist.core.sinks.NettyTextSink) Sink(edu.snu.mist.core.sinks.Sink) MqttSink(edu.snu.mist.core.sinks.MqttSink) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

MqttSink (edu.snu.mist.core.sinks.MqttSink)2 NettyTextSink (edu.snu.mist.core.sinks.NettyTextSink)2 Sink (edu.snu.mist.core.sinks.Sink)2 Server (io.moquette.server.Server)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 MqttException (org.eclipse.paho.client.mqttv3.MqttException)1 Test (org.junit.Test)1