use of edu.snu.mist.client.datastreams.configurations.SourceConfiguration in project mist by snuspl.
the class HelloMist method submitQuery.
/**
* Submit a stateless query.
* The query reads strings from a source server, filter strings which start with "HelloMist:",
* trim "HelloMist:" part of the filtered strings, and send them to a sink server.
* @return result of the submission
* @throws IOException
* @throws InjectionException
*/
public static APIQueryControlResult submitQuery(final Configuration configuration) throws IOException, InjectionException, URISyntaxException {
final String sourceSocket = Tang.Factory.getTang().newInjector(configuration).getNamedInstance(NettySourceAddress.class);
final SourceConfiguration localTextSocketSourceConf = MISTExampleUtils.getLocalTextSocketSourceConf(sourceSocket);
final MISTQueryBuilder queryBuilder = new MISTQueryBuilder();
queryBuilder.socketTextStream(localTextSocketSourceConf).filter(s -> s.startsWith("HelloMIST:")).map(s -> s.substring("HelloMIST:".length()).trim()).textSocketOutput(MISTExampleUtils.SINK_HOSTNAME, MISTExampleUtils.SINK_PORT);
return MISTExampleUtils.submit(queryBuilder, configuration);
}
use of edu.snu.mist.client.datastreams.configurations.SourceConfiguration in project mist by snuspl.
the class UnionMist method submitQuery.
/**
* Submit a query unifying two sources.
* The query reads strings from two source servers, unifies them, and send them to a sink server.
* @return result of the submission
* @throws IOException
* @throws InjectionException
*/
public static APIQueryControlResult submitQuery(final Configuration configuration) throws IOException, InjectionException, URISyntaxException {
final Injector injector = Tang.Factory.getTang().newInjector(configuration);
final String source1Socket = injector.getNamedInstance(UnionLeftSourceAddress.class);
final String source2Socket = injector.getNamedInstance(UnionRightSourceAddress.class);
final SourceConfiguration localTextSocketSource1Conf = MISTExampleUtils.getLocalTextSocketSourceConf(source1Socket);
final SourceConfiguration localTextSocketSource2Conf = MISTExampleUtils.getLocalTextSocketSourceConf(source2Socket);
// Simple reduce function.
final MISTBiFunction<Integer, Integer, Integer> reduceFunction = (v1, v2) -> {
return v1 + v2;
};
final MISTQueryBuilder queryBuilder = new MISTQueryBuilder();
final ContinuousStream sourceStream1 = queryBuilder.socketTextStream(localTextSocketSource1Conf).map(s -> new Tuple2(s, 1));
final ContinuousStream sourceStream2 = queryBuilder.socketTextStream(localTextSocketSource2Conf).map(s -> new Tuple2(s, 1));
sourceStream1.union(sourceStream2).reduceByKey(0, String.class, reduceFunction).map(s -> s.toString()).textSocketOutput(MISTExampleUtils.SINK_HOSTNAME, MISTExampleUtils.SINK_PORT);
return MISTExampleUtils.submit(queryBuilder, configuration);
}
use of edu.snu.mist.client.datastreams.configurations.SourceConfiguration in project mist by snuspl.
the class WordCount method submitQuery.
/**
* Submit a query containing reduce-by-key operator.
* The query reads strings from a source server, filters alphabetical words,
* counts words using reduce-by-key operator, and sends them to a sink server.
* @return result of the submission
* @throws IOException
* @throws InjectionException
*/
public static APIQueryControlResult submitQuery(final Configuration configuration) throws IOException, InjectionException, URISyntaxException {
final String sourceSocket = Tang.Factory.getTang().newInjector(configuration).getNamedInstance(NettySourceAddress.class);
final SourceConfiguration localTextSocketSourceConf = MISTExampleUtils.getLocalTextSocketSourceConf(sourceSocket);
// Simple reduce function.
final MISTBiFunction<Integer, Integer, Integer> reduceFunction = (v1, v2) -> {
return v1 + v2;
};
final MISTQueryBuilder queryBuilder = new MISTQueryBuilder();
queryBuilder.socketTextStream(localTextSocketSourceConf).filter(s -> isAlpha(s)).map(s -> new Tuple2(s, 1)).reduceByKey(0, String.class, reduceFunction).map(s -> s.toString()).textSocketOutput(MISTExampleUtils.SINK_HOSTNAME, MISTExampleUtils.SINK_PORT);
return MISTExampleUtils.submit(queryBuilder, configuration);
}
use of edu.snu.mist.client.datastreams.configurations.SourceConfiguration in project mist by snuspl.
the class WindowAndAggregate method submitQuery.
/**
* Submit a windowing and aggregating query.
* The query reads strings from a source server, puts them into window,
* concatenates all inputs in the window into a single string using toString function, and
* print out the start and end time of the window.
* @return result of the submission
* @throws IOException
* @throws InjectionException
*/
public static APIQueryControlResult submitQuery(final Configuration configuration) throws IOException, InjectionException, URISyntaxException {
// configurations for source and sink
final String sourceSocket = Tang.Factory.getTang().newInjector(configuration).getNamedInstance(NettySourceAddress.class);
final SourceConfiguration localTextSocketSourceConf = MISTExampleUtils.getLocalTextSocketSourceConf(sourceSocket);
// configurations for windowing and aggregation
final int windowSize = 5000;
final int windowEmissionInterval = 2500;
final MISTFunction<WindowData<String>, String> aggregateFunc = (windowData) -> {
return windowData.getDataCollection().toString() + ", window is started at " + windowData.getStart() + ", window is ended at " + windowData.getEnd() + ".";
};
final MISTQueryBuilder queryBuilder = new MISTQueryBuilder();
queryBuilder.socketTextStream(localTextSocketSourceConf).window(new TimeWindowInformation(windowSize, windowEmissionInterval)).aggregateWindow(aggregateFunc).textSocketOutput(MISTExampleUtils.SINK_HOSTNAME, MISTExampleUtils.SINK_PORT);
return MISTExampleUtils.submit(queryBuilder, configuration);
}
use of edu.snu.mist.client.datastreams.configurations.SourceConfiguration in project mist by snuspl.
the class MQTTNoiseSensing method submitQuery.
/**
* Submit a query fetching data from a MQTT source.
* The query reads strings from a MQTT topic and send them to a sink.
* @return result of the submission
* @throws IOException
* @throws InjectionException
*/
public static APIQueryControlResult submitQuery(final Configuration configuration) throws IOException, InjectionException, URISyntaxException {
final String brokerURI = Tang.Factory.getTang().newInjector(configuration).getNamedInstance(TestMQTTBrokerURI.class);
final SourceConfiguration localMQTTSourceConf = MISTExampleUtils.getMQTTSourceConf("MISTExampleSub", brokerURI);
final MISTQueryBuilder queryBuilder = new MISTQueryBuilder();
final ContinuousStream<Integer> sensedData = queryBuilder.mqttStream(localMQTTSourceConf).map((mqttMessage) -> Integer.parseInt(new String(mqttMessage.getPayload())));
final ContinuousStream<Integer> noisy = sensedData.filter((value) -> value < 200);
final ContinuousStream<Integer> calm = sensedData.filter((value) -> value >= 200);
// Text socket output
noisy.map((loudValue) -> new StringBuilder().append("It's noisy! The value was ").append(loudValue).toString()).textSocketOutput(MISTExampleUtils.SINK_HOSTNAME, MISTExampleUtils.SINK_PORT);
// MQTT output
noisy.map((value) -> new MqttMessage("ON".getBytes())).mqttOutput(brokerURI, "MISTExamplePub");
calm.map((value) -> new MqttMessage("OFF".getBytes())).mqttOutput(brokerURI, "MISTExamplePub");
return MISTExampleUtils.submit(queryBuilder, configuration);
}
Aggregations