You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@edgent.apache.org by dl...@apache.org on 2017/11/23 15:47:31 UTC
[6/9] incubator-edgent git commit: remove samples (now in separate
repo)
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/scripts/iotp/run-iotp-gwdevice-sample.sh
----------------------------------------------------------------------
diff --git a/samples/connectors/scripts/iotp/run-iotp-gwdevice-sample.sh b/samples/connectors/scripts/iotp/run-iotp-gwdevice-sample.sh
deleted file mode 100755
index 75b2dd6..0000000
--- a/samples/connectors/scripts/iotp/run-iotp-gwdevice-sample.sh
+++ /dev/null
@@ -1,46 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-
-CONNECTOR_SAMPLES_DIR=../..
-
-UBER_JAR=`echo ${CONNECTOR_SAMPLES_DIR}/target/edgent-samples-connectors-*-uber.jar`
-
-# Runs IBM Watson IoT Platform IotpGWDeviceSample sample.
-#
-# run-iotp-gwdevice-sample.sh [useGatewayClient|useManagedGateway] [useHttp] <device-cfg-path> # see iotp-gwdevice-sample.cfg
-#
-# Connects to WIoTP and sends Gateway and connected device events and receives device commands.
-#
-# This connects to your IBM Watson IoT Platform service
-# as the Gateway defined in a gateway config file.
-# The file format is the standard one for IBM Watson IoT Platform.
-#
-# Note, the config file also contains some additional information for this application.
-# A sample iot-gwdevice-sample.cfg is in the scripts/connectors/iotp directory.
-
-
-export CLASSPATH=${UBER_JAR}
-
-# https://github.com/ibm-watson-iot/iot-java/tree/master#migration-from-release-015-to-021
-# Uncomment the following to use the pre-0.2.1 WIoTP client behavior.
-#
-#USE_OLD_EVENT_FORMAT=-Dcom.ibm.iotf.enableCustomFormat=false
-
-VM_OPTS=${USE_OLD_EVENT_FORMAT}
-
-java ${VM_OPTS} org.apache.edgent.samples.connectors.iotp.IotpGWDeviceSample $*
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/scripts/iotp/runiotpquickstart.sh
----------------------------------------------------------------------
diff --git a/samples/connectors/scripts/iotp/runiotpquickstart.sh b/samples/connectors/scripts/iotp/runiotpquickstart.sh
deleted file mode 100755
index 5970fae..0000000
--- a/samples/connectors/scripts/iotp/runiotpquickstart.sh
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-
-CONNECTOR_SAMPLES_DIR=../..
-
-UBER_JAR=`echo ${CONNECTOR_SAMPLES_DIR}/target/edgent-samples-connectors-*-uber.jar`
-
-# Runs IBM Watson IoT Plaform Quickstart sample.
-#
-# runiotpquickstart.sh
-#
-# This connectors to the Qucikstart IBM Watson IoT Platform service
-# which requires no registration at all.
-#
-# The application prints out a URL which allows a browser
-# to see the data being sent from this sample to
-# IBM Watson IoT Plaform Quickstart sample.
-
-export CLASSPATH=${UBER_JAR}
-
-# https://github.com/ibm-watson-iot/iot-java/tree/master#migration-from-release-015-to-021
-# Uncomment the following to use the pre-0.2.1 WIoTP client behavior.
-#
-#USE_OLD_EVENT_FORMAT=-Dcom.ibm.iotf.enableCustomFormat=false
-
-VM_OPTS=${USE_OLD_EVENT_FORMAT}
-
-java ${VM_OPTS} org.apache.edgent.samples.connectors.iotp.IotpQuickstart
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/scripts/iotp/runiotpquickstart2.sh
----------------------------------------------------------------------
diff --git a/samples/connectors/scripts/iotp/runiotpquickstart2.sh b/samples/connectors/scripts/iotp/runiotpquickstart2.sh
deleted file mode 100755
index f712f6e..0000000
--- a/samples/connectors/scripts/iotp/runiotpquickstart2.sh
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-
-CONNECTOR_SAMPLES_DIR=../..
-
-UBER_JAR=`echo ${CONNECTOR_SAMPLES_DIR}/target/edgent-samples-connectors-*-uber.jar`
-
-# Runs IBM Watson IoT Plaform Quickstart sample.
-#
-# runiotpquickstart2.sh
-#
-# This connects to the Quickstart IBM Watson IoT Platform service
-# which requires no registration at all.
-#
-# The application prints out a URL which allows a browser
-# to see the data being sent from this sample to
-# IBM Watson IoT Platform Quickstart sample.
-
-export CLASSPATH=${UBER_JAR}
-
-# https://github.com/ibm-watson-iot/iot-java/tree/master#migration-from-release-015-to-021
-# Uncomment the following to use the pre-0.2.1 WIoTP client behavior.
-#
-#USE_OLD_EVENT_FORMAT=-Dcom.ibm.iotf.enableCustomFormat=false
-
-VM_OPTS=${USE_OLD_EVENT_FORMAT}
-
-java ${VM_OPTS} org.apache.edgent.samples.connectors.iotp.IotpQuickstart2 $*
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/scripts/iotp/runiotpsensors.sh
----------------------------------------------------------------------
diff --git a/samples/connectors/scripts/iotp/runiotpsensors.sh b/samples/connectors/scripts/iotp/runiotpsensors.sh
deleted file mode 100755
index a1e840b..0000000
--- a/samples/connectors/scripts/iotp/runiotpsensors.sh
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-
-CONNECTOR_SAMPLES_DIR=../..
-
-UBER_JAR=`echo ${CONNECTOR_SAMPLES_DIR}/target/edgent-samples-connectors-*-uber.jar`
-
-# Runs IBM Watson IoT Plaform sample.
-#
-# runiotpsensors.sh path/device.cfg
-#
-# e.g. runiotpsensors.sh $HOME/device.cfg
-#
-# This connectors to your IBM Watson IoT Platform service
-# as the device defined in the device.cfg.
-# The format of device.cfg is the standard one for
-# IBM Watson IoT Platform and a sample is in this directory
-# (omitting values for the authorization tokens).
-
-export CLASSPATH=${UBER_JAR}
-
-# https://github.com/ibm-watson-iot/iot-java/tree/master#migration-from-release-015-to-021
-# Uncomment the following to use the pre-0.2.1 WIoTP client behavior.
-#
-#USE_OLD_EVENT_FORMAT=-Dcom.ibm.iotf.enableCustomFormat=false
-
-VM_OPTS=${USE_OLD_EVENT_FORMAT}
-
-java ${VM_OPTS} org.apache.edgent.samples.connectors.iotp.IotpSensors $1
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/scripts/jdbc/.gitignore
----------------------------------------------------------------------
diff --git a/samples/connectors/scripts/jdbc/.gitignore b/samples/connectors/scripts/jdbc/.gitignore
deleted file mode 100644
index 3292c9c..0000000
--- a/samples/connectors/scripts/jdbc/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-# JDBC connector sample's outputs
-JdbcConnectorSampleDb/**
-derby.log
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/scripts/jdbc/README
----------------------------------------------------------------------
diff --git a/samples/connectors/scripts/jdbc/README b/samples/connectors/scripts/jdbc/README
deleted file mode 100644
index 112e02e..0000000
--- a/samples/connectors/scripts/jdbc/README
+++ /dev/null
@@ -1,35 +0,0 @@
-Sample JDBC connector dbms writer and reader topology applications.
-
-The following configuration is assumed:
-- Apache Derby is installed and the environment variable DERBY_HOME is set
-
-The writer is a simple JDBC connector sample demonstrating
-streaming write access of a dbms to add stream tuples to a table.
-
-The reader is a simple JDBC connector sample demonstrating
-streaming read access of a dbms table and creating stream
-tuples from the results.
-
-The source code for the samples is in the <edgent-release>/samples directory.
-
-Running the simple sample
--------------------------
-
-Modify the jdbc.properties file if required.
-
-# run the simple sample writer
-# the writer runs briefly and prints out additions to the table
-$ ./runjdbcsample.sh writer
-Inserting into persons table: person id=1 first=John last=Doe
-Inserting into persons table: person id=2 first=Jane last=Doe
-Inserting into persons table: person id=3 first=Billy last=McDoe
-$
-
-# run the simple sample reader
-# the reader runs briefly and prints out retrieved info
-$ ./runjdbcsample.sh reader
-retrieved person: id=1 first=John last=Doe
-retrieved person: id=2 first=Jane last=Doe
-retrieved person: id=3 first=Billy last=McDoe
-Unknown person id=99999
-$
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/scripts/jdbc/jdbc.properties
----------------------------------------------------------------------
diff --git a/samples/connectors/scripts/jdbc/jdbc.properties b/samples/connectors/scripts/jdbc/jdbc.properties
deleted file mode 100644
index 96a196a..0000000
--- a/samples/connectors/scripts/jdbc/jdbc.properties
+++ /dev/null
@@ -1,4 +0,0 @@
-#db.name= # defaults to "JdbcConnectorSampleDb"
-#db.user= # defaults to System.getProperties("user.name")
-#db.password= # defaults to no password
-persondata.path=persondata.txt
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/scripts/jdbc/persondata.txt
----------------------------------------------------------------------
diff --git a/samples/connectors/scripts/jdbc/persondata.txt b/samples/connectors/scripts/jdbc/persondata.txt
deleted file mode 100644
index 9037c44..0000000
--- a/samples/connectors/scripts/jdbc/persondata.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-# id,firstName,lastName
-1,John,Doe
-2,Jane,Doe
-3,Billy,McDoe
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/scripts/jdbc/runjdbcsample.sh
----------------------------------------------------------------------
diff --git a/samples/connectors/scripts/jdbc/runjdbcsample.sh b/samples/connectors/scripts/jdbc/runjdbcsample.sh
deleted file mode 100755
index 717abcf..0000000
--- a/samples/connectors/scripts/jdbc/runjdbcsample.sh
+++ /dev/null
@@ -1,48 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-
-CONNECTOR_SAMPLES_DIR=../..
-
-UBER_JAR=`echo ${CONNECTOR_SAMPLES_DIR}/target/edgent-samples-connectors-*-uber.jar`
-
-# Runs the Sample JDBC Writer or Reader
-#
-# ./runjdbcsample.sh writer
-# ./runjdbcsample.sh reader
-
-if [ -z "$DERBY_HOME" ]; then
- echo "\$DERBY_HOME not defined."
- exit 1;
-fi
-if [ ! -f $DERBY_HOME/lib/derby.jar ]; then
- echo "\$DERBY_HOME/lib/derby.jar: file not found"
- exit 1;
-fi
-
-export CLASSPATH=${UBER_JAR}:$DERBY_HOME/lib/derby.jar
-
-app=$1; shift
-if [ "$app" == "writer" ]; then
- java org.apache.edgent.samples.connectors.jdbc.SimpleWriterApp jdbc.properties
-elif [ "$app" == "reader" ]; then
- java org.apache.edgent.samples.connectors.jdbc.SimpleReaderApp jdbc.properties
-else
- echo "unrecognized mode '$app'"
- echo "usage: $0 writer|reader"
- exit 1
-fi
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/scripts/kafka/README
----------------------------------------------------------------------
diff --git a/samples/connectors/scripts/kafka/README b/samples/connectors/scripts/kafka/README
deleted file mode 100644
index b1c6bec..0000000
--- a/samples/connectors/scripts/kafka/README
+++ /dev/null
@@ -1,39 +0,0 @@
-Sample Kafka Publisher and Subscriber topology applications.
-
-By default the samples require the following kafka broker configuration:
-- bootstrap.servers="localhost:9092"
-- zookeeper.connect="localhost:2181"
-- kafka topic "kafkaSampleTopic" exists
-- no authentication
-
-See README-kafka for information about setting up a kafka server
-and creating the topic.
-
-The source code for the samples is in the <edgent-release>/samples directory.
-
-Running the simple sample
--------------------------
-
-Modify the kafka.properties file if required.
-
-# run the simple sample subscriber
-# the subscriber runs forever printing out each received message
-$ ./runkafkasample.sh sub
-
-# run the simple sample publisher
-# the publisher runs forever printing out each published message
-$ ./runkafkasample.sh pub
-
-Running the fully configurable clients
---------------------------------------
-
-# To see how to specify different values:
-$ ./runkafkaclient.sh -h
-
-# run the sample subscriber
-# the subscriber runs forever printing out each received message
-$ ./runkafkaclient.sh sub
-
-# run the sample producer
-# the producer runs forever printing out each published message
-$ ./runkafkaclient.sh pub
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/scripts/kafka/README-kafka
----------------------------------------------------------------------
diff --git a/samples/connectors/scripts/kafka/README-kafka b/samples/connectors/scripts/kafka/README-kafka
deleted file mode 100644
index e253963..0000000
--- a/samples/connectors/scripts/kafka/README-kafka
+++ /dev/null
@@ -1,25 +0,0 @@
-Setting up a Kafka/Zookeeper config on the default localhost ports is simple
-and well documented at https://kafka.apache.org/quickstart. This should do it:
-
-After downloading kafka:
-
-tar zxf ~/Downloads/kafka_2.11-0.10.1.0.tgz
-cd kafka_2.11-0.10.1.0/
-
-# start the servers (best in separate windows)
-bin/zookeeper-server-start.sh config/zookeeper.properties
-bin/kafka-server-start.sh config/server.properties
-
-The sample requires a topic. Create it:
-
-# create our kafka sample topic
-bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic kafkaSampleTopic
-bin/kafka-topics.sh --list --zookeeper localhost:2181
-
-# quick verify
-bin/kafka-console-producer.sh --broker-list localhost:9092 --topic kafkaSampleTopic
-hi
-there
-^D
-bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic kafkaSampleTopic --from-beginning
-... you should see the "hi" and "there" messages.
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/scripts/kafka/kafka.properties
----------------------------------------------------------------------
diff --git a/samples/connectors/scripts/kafka/kafka.properties b/samples/connectors/scripts/kafka/kafka.properties
deleted file mode 100644
index 2470078..0000000
--- a/samples/connectors/scripts/kafka/kafka.properties
+++ /dev/null
@@ -1,6 +0,0 @@
-# bootstrap.servers is for a kafka consumer
-bootstrap.servers=localhost:9092
-# zookeeper.connect is for a kafka producer
-zookeeper.connect=localhost:2181
-#group.id=
-topic=kafkaSampleTopic
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/scripts/kafka/runkafkaclient.sh
----------------------------------------------------------------------
diff --git a/samples/connectors/scripts/kafka/runkafkaclient.sh b/samples/connectors/scripts/kafka/runkafkaclient.sh
deleted file mode 100755
index 74aae1a..0000000
--- a/samples/connectors/scripts/kafka/runkafkaclient.sh
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-
-CONNECTOR_SAMPLES_DIR=../..
-
-UBER_JAR=`echo ${CONNECTOR_SAMPLES_DIR}/target/edgent-samples-connectors-*-uber.jar`
-
-# Runs the Kafka Publisher or Subscriber Client
-#
-# ./runkafkaclient.sh pub
-# ./runkafkaclient.sh sub
-# ./runkafkaclient.sh -h
-
-export CLASSPATH=${UBER_JAR}
-
-java org.apache.edgent.samples.connectors.kafka.KafkaClient $@
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/scripts/kafka/runkafkasample.sh
----------------------------------------------------------------------
diff --git a/samples/connectors/scripts/kafka/runkafkasample.sh b/samples/connectors/scripts/kafka/runkafkasample.sh
deleted file mode 100755
index 817da76..0000000
--- a/samples/connectors/scripts/kafka/runkafkasample.sh
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-
-CONNECTOR_SAMPLES_DIR=../..
-
-UBER_JAR=`echo ${CONNECTOR_SAMPLES_DIR}/target/edgent-samples-connectors-*-uber.jar`
-
-# Runs the Sample Kafka Publisher or Subscriber
-#
-# ./runkafkasample.sh pub
-# ./runkafkasample.sh sub
-
-export CLASSPATH=${UBER_JAR}
-
-app=$1; shift
-if [ "$app" == "pub" ]; then
- java org.apache.edgent.samples.connectors.kafka.SimplePublisherApp kafka.properties
-elif [ "$app" == "sub" ]; then
- java org.apache.edgent.samples.connectors.kafka.SimpleSubscriberApp kafka.properties
-else
- echo "unrecognized mode '$app'"
- echo "usage: $0 pub|sub"
- exit 1
-fi
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/scripts/mqtt/README
----------------------------------------------------------------------
diff --git a/samples/connectors/scripts/mqtt/README b/samples/connectors/scripts/mqtt/README
deleted file mode 100644
index 922807c..0000000
--- a/samples/connectors/scripts/mqtt/README
+++ /dev/null
@@ -1,37 +0,0 @@
-Sample MQTT Publisher and Subscriber topology applications.
-
-By default, the following MQTT broker configuration is assumed:
-- the broker's connection URL is tcp://localhost:1883
-- the broker is configured for no authentication
-
-See http://mqtt.org for the code and setup information for
-a mqtt broker.
-
-The source code for the samples is in the <edgent-release>/samples directory.
-
-Running the simple sample
--------------------------
-
-Modify the mqtt.properties file if required.
-
-# run the simple sample subscriber
-# the subscriber runs forever printing out each received message
-$ ./runmqttsample.sh sub
-
-# run the simple sample publisher
-# the publisher runs forever printing out each published message
-$ ./runmqttsample.sh pub
-
-Running the fully configurable clients
---------------------------------------
-
-# To see how to specify different values:
-$ ./runmqttclient.sh -h
-
-# run the subscriber client
-# the subscriber runs forever printing out each received message
-$ ./runmqttclient.sh sub
-
-# run the publisher client
-# the publisher runs forever printing out each published message
-$ ./runmqttclient.sh pub
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/scripts/mqtt/mqtt.properties
----------------------------------------------------------------------
diff --git a/samples/connectors/scripts/mqtt/mqtt.properties b/samples/connectors/scripts/mqtt/mqtt.properties
deleted file mode 100644
index 9f28c7c..0000000
--- a/samples/connectors/scripts/mqtt/mqtt.properties
+++ /dev/null
@@ -1,10 +0,0 @@
-mqtt.serverURLs=tcp://localhost:1883
-#mqtt.serverURLs=tcp://test.mosquitto.org:1883
-#mqtt.serverURLs=tcp://iot.eclipse.org:1883
-mqtt.topic=mqttSampleTopic
-#mqtt.userName=
-#mqtt.password=
-#mqtt.trustStore=
-#mqtt.trustStorePassword=
-#mqtt.keyStore=
-#mqtt.keyStorePassword=
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/scripts/mqtt/runmqttclient.sh
----------------------------------------------------------------------
diff --git a/samples/connectors/scripts/mqtt/runmqttclient.sh b/samples/connectors/scripts/mqtt/runmqttclient.sh
deleted file mode 100755
index f755bc9..0000000
--- a/samples/connectors/scripts/mqtt/runmqttclient.sh
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-
-CONNECTOR_SAMPLES_DIR=../..
-
-UBER_JAR=`echo ${CONNECTOR_SAMPLES_DIR}/target/edgent-samples-connectors-*-uber.jar`
-
-# Runs the MQTT Publisher or Subscriber client
-#
-# ./runmqttclient.sh pub
-# ./runmqttclient.sh sub
-# ./runmqttclient.sh -h
-
-export CLASSPATH=${UBER_JAR}
-
-java org.apache.edgent.samples.connectors.mqtt.MqttClient $@
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/scripts/mqtt/runmqttsample.sh
----------------------------------------------------------------------
diff --git a/samples/connectors/scripts/mqtt/runmqttsample.sh b/samples/connectors/scripts/mqtt/runmqttsample.sh
deleted file mode 100755
index 9d850dd..0000000
--- a/samples/connectors/scripts/mqtt/runmqttsample.sh
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-
-CONNECTOR_SAMPLES_DIR=../..
-
-UBER_JAR=`echo ${CONNECTOR_SAMPLES_DIR}/target/edgent-samples-connectors-*-uber.jar`
-
-# Runs the Sample MQTT Publisher or Subscriber
-#
-# ./runmqttsample.sh pub
-# ./runmqttsample.sh sub
-
-export CLASSPATH=${UBER_JAR}
-
-app=$1; shift
-if [ "$app" == "pub" ]; then
- java org.apache.edgent.samples.connectors.mqtt.SimplePublisherApp mqtt.properties
-elif [ "$app" == "sub" ]; then
- java org.apache.edgent.samples.connectors.mqtt.SimpleSubscriberApp mqtt.properties
-else
- echo "unrecognized mode '$app'"
- echo "usage: $0 pub|sub"
- exit 1
-fi
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/MsgSupplier.java
----------------------------------------------------------------------
diff --git a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/MsgSupplier.java b/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/MsgSupplier.java
deleted file mode 100644
index 13f2b4e..0000000
--- a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/MsgSupplier.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
-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.samples.connectors;
-
-import org.apache.edgent.function.Supplier;
-
-/**
- * A Supplier<String> for creating sample messages to publish.
- */
-public class MsgSupplier implements Supplier<String> {
- private static final long serialVersionUID = 1L;
- private final int maxCnt;
- private int cnt;
- private boolean done;
-
- public MsgSupplier(int maxCnt) {
- this.maxCnt = maxCnt;
- }
-
- @Override
- public synchronized String get() {
- ++cnt;
- if (maxCnt >= 0 && cnt >= maxCnt) {
- if (!done) {
- done = true;
- System.out.println("poll: no more messages to generate.");
- }
- return null;
- }
- String msg = String.format("Message-%d from %s", cnt, Util.simpleTS());
- System.out.println("poll generated msg to publish: " + msg);
- return msg;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/Options.java
----------------------------------------------------------------------
diff --git a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/Options.java b/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/Options.java
deleted file mode 100644
index fcab5c5..0000000
--- a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/Options.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
-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.samples.connectors;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.edgent.function.Function;
-
-/**
- * Simple command option processor.
- */
-public class Options {
- private static final Map<String,Function<String,?>> handlers = new HashMap<>();
- private static final Map<String,Object> options = new HashMap<>();
- private static final Map<String,Object> defaults = new HashMap<>();
-
- public <T> void addHandler(String opt, Function<String,T> cvtFn) {
- addHandler(opt, cvtFn, null);
- }
-
- public <T> void addHandler(String opt, Function<String,T> cvtFn, T dflt) {
- handlers.put(opt, cvtFn);
- if (dflt != null)
- defaults.put(opt, dflt);
- }
-
- public void processArgs(String[] args) {
- for (Map.Entry<String,Function<String,?>> e : handlers.entrySet()) {
- handleOpt(e.getKey(), e.getValue(), args);
- }
-
- for (String arg : args) {
- String[] item = arg.split("=");
- if (!handlers.containsKey(item[0]))
- throw new IllegalArgumentException("Unrecognized argument '"+arg+"'");
- }
- }
-
- private void handleOpt(String opt, Function<String,?> cvtFn, String[] args) {
- String v = getArg(cvtFn!=null ? opt : opt+"=true", args);
- if (v != null)
- options.put(opt, cvtFn==null ? true : cvtFn.apply(v));
- else if (defaults.get(opt) != null)
- options.put(opt, defaults.get(opt));
- }
-
- public <T> T get(String opt) {
- return get(opt, null);
- }
-
- @SuppressWarnings("unchecked")
- public <T> T get(String opt, T dflt) {
- return options.get(opt) == null ? dflt : (T)options.get(opt);
- }
-
- public Set<Map.Entry<String,Object>> getAll() {
- return Collections.unmodifiableSet(options.entrySet());
- }
-
- public void put(String opt, Object value) {
- options.put(opt, value);
- }
-
- private String getArg(String item, String[] args) {
- String[] itemParts = item.split("=");
- if (itemParts.length>1)
- item = itemParts[0];
- for (String arg : args) {
- String[] parts = arg.split("=");
- if (item.equals(parts[0])) {
- if (parts.length > 1)
- return parts[1];
- else
- return itemParts.length > 1 ? itemParts[1] : parts[1];
- }
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/Util.java
----------------------------------------------------------------------
diff --git a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/Util.java b/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/Util.java
deleted file mode 100644
index d9803ef..0000000
--- a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/Util.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
-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.samples.connectors;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.edgent.execution.Job;
-
-/**
- * Utilities for connector samples.
- */
-public class Util {
-
- /**
- * Generate a simple timestamp with the form {@code HH:mm:ss.SSS}
- * @return the timestamp
- */
- public static String simpleTS() {
- return new SimpleDateFormat("HH:mm:ss.SSS").format(new Date());
- }
-
-
- /**
- * Wait for the job to reach the specified state.
- * <p>
- * A placeholder till GraphJob directly supports awaitState()?
- * @param job the job
- * @param state the state to wait for
- * @param timeout specify -1 to wait forever (until interrupted)
- * @param unit may be null if timeout is -1
- * @return true if the state was reached, false otherwise: the time limit
- * was reached of the thread was interrupted.
- */
- public static boolean awaitState(Job job, Job.State state, long timeout, TimeUnit unit) {
- long endWait = -1;
- if (timeout != -1) {
- endWait = System.currentTimeMillis()
- + unit.toMillis(timeout);
- }
- while (true) {
- Job.State curState = job.getCurrentState();
- if (curState == state)
- return true;
- if (endWait != -1) {
- long now = System.currentTimeMillis();
- if (now >= endWait)
- return false;
- }
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- return false;
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/elm327/Cmd.java
----------------------------------------------------------------------
diff --git a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/elm327/Cmd.java b/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/elm327/Cmd.java
deleted file mode 100644
index f3ae61a..0000000
--- a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/elm327/Cmd.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
-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.samples.connectors.elm327;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-import com.google.gson.JsonObject;
-
-/**
- * ELM327 and OBD-II command interface.
- *
- */
-public interface Cmd {
- /**
- * Key ({@value}) for PID identifier in JSON result.
- */
- String PID = "pid";
-
- /**
- * Key ({@value}) for timestamp in JSON result. Timestamp value is the
- * number of milliseconds since the 1907 epoch.
- */
- String TS = "ts";
-
- /**
- * Key ({@value}) for the returned value in JSON result.
- * May not be present.
- */
- String VALUE = "value";
-
- /**
- * How the command is written to the serial port.
- *
- * @param out
- * OutputStream to write bytes to.
- * @throws IOException
- * Exception writing bytes.
- */
- void writeCmd(OutputStream out) throws IOException;
-
- /**
- * Process the reply into a result.
- *
- * @param result
- * JSON object to populate with the result.
- * @param reply
- * Bytes that were returned from the command execution.
- *
- * @return {@code true} result is valid, {@code false} otherwise.
- */
- boolean result(JsonObject result, byte[] reply);
-
- /**
- * Unique identifier of the command.
- *
- * @return Unique identifier of the command.
- */
- String id();
-}
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/elm327/Elm327Cmds.java
----------------------------------------------------------------------
diff --git a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/elm327/Elm327Cmds.java b/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/elm327/Elm327Cmds.java
deleted file mode 100644
index aed0c23..0000000
--- a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/elm327/Elm327Cmds.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
-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.samples.connectors.elm327;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.charset.StandardCharsets;
-
-import org.apache.edgent.connectors.serial.SerialDevice;
-import org.apache.edgent.samples.connectors.elm327.runtime.CommandExecutor;
-
-import com.google.gson.JsonObject;
-
-/**
- * ELM327 commands.
- *
- *
- */
-public enum Elm327Cmds implements Cmd {
-
- INIT("ATZ"),
- ECHO_OFF("ATE0"),
- PROTOCOL_3("ATSP3"),
- PROTOCOL_5("ATSP5"),
- BYPASS_INIT("ATBI"),
- FAST_INIT("ATFI"),
- SLOW_INIT("ATSI"),;
-
- private byte[] cmd;
-
- Elm327Cmds(String code) {
- cmd = (code + "\r").getBytes(StandardCharsets.US_ASCII);
- }
-
- @Override
- public void writeCmd(OutputStream out) throws IOException {
- out.write(cmd);
- }
-
- @Override
- public boolean result(JsonObject result, byte[] data) {
- return true;
- }
-
- @Override
- public String id() {
- return name();
- }
-
- /**
- * Initialize the ELM327 to a specific protocol.
- * @param device Serial device the ELM327 is connected to.
- * @param protocol OBD-II protocol to initialize to.
- */
- public static void initializeProtocol(SerialDevice device, Elm327Cmds protocol) {
- device.setInitializer(port -> CommandExecutor.initialize(protocol, port.getOutput(), port.getInput()));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/elm327/Elm327Streams.java
----------------------------------------------------------------------
diff --git a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/elm327/Elm327Streams.java b/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/elm327/Elm327Streams.java
deleted file mode 100644
index dbaf4db..0000000
--- a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/elm327/Elm327Streams.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
-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.samples.connectors.elm327;
-
-import java.util.concurrent.TimeUnit;
-
-import org.apache.edgent.connectors.serial.SerialDevice;
-import org.apache.edgent.function.Supplier;
-import org.apache.edgent.samples.connectors.elm327.runtime.CommandExecutor;
-import org.apache.edgent.topology.TStream;
-
-import com.google.gson.JsonArray;
-
-/**
- * Streams fetching OBD-II data from an ELM327 through
- * a serial device.
- *
- * @see <a href="https://en.wikipedia.org/wiki/ELM327">ELM327</a>
- */
-public class Elm327Streams {
-
- /**
- * Periodically execute a number of ELM327 commands.
- * Each tuple on the returned stream is a JSON array containing
- * the result for each command.
- * <BR>
- * Each result is a JSON object containing the
- * {@link Cmd#id() command identifier} with key {@link Cmd#PID pid}
- * and any result set by the individual command, typically with
- * the key {@link Cmd#VALUE value}.
- *
- * @param device Serial device the ELM327 is connected to.
- * @param period Period to poll.
- * @param unit Unit of {@code period}.
- * @param cmds Commands to execute.
- * @return Stream containing the results of the command exections.
- */
- public static TStream<JsonArray> poll(SerialDevice device, long period, TimeUnit unit, Cmd ... cmds) {
-
- Supplier<JsonArray> data = device.getSource(
- port ->
- {
- JsonArray array = new JsonArray();
- for (Cmd cmd : cmds) {
- array.add(CommandExecutor.execute(cmd, port.getOutput(), port.getInput()));
- }
- return array;
-
- });
-
- return device.topology().poll(data, period, unit);
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/elm327/Pids01.java
----------------------------------------------------------------------
diff --git a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/elm327/Pids01.java b/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/elm327/Pids01.java
deleted file mode 100644
index b42beb3..0000000
--- a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/elm327/Pids01.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
-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.samples.connectors.elm327;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.charset.StandardCharsets;
-
-import org.apache.edgent.samples.connectors.elm327.runtime.CommandExecutor;
-
-import com.google.gson.JsonObject;
-
-/**
- * OBD-II Standard Mode 01 Pids.
- *
- *
- * @see <a href="https://en.wikipedia.org/wiki/OBD-II_PIDs#Mode_01">OBD-II Mode 01 Pids</a>
- */
-public enum Pids01 implements Cmd {
-
- /**
- * Get the list of available PIDs.
- */
- AVAILABLE_PIDS("00"),
-
- /**
- * Engine coolant temperature in degrees C.
- */
- ENGINE_COOLANT_TEMP("05") {
- @Override
- protected boolean decode(JsonObject result, byte[] reply) {
-
- int[] binary = CommandExecutor.binary(reply, 4, 2);
-
- int c = binary[0] - 40;
- result.addProperty(VALUE, c);
-
- return true;
- }
- },
-
- /**
- * Engine speed in rpm.
- */
- RPM("0C") {
- @Override
- protected boolean decode(JsonObject result, byte[] reply) {
-
- int[] binary = CommandExecutor.binary(reply, 4, 4);
- int rpm = ((binary[0] * 256) + binary[1])/4;
- result.addProperty(VALUE, rpm);
-
- return true;
- }
- },
-
- /**
- * Vehicle speed in km/h.
- */
- SPEED("0D"){
- @Override
- protected boolean decode(JsonObject result, byte[] reply) {
-
- int[] binary = CommandExecutor.binary(reply, 4, 2);
-
- result.addProperty(VALUE, binary[0]);
-
- return true;
- }
- },
-
- /**
- * Engine air intake temperature in degrees C.
- */
- AIR_INTAKE_TEMP("0F"){
- @Override
- protected boolean decode(JsonObject result, byte[] reply) {
-
- int[] binary = CommandExecutor.binary(reply, 4, 2);
-
- int c = binary[0] - 40;
- result.addProperty(VALUE, c);
-
- return true;
- }
- },
- ;
-
- private final String pid;
- private final byte[] cmd;
-
- Pids01(String pid) {
- this.pid = pid;
- cmd = ("01" + pid + "1\r").getBytes(StandardCharsets.US_ASCII);
- }
-
- public String id() {
- return pid;
- }
-
- @Override
- public void writeCmd(OutputStream out) throws IOException {
- out.write(cmd);
- }
- @Override
- public final boolean result(JsonObject result, byte[] data) {
- return validateReply(data) && decode(result, data);
- }
- boolean decode(JsonObject result, byte[] data) {
- return true;
- }
-
- boolean validateReply(byte[] reply) {
- if (reply[0] != '4')
- return false;
- if (reply[1] != '1')
- return false;
- if (reply[2] != pid.charAt(0))
- return false;
- if (reply[3] != pid.charAt(1))
- return false;
-
- return true;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/elm327/package-info.java
----------------------------------------------------------------------
diff --git a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/elm327/package-info.java b/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/elm327/package-info.java
deleted file mode 100644
index 9d3a9b9..0000000
--- a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/elm327/package-info.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
-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.
-*/
-/**
- * OBD-II protocol sample using ELM327.
- *
- * ELM327 devices allow connectivity to a vehicle's OBD-II information.
- *
- * @see <a href="https://en.wikipedia.org/wiki/OBD-II">OBD-II</a>
- * @see <a href="https://en.wikipedia.org/wiki/ELM327">ELM327</a>
- */
-package org.apache.edgent.samples.connectors.elm327;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/elm327/runtime/CommandExecutor.java
----------------------------------------------------------------------
diff --git a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/elm327/runtime/CommandExecutor.java b/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/elm327/runtime/CommandExecutor.java
deleted file mode 100644
index b5a342f..0000000
--- a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/elm327/runtime/CommandExecutor.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
-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.samples.connectors.elm327.runtime;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import org.apache.edgent.samples.connectors.elm327.Cmd;
-import org.apache.edgent.samples.connectors.elm327.Elm327Cmds;
-
-import com.google.gson.JsonObject;
-
-/**
- * Runtime execution of ELM327 & OBD-II commands.
- *
- */
-public class CommandExecutor {
-
- public static int[] binary(byte[] reply, int offset, int length) {
- int[] binary = new int[length / 2];
- for (int i = 0; i < binary.length; i++) {
- int h = Character.digit(reply[offset++], 16);
- int l = Character.digit(reply[offset++], 16);
- binary[i] = ((h * 16) + l);
- }
- return binary;
- }
-
- public static void initialize(Cmd protocol, OutputStream out, InputStream in) {
- try {
-
- executeUntilOK(10, Elm327Cmds.INIT, out, in);
- Thread.sleep(1000);
-
- executeUntilOK(1, Elm327Cmds.ECHO_OFF, out, in);
-
- executeUntilOK(1, protocol, out, in);
- executeUntilOK(1, Elm327Cmds.SLOW_INIT, out, in);
- Thread.sleep(1000);
-
- } catch (Exception ioe) {
- throw new RuntimeException(ioe);
- }
- }
-
- private static boolean readUntilPrompt(InputStream in, ByteArrayOutputStream bytes) throws IOException {
- bytes.reset();
- for (;;) {
- int b = in.read();
- if (b == -1)
- return false;
- if (b == ' ')
- continue;
- if (b == '\r')
- continue;
- if (b == '>')
- return true;
-
- bytes.write(b);
- }
- }
-
- public static JsonObject executeUntilOK(int n, Cmd cmd, OutputStream out, InputStream in) throws IOException {
- try (ByteArrayOutputStream bytes = new ByteArrayOutputStream(16)) {
- for (int i = 0; i < n; i++) {
- cmd.writeCmd(out);
- out.flush();
-
- if (!readUntilPrompt(in, bytes))
- continue;
-
- byte[] reply = bytes.toByteArray();
- JsonObject j = new JsonObject();
- if (cmd.result(j, reply))
- return j;
- break;
- }
- }
- throw new IllegalStateException("Could not execute command:" + cmd);
- }
-
- public static JsonObject execute(Cmd cmd, OutputStream out, InputStream in) {
- try (ByteArrayOutputStream bytes = new ByteArrayOutputStream(16)) {
- cmd.writeCmd(out);
- out.flush();
-
- JsonObject result = new JsonObject();
- result.addProperty(Cmd.PID, cmd.id());
- result.addProperty(Cmd.TS, System.currentTimeMillis());
-
- readUntilPrompt(in, bytes);
-
- cmd.result(result, bytes.toByteArray());
-
- return result;
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/file/FileReaderApp.java
----------------------------------------------------------------------
diff --git a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/file/FileReaderApp.java b/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/file/FileReaderApp.java
deleted file mode 100644
index 80086b7..0000000
--- a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/file/FileReaderApp.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
-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.samples.connectors.file;
-
-import java.io.File;
-
-import org.apache.edgent.connectors.file.FileStreams;
-import org.apache.edgent.console.server.HttpServer;
-import org.apache.edgent.providers.development.DevelopmentProvider;
-import org.apache.edgent.topology.TStream;
-import org.apache.edgent.topology.Topology;
-
-/**
- * Watch a directory for files and convert their contents into a stream.
- */
-public class FileReaderApp {
- private final String directory;
- private static final String baseLeafname = "FileSample";
-
- public static void main(String[] args) throws Exception {
- if (args.length != 1)
- throw new Exception("missing pathname to an existing directory");
- FileReaderApp reader = new FileReaderApp(args[0]);
- reader.run();
- }
-
- /**
- *
- * @param directory an existing directory to watch for file
- */
- public FileReaderApp(String directory) {
- File dir = new File(directory);
- if (!dir.exists())
- throw new IllegalArgumentException("directory doesn't exist");
- this.directory = directory;
- }
-
- public void run() throws Exception {
- DevelopmentProvider tp = new DevelopmentProvider();
-
- // build the application / topology
-
- Topology t = tp.newTopology("FileSample consumer");
-
- // watch for files
- TStream<String> pathnames = FileStreams.directoryWatcher(t, () -> directory);
-
- // create a stream containing the files' contents.
- // use a preFn to include a separator in the results.
- // use a postFn to delete the file once its been processed.
- TStream<String> contents = FileStreams.textFileReader(pathnames,
- tuple -> "<PRE-FUNCTION> "+tuple,
- (tuple,exception) -> {
- // exercise a little caution in case the user pointed
- // us at a directory with other things in it
- if (tuple.contains("/"+baseLeafname+"_")) {
- new File(tuple).delete();
- }
- return null;
- });
-
- // print out what's being read
- contents.print();
-
- // run the application / topology
- System.out.println("starting the reader watching directory " + directory);
- System.out.println("Console URL for the job: "
- + tp.getServices().getService(HttpServer.class).getConsoleUrl());
- tp.submit(t);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/file/FileWriterApp.java
----------------------------------------------------------------------
diff --git a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/file/FileWriterApp.java b/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/file/FileWriterApp.java
deleted file mode 100644
index c956cb6..0000000
--- a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/file/FileWriterApp.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
-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.samples.connectors.file;
-
-import java.io.File;
-import java.util.Date;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.apache.edgent.connectors.file.FileStreams;
-import org.apache.edgent.connectors.file.FileWriterCycleConfig;
-import org.apache.edgent.connectors.file.FileWriterFlushConfig;
-import org.apache.edgent.connectors.file.FileWriterPolicy;
-import org.apache.edgent.connectors.file.FileWriterRetentionConfig;
-import org.apache.edgent.console.server.HttpServer;
-import org.apache.edgent.providers.development.DevelopmentProvider;
-import org.apache.edgent.topology.TStream;
-import org.apache.edgent.topology.Topology;
-
-/**
- * Write a TStream<String> to files.
- */
-public class FileWriterApp {
- private final String directory;
- private final String basePathname;
- private static final String baseLeafname = "FileSample";
-
- public static void main(String[] args) throws Exception {
- if (args.length != 1)
- throw new Exception("missing pathname to an existing directory");
- FileWriterApp writer = new FileWriterApp(args[0]);
- writer.run();
- }
-
- /**
- *
- * @param directory an existing directory to create files in
- */
- public FileWriterApp(String directory) {
- File dir = new File(directory);
- if (!dir.exists())
- throw new IllegalArgumentException("directory doesn't exist");
- this.directory = directory;
- basePathname = directory+"/"+baseLeafname;
- }
-
- public void run() throws Exception {
- DevelopmentProvider tp = new DevelopmentProvider();
-
- // build the application / topology
-
- Topology t = tp.newTopology("FileSample producer");
-
- FileWriterPolicy<String> policy = new FileWriterPolicy<String>(
- FileWriterFlushConfig.newImplicitConfig(),
- FileWriterCycleConfig.newCountBasedConfig(5),
- FileWriterRetentionConfig.newFileCountBasedConfig(3));
-
- // create a tuple stream to write out
- AtomicInteger cnt = new AtomicInteger();
- TStream<String> stream = t.poll(() -> {
- String str = String.format("sample tuple %d %s",
- cnt.incrementAndGet(), new Date().toString());
- System.out.println("created tuple: "+str);
- return str;
- }, 1, TimeUnit.SECONDS);
-
- // write the stream
- FileStreams.textFileWriter(stream, () -> basePathname, () -> policy);
-
- // run the application / topology
- System.out.println("starting the producer writing to directory " + directory);
- System.out.println("Console URL for the job: "
- + tp.getServices().getService(HttpServer.class).getConsoleUrl());
- tp.submit(t);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/file/README
----------------------------------------------------------------------
diff --git a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/file/README b/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/file/README
deleted file mode 100644
index 4477518..0000000
--- a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/file/README
+++ /dev/null
@@ -1,11 +0,0 @@
-Sample File Streams connector topology applications.
-
-The file writer application writes a stream's tuples to files.
-
-The file reader application watches a directory for files and reads their
-contents into a stream of tuples.
-
-see scripts/connectors/file/README to run them
-
-FileWriterApp.java - the writer application topology
-FileReaderApp.java - the reader application topology
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/file/package-info.java
----------------------------------------------------------------------
diff --git a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/file/package-info.java b/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/file/package-info.java
deleted file mode 100644
index a2cfe74..0000000
--- a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/file/package-info.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
-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.
-*/
-/**
- * Samples showing use of the
- * <a href="{@docRoot}/org/apache/edgent/connectors/file/package-summary.html">
- * File stream connector</a>.
- * <p>
- * See <edgent-release>/scripts/connectors/file/README to run the samples.
- * <p>
- * The following samples are provided:
- * <ul>
- * <li>FileReaderApp.java - a simple directory watcher and file reader application topology</li>
- * <li>FileWriterApp.java - a simple file writer application topology</li>
- * </ul>
- */
-package org.apache.edgent.samples.connectors.file;
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpAppClient.java
----------------------------------------------------------------------
diff --git a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpAppClient.java b/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpAppClient.java
deleted file mode 100644
index 4f4e2dc..0000000
--- a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpAppClient.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
-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.samples.connectors.iotp;
-
-import java.io.File;
-import java.io.FileReader;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Properties;
-
-import com.google.gson.JsonObject;
-import com.ibm.iotf.client.app.ApplicationClient;
-import com.ibm.iotf.client.app.Command;
-import com.ibm.iotf.client.app.Event;
-import com.ibm.iotf.client.app.EventCallback;
-
-/**
- * An IBM Watson IoT Platform ApplicationClient that publishes device cmds
- * and subscribes to device events for
- * {@link IotpDeviceSample} and {@link IotpGWDeviceSample}.
- * <p>
- * Usage: {@code [useGW] <app-cfg-path> # see scripts/connectors/iotp/iotp-app-client.cfg}
- * <p>
- * This connects to your IBM Watson IoT Platform service
- * as the Application defined in a application config file.
- * The file format is the standard one for IBM Watson IoT Platform.
- * <p>
- * Note, the config file also contains some additional information for this application.
- *
- * <p>See {@code scripts/connectors/iotp/README} for information about a
- * prototype application configuration file and running the application.
- */
-public class IotpAppClient {
-
- private static final String usage = "[useGW] <app-cfg-path> # see scripts/connectors/iotp/iotp-app-client.cfg";
-
- public static void main(String[] args) throws Exception {
- if (args.length == 0)
- throw new Exception("Usage: " + usage);
- List<String> argList = Arrays.asList(args);
- boolean useGW = argList.contains("useGW");
- String deviceCfgPath = argList.get(argList.size() - 1);
-
- Properties cfgProps = new Properties();
- cfgProps.load(new FileReader(new File(deviceCfgPath)));
-
- String iotpOrg = getProperty(cfgProps, "Organization-ID", "org");
- String iotpAppId = getProperty(cfgProps, "id");
- String iotpApiKey = getProperty(cfgProps, "API-Key", "auth-key");
- System.out.println("org: " + iotpOrg);
- System.out.println("id: " + iotpAppId);
- System.out.println("ApiKey: " + iotpApiKey);
-
- String iotpDevType = cfgProps.getProperty("deviceType");
- String iotpDevId = cfgProps.getProperty("deviceId");
- if (useGW) {
- iotpDevType = cfgProps.getProperty("gwDeviceType");
- iotpDevId = cfgProps.getProperty("gwDeviceId");
- }
- System.out.println("deviceType: " + iotpDevType);
- System.out.println("deviceId: " + iotpDevId);
-
- ApplicationClient client = new ApplicationClient(cfgProps);
-
- client.connect();
-
- boolean sendCmd = true;
- if (sendCmd) {
- sendCmd(client, iotpDevType, iotpDevId);
- if (useGW) {
- sendCmd(client, cfgProps.getProperty("cn-dev1-type"), cfgProps.getProperty("cn-dev1-id"));
- }
- }
-
- boolean subscribeToEvents = true;
- if (subscribeToEvents) {
- System.out.println("Subscribing to events...");
- client.subscribeToDeviceEvents();
- client.setEventCallback(new EventCallback() {
-
- @Override
- public void processCommand(Command cmd) {
- // TODO Auto-generated method stub
-
- }
-
- @SuppressWarnings("deprecation")
- @Override
- public void processEvent(Event event) {
- System.out.println(
- String.format("Received event: %s %s:%s %s %s", event.getEvent(),
- event.getDeviceType(), event.getDeviceId(),
- event.getFormat(),
- event.getPayload()));
- }
-
- });
- Thread.sleep(Integer.MAX_VALUE);
- }
-
- client.disconnect();
- }
-
- private static int msgNum = 0;
- private static void sendCmd(ApplicationClient client, String iotpDevType, String iotpDevId) throws Exception {
- String command = "cmdId-1";
- JsonObject jo = new JsonObject();
- jo.addProperty("msgNum", ++msgNum);
- jo.addProperty("deviceTypeAndId", iotpDevType + "/" + iotpDevId);
- jo.addProperty("cmdId", command);
- jo.addProperty("str", "a-string");
- jo.addProperty("num", 12345);
- JsonObject data = jo;
-
- System.out.println("Sending "+iotpDevType+"/"+iotpDevId+" command: "+command+" data: "+data);
-
- boolean ok = client.publishCommand(iotpDevType, iotpDevId, command, data);
-
- System.out.println("Sent: " + (ok ? "OK" : "NOT-OK"));
- }
-
- private static String getProperty(Properties props, String... keys) {
- for (String key : keys) {
- String val = props.getProperty(key);
- if (val != null)
- return val;
- }
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpDeviceSample.java
----------------------------------------------------------------------
diff --git a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpDeviceSample.java b/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpDeviceSample.java
deleted file mode 100644
index 2880c99..0000000
--- a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpDeviceSample.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
-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.samples.connectors.iotp;
-
-import java.io.File;
-import java.io.FileReader;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Properties;
-import java.util.Random;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.edgent.connectors.iot.QoS;
-import org.apache.edgent.connectors.iotp.IotpDevice;
-import org.apache.edgent.providers.direct.DirectProvider;
-import org.apache.edgent.topology.TStream;
-import org.apache.edgent.topology.Topology;
-
-import com.google.gson.JsonObject;
-import com.ibm.iotf.client.device.DeviceClient;
-import com.ibm.iotf.devicemgmt.DeviceData;
-import com.ibm.iotf.devicemgmt.device.ManagedDevice;
-
-/**
- * Send device events and subscribe to device commands as a registered IoT device
- * using a standard IBM Watson IoT Platform service instance.
- * <P>
- * Use {@link IotpAppClient} to print published events and generate a command
- * (start this app before running IotpAppClient).
- * <P>
- * This sample demonstrates:
- * <UL>
- * <LI>Using the IotpDevice connector</LI>
- * <LI>Initializing the IotpDevice connector using the WIoTP API objects</LI>
- * <LI>Publishing and subscribing to device events and commands</LI>
- * </UL>
- * <p>
- * This connects to your IBM Watson IoT Platform service
- * as the Device defined in a device config file.
- * The file format is the standard one for IBM Watson IoT Platform.
- *
- * <p>See {@code scripts/connectors/iotp/README} for information about a
- * prototype device configuration file and running the sample.
- */
-public class IotpDeviceSample {
- private static final String usage = "[useDeviceClient|useManagedDevice] [useHttp] <device-cfg-path>";
-
- public static void main(String[] args) throws Exception {
- if (args.length == 0)
- throw new Exception("Usage: " + usage);
- List<String> argList = Arrays.asList(args);
- boolean useDeviceClient = argList.contains("useDeviceClient");
- boolean useManagedDevice = argList.contains("useManagedDevice");
- boolean useInternalDeviceClient = !(useDeviceClient || useManagedDevice);
- boolean useHttp = argList.contains("useHttp");
- String deviceCfgPath = argList.get(argList.size() - 1);
-
- DirectProvider tp = new DirectProvider();
- Topology topology = tp.newTopology("IotpDeviceSample");
-
- Properties cfgProps = new Properties();
- cfgProps.load(new FileReader(new File(deviceCfgPath)));
-
- String iotpOrg = getProperty(cfgProps, "Organization-ID", "org");
- String iotpDevType = getProperty(cfgProps, "Device-Type", "type");
- String iotpDevId = getProperty(cfgProps, "Device-ID", "id");
- System.out.println("org: " + iotpOrg);
- System.out.println("DeviceType: " + iotpDevType);
- System.out.println("DeviceId: " + iotpDevId);
-
- // System.out.println("mosquitto_pub -u <api-auth-key> -P <api-quth-token> -h "+iotpOrg+".messaging.internetofthings.ibmcloud.com -p 1883 -i a:"+iotpOrg+":appId1 -t iot-2/type/"+iotpDevType+"/id/"+iotpDevId+"/cmd/cmd-1/fmt/json -m '{}'");
- // System.out.println("mosquitto_sub -d -u <api-auth-key> -P <api-quth-token> -h "+iotpOrg+".messaging.internetofthings.ibmcloud.com -p 1883 -i a:"+iotpOrg+":appId2 -t iot-2/type/+/id/+/evt/+/fmt/+");
-
- IotpDevice device;
- if (useInternalDeviceClient) {
- System.out.println("Using internal DeviceClient");
- device = new IotpDevice(topology, cfgProps);
- }
- else if (useDeviceClient) {
- System.out.println("Using WIoTP DeviceClient");
- device = new IotpDevice(topology, new DeviceClient(cfgProps));
- }
- else if (useManagedDevice) {
- System.out.println("Using WIoTP ManagedDevice");
- DeviceData deviceData = new DeviceData.Builder().build();
- device = new IotpDevice(topology, new ManagedDevice(cfgProps, deviceData));
- }
- else
- throw new Exception("woops");
-
- Random r = new Random();
- TStream<double[]> raw = topology.poll(() -> {
- double[] v = new double[3];
-
- v[0] = r.nextGaussian() * 10.0 + 40.0;
- v[1] = r.nextGaussian() * 10.0 + 50.0;
- v[2] = r.nextGaussian() * 10.0 + 60.0;
-
- return v;
- }, 3, TimeUnit.SECONDS);
-
- TStream<JsonObject> json = raw.map(v -> {
- JsonObject j = new JsonObject();
- j.addProperty("temp", v[0]);
- j.addProperty("humidity", v[1]);
- j.addProperty("objectTemp", v[2]);
- return j;
- });
-
- if (!useHttp) {
- device.events(json, "sensors", QoS.FIRE_AND_FORGET);
- }
- else {
- System.out.println("Publishing events using HTTP");
- device.httpEvents(json, "sensors");
- }
-
- // subscribe to / report device cmds
- device.commands().sink(jo -> System.out.println("Received cmd: " + jo));
-
- tp.submit(topology);
- }
-
- private static String getProperty(Properties props, String... keys) {
- for (String key : keys) {
- String val = props.getProperty(key);
- if (val != null)
- return val;
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/a7aeb2b4/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpGWDeviceSample.java
----------------------------------------------------------------------
diff --git a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpGWDeviceSample.java b/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpGWDeviceSample.java
deleted file mode 100644
index 74ec4d9..0000000
--- a/samples/connectors/src/main/java/org/apache/edgent/samples/connectors/iotp/IotpGWDeviceSample.java
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
-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.samples.connectors.iotp;
-
-import java.io.File;
-import java.io.FileReader;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Random;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.edgent.connectors.iot.IotDevice;
-import org.apache.edgent.connectors.iot.QoS;
-import org.apache.edgent.connectors.iotp.IotpGateway;
-import org.apache.edgent.providers.direct.DirectProvider;
-import org.apache.edgent.topology.TStream;
-import org.apache.edgent.topology.Topology;
-
-import com.google.gson.JsonObject;
-import com.ibm.iotf.client.gateway.GatewayClient;
-import com.ibm.iotf.devicemgmt.DeviceData;
-import com.ibm.iotf.devicemgmt.gateway.ManagedGateway;
-
-/**
- * Similar to IotpDeviceSample but behaving as a registered IoT Gateway device.
- * <P>
- * Use {@link IotpAppClient} to print published events and generate a command
- * (start this app before running IotpAppClient with the "useGW" option).
- * <P>
- * This sample demonstrates:
- * <UL>
- * <LI>Using the IotpGateway connector</LI>
- * <LI>Initializing the IotpGateway connector using the WIoTP API objects</LI>
- * <LI>Publishing and subscribing to Gateway device events and commands</LI>
- * <LI>Publishing and subscribing to connected device events and commands</LI>
- * </UL>
- * <p>
- * This connects to your IBM Watson IoT Platform service
- * as the Gateway defined in a gateway config file.
- * The file format is the standard one for IBM Watson IoT Platform.
- *
- * <p>See {@code scripts/connectors/iotp/README} for information about a
- * prototype gateway device configuration file and running the sample.
- */
-public class IotpGWDeviceSample {
-
- private static final String usage = "[useGatewayClient|useManagedGateway] [useHttp] <device-cfg-path>";
-
- public static void main(String[] args) throws Exception {
- if (args.length == 0)
- throw new Exception("Usage: " + usage);
- List<String> argList = Arrays.asList(args);
- boolean useGatewayClient = argList.contains("useGatewayClient");
- boolean useManagedGateway = argList.contains("useManagedGateway");
- boolean useInternalGatewayClient = !(useGatewayClient || useManagedGateway);
- boolean useHttp = argList.contains("useHttp");
- String deviceCfgPath = argList.get(argList.size() - 1);
-
- DirectProvider tp = new DirectProvider();
- Topology topology = tp.newTopology("IotpGWDeviceSample");
-
- Properties cfgProps = new Properties();
- cfgProps.load(new FileReader(new File(deviceCfgPath)));
-
- String iotpOrg = getProperty(cfgProps, "Organization-ID", "org");
- String iotpGWDevType = getProperty(cfgProps, "Gateway-Type", "Device-Type", "type");
- String iotpGWDevId = getProperty(cfgProps, "Gateway-ID", "Device-ID", "id");
- String iotpCnDev1Type = cfgProps.getProperty("cn-dev1-type");
- String iotpCnDev1Id = cfgProps.getProperty("cn-dev1-id");
-
- System.out.println("orgId: " + iotpOrg);
- System.out.println("GWDeviceType: " + iotpGWDevType);
- System.out.println("GWDeviceId: " + iotpGWDevId);
- System.out.println("cn-dev1 DeviceType: " + iotpCnDev1Type);
- System.out.println("cn-dev1 DeviceId: " + iotpCnDev1Id);
-
- // System.out.println("GW mosquitto_pub -u <api-auth-key> -P <api-auth-token> -h "+iotpOrg+".messaging.internetofthings.ibmcloud.com -p 1883 -i a:"+iotpOrg+":appId1 -t iot-2/type/"+iotpGWDevType+"/id/"+iotpGWDevId+"/cmd/cmd-1/fmt/json -m '{}'");
- // System.out.println("GW mosquitto_sub -d -u <api-auth-key> -P <api-auth-token> -h "+iotpOrg+".messaging.internetofthings.ibmcloud.com -p 1883 -i a:"+iotpOrg+":appId2 -t iot-2/type/+/id/+/evt/+/fmt/+");
- // System.out.println("cn-dev1 mosquitto_pub -u <api-auth-key> -P <api-quth-token> -h "+iotpOrg+".messaging.internetofthings.ibmcloud.com -p 1883 -i a:"+iotpOrg+":appId1 -t iot-2/type/"+iotpCnDev1Type+"/id/"+iotpCnDev1Id+"/cmd/cmd-1/fmt/json -m '{}'");
-
- IotpGateway gwDevice;
- if (useInternalGatewayClient) {
- System.out.println("Using internal GatewayClient");
- gwDevice = new IotpGateway(topology, cfgProps);
- }
- else if (useGatewayClient) {
- System.out.println("Using WIoTP GatewayClient");
- gwDevice = new IotpGateway(topology, new GatewayClient(cfgProps));
- }
- else if (useManagedGateway) {
- System.out.println("Using WIoTP ManagedGateway");
- DeviceData deviceData = new DeviceData.Builder().build();
- gwDevice = new IotpGateway(topology, new ManagedGateway(cfgProps, deviceData));
- }
- else
- throw new IllegalStateException("woops");
-
- Map<String,String> devAttrMap = new HashMap<>();
- devAttrMap.put(IotpGateway.ATTR_DEVICE_TYPE, iotpCnDev1Type);
- devAttrMap.put(IotpGateway.ATTR_DEVICE_ID, iotpCnDev1Id);
-
- String cnDev1FqDeviceId = gwDevice.getIotDeviceId(devAttrMap);
- IotDevice cnDev1Device = gwDevice.getIotDevice(cnDev1FqDeviceId);
-
- System.out.println("GW fqDeviceId: " + gwDevice.getDeviceId());
- System.out.println("cn-dev1 fqDeviceId: " + cnDev1FqDeviceId);
- System.out.println("IotDevice cn-dev1 fqDeviceId: " + cnDev1Device.getDeviceId());
-
- Random r = new Random();
- TStream<double[]> raw = topology.poll(() -> {
- double[] v = new double[3];
-
- v[0] = r.nextGaussian() * 10.0 + 40.0;
- v[1] = r.nextGaussian() * 10.0 + 50.0;
- v[2] = r.nextGaussian() * 10.0 + 60.0;
-
- return v;
- }, 3, TimeUnit.SECONDS);
-
- // Create a stream of Gateway device events
- TStream<JsonObject> gwJson = raw.map(v -> {
- JsonObject jo2 = new JsonObject();
- jo2.addProperty("gw-fqDeviceId", gwDevice.getDeviceId());
- jo2.addProperty("temp", v[0]);
- return jo2;
- });
-
- // Create a stream of a connected device's events
- TStream<JsonObject> cnDev1Json = raw.map(v -> {
- JsonObject jo2 = new JsonObject();
- jo2.addProperty("cnDev1-fqDeviceId", cnDev1Device.getDeviceId());
- jo2.addProperty("humidity", v[1]);
- return jo2;
- });
-
- if (!useHttp) {
- gwDevice.events(gwJson, "gw-device", QoS.FIRE_AND_FORGET);
- gwDevice.eventsForDevice(cnDev1FqDeviceId, cnDev1Json, "gw-events-for-cnDev1", QoS.FIRE_AND_FORGET);
- cnDev1Device.events(cnDev1Json, "cnDev1-events", QoS.FIRE_AND_FORGET);
- }
- else {
- System.out.println("Publishing events using HTTP");
- throw new IllegalStateException("GW httpEvents is NYI");
- // gwDevice.httpEvents(json, "sensors");
- // gwDevice.httpEventsForDevice(cnDev1FqDeviceId, cnDev1Json, "gw-events-for-cnDev1");
- }
-
- // subscribe to / report cmds for the GW and all its connected devices
- gwDevice.commandsForDevice(Collections.emptySet()).sink(jo -> System.out.println("Received all-cmds cmd: " + jo));
-
- // subscribe to / report just GW device cmds
- gwDevice.commands().sink(jo -> System.out.println("Received gwDevice cmd: " + jo));
-
- // subscribe to / report just cnDev1 device cmds
- gwDevice.commandsForDevice(cnDev1FqDeviceId).sink(jo -> System.out.println("Received gwDevice-for-cnDev1 cmd: " + jo));
- cnDev1Device.commands().sink(jo -> System.out.println("Received cnDev1 cmd: " + jo));
-
- // subscribe to / report just cmds for a specific device type
- gwDevice.commandsForType(iotpGWDevType).sink(jo -> System.out.println("Received for-type-gwDeviceType cmd: " + jo));
- gwDevice.commandsForType(iotpCnDev1Type).sink(jo -> System.out.println("Received for-type-cnDev1DeviceType cmd: " + jo));
-
- tp.submit(topology);
- }
-
- private static String getProperty(Properties props, String... keys) {
- for (String key : keys) {
- String val = props.getProperty(key);
- if (val != null)
- return val;
- }
- return null;
- }
- }