You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@edgent.apache.org by jf...@apache.org on 2019/07/16 06:14:35 UTC
[incubator-edgent] 01/01: First Example for Edgent Next
This is an automated email from the ASF dual-hosted git repository.
jfeinauer pushed a commit to branch edgent-next
in repository https://gitbox.apache.org/repos/asf/incubator-edgent.git
commit 8328795d69e3d7daa7f723fc6788930c6229bfda
Author: Julian Feinauer <j....@pragmaticminds.de>
AuthorDate: Tue Jul 16 08:13:56 2019 +0200
First Example for Edgent Next
---
next/pom.xml | 49 +++++++++++
.../main/java/org/apache/edgent/next/Example.java | 97 ++++++++++++++++++++++
pom.xml | 1 +
3 files changed, 147 insertions(+)
diff --git a/next/pom.xml b/next/pom.xml
new file mode 100644
index 0000000..acc51d2
--- /dev/null
+++ b/next/pom.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>8</source>
+ <target>8</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <parent>
+ <groupId>org.apache.edgent</groupId>
+ <artifactId>edgent-parent</artifactId>
+ <version>1.3.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>edgent-next</artifactId>
+ <packaging>pom</packaging>
+
+ <name>Next Generation Apache Edgent</name>
+
+ <dependencies>
+ </dependencies>
+
+</project>
diff --git a/next/src/main/java/org/apache/edgent/next/Example.java b/next/src/main/java/org/apache/edgent/next/Example.java
new file mode 100644
index 0000000..5787589
--- /dev/null
+++ b/next/src/main/java/org/apache/edgent/next/Example.java
@@ -0,0 +1,97 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you 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.apache.edgent.next;
+
+import java.util.concurrent.TimeUnit;
+
+public class Example {
+
+ public static void main(String[] args) {
+ // Example 1 - Generic handler
+ from("s7://192.168.167.210/0/0")
+ .scrape(10, TimeUnit.SECONDS)
+ .field("%DB500.DBX10:BOOL")
+ .field("%DB500.DBX10:BOOL", Boolean.class)
+ .handle((field, result, clazz) -> System.out.println(field + ": " + result));
+
+ // Example 2 - Store to JDBC
+ from("s7://192.168.167.210/0/0")
+ .scrape(10, TimeUnit.SECONDS)
+ .field("%DB500.DBX10:BOOL")
+ .field("%DB500.DBX10:BOOL", Boolean.class)
+ .transform(new JsonTransformer())
+ .to(new JdbcSink());
+
+ // Example 3 - Store to InfluxDB
+ from("s7://192.168.167.210/0/0")
+ .scrape(10, TimeUnit.SECONDS)
+ .field("%DB500.DBX10:BOOL")
+ .field("%DB500.DBX10:BOOL", Boolean.class)
+ .to(new InfluxDbSink());
+
+ // Example 4 - CRUNCH
+ from("s7://192.168.167.210/0/0")
+ .scrape(10, TimeUnit.SECONDS)
+ .field("%DB500.DBX10:BOOL", Boolean.class).analyze()
+ .flank(UP).handle(...)
+ }
+
+ public static ScraperBuilder from(String plcConnection) {
+ return new ScraperBuilder(plcConnection);
+ }
+
+ public static class ScraperBuilder {
+ private final String connection;
+
+ public ScraperBuilder(String connection) {
+ this.connection = connection;
+ }
+
+ public FieldCollector scrape(int time, TimeUnit unit) {
+ return new FieldCollector(this);
+ }
+ }
+
+ private static class FieldCollector {
+ private final ScraperBuilder scraperBuilder;
+
+ public FieldCollector(ScraperBuilder scraperBuilder) {
+ this.scraperBuilder = scraperBuilder;
+ }
+
+ private FieldCollector field(String fieldAdress) {
+ return this;
+ }
+
+ private FieldCollector field(String fieldAdress, Class<?> clazz) {
+ return this;
+ }
+
+ private void handle(ResultHandler handler) {
+
+ }
+ }
+
+ @FunctionalInterface
+ private interface ResultHandler {
+
+ void handle(String fieldName, Object result, Class<?> clazz);
+
+ }
+}
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 177a29f..d82045b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -100,6 +100,7 @@
<module>test</module>
<module>utils</module>
<module>platforms</module>
+ <module>next</module>
</modules>
<build>