streampipes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zehn...@apache.org
Subject [incubator-streampipes] 06/25: Add event model reference
Date Tue, 17 Dec 2019 09:48:07 GMT
This is an automated email from the ASF dual-hosted git repository.

zehnder pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git

commit 403bd59e20d74c12773b4db5e7870b8f384cc2f0
Author: Dominik Riemer <riemer@fzi.de>
AuthorDate: Thu Feb 28 21:48:09 2019 +0100

    Add event model reference
---
 .../jvm/eventmodel/EventModelExamples.java         | 70 ++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git a/streampipes-pipeline-elements-examples-processors-jvm/src/main/java/org/streampipes/pe/examples/jvm/eventmodel/EventModelExamples.java
b/streampipes-pipeline-elements-examples-processors-jvm/src/main/java/org/streampipes/pe/examples/jvm/eventmodel/EventModelExamples.java
new file mode 100644
index 0000000..b4059e9
--- /dev/null
+++ b/streampipes-pipeline-elements-examples-processors-jvm/src/main/java/org/streampipes/pe/examples/jvm/eventmodel/EventModelExamples.java
@@ -0,0 +1,70 @@
+/*
+Copyright 2019 FZI Forschungszentrum Informatik
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+package org.streampipes.pe.examples.jvm.eventmodel;
+
+import org.streampipes.commons.exceptions.SpRuntimeException;
+import org.streampipes.model.runtime.Event;
+import org.streampipes.pe.examples.jvm.base.DummyParameters;
+import org.streampipes.wrapper.context.EventProcessorRuntimeContext;
+import org.streampipes.wrapper.routing.SpOutputCollector;
+import org.streampipes.wrapper.runtime.EventProcessor;
+
+import java.util.List;
+
+public class EventModelExamples implements EventProcessor<DummyParameters> {
+
+  /**
+   * Example event:
+   * { "timestamp" : 12345, "temperature" : 45.6, "deviceId" : "sensor1", "running" : true,
+   * "location" : {"latitude" : 34.4, "longitude" : -47}, "lastValues" : [45, 22, 21]}
+   */
+
+  private String temperatureSelector;
+  private String runningSelector;
+  private String deviceIdSelector;
+  private String latitudeSelector;
+  private String lastValueSelector;
+
+  @Override
+  public void onInvocation(DummyParameters parameters, SpOutputCollector spOutputCollector,
EventProcessorRuntimeContext runtimeContext) throws SpRuntimeException {
+
+    // usually, the fields such as temperatureSelector would be retrieved from the parameter
class
+  }
+
+  @Override
+  public void onEvent(Event event, SpOutputCollector collector) throws SpRuntimeException
{
+
+    Float temperatureValue = event.getFieldBySelector(temperatureSelector).getAsPrimitive().getAsFloat();
+    String deviceId = event.getFieldBySelector(deviceIdSelector).getAsPrimitive().getAsString();
+
+    Double latitude = event.getFieldBySelector(latitudeSelector).getAsPrimitive().getAsDouble();
+
+    Boolean running = event.getFieldBySelector(runningSelector).getAsPrimitive().getAsBoolean();
+
+    List<Integer> lastValues = event.getFieldBySelector(lastValueSelector).getAsList().parseAsSimpleType(Integer.class);
+
+
+    event.addField("city", "Karlsruhe");
+    event.removeFieldBySelector(temperatureSelector);
+    event.addField("fahrenheit", 48);
+
+  }
+
+  @Override
+  public void onDetach() throws SpRuntimeException {
+
+  }
+}


Mime
View raw message