You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@plc4x.apache.org by GitBox <gi...@apache.org> on 2018/09/26 16:04:01 UTC

[GitHub] sruehl closed pull request #23: Added note for Service Loader.

sruehl closed pull request #23: Added note for Service Loader.
URL: https://github.com/apache/incubator-plc4x/pull/23
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/examples/google/src/main/java/org/apache/plc4x/java/examples/google/iotcore/S7PlcToGoogleIoTCoreSample.java b/examples/google/src/main/java/org/apache/plc4x/java/examples/google/iotcore/S7PlcToGoogleIoTCoreSample.java
index eb538fb7b..48b2d6a3f 100644
--- a/examples/google/src/main/java/org/apache/plc4x/java/examples/google/iotcore/S7PlcToGoogleIoTCoreSample.java
+++ b/examples/google/src/main/java/org/apache/plc4x/java/examples/google/iotcore/S7PlcToGoogleIoTCoreSample.java
@@ -18,16 +18,19 @@ Licensed to the Apache Software Foundation (ASF) under one
 */
 package org.apache.plc4x.java.examples.google.iotcore;
 
+import io.jsonwebtoken.JwtBuilder;
+import io.jsonwebtoken.Jwts;
+import io.jsonwebtoken.SignatureAlgorithm;
 import org.apache.plc4x.java.PlcDriverManager;
 import org.apache.plc4x.java.api.connection.PlcConnection;
 import org.apache.plc4x.java.api.connection.PlcReader;
 import org.apache.plc4x.java.api.messages.PlcReadRequest;
 import org.apache.plc4x.java.api.messages.PlcReadResponse;
-
-// [START iot_mqtt_includes]
-import io.jsonwebtoken.JwtBuilder;
-import io.jsonwebtoken.Jwts;
-import io.jsonwebtoken.SignatureAlgorithm;
+import org.eclipse.paho.client.mqttv3.*;
+import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
+import org.joda.time.DateTime;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.nio.ByteBuffer;
 import java.nio.file.Files;
@@ -35,16 +38,7 @@ Licensed to the Apache Software Foundation (ASF) under one
 import java.security.KeyFactory;
 import java.security.spec.PKCS8EncodedKeySpec;
 
-import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
-import org.eclipse.paho.client.mqttv3.MqttCallback;
-import org.eclipse.paho.client.mqttv3.MqttClient;
-import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
-import org.eclipse.paho.client.mqttv3.MqttException;
-import org.eclipse.paho.client.mqttv3.MqttMessage;
-import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
-import org.joda.time.DateTime;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+// [START iot_mqtt_includes]
 // [END iot_mqtt_includes]
 
 public class S7PlcToGoogleIoTCoreSample {
diff --git a/integrations/apache-edgent/src/test/java/org/apache/plc4x/edgent/PlcFunctionsTest.java b/integrations/apache-edgent/src/test/java/org/apache/plc4x/edgent/PlcFunctionsTest.java
index 6a3bbcdff..802f68ebc 100644
--- a/integrations/apache-edgent/src/test/java/org/apache/plc4x/edgent/PlcFunctionsTest.java
+++ b/integrations/apache-edgent/src/test/java/org/apache/plc4x/edgent/PlcFunctionsTest.java
@@ -18,128 +18,127 @@ Licensed to the Apache Software Foundation (ASF) under one
 */
 package org.apache.plc4x.edgent;
 
+import com.google.gson.JsonObject;
 import org.apache.edgent.function.Consumer;
 import org.apache.edgent.function.Function;
 import org.apache.edgent.function.Supplier;
-import org.apache.plc4x.edgent.mock.MockField;
 import org.apache.plc4x.edgent.mock.MockConnection;
+import org.apache.plc4x.edgent.mock.MockField;
 import org.apache.plc4x.java.PlcDriverManager;
 import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
 import org.apache.plc4x.test.FastTests;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-import com.google.gson.JsonObject;
-
 public class PlcFunctionsTest {
-  
-  protected MockConnection getMockConnection() throws PlcConnectionException {
-    return (MockConnection) new PlcDriverManager().getConnection("mock-for-edgent-integration://some-cool-url");
-  }
-
-  /*
-   * test PlcConnectionAdapter.newSupplier
-   */
-  @SuppressWarnings("unchecked")
-  @Test
-  @Category(FastTests.class)
-  public void testSupplier() throws Exception {
-    String addressStr = "MyReadWriteAddress/0";
-    MockField address = new MockField(addressStr);
-    PlcConnectionAdapter adapter = new PlcConnectionAdapter(getMockConnection());
-    MockConnection connection = (MockConnection) adapter.getConnection();
-
-    Supplier<?> supplier;
-    
-    supplier = PlcFunctions.booleanSupplier(adapter, addressStr);
-    PlcConnectionAdapterTest.checkSupplier(connection, address, supplier, true, false);
-    
-    supplier = PlcFunctions.byteSupplier(adapter, addressStr);
-    PlcConnectionAdapterTest.checkSupplier(connection, address, supplier, (byte)0x1, (byte)0x2, (byte)0x3);
-
-    supplier = PlcFunctions.shortSupplier(adapter, addressStr);
-    PlcConnectionAdapterTest.checkSupplier(connection, address, supplier, (short)1, (short)2, (short)3);
-
-    supplier = PlcFunctions.integerSupplier(adapter, addressStr);
-    PlcConnectionAdapterTest.checkSupplier(connection, address, supplier, 1000, 1001, 1002);
-    
-    supplier = PlcFunctions.floatSupplier(adapter, addressStr);
-    PlcConnectionAdapterTest.checkSupplier(connection, address, supplier, 1000.5f, 1001.5f, 1002.5f);
-    
-    supplier = PlcFunctions.stringSupplier(adapter, addressStr);
-    PlcConnectionAdapterTest.checkSupplier(connection, address, supplier, "one", "two", "three");
-    
-    adapter.close();
-  }
-
-  /*
-   * test PlcConnectionAdapter.newJsonConsumer(address)
-   */
-  @Test
-  @Category(FastTests.class)
-  public void testNewConsumer1() throws Exception {
-    String addressStr = "MyReadWriteAddress/0";
-    MockField address = new MockField(addressStr);
-    PlcConnectionAdapter adapter = new PlcConnectionAdapter(getMockConnection());
-    MockConnection connection = (MockConnection) adapter.getConnection();
-
-    Consumer<?> consumer;
-    
-    consumer = PlcFunctions.booleanConsumer(adapter, addressStr);
-    PlcConnectionAdapterTest.checkConsumer(connection, address, consumer, true, false);
-    
-    consumer = PlcFunctions.byteConsumer(adapter, addressStr);
-    PlcConnectionAdapterTest.checkConsumer(connection, address, consumer, (byte)0x1, (byte)0x2, (byte)0x3);
-    
-    consumer = PlcFunctions.shortConsumer(adapter, addressStr);
-    PlcConnectionAdapterTest.checkConsumer(connection, address, consumer, (short)1, (short)2, (short)3);
-
-    consumer = PlcFunctions.integerConsumer(adapter, addressStr);
-    PlcConnectionAdapterTest.checkConsumer(connection, address, consumer, 1000, 1001, 1002);
-    
-    consumer = PlcFunctions.floatConsumer(adapter, addressStr);
-    PlcConnectionAdapterTest.checkConsumer(connection, address, consumer, 1000.5f, 1001.5f, 1002.5f);
-    
-    consumer = PlcFunctions.stringConsumer(adapter, addressStr);
-    PlcConnectionAdapterTest.checkConsumer(connection, address, consumer, "one", "two", "three");
-    
-    adapter.close();
-  }
-
-  /*
-   * test PlcConnectionAdapter.newJsonConsumer(addressFn, valueFn)
-   */
-  @Test
-  @Category(FastTests.class)
-  public void testNewConsumer2() throws Exception {
-    String addressStr = "MyReadWriteAddress/0";
-    MockField address = new MockField(addressStr);
-    PlcConnectionAdapter adapter = new PlcConnectionAdapter(getMockConnection());
-    MockConnection connection = (MockConnection) adapter.getConnection();
-
-    Consumer<JsonObject> consumer;
-    
-    Function<JsonObject,String> addressFn = t -> t.get("address").getAsString(); 
-    
-    consumer = PlcFunctions.booleanConsumer(adapter, addressFn, t -> t.get("value").getAsBoolean());
-    PlcConnectionAdapterTest.checkConsumerJson(connection, address, consumer, true, false);
-    
-    consumer = PlcFunctions.byteConsumer(adapter, addressFn, t -> t.get("value").getAsByte());
-    PlcConnectionAdapterTest.checkConsumerJson(connection, address, consumer, (byte)0x1, (byte)0x2, (byte)0x3);
-
-    consumer = PlcFunctions.shortConsumer(adapter, addressFn, t -> t.get("value").getAsShort());
-    PlcConnectionAdapterTest.checkConsumerJson(connection, address, consumer, (short)1, (short)2, (short)3);
-
-    consumer = PlcFunctions.integerConsumer(adapter, addressFn, t -> t.get("value").getAsInt());
-    PlcConnectionAdapterTest.checkConsumerJson(connection, address, consumer, 1000, 1001, 1002);
-    
-    consumer = PlcFunctions.floatConsumer(adapter, addressFn, t -> t.get("value").getAsFloat());
-    PlcConnectionAdapterTest.checkConsumerJson(connection, address, consumer, 1000.5f, 1001.5f, 1002.5f);
-    
-    consumer = PlcFunctions.stringConsumer(adapter, addressFn, t -> t.get("value").getAsString());
-    PlcConnectionAdapterTest.checkConsumerJson(connection, address, consumer, "one", "two", "three");
-    
-    adapter.close();
-  }
+
+    protected MockConnection getMockConnection() throws PlcConnectionException {
+        return (MockConnection) new PlcDriverManager().getConnection("mock-for-edgent-integration://some-cool-url");
+    }
+
+    /*
+     * test PlcConnectionAdapter.newSupplier
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    @Category(FastTests.class)
+    public void testSupplier() throws Exception {
+        String addressStr = "MyReadWriteAddress/0";
+        MockField address = new MockField(addressStr);
+        PlcConnectionAdapter adapter = new PlcConnectionAdapter(getMockConnection());
+        MockConnection connection = (MockConnection) adapter.getConnection();
+
+        Supplier<?> supplier;
+
+        supplier = PlcFunctions.booleanSupplier(adapter, addressStr);
+        PlcConnectionAdapterTest.checkSupplier(connection, address, supplier, true, false);
+
+        supplier = PlcFunctions.byteSupplier(adapter, addressStr);
+        PlcConnectionAdapterTest.checkSupplier(connection, address, supplier, (byte)0x1, (byte)0x2, (byte)0x3);
+
+        supplier = PlcFunctions.shortSupplier(adapter, addressStr);
+        PlcConnectionAdapterTest.checkSupplier(connection, address, supplier, (short)1, (short)2, (short)3);
+
+        supplier = PlcFunctions.integerSupplier(adapter, addressStr);
+        PlcConnectionAdapterTest.checkSupplier(connection, address, supplier, 1000, 1001, 1002);
+
+        supplier = PlcFunctions.floatSupplier(adapter, addressStr);
+        PlcConnectionAdapterTest.checkSupplier(connection, address, supplier, 1000.5f, 1001.5f, 1002.5f);
+
+        supplier = PlcFunctions.stringSupplier(adapter, addressStr);
+        PlcConnectionAdapterTest.checkSupplier(connection, address, supplier, "one", "two", "three");
+
+        adapter.close();
+    }
+
+    /*
+     * test PlcConnectionAdapter.newJsonConsumer(address)
+     */
+    @Test
+    @Category(FastTests.class)
+    public void testNewConsumer1() throws Exception {
+        String addressStr = "MyReadWriteAddress/0";
+        MockField address = new MockField(addressStr);
+        PlcConnectionAdapter adapter = new PlcConnectionAdapter(getMockConnection());
+        MockConnection connection = (MockConnection) adapter.getConnection();
+
+        Consumer<?> consumer;
+
+        consumer = PlcFunctions.booleanConsumer(adapter, addressStr);
+        PlcConnectionAdapterTest.checkConsumer(connection, address, consumer, true, false);
+
+        consumer = PlcFunctions.byteConsumer(adapter, addressStr);
+        PlcConnectionAdapterTest.checkConsumer(connection, address, consumer, (byte)0x1, (byte)0x2, (byte)0x3);
+
+        consumer = PlcFunctions.shortConsumer(adapter, addressStr);
+        PlcConnectionAdapterTest.checkConsumer(connection, address, consumer, (short)1, (short)2, (short)3);
+
+        consumer = PlcFunctions.integerConsumer(adapter, addressStr);
+        PlcConnectionAdapterTest.checkConsumer(connection, address, consumer, 1000, 1001, 1002);
+
+        consumer = PlcFunctions.floatConsumer(adapter, addressStr);
+        PlcConnectionAdapterTest.checkConsumer(connection, address, consumer, 1000.5f, 1001.5f, 1002.5f);
+
+        consumer = PlcFunctions.stringConsumer(adapter, addressStr);
+        PlcConnectionAdapterTest.checkConsumer(connection, address, consumer, "one", "two", "three");
+
+        adapter.close();
+    }
+
+    /*
+     * test PlcConnectionAdapter.newJsonConsumer(addressFn, valueFn)
+     */
+    @Test
+    @Category(FastTests.class)
+    public void testNewConsumer2() throws Exception {
+        String addressStr = "MyReadWriteAddress/0";
+        MockField address = new MockField(addressStr);
+        PlcConnectionAdapter adapter = new PlcConnectionAdapter(getMockConnection());
+        MockConnection connection = (MockConnection) adapter.getConnection();
+
+        Consumer<JsonObject> consumer;
+
+        Function<JsonObject,String> addressFn = t -> t.get("address").getAsString();
+
+        consumer = PlcFunctions.booleanConsumer(adapter, addressFn, t -> t.get("value").getAsBoolean());
+        PlcConnectionAdapterTest.checkConsumerJson(connection, address, consumer, true, false);
+
+        consumer = PlcFunctions.byteConsumer(adapter, addressFn, t -> t.get("value").getAsByte());
+        PlcConnectionAdapterTest.checkConsumerJson(connection, address, consumer, (byte)0x1, (byte)0x2, (byte)0x3);
+
+        consumer = PlcFunctions.shortConsumer(adapter, addressFn, t -> t.get("value").getAsShort());
+        PlcConnectionAdapterTest.checkConsumerJson(connection, address, consumer, (short)1, (short)2, (short)3);
+
+        consumer = PlcFunctions.integerConsumer(adapter, addressFn, t -> t.get("value").getAsInt());
+        PlcConnectionAdapterTest.checkConsumerJson(connection, address, consumer, 1000, 1001, 1002);
+
+        consumer = PlcFunctions.floatConsumer(adapter, addressFn, t -> t.get("value").getAsFloat());
+        PlcConnectionAdapterTest.checkConsumerJson(connection, address, consumer, 1000.5f, 1001.5f, 1002.5f);
+
+        consumer = PlcFunctions.stringConsumer(adapter, addressFn, t -> t.get("value").getAsString());
+        PlcConnectionAdapterTest.checkConsumerJson(connection, address, consumer, "one", "two", "three");
+
+        adapter.close();
+    }
 
 }
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/PlcDriver.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/PlcDriver.java
index d1ed283ba..c2d45fb1f 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/PlcDriver.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/PlcDriver.java
@@ -24,6 +24,10 @@ Licensed to the Apache Software Foundation (ASF) under one
 
 /**
  * General interface defining the minimal methods required for adding a new type of driver to the PLC4J system.
+ *
+ * <b>Note that each driver has to add a service file called org.apache.plc4x.java.PlcDriver to
+ * src/main/resources/META-INF which contains the fully qualified classname in order to get loaded
+ * by the PlcDriverManager instances.</b>
  */
 public interface PlcDriver {
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services