[GitHub] sruehl closed pull request #8: cleanup warnings in plc4j-api, plc4j-core, dummy-driver

2018-06-13 Thread GitBox
sruehl closed pull request #8: cleanup warnings in plc4j-api, plc4j-core, 
dummy-driver
URL: https://github.com/apache/incubator-plc4x/pull/8
 
 
   

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/dummy-driver/src/main/java/org/apache/plc4x/java/examples/dummydriver/netty/DummyProtocol.java
 
b/examples/dummy-driver/src/main/java/org/apache/plc4x/java/examples/dummydriver/netty/DummyProtocol.java
index bf448ea4f..3c4064551 100644
--- 
a/examples/dummy-driver/src/main/java/org/apache/plc4x/java/examples/dummydriver/netty/DummyProtocol.java
+++ 
b/examples/dummy-driver/src/main/java/org/apache/plc4x/java/examples/dummydriver/netty/DummyProtocol.java
@@ -31,13 +31,13 @@ Licensed to the Apache Software Foundation (ASF) under one
 
 import java.util.List;
 
-public class DummyProtocol extends MessageToMessageCodec {
+public class DummyProtocol extends MessageToMessageCodec> {
 
 private static final Logger logger = 
LoggerFactory.getLogger(DummyProtocol.class);
 
 @Override
-protected void encode(ChannelHandlerContext ctx, PlcRequestContainer in, 
List out) throws Exception {
-PlcRequest request = in.getRequest();
+protected void encode(ChannelHandlerContext ctx, PlcRequestContainer 
in, List out) throws Exception {
+PlcRequest request = in.getRequest();
 if (request instanceof PlcReadRequest) {
 
 // Simple ICMP (Ping packet)
diff --git 
a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadRequest.java
 
b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadRequest.java
index 96db08f0e..01431edfa 100644
--- 
a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadRequest.java
+++ 
b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadRequest.java
@@ -66,7 +66,7 @@ public final Builder addItem(Class dataType, Address 
address, int size) {
 return this;
 }
 
-public final Builder addItem(ReadRequestItem readRequestItem) {
+public final Builder addItem(ReadRequestItem readRequestItem) {
 checkType(readRequestItem.getDatatype());
 requests.add(readRequestItem);
 return this;
@@ -82,7 +82,7 @@ public final PlcReadRequest build() {
 } else {
 plcReadRequest = new TypeSafePlcReadRequest<>(firstType);
 }
-for (ReadRequestItem request : requests) {
+for (ReadRequestItem request : requests) {
 plcReadRequest.addItem(request);
 }
 return plcReadRequest;
diff --git 
a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadResponse.java
 
b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadResponse.java
index 78ebdea77..9a2cd5167 100644
--- 
a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadResponse.java
+++ 
b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadResponse.java
@@ -37,6 +37,9 @@ public PlcReadResponse(PlcReadRequest request, List Optional> getValue(ReadRequestItem item) 
{
-return (Optional) super.getValue(item);
+Optional> value = super.getValue(item);
+// Directly casting to Optional> yields a compile 
time error.
+// First casting to Object eliminates it.
+return (Optional>) ((Object) value);
 }
 }
diff --git 
a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcRequest.java 
b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcRequest.java
index d41453afd..aa6162dde 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcRequest.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcRequest.java
@@ -29,7 +29,7 @@ Licensed to the Apache Software Foundation (ASF) under one
  * Base type for all messages sent from the plc4x system to a connected plc.
  * @param  
  */
-public abstract class PlcRequest implements 
PlcMessage {
+public abstract class PlcRequest> 
implements PlcMessage {
 
 protected final List requestItems;
 
@@ -88,7 +88,7 @@ public boolean isEmpty() {
 
 List requests = new LinkedList<>();
 
-void checkType(Class dataType) {
+void checkType(Class dataType) {
 if (firstType == null) {
 firstType = dataType;
 }
diff --git 
a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcRequestContainer.java
 
b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcRequestContainer.java
index 203839910..6bdd6b026 100644
--- 
a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcRequestContainer.java
+++ 
b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcRequestContainer.java
@@ -21,7 +21,7 @@ Licensed to the Apache 

[GitHub] dlaboss commented on issue #1: Warning cleanup

2018-01-09 Thread GitBox
dlaboss commented on issue #1: Warning cleanup
URL: https://github.com/apache/incubator-plc4x/pull/1#issuecomment-356292913
 
 
   Hi Justin, I was expecting to merge it myself, but thanks :-)
   Isn't is just better to consistently work in the github 
fork/feature-branch/PR flow so as to reinforce its use?  It just makes it 
easier for folks to identify/review/comment on changes. And when build/test 
checks are integrated into the PR flow their "passing" is made readily apparent 
in the PR.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] chrisdutz commented on issue #1: Warning cleanup

2018-01-09 Thread GitBox
chrisdutz commented on issue #1: Warning cleanup
URL: https://github.com/apache/incubator-plc4x/pull/1#issuecomment-356294407
 
 
   Well we should get the Travis support working first or you will be working 
without CI ... I've already setup the travis file thing, but still have to have 
Infra enable it.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] justinmclean closed pull request #1: Warning cleanup

2018-01-08 Thread GitBox
justinmclean closed pull request #1: Warning cleanup
URL: https://github.com/apache/incubator-plc4x/pull/1
 
 
   

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/applications/iotree/pom.xml b/applications/iotree/pom.xml
index b1139dbe..541b3164 100644
--- a/applications/iotree/pom.xml
+++ b/applications/iotree/pom.xml
@@ -29,8 +29,6 @@
   
 
   iotree
-  0.0.1-SNAPSHOT
-
   Applications: IoTree (The IoT Christmas Tree)
   An example Application for the IoT Frankfurt meetup on 
14.12.2017.
 
diff --git a/applications/plclogger/pom.xml b/applications/plclogger/pom.xml
index 06079459..505bd6cf 100644
--- a/applications/plclogger/pom.xml
+++ b/applications/plclogger/pom.xml
@@ -29,8 +29,6 @@
   
 
   plclogger
-  0.0.1-SNAPSHOT
-
   Applications: PLC Data Logger
   Application using Edgent and Elastic-Search to implement a PLC 
data logger.
 
diff --git a/applications/pom.xml b/applications/pom.xml
index 0cf29bbf..6abbd670 100644
--- a/applications/pom.xml
+++ b/applications/pom.xml
@@ -30,7 +30,6 @@
 
   org.apache.plc4x.applications
   applications
-  0.0.1-SNAPSHOT
   pom
 
   Applications
diff --git a/integrations/apache-brooklyn/pom.xml 
b/integrations/apache-brooklyn/pom.xml
index 5f5265c5..e9630b39 100644
--- a/integrations/apache-brooklyn/pom.xml
+++ b/integrations/apache-brooklyn/pom.xml
@@ -29,7 +29,6 @@
   
 
   apache-brooklyn
-  0.0.1-SNAPSHOT
   pom
 
   Integrations: Apache Brooklyn
diff --git a/integrations/apache-camel/pom.xml 
b/integrations/apache-camel/pom.xml
index 71099c9a..c785279a 100644
--- a/integrations/apache-camel/pom.xml
+++ b/integrations/apache-camel/pom.xml
@@ -29,8 +29,6 @@
   
 
   apache-camel
-  0.0.1-SNAPSHOT
-
   Integrations: Apache Camel
   Integration module for integrating PLC4X into Apache 
Camel.
 
diff --git a/integrations/apache-edgent/pom.xml 
b/integrations/apache-edgent/pom.xml
index 237618ad..ce812817 100644
--- a/integrations/apache-edgent/pom.xml
+++ b/integrations/apache-edgent/pom.xml
@@ -29,8 +29,6 @@
   
 
   apache-edgent
-  0.0.1-SNAPSHOT
-
   Integrations: Apache Edgent
   Integration module for integrating PLC4X into Apache 
Edgent.
 
diff --git 
a/integrations/apache-edgent/src/main/java/org/apache/plc4x/edgent/PlcConnectionAdapter.java
 
b/integrations/apache-edgent/src/main/java/org/apache/plc4x/edgent/PlcConnectionAdapter.java
index 75bc9de1..162a2e28 100644
--- 
a/integrations/apache-edgent/src/main/java/org/apache/plc4x/edgent/PlcConnectionAdapter.java
+++ 
b/integrations/apache-edgent/src/main/java/org/apache/plc4x/edgent/PlcConnectionAdapter.java
@@ -184,13 +184,11 @@ static void checkDatatype(Class cls) {
 throw new IllegalArgumentException("Not a legal plc data type: 
"+cls.getSimpleName());
   }
 
-  @SuppressWarnings("unchecked")
   static  PlcWriteRequest newPlcWriteRequest(Address address, T value) {
 Class cls = value.getClass();
 return new PlcWriteRequest(cls, address, value);
   }
 
-  @SuppressWarnings("unchecked")
   static  PlcReadRequest newPlcReadRequest(Class datatype, Address 
address) {
   return new PlcReadRequest(datatype, address);
   }
diff --git 
a/integrations/apache-edgent/src/test/java/org/apache/plc4x/edgent/PlcConnectionAdapterTest.java
 
b/integrations/apache-edgent/src/test/java/org/apache/plc4x/edgent/PlcConnectionAdapterTest.java
index 88cec7d0..5a9d1077 100644
--- 
a/integrations/apache-edgent/src/test/java/org/apache/plc4x/edgent/PlcConnectionAdapterTest.java
+++ 
b/integrations/apache-edgent/src/test/java/org/apache/plc4x/edgent/PlcConnectionAdapterTest.java
@@ -142,7 +142,6 @@ public void testCheckDatatype() throws Exception {
   /*
* Verify the adapter yields the appropriate PlcReadRequest for each type 
and that it works.
*/
-  @SuppressWarnings("unchecked")
   @Test
   @Tag("fast")
   public void testNewPlcReadRequest() throws Exception {
@@ -215,7 +214,6 @@ public void testNewPlcReadRequest() throws Exception {
   /*
* Verify the adapter yields the appropriate PlcWriteRequest for each type 
and that it works.
*/
-  @SuppressWarnings("unchecked")
   @Test
   @Tag("fast")
   public void testNewPlcWriteRequest() throws Exception {
@@ -362,7 +360,6 @@ public void testNewSupplierNeg() throws Exception {
   /*
* test PlcConnectionAdapter.newConsumer(address)
*/
-  @SuppressWarnings("unchecked")
   @Test
   @Tag("fast")
   public void testNewConsumer1() throws Exception {
@@ -504,6 +501,7 @@ public void testNewConsumer2Neg() throws Exception {
   static  void checkConsumerJson(MockConnection connection, MockAddress 
address, Consumer consumer, Object ... values) throws Exception {
 checkConsumerJson(0, connection, address, consumer, values);
   }
+  @SuppressWarnings("unchecked")
   private static  void checkConsumerJson(int 

[GitHub] justinmclean commented on issue #1: Warning cleanup

2018-01-08 Thread GitBox
justinmclean commented on issue #1: Warning cleanup
URL: https://github.com/apache/incubator-plc4x/pull/1#issuecomment-356121460
 
 
   IMO no need for a PR for still like this feel free to commit yourself.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] dlaboss opened a new pull request #1: Warning cleanup

2018-01-08 Thread GitBox
dlaboss opened a new pull request #1: Warning cleanup
URL: https://github.com/apache/incubator-plc4x/pull/1
 
 
   Cleanup a number of warnings reported by Eclipse.  
   There are still 50+ warnings related to raw types, casts, type safety as 
well as unused field/local-variables.
   
   Please comment if you have concerns with any of these changes.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] asfgit closed pull request #2: [WIP]Test travis integration

2018-01-26 Thread GitBox
asfgit closed pull request #2: [WIP]Test travis integration
URL: https://github.com/apache/incubator-plc4x/pull/2
 
 
   


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] crazzle closed pull request #3: Remove response reference in request item

2018-01-13 Thread GitBox
crazzle closed pull request #3: Remove response reference in request item
URL: https://github.com/apache/incubator-plc4x/pull/3
 
 
   


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] niclash opened a new pull request #4: Change from AsserttJ to Hamcrest

2018-02-14 Thread GitBox
niclash opened a new pull request #4: Change from AsserttJ to Hamcrest
URL: https://github.com/apache/incubator-plc4x/pull/4
 
 
   


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] dlaboss opened a new pull request #6: cleanup sonar edgent complaints

2018-02-26 Thread GitBox
dlaboss opened a new pull request #6: cleanup sonar edgent complaints
URL: https://github.com/apache/incubator-plc4x/pull/6
 
 
   


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] asfgit closed pull request #6: cleanup sonar edgent complaints

2018-02-26 Thread GitBox
asfgit closed pull request #6: cleanup sonar edgent complaints
URL: https://github.com/apache/incubator-plc4x/pull/6
 
 
   

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/integrations/apache-edgent/src/main/java/org/apache/plc4x/edgent/PlcConnectionAdapter.java
 
b/integrations/apache-edgent/src/main/java/org/apache/plc4x/edgent/PlcConnectionAdapter.java
index eedfc794..bc4eaefe 100644
--- 
a/integrations/apache-edgent/src/main/java/org/apache/plc4x/edgent/PlcConnectionAdapter.java
+++ 
b/integrations/apache-edgent/src/main/java/org/apache/plc4x/edgent/PlcConnectionAdapter.java
@@ -108,28 +108,38 @@ public Address parseAddress(String addressString) throws 
PlcException {
 
  Supplier newSupplier(Class datatype, String addressStr) {
 PlcConnectionAdapter.checkDatatype(datatype);
-return new Supplier() {
-private static final long serialVersionUID = 1L;
+// satisfy sonar's "Reduce number of anonymous class lines" code smell
+return new MySupplier(datatype, addressStr);
+}
+
+private class MySupplier implements Supplier {
+private static final long serialVersionUID = 1L;
+private Class datatype;
+private String addressStr;
+  
+MySupplier(Class datatype, String addressStr) {
+this.datatype = datatype;
+this.addressStr = addressStr;
+}
 
-@Override
-public T get() {
-PlcConnection connection = null;
-Address address = null;
-try {
-connection = getConnection();
-address = connection.parseAddress(addressStr);
-PlcReader reader = connection.getReader()
-.orElseThrow(() -> new NullPointerException("No reader 
available"));
-TypeSafePlcReadRequest readRequest = 
PlcConnectionAdapter.newPlcReadRequest(datatype, address);
-return reader.read(readRequest).get().getResponseItem()
-.orElseThrow(() -> new IllegalStateException("No 
response available"))
-.getValues().get(0);
-} catch (Exception e) {
-logger.error("reading from plc device {} {} failed", 
connection, address, e);
-return null;
-}
+@Override
+public T get() {
+PlcConnection connection = null;
+Address address = null;
+try {
+connection = getConnection();
+address = connection.parseAddress(addressStr);
+PlcReader reader = connection.getReader()
+  .orElseThrow(() -> new NullPointerException("No reader 
available"));
+TypeSafePlcReadRequest readRequest = 
PlcConnectionAdapter.newPlcReadRequest(datatype, address);
+return reader.read(readRequest).get().getResponseItem()
+  .orElseThrow(() -> new IllegalStateException("No response 
available"))
+  .getValues().get(0);
+} catch (Exception e) {
+logger.error("reading from plc device {} {} failed", 
connection, address, e);
+return null;
 }
-};
+}
 }
 
 Supplier newSupplier(PlcReadRequest readRequest) {


 


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] asfgit closed pull request #7: cleanup some warnings (in Eclipse)

2018-02-26 Thread GitBox
asfgit closed pull request #7: cleanup some warnings (in Eclipse)
URL: https://github.com/apache/incubator-plc4x/pull/7
 
 
   

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/dummy-driver/src/main/java/org/apache/plc4x/java/examples/dummydriver/connection/DummyConnection.java
 
b/examples/dummy-driver/src/main/java/org/apache/plc4x/java/examples/dummydriver/connection/DummyConnection.java
index 9619fe4c..a61686bc 100644
--- 
a/examples/dummy-driver/src/main/java/org/apache/plc4x/java/examples/dummydriver/connection/DummyConnection.java
+++ 
b/examples/dummy-driver/src/main/java/org/apache/plc4x/java/examples/dummydriver/connection/DummyConnection.java
@@ -18,13 +18,18 @@ Licensed to the Apache Software Foundation (ASF) under one
 */
 package org.apache.plc4x.java.examples.dummydriver.connection;
 
-import io.netty.bootstrap.Bootstrap;
-import io.netty.channel.*;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
 import org.apache.plc4x.java.api.connection.AbstractPlcConnection;
 import org.apache.plc4x.java.api.connection.PlcReader;
 import org.apache.plc4x.java.api.connection.PlcWriter;
 import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
-import org.apache.plc4x.java.api.messages.*;
+import org.apache.plc4x.java.api.messages.PlcReadRequest;
+import org.apache.plc4x.java.api.messages.PlcReadResponse;
+import org.apache.plc4x.java.api.messages.PlcRequestContainer;
+import org.apache.plc4x.java.api.messages.PlcWriteRequest;
+import org.apache.plc4x.java.api.messages.PlcWriteResponse;
 import org.apache.plc4x.java.api.model.Address;
 import org.apache.plc4x.java.examples.dummydriver.model.DummyAddress;
 import org.apache.plc4x.java.examples.dummydriver.netty.DummyProtocol;
@@ -33,17 +38,24 @@ Licensed to the Apache Software Foundation (ASF) under one
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutionException;
+import io.netty.bootstrap.Bootstrap;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelPipeline;
+import io.netty.channel.DefaultEventLoopGroup;
+import io.netty.channel.EventLoopGroup;
 
 public class DummyConnection extends AbstractPlcConnection implements 
PlcReader, PlcWriter {
 
+@SuppressWarnings("unused")
 private static final Logger logger = 
LoggerFactory.getLogger(DummyConnection.class);
 
 private final String hostName;
 
 private EventLoopGroup workerGroup;
 private Channel channel;
+@SuppressWarnings("unused")
 private boolean connected;
 
 public DummyConnection(String hostName) {
@@ -71,7 +83,7 @@ public void connect() throws PlcConnectionException {
 Bootstrap bootstrap = new Bootstrap();
 bootstrap.group(workerGroup);
 bootstrap.channel(RawSocketChannel.class);
-bootstrap.handler(new ChannelInitializer() {
+bootstrap.handler(new ChannelInitializer() {
 @Override
 protected void initChannel(Channel channel) throws Exception {
 ChannelPipeline pipeline = channel.pipeline();
diff --git 
a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcRequest.java 
b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcRequest.java
index da2fed4a..d41453af 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcRequest.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcRequest.java
@@ -18,15 +18,16 @@ Licensed to the Apache Software Foundation (ASF) under one
 */
 package org.apache.plc4x.java.api.messages;
 
-import org.apache.plc4x.java.api.messages.items.RequestItem;
-
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Objects;
 import java.util.Optional;
 
+import org.apache.plc4x.java.api.messages.items.RequestItem;
+
 /**
  * Base type for all messages sent from the plc4x system to a connected plc.
+ * @param  
  */
 public abstract class PlcRequest implements 
PlcMessage {
 
diff --git 
a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcResponse.java 
b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcResponse.java
index 1ab12820..8f054cc4 100644
--- 
a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcResponse.java
+++ 
b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcResponse.java
@@ -18,16 +18,19 @@ Licensed to the Apache Software Foundation (ASF) under one
 */
 package org.apache.plc4x.java.api.messages;
 
-import org.apache.plc4x.java.api.messages.items.RequestItem;
-import 

[GitHub] sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, plc4j-core, dummy-driver

2018-02-26 Thread GitBox
sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, 
plc4j-core, dummy-driver
URL: https://github.com/apache/incubator-plc4x/pull/8#discussion_r170833373
 
 

 ##
 File path: 
plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcWriteRequest.java
 ##
 @@ -18,14 +18,14 @@ Licensed to the Apache Software Foundation (ASF) under one
 */
 package org.apache.plc4x.java.api.messages.specific;
 
-import org.apache.plc4x.java.api.messages.PlcWriteRequest;
-import org.apache.plc4x.java.api.messages.items.WriteRequestItem;
-import org.apache.plc4x.java.api.model.Address;
-
 import java.util.List;
 import java.util.Objects;
 import java.util.Optional;
 
+import org.apache.plc4x.java.api.messages.PlcWriteRequest;
+import org.apache.plc4x.java.api.messages.items.WriteRequestItem;
+import org.apache.plc4x.java.api.model.Address;
+
 
 Review comment:
   import reordering see other comment


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, plc4j-core, dummy-driver

2018-02-26 Thread GitBox
sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, 
plc4j-core, dummy-driver
URL: https://github.com/apache/incubator-plc4x/pull/8#discussion_r170833246
 
 

 ##
 File path: 
plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadRequest.java
 ##
 @@ -18,13 +18,13 @@ Licensed to the Apache Software Foundation (ASF) under one
 */
 package org.apache.plc4x.java.api.messages;
 
+import java.util.List;
+import java.util.Objects;
+
 import org.apache.plc4x.java.api.messages.items.ReadRequestItem;
 import org.apache.plc4x.java.api.messages.specific.TypeSafePlcReadRequest;
 import org.apache.plc4x.java.api.model.Address;
 
-import java.util.List;
-import java.util.Objects;
-
 
 Review comment:
   import reordering see other comment


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, plc4j-core, dummy-driver

2018-02-26 Thread GitBox
sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, 
plc4j-core, dummy-driver
URL: https://github.com/apache/incubator-plc4x/pull/8#discussion_r170832548
 
 

 ##
 File path: 
plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcReadResponse.java
 ##
 @@ -59,17 +59,49 @@ public TypeSafePlcReadResponse(TypeSafePlcReadRequest 
request, List>) super.getResponseItem();
 }
 
+/**
+ * Cast or convert a PlcReadResponse to a TypeSafePlcReadReadResponse.
+ * 
+ * WARNING: this is inherently a non-type-safe operation.  It was 
introduced
+ * to serve the implementation of 
PlcReader.read(TypeSafePlcReadRequest).
+ * Additional use of it is not recommended.  This interface is subject to 
change.
+ * 
+ * @param plcReadResponse the response implicitly with items of type T
+ * @return TypeSafePlcReadReadResponse
+ */
 @SuppressWarnings("unchecked")
 public static  TypeSafePlcReadResponse of(PlcReadResponse 
plcReadResponse) {
+// BUG: there seems to be no checking that the readResponse/items
+// in fact are for type T.
+// I don't even think it's possible to do that with the current 'of()' 
signature
+// and plcReadResponse content.
+//
+// The only consolation is that currently, 'of()' is only really used 
in the
+// impl of PlcReader.read(TypeSafePlcReadRequest) and that case 
guarantees
+// that all items are a T.  plcReadResponse isa 
TypeSafePlcReadResponse in
+// this case.
+//
+// Maybe we just need to doc that this conversion is unsafe and/or 
rename
+// the method to "unsafeOf()"? 
+// Or, if there were an AbstractPlcReader, that could internally 
implement
+// this method without exposing this generally it, the PlcReader 
interface
+// could remove the default implementation of 
read(TypeSafePlcReadRequest),
+// and protocol implementations could extend AbstractPlcReader.
+//
+// FWIW, in one case there is some checking that all of the items in a 
response
+// are at least of the same type.
+  
 if (plcReadResponse instanceof TypeSafePlcReadResponse) {
-return (TypeSafePlcReadResponse) plcReadResponse;
+// Warning: no validation that everything in the response is a T.
 
 Review comment:
   then we would need to check here if the requested `Class class` is equals to 
the supplied type


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, plc4j-core, dummy-driver

2018-02-26 Thread GitBox
sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, 
plc4j-core, dummy-driver
URL: https://github.com/apache/incubator-plc4x/pull/8#discussion_r170833305
 
 

 ##
 File path: 
plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcWriteRequest.java
 ##
 @@ -18,13 +18,13 @@ Licensed to the Apache Software Foundation (ASF) under one
 */
 package org.apache.plc4x.java.api.messages;
 
+import java.util.List;
+import java.util.Objects;
+
 import org.apache.plc4x.java.api.messages.items.WriteRequestItem;
 import org.apache.plc4x.java.api.messages.specific.TypeSafePlcWriteRequest;
 import org.apache.plc4x.java.api.model.Address;
 
-import java.util.List;
-import java.util.Objects;
-
 
 Review comment:
   import reordering see other comment


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, plc4j-core, dummy-driver

2018-02-26 Thread GitBox
sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, 
plc4j-core, dummy-driver
URL: https://github.com/apache/incubator-plc4x/pull/8#discussion_r170833183
 
 

 ##
 File path: 
plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcWriteRequest.java
 ##
 @@ -71,7 +71,7 @@ public void addItem(WriteRequestItem writeRequestItem) {
 
 @SuppressWarnings("unchecked")
 public List getCheckedRequestItems() {
-return (List) getRequestItems();
+return (List) ((Object) getRequestItems());
 
 Review comment:
   strange cast see other comment


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, plc4j-core, dummy-driver

2018-02-26 Thread GitBox
sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, 
plc4j-core, dummy-driver
URL: https://github.com/apache/incubator-plc4x/pull/8#discussion_r170831995
 
 

 ##
 File path: 
examples/dummy-driver/src/main/java/org/apache/plc4x/java/examples/dummydriver/netty/DummyProtocol.java
 ##
 @@ -18,26 +18,27 @@ Licensed to the Apache Software Foundation (ASF) under one
 */
 package org.apache.plc4x.java.examples.dummydriver.netty;
 
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.ByteBufUtil;
-import io.netty.buffer.Unpooled;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.handler.codec.MessageToMessageCodec;
+import java.util.List;
+
 import org.apache.plc4x.java.api.messages.PlcReadRequest;
 import org.apache.plc4x.java.api.messages.PlcRequest;
 import org.apache.plc4x.java.api.messages.PlcRequestContainer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.List;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.handler.codec.MessageToMessageCodec;
 
 Review comment:
   we should look into why eclipse does sort the imports other than idea. We 
have a [.editorconfig](http://editorconfig.org/) (which eclipse doesn't do 
out-of-box and needs the plugin installed) but I don't think it respects import 
order. Without a unified import order we mess up our diff from time to time.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, plc4j-core, dummy-driver

2018-02-26 Thread GitBox
sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, 
plc4j-core, dummy-driver
URL: https://github.com/apache/incubator-plc4x/pull/8#discussion_r170833285
 
 

 ##
 File path: 
plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadResponse.java
 ##
 @@ -18,13 +18,13 @@ Licensed to the Apache Software Foundation (ASF) under one
 */
 package org.apache.plc4x.java.api.messages;
 
-import org.apache.plc4x.java.api.messages.items.ReadRequestItem;
-import org.apache.plc4x.java.api.messages.items.ReadResponseItem;
-
 import java.util.Collections;
 import java.util.List;
 import java.util.Optional;
 
+import org.apache.plc4x.java.api.messages.items.ReadRequestItem;
+import org.apache.plc4x.java.api.messages.items.ReadResponseItem;
+
 
 Review comment:
   import reordering see other comment


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, plc4j-core, dummy-driver

2018-02-26 Thread GitBox
sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, 
plc4j-core, dummy-driver
URL: https://github.com/apache/incubator-plc4x/pull/8#discussion_r170833353
 
 

 ##
 File path: 
plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcReadResponse.java
 ##
 @@ -18,13 +18,13 @@ Licensed to the Apache Software Foundation (ASF) under one
 */
 package org.apache.plc4x.java.api.messages.specific;
 
-import org.apache.plc4x.java.api.messages.PlcReadResponse;
-import org.apache.plc4x.java.api.messages.items.ReadResponseItem;
-
 import java.util.List;
 import java.util.Objects;
 import java.util.Optional;
 
+import org.apache.plc4x.java.api.messages.PlcReadResponse;
+import org.apache.plc4x.java.api.messages.items.ReadResponseItem;
+
 
 Review comment:
   import reordering see other comment


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, plc4j-core, dummy-driver

2018-02-26 Thread GitBox
sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, 
plc4j-core, dummy-driver
URL: https://github.com/apache/incubator-plc4x/pull/8#discussion_r170833513
 
 

 ##
 File path: 
plc4j/core/src/test/java/org/apache/plc4x/java/PlcDriverManagerTest.java
 ##
 @@ -26,21 +37,11 @@ Licensed to the Apache Software Foundation (ASF) under one
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsInstanceOf.instanceOf;
-import static org.hamcrest.core.IsNull.notNullValue;
-import static org.hamcrest.core.IsNull.nullValue;
-import static org.junit.Assert.assertThat;
-
 public class PlcDriverManagerTest {
 
 /**
  * Tries to get the mock plc driver which is part of this testsuite.
+ * @throws PlcException 
 
 Review comment:
   theses doesn't make sense in Unit-Tests. Better just remove on star `*`


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, plc4j-core, dummy-driver

2018-02-26 Thread GitBox
sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, 
plc4j-core, dummy-driver
URL: https://github.com/apache/incubator-plc4x/pull/8#discussion_r170832428
 
 

 ##
 File path: 
plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcReadResponse.java
 ##
 @@ -59,17 +59,49 @@ public TypeSafePlcReadResponse(TypeSafePlcReadRequest 
request, List>) super.getResponseItem();
 }
 
+/**
+ * Cast or convert a PlcReadResponse to a TypeSafePlcReadReadResponse.
+ * 
+ * WARNING: this is inherently a non-type-safe operation.  It was 
introduced
+ * to serve the implementation of 
PlcReader.read(TypeSafePlcReadRequest).
+ * Additional use of it is not recommended.  This interface is subject to 
change.
+ * 
+ * @param plcReadResponse the response implicitly with items of type T
+ * @return TypeSafePlcReadReadResponse
+ */
 @SuppressWarnings("unchecked")
 public static  TypeSafePlcReadResponse of(PlcReadResponse 
plcReadResponse) {
 
 Review comment:
   fair Point, we would need a type Parameter `Class clazz` here.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, plc4j-core, dummy-driver

2018-02-26 Thread GitBox
sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, 
plc4j-core, dummy-driver
URL: https://github.com/apache/incubator-plc4x/pull/8#discussion_r170833118
 
 

 ##
 File path: 
plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcReadResponse.java
 ##
 @@ -84,7 +116,9 @@ public TypeSafePlcReadResponse(TypeSafePlcReadRequest 
request, List

[GitHub] sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, plc4j-core, dummy-driver

2018-02-26 Thread GitBox
sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, 
plc4j-core, dummy-driver
URL: https://github.com/apache/incubator-plc4x/pull/8#discussion_r170833397
 
 

 ##
 File path: 
plc4j/core/src/test/java/org/apache/plc4x/java/PlcDriverManagerTest.java
 ##
 @@ -26,21 +37,11 @@ Licensed to the Apache Software Foundation (ASF) under one
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsInstanceOf.instanceOf;
-import static org.hamcrest.core.IsNull.notNullValue;
-import static org.hamcrest.core.IsNull.nullValue;
-import static org.junit.Assert.assertThat;
-
 
 Review comment:
   import reordering see other comment


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, plc4j-core, dummy-driver

2018-02-26 Thread GitBox
sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, 
plc4j-core, dummy-driver
URL: https://github.com/apache/incubator-plc4x/pull/8#discussion_r170832166
 
 

 ##
 File path: 
plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcWriteResponse.java
 ##
 @@ -37,6 +37,7 @@ public PlcWriteResponse(PlcWriteRequest request, List Optional getValue(WriteRequestItem 
item) {
-return (Optional) super.getValue(item);
+Optional value = super.getValue(item); 
+return (Optional) ((Object) value); 
 
 Review comment:
   This cast to Object and then a type again is a bit confusing. Is this just 
to silence a warning?


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on issue #10: Fixed NPE in S7PlcConnection#close.

2018-08-02 Thread GitBox
sruehl commented on issue #10: Fixed NPE in S7PlcConnection#close.
URL: https://github.com/apache/incubator-plc4x/pull/10#issuecomment-409959876
 
 
   one note at this point. As far as I understand netty throws this exception 
to indicate that it dislikes when the thread gets blocked. By using @chrisdutz 
or @JulianFeinauer code we might just trick the detection of netty. Im not 
quite sure but I think this is then more a hack/workaround rather then the 
intended use of netty. What I found what should come close to the intended 
behavior ist 
[this](https://netty.io/4.0/api/io/netty/util/concurrent/SingleThreadEventExecutor.html#addShutdownHook-java.lang.Runnable-).
 Maybe we should ask on the netty list how it is expected to do such things...


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] JulianFeinauer commented on issue #10: Fixed NPE in S7PlcConnection#close.

2018-08-02 Thread GitBox
JulianFeinauer commented on issue #10: Fixed NPE in S7PlcConnection#close.
URL: https://github.com/apache/incubator-plc4x/pull/10#issuecomment-409958048
 
 
   @chrisdutz your fixes in the master made it work for me also.
   As I found a solution to avoid the blocking exception in the meanwhile I 
combined your code with mine.
   I think the only obvious solution is, as i propose, to use a CountDownLatch 
to communicate between the ChannelCloseFuture and the close method on another 
ThreadPool than the EventLoopGroup (which netty forbids).
   Is this solution feasible for you?


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] JulianFeinauer commented on issue #10: Fixed NPE in S7PlcConnection#close.

2018-08-02 Thread GitBox
JulianFeinauer commented on issue #10: Fixed NPE in S7PlcConnection#close.
URL: https://github.com/apache/incubator-plc4x/pull/10#issuecomment-409963436
 
 
   @sruehl my understanding is that netty avoids a scenario where one uses the 
event loop executors threads for blocking and thus, risks a deadlock. This 
should not be the case in this situation because the EventLoops Thread wich 
does the listener notification only counts down the latch.
   
   But as this solution seems uglier than it should be it is possibly a good 
idea to go over to the netty list and ask there (I am totally new to netty).


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] chrisdutz commented on issue #10: Fixed NPE in S7PlcConnection#close.

2018-08-02 Thread GitBox
chrisdutz commented on issue #10: Fixed NPE in S7PlcConnection#close.
URL: https://github.com/apache/incubator-plc4x/pull/10#issuecomment-409995467
 
 
   Well I Ave started working on an option that works exactly the same way we 
are doing the connection, by creating a CompletableFuture and commuting this in 
a channel.closeListener ... Will finish that option tomorrow and have a look at 
your proposal tomorrow as well. Think we are all learning more and more with 
stuff like this ;-)


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] chrisdutz commented on issue #10: Fixed NPE in S7PlcConnection#close.

2018-08-03 Thread GitBox
chrisdutz commented on issue #10: Fixed NPE in S7PlcConnection#close.
URL: https://github.com/apache/incubator-plc4x/pull/10#issuecomment-410171496
 
 
   And I don't agree with Sebastians assumption. Even if it might be the same 
thread when running in unit-tests (Here we have to write the response to a 
request manually ans therefore no thread pool can be used), still I don't think 
that this pattern is invalid. I have seen it when connecting in other code (I 
didn't invent that pattern). Blocking inside the protocol handler indeed would 
be bad, but in this case we have to block somewhere, if we want to shut-down 
gracefully. Another option would be to return the closable future and to wait 
for that to finish outside of PLC4X, but that would make things needlessly more 
complex for our users - I think.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] chrisdutz commented on issue #10: Fixed NPE in S7PlcConnection#close.

2018-08-03 Thread GitBox
chrisdutz commented on issue #10: Fixed NPE in S7PlcConnection#close.
URL: https://github.com/apache/incubator-plc4x/pull/10#issuecomment-410170620
 
 
   Ok ... so I just checked in the version I was talking about. It is basically 
structurally equal to the way we are doing things in the connection part. Also 
I just had a look at your change ... seems we are doing the same thing, but I 
would like to stick to CompletableFutures as your option is just doing the same 
but with a different syntax.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] JulianFeinauer commented on issue #10: Fixed NPE in S7PlcConnection#close.

2018-08-03 Thread GitBox
JulianFeinauer commented on issue #10: Fixed NPE in S7PlcConnection#close.
URL: https://github.com/apache/incubator-plc4x/pull/10#issuecomment-410172284
 
 
   @chrisdutz I guess due to my partial scala background I totally ignore Javas 
Completable futures as superior and thus didnt think about using them : D
   But I agree that it shows the intention of the code clearer.
   Perhaps we add a Util Class that "converts" a Netty Future into a 
Completable Future, as we surely need this functionality more often. What do 
you think?


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] JulianFeinauer opened a new pull request #10: Fixed NPE in S7PlcConnection#close.

2018-08-02 Thread GitBox
JulianFeinauer opened a new pull request #10: Fixed NPE in 
S7PlcConnection#close.
URL: https://github.com/apache/incubator-plc4x/pull/10
 
 
   Fix for the NPE in S7PlcConnection's close method.
   After fixing the NPE there was a netty blockingException, thus I had to 
refactor the program logic a bit.
   Please check if this is suitable the way I dit this (I tried to add enough 
comment to make it understandable).


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] chrisdutz commented on a change in pull request #9: Added some javadoc to S7 communication path and several todos that ma…

2018-08-02 Thread GitBox
chrisdutz commented on a change in pull request #9: Added some javadoc to S7 
communication path and several todos that ma…
URL: https://github.com/apache/incubator-plc4x/pull/9#discussion_r207142023
 
 

 ##
 File path: 
plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/ReadRequestItem.java
 ##
 @@ -52,6 +64,8 @@ public boolean equals(Object o) {
 return false;
 }
 ReadRequestItem that = (ReadRequestItem) o;
+// TODO 01.18.18 jf: we should also call the comparison of super at 
least otherwise this can lead to unwanted behavior.
 
 Review comment:
   Aren't we doing exactly this super check 4 lines above?


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] JulianFeinauer commented on a change in pull request #9: Added some javadoc to S7 communication path and several todos that ma…

2018-08-02 Thread GitBox
JulianFeinauer commented on a change in pull request #9: Added some javadoc to 
S7 communication path and several todos that ma…
URL: https://github.com/apache/incubator-plc4x/pull/9#discussion_r207149237
 
 

 ##
 File path: 
plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/model/params/VarParameter.java
 ##
 @@ -24,6 +24,13 @@ Licensed to the Apache Software Foundation (ASF) under one
 
 import java.util.List;
 
+/**
+ * "Command" Message to inform PLC of wanted operation.
+ * Also contains {@link VarParameter#items} that hold detailed information on 
the "Command", e.g.,
+ * addresses to read or to write to.
+ *
+ * TODO 01.08.18 jf: Could this be renamed to Something like Command as this 
seems to be the command message pattern?
 
 Review comment:
   Okay, the correlation makes sense.
   But its good to know that my assumption was right.
   It simply helped my understanding of the process to see them as that.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] asfgit closed pull request #9: Added some javadoc to S7 communication path and several todos that ma…

2018-08-02 Thread GitBox
asfgit closed pull request #9: Added some javadoc to S7 communication path and 
several todos that ma…
URL: https://github.com/apache/incubator-plc4x/pull/9
 
 
   

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/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadRequest.java
 
b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadRequest.java
index 96db08f0e..456f1f3d9 100644
--- 
a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadRequest.java
+++ 
b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadRequest.java
@@ -25,9 +25,24 @@ Licensed to the Apache Software Foundation (ASF) under one
 import java.util.List;
 import java.util.Objects;
 
+/**
+ * Request to read one or more values from a plc.
+ * The {@link PlcReadRequest} is a container for one or more {@link 
ReadRequestItem}s that are contained.
+ *
+ * By default this is NOT typesafe as it can contain {@link ReadRequestItem}s 
for different types.
+ * If there are only {@link ReadRequestItem}s of the same type one can use the 
{@link TypeSafePlcReadRequest} to enforce
+ * type safety.
+ *
+ * Provides a builder for object construction through {@link 
PlcReadRequest#builder()}.
+ *
+ * TODO 01.08.2018 jf: Can we make constructors private and force users to use 
the Builder to enforce immutability?
+ *
+ * @see TypeSafePlcReadRequest
+ */
 public class PlcReadRequest extends PlcRequest> {
 
 public PlcReadRequest() {
+// Exists for construction of inherited classes
 }
 
 public PlcReadRequest(ReadRequestItem requestItem) {
diff --git 
a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadResponse.java
 
b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadResponse.java
index 78ebdea77..136f47848 100644
--- 
a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadResponse.java
+++ 
b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadResponse.java
@@ -25,6 +25,16 @@ Licensed to the Apache Software Foundation (ASF) under one
 import java.util.List;
 import java.util.Optional;
 
+/**
+ * Response to a {@link PlcReadRequest}.
+ * Contains the values read from the PLC but untyped.
+ *
+ * Values are extracted using the {@link ReadRequestItem}s that were send in 
the read request.
+ *
+ * If only a variables of one type are requested it is better to use
+ * {@link org.apache.plc4x.java.api.messages.specific.TypeSafePlcReadRequest} 
which leads to a
+ * {@link org.apache.plc4x.java.api.messages.specific.TypeSafePlcReadResponse}.
+ */
 public class PlcReadResponse extends PlcResponse, ReadRequestItem> {
 
 public PlcReadResponse(PlcReadRequest request, ReadResponseItem 
responseItems) {
diff --git 
a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/ReadRequestItem.java
 
b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/ReadRequestItem.java
index bc77dc518..3f4f68e0a 100644
--- 
a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/ReadRequestItem.java
+++ 
b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/ReadRequestItem.java
@@ -22,6 +22,18 @@ Licensed to the Apache Software Foundation (ASF) under one
 
 import java.util.Objects;
 
+/**
+ * Encapsulats one {@link RequestItem} that could be read multiple times, 
i.e., from the given Address on
+ * {@link ReadRequestItem#size} number of Items with equal datatype are read.
+ *
+ * Thus,
+ * 
+ * new ReadRequestItem(Int.class, adress, 5)
+ * 
+ * basically reads 5 consecutive integers starting at the given {@link 
Address}.
+ *
+ * @param  Generic Type of expected Datatype.
+ */
 public class ReadRequestItem extends RequestItem {
 
 private final int size;
@@ -52,6 +64,8 @@ public boolean equals(Object o) {
 return false;
 }
 ReadRequestItem that = (ReadRequestItem) o;
+// TODO 01.18.18 jf: we should also call the comparison of super at 
least otherwise this can lead to unwanted behavior.
+// Perhaps we should generate a UUID or something for each ReadRequest 
to have a good equality comparison
 return size == that.size;
 }
 
diff --git 
a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/ReadResponseItem.java
 
b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/ReadResponseItem.java
index f7736e879..97cb36e7c 100644
--- 
a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/ReadResponseItem.java
+++ 
b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/ReadResponseItem.java
@@ -24,6 +24,12 @@ Licensed to the Apache Software Foundation (ASF) under one
 import java.util.List;
 import java.util.Objects;
 
+/**
+ * Response to a {@link ReadRequestItem}.
+ * Can 

[GitHub] sruehl commented on a change in pull request #10: Fixed NPE in S7PlcConnection#close.

2018-08-02 Thread GitBox
sruehl commented on a change in pull request #10: Fixed NPE in 
S7PlcConnection#close.
URL: https://github.com/apache/incubator-plc4x/pull/10#discussion_r207145613
 
 

 ##
 File path: 
plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/connection/S7PlcConnection.java
 ##
 @@ -183,14 +194,19 @@ public void close() {
 (short) 0x, (short) 0x000F, DisconnectReason.NORMAL, 
Collections.emptyList(),
 null);
 ChannelFuture sendDisconnectRequestFuture = 
channel.writeAndFlush(disconnectRequest);
-sendDisconnectRequestFuture.addListener((ChannelFutureListener) 
future -> {
-// Close the session itself.
-channel.closeFuture().await();
+// Wait if the PLC closes the connection
+try {
+// TODO 02.08.18 jf: Do we have global constants for things 
like timeouts?
+channel.closeFuture().await(1_000);
+} catch (InterruptedException e) {
+logger.warn("Connection was not closed by PLC, has to be 
closed from driver side now.", e);
 
 Review comment:
   Here we should add a `Thread.currentThread().interrupt();` after the 
logging. (Sonar would tell you this later anyway ;)


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #10: Fixed NPE in S7PlcConnection#close.

2018-08-02 Thread GitBox
sruehl commented on a change in pull request #10: Fixed NPE in 
S7PlcConnection#close.
URL: https://github.com/apache/incubator-plc4x/pull/10#discussion_r207149145
 
 

 ##
 File path: 
plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/connection/S7PlcConnection.java
 ##
 @@ -183,14 +194,19 @@ public void close() {
 (short) 0x, (short) 0x000F, DisconnectReason.NORMAL, 
Collections.emptyList(),
 null);
 ChannelFuture sendDisconnectRequestFuture = 
channel.writeAndFlush(disconnectRequest);
-sendDisconnectRequestFuture.addListener((ChannelFutureListener) 
future -> {
-// Close the session itself.
-channel.closeFuture().await();
+// Wait if the PLC closes the connection
+try {
+// TODO 02.08.18 jf: Do we have global constants for things 
like timeouts?
+channel.closeFuture().await(1_000);
+} catch (InterruptedException e) {
+logger.warn("Connection was not closed by PLC, has to be 
closed from driver side now.", e);
+} finally {
+// close the session itself.
 channel.eventLoop().parent().shutdownGracefully();
 
 Review comment:
   example code: 
   ```
   try {
   try {
   throw new RuntimeException("Important information");
   } finally {
   throw new OutOfMemoryError("Something failed gracefully");
   }
   } catch (Throwable e) {
   assert e.class == OutOfMemoryError.class;
   }
   ```


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #10: Fixed NPE in S7PlcConnection#close.

2018-08-02 Thread GitBox
sruehl commented on a change in pull request #10: Fixed NPE in 
S7PlcConnection#close.
URL: https://github.com/apache/incubator-plc4x/pull/10#discussion_r207148665
 
 

 ##
 File path: 
plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/connection/S7PlcConnection.java
 ##
 @@ -183,14 +194,19 @@ public void close() {
 (short) 0x, (short) 0x000F, DisconnectReason.NORMAL, 
Collections.emptyList(),
 null);
 ChannelFuture sendDisconnectRequestFuture = 
channel.writeAndFlush(disconnectRequest);
-sendDisconnectRequestFuture.addListener((ChannelFutureListener) 
future -> {
-// Close the session itself.
-channel.closeFuture().await();
+// Wait if the PLC closes the connection
+try {
+// TODO 02.08.18 jf: Do we have global constants for things 
like timeouts?
+channel.closeFuture().await(1_000);
+} catch (InterruptedException e) {
+logger.warn("Connection was not closed by PLC, has to be 
closed from driver side now.", e);
+} finally {
+// close the session itself.
 channel.eventLoop().parent().shutdownGracefully();
 
 Review comment:
   One thing to note here. If we put this in the finally blog  a potential 
thrown exception is omitted. Especially as the method is called `gracefully`. I 
would suggest to put it outside a finally or wrap it with a try catch ignore.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] JulianFeinauer commented on a change in pull request #10: Fixed NPE in S7PlcConnection#close.

2018-08-02 Thread GitBox
JulianFeinauer commented on a change in pull request #10: Fixed NPE in 
S7PlcConnection#close.
URL: https://github.com/apache/incubator-plc4x/pull/10#discussion_r207178132
 
 

 ##
 File path: 
plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/connection/S7PlcConnection.java
 ##
 @@ -183,14 +194,19 @@ public void close() {
 (short) 0x, (short) 0x000F, DisconnectReason.NORMAL, 
Collections.emptyList(),
 null);
 ChannelFuture sendDisconnectRequestFuture = 
channel.writeAndFlush(disconnectRequest);
-sendDisconnectRequestFuture.addListener((ChannelFutureListener) 
future -> {
-// Close the session itself.
-channel.closeFuture().await();
+// Wait if the PLC closes the connection
+try {
+// TODO 02.08.18 jf: Do we have global constants for things 
like timeouts?
 
 Review comment:
   fixed and removed todo.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] chrisdutz commented on a change in pull request #10: Fixed NPE in S7PlcConnection#close.

2018-08-02 Thread GitBox
chrisdutz commented on a change in pull request #10: Fixed NPE in 
S7PlcConnection#close.
URL: https://github.com/apache/incubator-plc4x/pull/10#discussion_r207224977
 
 

 ##
 File path: 
plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/connection/S7PlcConnectionIT.java
 ##
 @@ -58,7 +58,12 @@ public void setUp() {
 @After
 public void tearDown() {
 if(s7PlcConnection.isConnected()) {
-s7PlcConnection.close();
+try {
+s7PlcConnection.close();
+} catch (NullPointerException e) {
 
 Review comment:
   Hi Julian ... I just updated master ... could you check if this solves your 
problem?


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] JulianFeinauer opened a new pull request #9: Added some javadoc to S7 communication path and several todos that ma…

2018-08-01 Thread GitBox
JulianFeinauer opened a new pull request #9: Added some javadoc to S7 
communication path and several todos that ma…
URL: https://github.com/apache/incubator-plc4x/pull/9
 
 
   Hey all,
   
   i went through the S7 Communication path to understand it for myself and by 
doing that I tried adding useful javadoc at several classes.
   Furthermore, I added several TODOs where I observed possible problems.
   
   I am not sure if all of this javadoc is right so before merging this PR 
someone should go through it carefully and check if the things I state are 
right.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #10: Fixed NPE in S7PlcConnection#close.

2018-08-02 Thread GitBox
sruehl commented on a change in pull request #10: Fixed NPE in 
S7PlcConnection#close.
URL: https://github.com/apache/incubator-plc4x/pull/10#discussion_r207198528
 
 

 ##
 File path: 
plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/connection/S7PlcConnectionIT.java
 ##
 @@ -58,7 +58,12 @@ public void setUp() {
 @After
 public void tearDown() {
 if(s7PlcConnection.isConnected()) {
-s7PlcConnection.close();
+try {
+s7PlcConnection.close();
+} catch (NullPointerException e) {
 
 Review comment:
   apparently blocking operations are not allowed (`await()`)


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] JulianFeinauer commented on a change in pull request #10: Fixed NPE in S7PlcConnection#close.

2018-08-02 Thread GitBox
JulianFeinauer commented on a change in pull request #10: Fixed NPE in 
S7PlcConnection#close.
URL: https://github.com/apache/incubator-plc4x/pull/10#discussion_r207200954
 
 

 ##
 File path: 
plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/connection/S7PlcConnectionIT.java
 ##
 @@ -58,7 +58,12 @@ public void setUp() {
 @After
 public void tearDown() {
 if(s7PlcConnection.isConnected()) {
-s7PlcConnection.close();
+try {
+s7PlcConnection.close();
+} catch (NullPointerException e) {
 
 Review comment:
   @chrisdutz how is your setup?
   For me, this removed the exception here for me with my S7.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #10: Fixed NPE in S7PlcConnection#close.

2018-08-02 Thread GitBox
sruehl commented on a change in pull request #10: Fixed NPE in 
S7PlcConnection#close.
URL: https://github.com/apache/incubator-plc4x/pull/10#discussion_r207197726
 
 

 ##
 File path: 
plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/connection/S7PlcConnectionIT.java
 ##
 @@ -58,7 +58,12 @@ public void setUp() {
 @After
 public void tearDown() {
 if(s7PlcConnection.isConnected()) {
-s7PlcConnection.close();
+try {
+s7PlcConnection.close();
+} catch (NullPointerException e) {
 
 Review comment:
   route cause of failing test is 
`io.netty.util.concurrent.BlockingOperationException` and only NPE gets caught 
so the test still fails


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] asfgit closed pull request #11: Implement basic example of connecting an S7 device to Azure IoT Hub

2018-08-13 Thread GitBox
asfgit closed pull request #11: Implement basic example of connecting an S7 
device to Azure IoT Hub
URL: https://github.com/apache/incubator-plc4x/pull/11
 
 
   

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/azure/pom.xml b/examples/azure/pom.xml
new file mode 100644
index 0..0e010a9c1
--- /dev/null
+++ b/examples/azure/pom.xml
@@ -0,0 +1,38 @@
+
+http://maven.apache.org/POM/4.0.0;
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd;>
+  
+examples
+org.apache.plc4x.examples
+0.0.1-SNAPSHOT
+  
+  4.0.0
+
+  azure
+
+  
+
+  org.apache.plc4x
+  plc4j-api
+  0.0.1-SNAPSHOT
+
+
+  org.apache.plc4x
+  plc4j-core
+  0.0.1-SNAPSHOT
+
+
+  org.apache.plc4x
+  plc4j-protocol-s7
+  0.0.1-SNAPSHOT
+
+
+
+  com.microsoft.azure.sdk.iot
+  iot-device-client
+  1.3.30
+
+  
+
+
\ No newline at end of file
diff --git 
a/examples/azure/src/main/java/org/apache/plc4x/java/examples/azure/iothub/S7PlcToAzureIoTHubSample.java
 
b/examples/azure/src/main/java/org/apache/plc4x/java/examples/azure/iothub/S7PlcToAzureIoTHubSample.java
new file mode 100644
index 0..0e183c3c0
--- /dev/null
+++ 
b/examples/azure/src/main/java/org/apache/plc4x/java/examples/azure/iothub/S7PlcToAzureIoTHubSample.java
@@ -0,0 +1,76 @@
+package org.apache.plc4x.java.examples.azure.iothub;
+
+import com.microsoft.azure.sdk.iot.device.*;
+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.specific.TypeSafePlcReadRequest;
+import org.apache.plc4x.java.api.messages.specific.TypeSafePlcReadResponse;
+import org.apache.plc4x.java.api.model.Address;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Optional;
+
+public class S7PlcToAzureIoTHubSample {
+
+private static final Logger logger = 
LoggerFactory.getLogger(S7PlcToAzureIoTHubSample.class);
+
+private static IotHubClientProtocol protocol = IotHubClientProtocol.MQTT;
+private static DeviceClient client;
+
+public static class Callback implements IotHubEventCallback {
+
+@Override
+public void execute(IotHubStatusCode iotHubStatusCode, Object ctx) {
+System.out.println("Received status: " + iotHubStatusCode.name());
+}
+}
+
+/**
+ * Example code do demonstrate sending events from an S7 device to 
Microsoft Azure IoT Hub
+ *
+ * @param args Expected: [device address, IoT-Hub connection string].
+ */
+public static void main(String[] args) {
+logger.info("Connecting");
+try (PlcConnection plcConnection = new 
PlcDriverManager().getConnection(args[0])) {
+logger.info("Connected");
+
+client = new DeviceClient(args[1], protocol);
+client.open();
+
+Optional reader = plcConnection.getReader();
+
+if (reader.isPresent()) {
+PlcReader plcReader = reader.get();
+Address outputs = plcConnection.parseAddress("OUTPUTS/0");
+
+while (true) {
+// Simulate telemetry.
+TypeSafePlcReadResponse plcReadResponse = 
plcReader.read(new TypeSafePlcReadRequest<>(Byte.class, outputs)).get();
+
+System.out.println("Outputs: " + 
Long.toBinaryString(plcReadResponse.getResponseItem()
+.orElseThrow(() -> new IllegalStateException("No 
response available"))
+.getValues().get(0).longValue()));
+
+plcReadResponse.getResponseItem().map(byt -> {
+String result = 
Long.toBinaryString(byt.getValues().get(0).longValue());
+Message msg = new Message("{ \"bits\" : \"" + 
result + "\"}");
+// Send the message.
+Callback callback = new Callback();
+
+client.sendEventAsync(msg, callback, new Object());
+return byt;
+}
+);
+
+Thread.sleep(1000);
+}
+}
+
+} catch (Exception e) {
+e.printStackTrace();
+}
+}
+}
diff --git a/examples/pom.xml b/examples/pom.xml
index 574edcdd6..5e6379431 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -41,6 +41,7 @@
 iotree
 kafka-bridge
 plclogger
+azure
   
 
   


 



[GitHub] chrisdutz commented on issue #12: fix a few typos

2018-08-13 Thread GitBox
chrisdutz commented on issue #12: fix a few typos
URL: https://github.com/apache/incubator-plc4x/pull/12#issuecomment-412528417
 
 
   Well I guess I can simply merge this from the GitHub ui ... thanks for this 
:-)


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] chrisdutz commented on issue #12: fix a few typos

2018-08-13 Thread GitBox
chrisdutz commented on issue #12: fix a few typos
URL: https://github.com/apache/incubator-plc4x/pull/12#issuecomment-412530954
 
 
   And it does seem as if this revealed syncing problems from GitHub back to 
GitBox ... will investigate this.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] bodewig commented on issue #12: fix a few typos

2018-08-13 Thread GitBox
bodewig commented on issue #12: fix a few typos
URL: https://github.com/apache/incubator-plc4x/pull/12#issuecomment-412537899
 
 
   As somebody toying with the idea of using gitbox for some other projects I'd 
be interested in hearing what went wrong :-)
   


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] chrisdutz closed pull request #12: fix a few typos

2018-08-13 Thread GitBox
chrisdutz closed pull request #12: fix a few typos
URL: https://github.com/apache/incubator-plc4x/pull/12
 
 
   

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/src/site/asciidoc/protocols/delta-v/reverse-engineering.adoc 
b/src/site/asciidoc/protocols/delta-v/reverse-engineering.adoc
index 47ac51058..53211fa8c 100644
--- a/src/site/asciidoc/protocols/delta-v/reverse-engineering.adoc
+++ b/src/site/asciidoc/protocols/delta-v/reverse-engineering.adoc
@@ -28,7 +28,7 @@ We kindly were provided with access to a DeltaV system used 
for training.
 
 Therefore we were able to change a few things without fearing to break 
anything important.
 
-This system consisted of tree DeltaV controllers, two Operator-System instances
+This system consisted of three DeltaV controllers, two Operator-System 
instances
 So in general there were three types of systems involved:
 
 1. DeltaV Controller
@@ -156,6 +156,7 @@ During this we managed to reverse engineer the connection 
on the wrapper-protoco
  Connecting
 
 When an OS is booted, the following communication could be observed:
+
 1. The OS sends a wrapper-protocol type `0x0003` to the controller.
 2. The controller responds with a `0x0004` message back to the controller.
 3. After receiving the `0x0004` message, the OS sends a type `0x0002` message 
with a wrapped type `0x0501`
@@ -163,7 +164,7 @@ When an OS is booted, the following communication could be 
observed:
 5. The controller sends a very similar packet as the `0x0501` packet back to 
the OS
 6. The OS acknowledges this packet back to the controller
 
-From looking at the packet in WireSharks byte and ASCII view, we could see 
ASCII characters that seem to relate to test strings.
+From looking at the packet in WireShark's byte and ASCII view, we could see 
ASCII characters that seem to relate to test strings.
 A quick consultation of the guy in charge of these systems made us realize 
that these strings refer to parts of the controllers software.
 Digging even deeper made us realize that the 4 byte values relate to unix 
timestamps - at least we could decode the byte values to absolutely sensible 
dates.
 So it seems that In these packets each participant compares it's software 
state in order to know all are using compatible versions.
@@ -198,9 +199,9 @@ So we started with the value 0 and incremented that in 
steps of 1 till 20 and th
 
 And we could see that there were certain parts of the packet that seem to 
change when changing values, most of the packet remaining constant.
 When changing a value back to the original value, the packets payload was 
identical in this part.
-As the packets didn't all have the same content and some times blocksp were 
added and left away in regular intervals, lead us to the impression, that these 
packets too consist of a fixed packet header followed by blocks.
+As the packets didn't all have the same content and some times blocks were 
added and left away in regular intervals, lead us to the impression, that these 
packets too consist of a fixed packet header followed by blocks.
 In our case the changing blocks all had two indicator bytes `0x0b08` with the 
4 bytes after that changing according to the input.
-Some times a block of bytes was added before this block, then the entire 
content was just pushed back.
+Sometimes a block of bytes was added before this block, then the entire 
content was just pushed back.
 
 The last of such blocks would always be a sequence of 9 bytes: 
`0x0100`, so we assume this is sort of the `terminating block` 
of such a packet.
 
@@ -228,7 +229,7 @@ However when using what we learnt on the old captures we 
did, it turned out that
 So it seems that `0x08` indicates the type of an `signed 32 bit IEE 754 
floating point value`.
 Eventually the `0x0b` part referred to some sort subscription-id.
 
-As we seem to be doing a subscription based communication, the OS has to tell 
the controller what information he is interested in.
+As we seem to be doing a subscription based communication, the OS has to tell 
the controller what information it is interested in.
 
 Right now we are assuming that in one of the other `0x04` packets a 
subscription is initiated and assigned with some sort of id and this id is used 
to identify which value is actually changed.
 
diff --git a/src/site/site.xml b/src/site/site.xml
index 472490e01..e2339a800 100644
--- a/src/site/site.xml
+++ b/src/site/site.xml
@@ -112,7 +112,7 @@
 
   
   
-  
+  
   
   
   


 


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 

[GitHub] DerDackel commented on issue #11: Implement basic example of connecting an S7 device to Azure IoT Hub

2018-08-10 Thread GitBox
DerDackel commented on issue #11: Implement basic example of connecting an S7 
device to Azure IoT Hub
URL: https://github.com/apache/incubator-plc4x/pull/11#issuecomment-412079165
 
 
   Whatever do you mean? ;)
   
   Realized my mistake immediately after submitting this PR and re-pushed the 
whole branch.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] pisquaredover6 opened a new pull request #13: Basic example to connect S7 device to Google Cloud IoT Core

2018-08-28 Thread GitBox
pisquaredover6 opened a new pull request #13: Basic example to connect S7 
device to Google Cloud IoT Core
URL: https://github.com/apache/incubator-plc4x/pull/13
 
 
   Implement basic example of connecting a S7 device to Google Cloud IoT Core


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #14: WIP: Api Refactoring

2018-09-05 Thread GitBox
sruehl commented on a change in pull request #14: WIP: Api Refactoring
URL: https://github.com/apache/incubator-plc4x/pull/14#discussion_r214037249
 
 

 ##
 File path: 
plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcWriteRequest.java
 ##
 @@ -24,6 +24,8 @@ Licensed to the Apache Software Foundation (ASF) under one
 
 public interface PlcWriteRequest extends PlcFieldRequest {
 
+int getNumValues(String name);
 
 Review comment:
   in the java world one would name these `getNumberOfValues` even if this is a 
bit more verbose but these shortcuts are not seen that much. 


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] chrisdutz commented on a change in pull request #14: WIP: Api Refactoring

2018-09-05 Thread GitBox
chrisdutz commented on a change in pull request #14: WIP: Api Refactoring
URL: https://github.com/apache/incubator-plc4x/pull/14#discussion_r215170934
 
 

 ##
 File path: 
plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcFieldRequest.java
 ##
 @@ -20,11 +20,13 @@ Licensed to the Apache Software Foundation (ASF) under one
 
 import org.apache.plc4x.java.api.model.PlcField;
 
-import java.util.Collection;
+import java.util.LinkedHashSet;
 
 public interface PlcFieldRequest extends PlcRequest {
 
-Collection getFieldNames();
+int getNumFields();
+
+LinkedHashSet getFieldNames();
 
 Review comment:
   Because that is the most generic container that is: 
   - A Map (We need to map names to obects)
   - Preserves the order (might be obsolete now ... have to re-check)


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] asfgit closed pull request #13: Basic example to connect S7 device to Google Cloud IoT Core

2018-09-06 Thread GitBox
asfgit closed pull request #13: Basic example to connect S7 device to Google 
Cloud IoT Core
URL: https://github.com/apache/incubator-plc4x/pull/13
 
 
   

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/README.md b/examples/google/README.md
new file mode 100644
index 0..42f5f71e5
--- /dev/null
+++ b/examples/google/README.md
@@ -0,0 +1,61 @@
+
+# Plc to Goolgle IoT Core Adapter
+
+This Adapter opens a MQTT Bridge to Google Cloud IoT Core.
+
+To run this code, you need an account to the google cloud and a project.
+You need to create a device registry and add a device to it, as described here:
+https://cloud.google.com/iot/docs/how-tos/devices
+
+Then, you can run the PlcToGoogleIoTCoreSample to connect tho google and send 
some values into the cloud.
+Some sample arguments:
+
+-project_id=myprojectname
+-registry_id=plc4x-test
+-cloud_region=europe-west1
+-device_id=plc4x-test-device
+-private_key_file=../../../rsa_private_pkcs8
+-algorithm=RS256
+
+Some documentation can be found here:
+https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/iot/api-client/manager#cloud-iot-core-java-mqtt-example
+This code was adapted from:
+https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/iot/api-client/manager#cloud-iot-core-java-mqtt-example
+
+To retrive the messages, you can subscribe to Cloud Pub/Sub.
+For example, you could install the google cloud sdk (gcloud) and run:
+
+gcloud auth login
+gcloud config set myprojectname
+gcloud iot devices configs list --project=myprojectname \\
+--region=europe-west1 \\
+--registry=myplc4x-test-registry \\
+--device=myplc4x-test-device \\
+--limit=5
+gcloud pubsub subscriptions create --topic plc4x-test-events 
plc4x-test-subscription
+gcloud pubsub subscriptions pull --auto-ack plc4x-test-subscription
+
+
+To pull more than one message, use the option --limit [number]
+
+For further reference to the Cloud Pub/Sub, see:
+https://cloud.google.com/pubsub/docs/quickstart-cli
+https://cloud.google.com/sdk/gcloud/reference/alpha/pubsub/subscriptions/pull
+
diff --git a/examples/google/pom.xml b/examples/google/pom.xml
new file mode 100644
index 0..173c7f2fc
--- /dev/null
+++ b/examples/google/pom.xml
@@ -0,0 +1,118 @@
+
+
+http://maven.apache.org/POM/4.0.0;
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd;>
+  
+examples
+org.apache.plc4x.examples
+0.0.1-SNAPSHOT
+  
+  4.0.0
+
+  google
+  Examples: Google Cloud IoT Core
+  
+Implementation of a PLC4X application gathering information from
+a PLC and making that available in an the Google Cloud IoT Core.
+  
+
+
+  
+
+  
+org.apache.maven.plugins
+maven-dependency-plugin
+
+  
+org.apache.plc4x:plc4j-protocol-s7
+  
+
+  
+
+  
+
+  
+
+  org.apache.plc4x
+  plc4j-api
+  0.0.1-SNAPSHOT
+
+
+  org.apache.plc4x
+  plc4j-core
+  0.0.1-SNAPSHOT
+
+
+  org.eclipse.paho
+  org.eclipse.paho.client.mqttv3
+  1.2.0
+
+
+  org.apache.plc4x
+  plc4j-protocol-s7
+  0.0.1-SNAPSHOT
+  runtime
+
+
+  joda-time
+  joda-time
+  2.3
+  compile
+
+
+
+  io.jsonwebtoken
+  jjwt
+  0.9.1
+
+
+
+  commons-cli
+  commons-cli
+  1.4
+
+
+
+  org.apache.beam
+  beam-runners-google-cloud-dataflow-java
+  2.6.0
+
+
+  org.slf4j
+  log4j-over-slf4j
+  1.7.25
+
+
+  ch.qos.logback
+  logback-classic
+
+  
+
+  
+
+  
+org.apache.qpid
+proton-j
+0.18.0
+  
+
+  
+
\ No newline at end of file
diff --git 
a/examples/google/src/main/java/org/apache/plc4x/java/examples/google/iotcore/MqttExampleOptions.java
 
b/examples/google/src/main/java/org/apache/plc4x/java/examples/google/iotcore/MqttExampleOptions.java
new file mode 100644
index 0..7cdbc9c75
--- /dev/null
+++ 
b/examples/google/src/main/java/org/apache/plc4x/java/examples/google/iotcore/MqttExampleOptions.java
@@ -0,0 +1,166 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR 

[GitHub] skorikov opened a new pull request #16: Implemented throttling in Kafka Source Connector

2018-09-10 Thread GitBox
skorikov opened a new pull request #16: Implemented throttling in Kafka Source 
Connector
URL: https://github.com/apache/incubator-plc4x/pull/16
 
 
   A new configuration option `rate` is implemented, which allows to limit the 
polling rate to a given value (for example every 1000 milliseconds). This 
ensures that the source will not be flooded with request from the connector.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] chrisdutz closed pull request #16: Implemented throttling in Kafka Source Connector

2018-09-10 Thread GitBox
chrisdutz closed pull request #16: Implemented throttling in Kafka Source 
Connector
URL: https://github.com/apache/incubator-plc4x/pull/16
 
 
   

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/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSinkConnector.java
 
b/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSinkConnector.java
index 021b0233f..45ae926eb 100644
--- 
a/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSinkConnector.java
+++ 
b/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSinkConnector.java
@@ -21,20 +21,26 @@ Licensed to the Apache Software Foundation (ASF) under one
 import org.apache.kafka.common.config.ConfigDef;
 import org.apache.kafka.connect.connector.Task;
 import org.apache.kafka.connect.sink.SinkConnector;
-import org.apache.plc4x.kafka.sink.Plc4xSinkConfig;
-import org.apache.plc4x.kafka.sink.Plc4xSinkTask;
 import org.apache.plc4x.kafka.util.VersionUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
-import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 public class Plc4xSinkConnector extends SinkConnector {
-private static Logger log = 
LoggerFactory.getLogger(Plc4xSinkConnector.class);
+static final String URL_CONFIG = "url";
+private static final String URL_DOC = "Connection string used by PLC4X to 
connect to the PLC";
 
-private Map configProperties;
+static final String QUERY_CONFIG = "query";
+private static final String QUERY_DOC = "Field query to be sent to the 
PLC";
+
+private static final ConfigDef CONFIG_DEF = new ConfigDef()
+.define(URL_CONFIG, ConfigDef.Type.STRING, ConfigDef.Importance.HIGH, 
URL_DOC)
+.define(QUERY_CONFIG, ConfigDef.Type.STRING, 
ConfigDef.Importance.HIGH, QUERY_DOC);
+
+private String url;
+private String query;
 
 @Override
 public Class taskClass() {
@@ -43,27 +49,26 @@ Licensed to the Apache Software Foundation (ASF) under one
 
 @Override
 public List> taskConfigs(int maxTasks) {
-log.info("Setting task configurations for {} workers.", maxTasks);
-final List> configs = new ArrayList<>(maxTasks);
-for (int i = 0; i < maxTasks; ++i) {
-configs.add(configProperties);
-}
-return configs;
+Map taskConfig = new HashMap<>();
+taskConfig.put(URL_CONFIG, url);
+taskConfig.put(QUERY_CONFIG, query);
+
+// Only one task will be created; ignoring maxTasks for now
+return Collections.singletonList(taskConfig);
 }
 
 @Override
 public void start(Map props) {
-configProperties = props;
+url = props.get(URL_CONFIG);
+query = props.get(QUERY_CONFIG);
 }
 
 @Override
-public void stop() {
-// Nothing to do here ...
-}
+public void stop() {}
 
 @Override
 public ConfigDef config() {
-return Plc4xSinkConfig.CONFIG_DEF;
+return CONFIG_DEF;
 }
 
 @Override
diff --git 
a/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSinkTask.java
 
b/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSinkTask.java
new file mode 100644
index 0..b29418f18
--- /dev/null
+++ 
b/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSinkTask.java
@@ -0,0 +1,101 @@
+/*
+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.plc4x.kafka;
+
+import org.apache.kafka.connect.errors.ConnectException;
+import org.apache.kafka.connect.sink.SinkRecord;
+import org.apache.kafka.connect.sink.SinkTask;
+import org.apache.plc4x.java.PlcDriverManager;
+import org.apache.plc4x.java.api.connection.PlcConnection;
+import org.apache.plc4x.java.api.connection.PlcWriter;
+import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
+import org.apache.plc4x.java.api.messages.PlcWriteRequest;
+import org.apache.plc4x.kafka.util.VersionUtil;
+
+import 

[GitHub] sruehl commented on a change in pull request #14: WIP: Api Refactoring

2018-08-30 Thread GitBox
sruehl commented on a change in pull request #14: WIP: Api Refactoring
URL: https://github.com/apache/incubator-plc4x/pull/14#discussion_r213965185
 
 

 ##
 File path: 
integrations/apache-camel/src/main/java/org/apache/plc4x/camel/Plc4XConsumer.java
 ##
 @@ -84,22 +79,29 @@ public void setExceptionHandler(ExceptionHandler 
exceptionHandler) {
 }
 
 @Override
-protected void doStart() throws InterruptedException, ExecutionException, 
TimeoutException {
-PlcSubscriptionRequest request = new PlcSubscriptionRequest();
-@SuppressWarnings("unchecked")
-SubscriptionRequestCyclicItem subscriptionRequestCyclicItem = new 
SubscriptionRequestCyclicItem(dataType, address, TimeUnit.SECONDS, 3, this);
-request.addItem(subscriptionRequestCyclicItem);
+protected void doStart() throws InterruptedException, ExecutionException, 
TimeoutException, PlcException {
+PlcSubscriber plcSubscriber = 
plcConnection.getSubscriber().orElseThrow(
+() -> new PlcException("Connection doesn't support 
subscriptions."));
+// TODO: Is it correct to only support one field?
+PlcSubscriptionRequest request = 
plcSubscriber.subscriptionRequestBuilder()
+.addCyclicField("default", fieldQuery, Duration.of(3, 
ChronoUnit.SECONDS)).build();
 CompletableFuture subscriptionFuture = 
getSubscriber().subscribe(request);
 subscriptionResponse = subscriptionFuture.get(5, TimeUnit.SECONDS);
 }
 
 @Override
-protected void doStop() {
-PlcUnsubscriptionRequest request = new PlcUnsubscriptionRequest();
-subscriptionResponse.getResponseItems().stream()
-.map(SubscriptionResponseItem::getSubscriptionHandle)
-.map(UnsubscriptionRequestItem::new)
-.forEach(request::addItem);
+protected void doStop() throws InterruptedException, ExecutionException, 
TimeoutException, PlcException {
+PlcSubscriber plcSubscriber = 
plcConnection.getSubscriber().orElseThrow(
+() -> new PlcException("Connection doesn't support 
subscriptions."));
+PlcUnsubscriptionRequest.Builder builder = 
plcSubscriber.unsubscriptionRequestBuilder();
+// For every field we subscribed for, now unsubscribe.
+subscriptionResponse.getFieldNames().forEach(fieldName -> {
 
 Review comment:
   maybe this can be moved into the unsubscription builder so we don't repeat 
that code everywhere.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #14: WIP: Api Refactoring

2018-08-30 Thread GitBox
sruehl commented on a change in pull request #14: WIP: Api Refactoring
URL: https://github.com/apache/incubator-plc4x/pull/14#discussion_r213966073
 
 

 ##
 File path: 
plc4j/api/src/main/java/org/apache/plc4x/java/api/connection/PlcProprietarySender.java
 ##
 @@ -1,41 +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.plc4x.java.api.connection;
-
-import org.apache.plc4x.java.api.messages.PlcProprietaryRequest;
-import org.apache.plc4x.java.api.messages.PlcProprietaryResponse;
-
-import java.util.concurrent.CompletableFuture;
-
-/**
- * Interface implemented by all PlcConnections that are able to send custom 
commands to resources.
- */
-@FunctionalInterface
-public interface PlcProprietarySender {
 
 Review comment:
   why did this got deleted?


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #14: WIP: Api Refactoring

2018-08-30 Thread GitBox
sruehl commented on a change in pull request #14: WIP: Api Refactoring
URL: https://github.com/apache/incubator-plc4x/pull/14#discussion_r213967016
 
 

 ##
 File path: 
plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcFieldResponse.java
 ##
 @@ -0,0 +1,42 @@
+/*
+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.plc4x.java.api.messages;
+
+import org.apache.plc4x.java.api.model.PlcField;
+import org.apache.plc4x.java.api.types.PlcResponseCode;
+
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * Base type for all response messages sent as response for a prior request
+ * from a plc to the plc4x system.
+ * @param 
+ */
+public interface PlcFieldResponse 
extends PlcResponse {
+
+Map getFields();
+
+Collection getFieldNames();
 
 Review comment:
   This should be more a `java.util.Set` as these are unique, aren't they?


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #14: WIP: Api Refactoring

2018-08-30 Thread GitBox
sruehl commented on a change in pull request #14: WIP: Api Refactoring
URL: https://github.com/apache/incubator-plc4x/pull/14#discussion_r213965327
 
 

 ##
 File path: 
integrations/apache-camel/src/main/java/org/apache/plc4x/camel/Plc4XConsumer.java
 ##
 @@ -112,25 +114,25 @@ private PlcSubscriber getSubscriber() {
 }
 
 @Override
-public void accept(SubscriptionEventItem subscriptionEventItem) {
-LOGGER.debug("Received {}", subscriptionEventItem);
+public void accept(PlcSubscriptionEvent plcSubscriptionEvent) {
+LOGGER.debug("Received {}", plcSubscriptionEvent);
 try {
 Exchange exchange = endpoint.createExchange();
-
exchange.getIn().setBody(unwrapIfSingle(subscriptionEventItem.getValues()));
+
exchange.getIn().setBody(unwrapIfSingle(plcSubscriptionEvent.getAllObjects("default")));
 
 Review comment:
   where does this "default" constant come from?


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] chrisdutz commented on a change in pull request #14: WIP: Api Refactoring

2018-08-30 Thread GitBox
chrisdutz commented on a change in pull request #14: WIP: Api Refactoring
URL: https://github.com/apache/incubator-plc4x/pull/14#discussion_r213980628
 
 

 ##
 File path: 
plc4j/api/src/main/java/org/apache/plc4x/java/api/connection/PlcProprietarySender.java
 ##
 @@ -1,41 +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.plc4x.java.api.connection;
-
-import org.apache.plc4x.java.api.messages.PlcProprietaryRequest;
-import org.apache.plc4x.java.api.messages.PlcProprietaryResponse;
-
-import java.util.concurrent.CompletableFuture;
-
-/**
- * Interface implemented by all PlcConnections that are able to send custom 
commands to resources.
- */
-@FunctionalInterface
-public interface PlcProprietarySender {
 
 Review comment:
   This is for now ... I am in the process of updating the existing drivers and 
would re-add it as soon as I come to the ads driver.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] chrisdutz commented on a change in pull request #14: WIP: Api Refactoring

2018-08-30 Thread GitBox
chrisdutz commented on a change in pull request #14: WIP: Api Refactoring
URL: https://github.com/apache/incubator-plc4x/pull/14#discussion_r213981646
 
 

 ##
 File path: 
plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcFieldRequest.java
 ##
 @@ -0,0 +1,31 @@
+/*
+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.plc4x.java.api.messages;
+
+import org.apache.plc4x.java.api.model.PlcField;
+
+import java.util.Collection;
+
+public interface PlcFieldRequest extends PlcRequest {
+
+Collection getFieldNames();
 
 Review comment:
   Well yes and no ... this hasn't been finalized, but the order of the items 
it important and Set isn't ordered but Collection isn't either, so I'll have to 
change that to something else anyway.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] chrisdutz commented on a change in pull request #14: WIP: Api Refactoring

2018-08-30 Thread GitBox
chrisdutz commented on a change in pull request #14: WIP: Api Refactoring
URL: https://github.com/apache/incubator-plc4x/pull/14#discussion_r213981663
 
 

 ##
 File path: 
plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcFieldResponse.java
 ##
 @@ -0,0 +1,42 @@
+/*
+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.plc4x.java.api.messages;
+
+import org.apache.plc4x.java.api.model.PlcField;
+import org.apache.plc4x.java.api.types.PlcResponseCode;
+
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * Base type for all response messages sent as response for a prior request
+ * from a plc to the plc4x system.
+ * @param 
+ */
+public interface PlcFieldResponse 
extends PlcResponse {
+
+Map getFields();
+
+Collection getFieldNames();
 
 Review comment:
   Well yes and no ... this hasn't been finalized, but the order of the items 
it important and Set isn't ordered but Collection isn't either, so I'll have to 
change that to something else anyway.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] chrisdutz commented on a change in pull request #14: WIP: Api Refactoring

2018-08-30 Thread GitBox
chrisdutz commented on a change in pull request #14: WIP: Api Refactoring
URL: https://github.com/apache/incubator-plc4x/pull/14#discussion_r213981675
 
 

 ##
 File path: 
plc4j/api/src/test/java/org/apache/plc4x/java/api/connection/PlcReaderTest.java
 ##
 @@ -38,24 +36,24 @@ Licensed to the Apache Software Foundation (ASF) under one
 
 public class PlcReaderTest {
 
-@Test
+/*@Test
 
 Review comment:
   Well the API is currently just interfaces ... how do you test them? ... and 
that's why there's a WIP in the Pull-Request as I will probably move these to 
driver-base where the real datatypes will be. I commented them out so I can 
compile the parts I have migrated and don't have to fetch them from the history 
when re-adding them somewhere else.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #14: WIP: Api Refactoring

2018-08-30 Thread GitBox
sruehl commented on a change in pull request #14: WIP: Api Refactoring
URL: https://github.com/apache/incubator-plc4x/pull/14#discussion_r213981954
 
 

 ##
 File path: 
plc4j/api/src/test/java/org/apache/plc4x/java/api/connection/PlcReaderTest.java
 ##
 @@ -38,24 +36,24 @@ Licensed to the Apache Software Foundation (ASF) under one
 
 public class PlcReaderTest {
 
-@Test
+/*@Test
 
 Review comment:
   ok, fair enough :)


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] skorikov opened a new pull request #18: Add support for multiple tasks in kafka sink connector

2018-09-11 Thread GitBox
skorikov opened a new pull request #18: Add support for multiple tasks in kafka 
sink connector
URL: https://github.com/apache/incubator-plc4x/pull/18
 
 
   


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] asfgit closed pull request #17: Add support for multiple queries in kafka source connector

2018-09-11 Thread GitBox
asfgit closed pull request #17: Add support for multiple queries in kafka 
source connector
URL: https://github.com/apache/incubator-plc4x/pull/17
 
 
   

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/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSinkConnector.java
 
b/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSinkConnector.java
index 45ae926eb..189920886 100644
--- 
a/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSinkConnector.java
+++ 
b/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSinkConnector.java
@@ -18,6 +18,7 @@ Licensed to the Apache Software Foundation (ASF) under one
 */
 package org.apache.plc4x.kafka;
 
+import org.apache.kafka.common.config.AbstractConfig;
 import org.apache.kafka.common.config.ConfigDef;
 import org.apache.kafka.connect.connector.Task;
 import org.apache.kafka.connect.sink.SinkConnector;
@@ -35,7 +36,7 @@ Licensed to the Apache Software Foundation (ASF) under one
 static final String QUERY_CONFIG = "query";
 private static final String QUERY_DOC = "Field query to be sent to the 
PLC";
 
-private static final ConfigDef CONFIG_DEF = new ConfigDef()
+static final ConfigDef CONFIG_DEF = new ConfigDef()
 .define(URL_CONFIG, ConfigDef.Type.STRING, ConfigDef.Importance.HIGH, 
URL_DOC)
 .define(QUERY_CONFIG, ConfigDef.Type.STRING, 
ConfigDef.Importance.HIGH, QUERY_DOC);
 
@@ -59,8 +60,9 @@ Licensed to the Apache Software Foundation (ASF) under one
 
 @Override
 public void start(Map props) {
-url = props.get(URL_CONFIG);
-query = props.get(QUERY_CONFIG);
+AbstractConfig config = new 
AbstractConfig(Plc4xSinkConnector.CONFIG_DEF, props);
+url = config.getString(URL_CONFIG);
+query = config.getString(QUERY_CONFIG);
 }
 
 @Override
diff --git 
a/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSinkTask.java
 
b/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSinkTask.java
index b29418f18..a54d5b08b 100644
--- 
a/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSinkTask.java
+++ 
b/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSinkTask.java
@@ -18,6 +18,7 @@ Licensed to the Apache Software Foundation (ASF) under one
 */
 package org.apache.plc4x.kafka;
 
+import org.apache.kafka.common.config.AbstractConfig;
 import org.apache.kafka.connect.errors.ConnectException;
 import org.apache.kafka.connect.sink.SinkRecord;
 import org.apache.kafka.connect.sink.SinkTask;
@@ -33,8 +34,6 @@ Licensed to the Apache Software Foundation (ASF) under one
 import java.util.concurrent.ExecutionException;
 
 public class Plc4xSinkTask extends SinkTask {
-private final static String FIELD_KEY = "key"; // TODO: is this really 
necessary?
-
 private String url;
 private String query;
 
@@ -48,8 +47,9 @@ public String version() {
 
 @Override
 public void start(Map props) {
-url = props.get(Plc4xSinkConnector.URL_CONFIG);
-query = props.get(Plc4xSinkConnector.QUERY_CONFIG);
+AbstractConfig config = new 
AbstractConfig(Plc4xSinkConnector.CONFIG_DEF, props);
+url = config.getString(Plc4xSinkConnector.URL_CONFIG);
+query = config.getString(Plc4xSinkConnector.QUERY_CONFIG);
 
 openConnection();
 
@@ -66,7 +66,7 @@ public void stop() {
 public void put(Collection records) {
 for (SinkRecord record: records) {
 String value = record.value().toString(); // TODO: implement other 
data types
-PlcWriteRequest plcRequest = 
plcWriter.writeRequestBuilder().addItem(FIELD_KEY, query, value).build();
+PlcWriteRequest plcRequest = 
plcWriter.writeRequestBuilder().addItem(query, query, value).build();
 doWrite(plcRequest);
 }
 }
diff --git 
a/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSourceConnector.java
 
b/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSourceConnector.java
index 4d1d9d026..4d014a535 100644
--- 
a/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSourceConnector.java
+++ 
b/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSourceConnector.java
@@ -18,13 +18,15 @@ Licensed to the Apache Software Foundation (ASF) under one
 */
 package org.apache.plc4x.kafka;
 
+import org.apache.kafka.common.config.AbstractConfig;
 import org.apache.kafka.common.config.ConfigDef;
 import org.apache.kafka.connect.connector.Task;
 import org.apache.kafka.connect.source.SourceConnector;
+import org.apache.kafka.connect.util.ConnectorUtils;
 import org.apache.plc4x.kafka.util.VersionUtil;
 
-import java.util.Collections;
 

[GitHub] asfgit closed pull request #18: Add support for multiple tasks in kafka sink connector

2018-09-11 Thread GitBox
asfgit closed pull request #18: Add support for multiple tasks in kafka sink 
connector
URL: https://github.com/apache/incubator-plc4x/pull/18
 
 
   

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/iot-factory/src/main/java/org/apache/plc4x/java/examples/iotfactory/IotElasticsearchFactory.java
 
b/examples/iot-factory/src/main/java/org/apache/plc4x/java/examples/iotfactory/IotElasticsearchFactory.java
index 41090f8f5..35e78f4eb 100644
--- 
a/examples/iot-factory/src/main/java/org/apache/plc4x/java/examples/iotfactory/IotElasticsearchFactory.java
+++ 
b/examples/iot-factory/src/main/java/org/apache/plc4x/java/examples/iotfactory/IotElasticsearchFactory.java
@@ -148,7 +148,7 @@ private void runFactory() {
 
 // Define the event stream.
 // 1) PLC4X source generating a stream of bytes.
-Supplier plcSupplier = PlcFunctions.byteSupplier(plcAdapter, 
"OUTPUTS/0");
+Supplier plcSupplier = PlcFunctions.byteSupplier(plcAdapter, 
"%Q0:BYTE");
 // 2) Use polling to get an item from the byte-stream in regular 
intervals.
 TStream plcOutputStates = top.poll(plcSupplier, 100, 
TimeUnit.MILLISECONDS);
 
diff --git 
a/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSinkConnector.java
 
b/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSinkConnector.java
index 45ae926eb..fa2e32d62 100644
--- 
a/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSinkConnector.java
+++ 
b/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSinkConnector.java
@@ -18,26 +18,20 @@ Licensed to the Apache Software Foundation (ASF) under one
 */
 package org.apache.plc4x.kafka;
 
+import org.apache.kafka.common.config.AbstractConfig;
 import org.apache.kafka.common.config.ConfigDef;
 import org.apache.kafka.connect.connector.Task;
 import org.apache.kafka.connect.sink.SinkConnector;
 import org.apache.plc4x.kafka.util.VersionUtil;
 
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 public class Plc4xSinkConnector extends SinkConnector {
 static final String URL_CONFIG = "url";
 private static final String URL_DOC = "Connection string used by PLC4X to 
connect to the PLC";
 
-static final String QUERY_CONFIG = "query";
-private static final String QUERY_DOC = "Field query to be sent to the 
PLC";
-
-private static final ConfigDef CONFIG_DEF = new ConfigDef()
-.define(URL_CONFIG, ConfigDef.Type.STRING, ConfigDef.Importance.HIGH, 
URL_DOC)
-.define(QUERY_CONFIG, ConfigDef.Type.STRING, 
ConfigDef.Importance.HIGH, QUERY_DOC);
+static final ConfigDef CONFIG_DEF = new ConfigDef()
+.define(URL_CONFIG, ConfigDef.Type.STRING, ConfigDef.Importance.HIGH, 
URL_DOC);
 
 private String url;
 private String query;
@@ -49,18 +43,19 @@ Licensed to the Apache Software Foundation (ASF) under one
 
 @Override
 public List> taskConfigs(int maxTasks) {
-Map taskConfig = new HashMap<>();
-taskConfig.put(URL_CONFIG, url);
-taskConfig.put(QUERY_CONFIG, query);
-
-// Only one task will be created; ignoring maxTasks for now
-return Collections.singletonList(taskConfig);
+List> configs = new LinkedList<>();
+for (int i = 0; i < maxTasks; i++) {
+Map taskConfig = new HashMap<>();
+taskConfig.put(URL_CONFIG, url);
+configs.add(taskConfig);
+}
+return configs;
 }
 
 @Override
 public void start(Map props) {
-url = props.get(URL_CONFIG);
-query = props.get(QUERY_CONFIG);
+AbstractConfig config = new 
AbstractConfig(Plc4xSinkConnector.CONFIG_DEF, props);
+url = config.getString(URL_CONFIG);
 }
 
 @Override
diff --git 
a/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSinkTask.java
 
b/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSinkTask.java
index b29418f18..648a32e4a 100644
--- 
a/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSinkTask.java
+++ 
b/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSinkTask.java
@@ -18,6 +18,7 @@ Licensed to the Apache Software Foundation (ASF) under one
 */
 package org.apache.plc4x.kafka;
 
+import org.apache.kafka.common.config.AbstractConfig;
 import org.apache.kafka.connect.errors.ConnectException;
 import org.apache.kafka.connect.sink.SinkRecord;
 import org.apache.kafka.connect.sink.SinkTask;
@@ -33,10 +34,7 @@ Licensed to the Apache Software Foundation (ASF) under one
 import java.util.concurrent.ExecutionException;
 
 public class Plc4xSinkTask extends SinkTask {
-private 

[GitHub] asfgit closed pull request #19: Add URL Field to Key Schema in Kafka Source Connector

2018-09-11 Thread GitBox
asfgit closed pull request #19: Add URL Field to Key Schema in Kafka Source 
Connector
URL: https://github.com/apache/incubator-plc4x/pull/19
 
 
   

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/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSourceTask.java
 
b/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSourceTask.java
index c354a1ea2..7d0ed8621 100644
--- 
a/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSourceTask.java
+++ 
b/integrations/apache-kafka/src/main/java/org/apache/plc4x/kafka/Plc4xSourceTask.java
@@ -20,6 +20,8 @@ Licensed to the Apache Software Foundation (ASF) under one
 
 import org.apache.kafka.common.config.AbstractConfig;
 import org.apache.kafka.connect.data.Schema;
+import org.apache.kafka.connect.data.SchemaBuilder;
+import org.apache.kafka.connect.data.Struct;
 import org.apache.kafka.connect.errors.ConnectException;
 import org.apache.kafka.connect.source.SourceRecord;
 import org.apache.kafka.connect.source.SourceTask;
@@ -32,10 +34,7 @@ Licensed to the Apache Software Foundation (ASF) under one
 import org.apache.plc4x.java.api.types.PlcResponseCode;
 import org.apache.plc4x.kafka.util.VersionUtil;
 
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.concurrent.*;
 
 /**
@@ -48,6 +47,15 @@ Licensed to the Apache Software Foundation (ASF) under one
 private final static long WAIT_LIMIT_MILLIS = 100;
 private final static long TIMEOUT_LIMIT_MILLIS = 5000;
 
+private final static String URL_FIELD = "url";
+private final static String QUERY_FIELD = "query";
+
+private final static Schema KEY_SCHEMA =
+new SchemaBuilder(Schema.Type.STRUCT)
+.field(URL_FIELD, Schema.STRING_SCHEMA)
+.field(QUERY_FIELD, Schema.STRING_SCHEMA)
+.build();
+
 private String topic;
 private String url;
 private List queries;
@@ -56,6 +64,8 @@ Licensed to the Apache Software Foundation (ASF) under one
 private PlcReader plcReader;
 private PlcReadRequest plcRequest;
 
+
+
 // TODO: should we use shared (static) thread pool for this?
 private ScheduledExecutorService scheduler;
 private ScheduledFuture timer;
@@ -166,11 +176,16 @@ private synchronized boolean awaitFetch(long 
milliseconds) throws InterruptedExc
 continue;
 }
 
-Object rawValue = response.getObject(query);
-Schema valueSchema = getSchema(rawValue.getClass());
-Object value = valueSchema.equals(Schema.STRING_SCHEMA) ? 
rawValue.toString() : rawValue;
+Struct key = new Struct(KEY_SCHEMA)
+.put(URL_FIELD, url)
+.put(QUERY_FIELD, query);
+
+Object value = response.getObject(query);
+Schema valueSchema = getSchema(value);
 Long timestamp = System.currentTimeMillis();
-Map sourcePartition = 
Collections.singletonMap("url", url);
+Map sourcePartition = new HashMap<>();
+sourcePartition.put("url", url);
+sourcePartition.put("query", query);
 Map sourceOffset = 
Collections.singletonMap("offset", timestamp);
 
 SourceRecord record =
@@ -178,8 +193,8 @@ private synchronized boolean awaitFetch(long milliseconds) 
throws InterruptedExc
 sourcePartition,
 sourceOffset,
 topic,
-Schema.STRING_SCHEMA,
-query,
+KEY_SCHEMA,
+key,
 valueSchema,
 value
 );
@@ -190,20 +205,38 @@ private synchronized boolean awaitFetch(long 
milliseconds) throws InterruptedExc
 return result;
 }
 
-private Schema getSchema(Class type) {
-if (type.equals(Byte.class))
+private Schema getSchema(Object value) {
+Objects.requireNonNull(value);
+
+if (value instanceof Byte)
 return Schema.INT8_SCHEMA;
 
-if (type.equals(Short.class))
+if (value instanceof Short)
 return Schema.INT16_SCHEMA;
 
-if (type.equals(Integer.class))
+if (value instanceof Integer)
 return Schema.INT32_SCHEMA;
 
-if (type.equals(Long.class))
+if (value instanceof Long)
 return Schema.INT64_SCHEMA;
 
-return Schema.STRING_SCHEMA; // default case; invoke .toString on value
+if (value instanceof Float)
+return Schema.FLOAT32_SCHEMA;
+
+if (value instanceof Double)
+return Schema.FLOAT64_SCHEMA;
+
+if (value instanceof Boolean)
+  

[GitHub] dlaboss commented on a change in pull request #8: cleanup warnings in plc4j-api, plc4j-core, dummy-driver

2018-02-27 Thread GitBox
dlaboss commented on a change in pull request #8: cleanup warnings in 
plc4j-api, plc4j-core, dummy-driver
URL: https://github.com/apache/incubator-plc4x/pull/8#discussion_r170929853
 
 

 ##
 File path: 
plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcReadResponse.java
 ##
 @@ -59,17 +59,49 @@ public TypeSafePlcReadResponse(TypeSafePlcReadRequest 
request, List>) super.getResponseItem();
 }
 
+/**
+ * Cast or convert a PlcReadResponse to a TypeSafePlcReadReadResponse.
+ * 
+ * WARNING: this is inherently a non-type-safe operation.  It was 
introduced
+ * to serve the implementation of 
PlcReader.read(TypeSafePlcReadRequest).
+ * Additional use of it is not recommended.  This interface is subject to 
change.
+ * 
+ * @param plcReadResponse the response implicitly with items of type T
+ * @return TypeSafePlcReadReadResponse
+ */
 @SuppressWarnings("unchecked")
 public static  TypeSafePlcReadResponse of(PlcReadResponse 
plcReadResponse) {
 
 Review comment:
   Seems like it.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] dlaboss commented on a change in pull request #8: cleanup warnings in plc4j-api, plc4j-core, dummy-driver

2018-02-27 Thread GitBox
dlaboss commented on a change in pull request #8: cleanup warnings in 
plc4j-api, plc4j-core, dummy-driver
URL: https://github.com/apache/incubator-plc4x/pull/8#discussion_r170931306
 
 

 ##
 File path: 
plc4j/core/src/test/java/org/apache/plc4x/java/PlcDriverManagerTest.java
 ##
 @@ -26,21 +37,11 @@ Licensed to the Apache Software Foundation (ASF) under one
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsInstanceOf.instanceOf;
-import static org.hamcrest.core.IsNull.notNullValue;
-import static org.hamcrest.core.IsNull.nullValue;
-import static org.junit.Assert.assertThat;
-
 public class PlcDriverManagerTest {
 
 /**
  * Tries to get the mock plc driver which is part of this testsuite.
+ * @throws PlcException 
 
 Review comment:
   I can make that transformation if that's the policy the team wants.  Anyone 
want to toss in a +1 on that?  (another policy to document in a DEVELOPMENT.md)


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] dlaboss commented on a change in pull request #8: cleanup warnings in plc4j-api, plc4j-core, dummy-driver

2018-02-27 Thread GitBox
dlaboss commented on a change in pull request #8: cleanup warnings in 
plc4j-api, plc4j-core, dummy-driver
URL: https://github.com/apache/incubator-plc4x/pull/8#discussion_r171087658
 
 

 ##
 File path: 
plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcWriteResponse.java
 ##
 @@ -37,6 +37,7 @@ public PlcWriteResponse(PlcWriteRequest request, List Optional getValue(WriteRequestItem 
item) {
-return (Optional) super.getValue(item);
+Optional value = super.getValue(item); 
+return (Optional) ((Object) value); 
 
 Review comment:
   Fwiw, actually, directly casting to Optional is an 
error.  First casting to Object eliminates it. Will add comment.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] JulianFeinauer commented on a change in pull request #26: connection manager for connection pool initial version

2018-09-30 Thread GitBox
JulianFeinauer commented on a change in pull request #26: connection manager 
for connection pool initial version
URL: https://github.com/apache/incubator-plc4x/pull/26#discussion_r221467015
 
 

 ##
 File path: 
plc4j/core/src/main/java/org/apache/plc4x/java/connectionpool/PlcConnectionManager.java
 ##
 @@ -0,0 +1,154 @@
+/*
+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.plc4x.java.connectionpool;
+
+import org.apache.plc4x.java.PlcDriverManager;
+import org.apache.plc4x.java.PlcDriverManagerInterface;
+import org.apache.plc4x.java.api.authentication.PlcAuthentication;
+import org.apache.plc4x.java.api.connection.PlcConnection;
+import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
+import org.apache.plc4x.java.exceptions.NoConnectionAvailableException;
+import org.apache.plc4x.java.exceptions.NotConnectedException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.PreDestroy;
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * Plc Connection Manager to act as a controller to give threads access to a 
connection in the pool only if it is not
+ * used by a different thread
+ */
+public class PlcConnectionManager implements PlcDriverManagerInterface {
+private static final Logger logger = 
LoggerFactory.getLogger(PlcConnectionManager.class);
+//TODO: implement connection Pool with more than one connection
+private Map connections = new HashMap<>();
 
 Review comment:
   I think we have to use a ConcurrentMap or to use locks to avoid 
ConcurrentModificationExceptions, as multiple threads could modify the list 
concurrently.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] JulianFeinauer commented on a change in pull request #26: connection manager for connection pool initial version

2018-09-30 Thread GitBox
JulianFeinauer commented on a change in pull request #26: connection manager 
for connection pool initial version
URL: https://github.com/apache/incubator-plc4x/pull/26#discussion_r221466988
 
 

 ##
 File path: 
plc4j/core/src/main/java/org/apache/plc4x/java/connectionpool/PlcConnectionManager.java
 ##
 @@ -0,0 +1,154 @@
+/*
+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.plc4x.java.connectionpool;
+
+import org.apache.plc4x.java.PlcDriverManager;
+import org.apache.plc4x.java.PlcDriverManagerInterface;
+import org.apache.plc4x.java.api.authentication.PlcAuthentication;
+import org.apache.plc4x.java.api.connection.PlcConnection;
+import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
+import org.apache.plc4x.java.exceptions.NoConnectionAvailableException;
+import org.apache.plc4x.java.exceptions.NotConnectedException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.PreDestroy;
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * Plc Connection Manager to act as a controller to give threads access to a 
connection in the pool only if it is not
+ * used by a different thread
+ */
+public class PlcConnectionManager implements PlcDriverManagerInterface {
 
 Review comment:
   Perhaps it is more intuitive to name the Thing PlcConnectionPool or 
something.
   And it should (as stated above) implement PlcDriverManager directly.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] JulianFeinauer commented on a change in pull request #26: connection manager for connection pool initial version

2018-09-30 Thread GitBox
JulianFeinauer commented on a change in pull request #26: connection manager 
for connection pool initial version
URL: https://github.com/apache/incubator-plc4x/pull/26#discussion_r221466969
 
 

 ##
 File path: 
plc4j/core/src/main/java/org/apache/plc4x/java/connectionpool/ConnectionProxy.java
 ##
 @@ -0,0 +1,24 @@
+/*
+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.plc4x.java.connectionpool;
+
+import org.apache.plc4x.java.api.connection.PlcConnection;
+
+public interface ConnectionProxy extends PlcConnection {
 
 Review comment:
   Do we need this? I guess not?


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] JulianFeinauer commented on issue #21: Made PlcInvalidFieldException.java checked.

2018-09-30 Thread GitBox
JulianFeinauer commented on issue #21: Made PlcInvalidFieldException.java 
checked.
URL: https://github.com/apache/incubator-plc4x/pull/21#issuecomment-425737626
 
 
   Hey @chrisdutz and @sruehl just wanted to bump that up. I think we should 
decide here on something and either merge or decline the PR. What do you hink 
about the checked exceptions for wrong user inputs?


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] JulianFeinauer opened a new pull request #29: Opm plcentitymanager

2018-10-22 Thread GitBox
JulianFeinauer opened a new pull request #29: Opm plcentitymanager
URL: https://github.com/apache/incubator-plc4x/pull/29
 
 
   I just finished the first (working) implementation of the Object-Plc-Mapping 
(OPM).
   This is a JPA Like functionality on top of plc4x which allows to issue 
requests against plc4x by calling Methods on POJOs!
   
   Basically, it uses 3 classes.
   
 *   PlcEntityManager: This is the main class. A call on read(…) or 
connect(…) does all the necessary magic
 *   PlcEntity (Annotation): A Pojo needs this annotation to be used with 
read(…) or connect(…) above
 *   PlcField (Annotation): Fields in the Pojo that are annotated with this 
field are fetched from the plc
   
   Some simple tests (with mocking) can be found in PlcEntityManagerTest.
   
   I would be really happy for some feedback on the basic semantics (which 
annotations, where to put them, …) or even some testing.
   If the feedback on this is positive I would like issue a PR for this.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] JulianFeinauer commented on issue #26: connection manager for connection pool initial version

2018-10-22 Thread GitBox
JulianFeinauer commented on issue #26: connection manager for connection pool 
initial version
URL: https://github.com/apache/incubator-plc4x/pull/26#issuecomment-431838474
 
 
   This PR *should* not be merged but all necessary changes should be done in 
#30.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] JulianFeinauer opened a new pull request #30: connection manager for connection pool initial version

2018-10-22 Thread GitBox
JulianFeinauer opened a new pull request #30: connection manager for connection 
pool initial version
URL: https://github.com/apache/incubator-plc4x/pull/30
 
 
   This is a duplicate of #26  to allow @sruehl or @JulianFeinauer to do 
changes on the branch as Marcel is currenlty not available.
   Old PR is kept "live" to save the comments but should be declined as soon as 
all necessary fixes are done in *this* branch.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] skorikov opened a new pull request #32: Provide connection metadata

2018-10-26 Thread GitBox
skorikov opened a new pull request #32: Provide connection metadata
URL: https://github.com/apache/incubator-plc4x/pull/32
 
 
   As discussed in the mailing list, connection capabilities should be obtained 
via metadata and remove `Optional`s from the `PlcConnection`.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl closed pull request #30: connection manager for connection pool initial version

2018-10-26 Thread GitBox
sruehl closed pull request #30: connection manager for connection pool initial 
version
URL: https://github.com/apache/incubator-plc4x/pull/30
 
 
   


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] asfgit closed pull request #32: Provide connection metadata

2018-10-26 Thread GitBox
asfgit closed pull request #32: Provide connection metadata
URL: https://github.com/apache/incubator-plc4x/pull/32
 
 
   


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] chrisdutz commented on issue #36: Add simple mock driver

2018-11-01 Thread GitBox
chrisdutz commented on issue #36: Add simple mock driver
URL: https://github.com/apache/incubator-plc4x/pull/36#issuecomment-435013325
 
 
   I thought it would make more sense to start removing all of these mock 
drivers and instead extend the "Test-Driver" as this should provide everything 
that's needed.
   
   On the one side, we can use this internally for testing our integrations and 
examples.
   
   On the other side users can play around with PLC4X without having a real PLC.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] JulianFeinauer commented on issue #36: Add simple mock driver

2018-11-01 Thread GitBox
JulianFeinauer commented on issue #36: Add simple mock driver
URL: https://github.com/apache/incubator-plc4x/pull/36#issuecomment-435101505
 
 
   @chrisdutz I'll check if I can add this Mock functionality in there. As I 
recall the test driver is currently working against internal values or random 
values. But what I want is an object to put assertions on, so I'll check that 
and close this PR for the time beeing.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] JulianFeinauer closed pull request #36: Add simple mock driver

2018-11-01 Thread GitBox
JulianFeinauer closed pull request #36: Add simple mock driver
URL: https://github.com/apache/incubator-plc4x/pull/36
 
 
   


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] JulianFeinauer opened a new pull request #37: Extend test driver with mock

2018-11-01 Thread GitBox
JulianFeinauer opened a new pull request #37: Extend test driver with mock
URL: https://github.com/apache/incubator-plc4x/pull/37
 
 
   @chrisdutz here is my approach as extension to the Test Driver.
   @sruehl It is still not in the Test-utils package but I'm unsure if it 
should as I'm unsure about all the dependency mambo jambo.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on issue #30: connection manager for connection pool initial version

2018-10-26 Thread GitBox
sruehl commented on issue #30: connection manager for connection pool initial 
version
URL: https://github.com/apache/incubator-plc4x/pull/30#issuecomment-433380970
 
 
   I haven't closed this... What the...???


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #29: Opm plcentitymanager

2018-10-25 Thread GitBox
sruehl commented on a change in pull request #29: Opm plcentitymanager
URL: https://github.com/apache/incubator-plc4x/pull/29#discussion_r228232133
 
 

 ##
 File path: 
plc4j/utils/opm/src/main/java/org/apache/plc4x/java/opm/PlcEntityManager.java
 ##
 @@ -0,0 +1,380 @@
+/*
+ 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.plc4x.java.opm;
+
+import net.bytebuddy.ByteBuddy;
+import net.bytebuddy.implementation.MethodDelegation;
+import net.bytebuddy.implementation.bind.annotation.*;
+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.exceptions.PlcConnectionException;
+import org.apache.plc4x.java.api.exceptions.PlcInvalidFieldException;
+import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
+import org.apache.plc4x.java.api.messages.PlcReadRequest;
+import org.apache.plc4x.java.api.messages.PlcReadResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import static net.bytebuddy.matcher.ElementMatchers.any;
+
+/**
+ * Plc4x equivalent of Jpas EntityManager for implementing Object-Plc-Mapping.
+ * This means that calls to a plc can be done by using plain POJOs with 
Annotations.
+ * 
+ * First, the necessary annotations are {@link PlcEntity} and {@link PlcField}.
+ * For a class to be usable as PlcEntity it needs
+ * 
+ * be non-final (as proxiing has to be used in case of {@link 
#connect(Class)}
+ * a public no args constructor for instanciation
+ * Needs to be annotated with {@link PlcEntity} and has a valid value 
which is the connection string
+ * 
+ * 
+ * Basically, the {@link PlcEntityManager} has to operation "modes" 
represented by the methods {@link #read(Class)} and
+ * {@link #connect(Class)}.
+ * 
+ * For a field to get Values from the Plc Injected it needs to be annotated 
with the {@link PlcField} annotation.
+ * The value has to be the plc fields string (which is inserted in the {@link 
PlcReadRequest}).
+ * The connection string is taken from the value of the {@link PlcEntity} 
annotation on the class.
+ * 
+ * The {@link #read(Class)} method has no direkt equivalent in JPA (as far as 
I know) as it only returns a "detached"
+ * entity. This means it fetches all values from the plc that are annotated 
wiht the {@link PlcField} annotations.
+ * 
+ * The {@link #connect(Class)} method is more JPA-like as it returns a 
"connected" entity. This means, that each
+ * time one of the getters on the returned entity is called a call is made to 
the plc (and the field value is changed
+ * for this specific field).
+ * Furthermore, if a method which is no getter is called, then all {@link 
PlcField}s are refreshed before doing the call.
+ * Thus, all operations on fields that are annotated with {@link PlcField} are 
always done against the "live" values
+ * from the PLC.
+ * 
+ * // TODO Add detach method
+ */
+public class PlcEntityManager {
+
+private static final Logger LOGGER = 
LoggerFactory.getLogger(PlcEntityManager.class);
+
+private final PlcDriverManager driverManager;
+
+public PlcEntityManager() {
+this.driverManager = new PlcDriverManager();
+}
+
+public PlcEntityManager(PlcDriverManager driverManager) {
+this.driverManager = driverManager;
+}
+
+public  T read(Class clazz) throws OPMException {
+PlcEntity annotation = getPlcEntityAndCheckPreconditions(clazz);
+String source = annotation.value();
+
+try (PlcConnection connection = driverManager.getConnection(source)) {
+
+if (!connection.getReader().isPresent()) {
+throw new OPMException("Unable to get Reader for connection 
with url '" + source + "'");
+}
+
+PlcReader reader = connection.getReader().get();
+
+PlcReadRequest.Builder requestBuilder = 
reader.readRequestBuilder();
+
+  

[GitHub] sruehl commented on a change in pull request #29: Opm plcentitymanager

2018-10-25 Thread GitBox
sruehl commented on a change in pull request #29: Opm plcentitymanager
URL: https://github.com/apache/incubator-plc4x/pull/29#discussion_r228230429
 
 

 ##
 File path: 
plc4j/utils/opm/src/main/java/org/apache/plc4x/java/opm/PlcEntityManager.java
 ##
 @@ -0,0 +1,380 @@
+/*
+ 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.plc4x.java.opm;
+
+import net.bytebuddy.ByteBuddy;
+import net.bytebuddy.implementation.MethodDelegation;
+import net.bytebuddy.implementation.bind.annotation.*;
+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.exceptions.PlcConnectionException;
+import org.apache.plc4x.java.api.exceptions.PlcInvalidFieldException;
+import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
+import org.apache.plc4x.java.api.messages.PlcReadRequest;
+import org.apache.plc4x.java.api.messages.PlcReadResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import static net.bytebuddy.matcher.ElementMatchers.any;
+
+/**
+ * Plc4x equivalent of Jpas EntityManager for implementing Object-Plc-Mapping.
+ * This means that calls to a plc can be done by using plain POJOs with 
Annotations.
+ * 
+ * First, the necessary annotations are {@link PlcEntity} and {@link PlcField}.
+ * For a class to be usable as PlcEntity it needs
+ * 
+ * be non-final (as proxiing has to be used in case of {@link 
#connect(Class)}
+ * a public no args constructor for instanciation
+ * Needs to be annotated with {@link PlcEntity} and has a valid value 
which is the connection string
+ * 
+ * 
+ * Basically, the {@link PlcEntityManager} has to operation "modes" 
represented by the methods {@link #read(Class)} and
+ * {@link #connect(Class)}.
+ * 
+ * For a field to get Values from the Plc Injected it needs to be annotated 
with the {@link PlcField} annotation.
+ * The value has to be the plc fields string (which is inserted in the {@link 
PlcReadRequest}).
+ * The connection string is taken from the value of the {@link PlcEntity} 
annotation on the class.
+ * 
+ * The {@link #read(Class)} method has no direkt equivalent in JPA (as far as 
I know) as it only returns a "detached"
+ * entity. This means it fetches all values from the plc that are annotated 
wiht the {@link PlcField} annotations.
+ * 
+ * The {@link #connect(Class)} method is more JPA-like as it returns a 
"connected" entity. This means, that each
+ * time one of the getters on the returned entity is called a call is made to 
the plc (and the field value is changed
+ * for this specific field).
+ * Furthermore, if a method which is no getter is called, then all {@link 
PlcField}s are refreshed before doing the call.
+ * Thus, all operations on fields that are annotated with {@link PlcField} are 
always done against the "live" values
+ * from the PLC.
+ * 
+ * // TODO Add detach method
+ */
+public class PlcEntityManager {
+
+private static final Logger LOGGER = 
LoggerFactory.getLogger(PlcEntityManager.class);
+
+private final PlcDriverManager driverManager;
+
+public PlcEntityManager() {
+this.driverManager = new PlcDriverManager();
+}
+
+public PlcEntityManager(PlcDriverManager driverManager) {
+this.driverManager = driverManager;
+}
+
+public  T read(Class clazz) throws OPMException {
+PlcEntity annotation = getPlcEntityAndCheckPreconditions(clazz);
+String source = annotation.value();
+
+try (PlcConnection connection = driverManager.getConnection(source)) {
+
+if (!connection.getReader().isPresent()) {
 
 Review comment:
   could be replaced with orThrow()


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 

[GitHub] sruehl commented on a change in pull request #29: Opm plcentitymanager

2018-10-25 Thread GitBox
sruehl commented on a change in pull request #29: Opm plcentitymanager
URL: https://github.com/apache/incubator-plc4x/pull/29#discussion_r228231695
 
 

 ##
 File path: 
plc4j/utils/opm/src/main/java/org/apache/plc4x/java/opm/PlcEntityManager.java
 ##
 @@ -0,0 +1,380 @@
+/*
+ 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.plc4x.java.opm;
+
+import net.bytebuddy.ByteBuddy;
+import net.bytebuddy.implementation.MethodDelegation;
+import net.bytebuddy.implementation.bind.annotation.*;
+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.exceptions.PlcConnectionException;
+import org.apache.plc4x.java.api.exceptions.PlcInvalidFieldException;
+import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
+import org.apache.plc4x.java.api.messages.PlcReadRequest;
+import org.apache.plc4x.java.api.messages.PlcReadResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import static net.bytebuddy.matcher.ElementMatchers.any;
+
+/**
+ * Plc4x equivalent of Jpas EntityManager for implementing Object-Plc-Mapping.
+ * This means that calls to a plc can be done by using plain POJOs with 
Annotations.
+ * 
+ * First, the necessary annotations are {@link PlcEntity} and {@link PlcField}.
+ * For a class to be usable as PlcEntity it needs
+ * 
+ * be non-final (as proxiing has to be used in case of {@link 
#connect(Class)}
+ * a public no args constructor for instanciation
+ * Needs to be annotated with {@link PlcEntity} and has a valid value 
which is the connection string
+ * 
+ * 
+ * Basically, the {@link PlcEntityManager} has to operation "modes" 
represented by the methods {@link #read(Class)} and
+ * {@link #connect(Class)}.
+ * 
+ * For a field to get Values from the Plc Injected it needs to be annotated 
with the {@link PlcField} annotation.
+ * The value has to be the plc fields string (which is inserted in the {@link 
PlcReadRequest}).
+ * The connection string is taken from the value of the {@link PlcEntity} 
annotation on the class.
+ * 
+ * The {@link #read(Class)} method has no direkt equivalent in JPA (as far as 
I know) as it only returns a "detached"
+ * entity. This means it fetches all values from the plc that are annotated 
wiht the {@link PlcField} annotations.
+ * 
+ * The {@link #connect(Class)} method is more JPA-like as it returns a 
"connected" entity. This means, that each
+ * time one of the getters on the returned entity is called a call is made to 
the plc (and the field value is changed
+ * for this specific field).
+ * Furthermore, if a method which is no getter is called, then all {@link 
PlcField}s are refreshed before doing the call.
+ * Thus, all operations on fields that are annotated with {@link PlcField} are 
always done against the "live" values
+ * from the PLC.
+ * 
+ * // TODO Add detach method
+ */
+public class PlcEntityManager {
+
+private static final Logger LOGGER = 
LoggerFactory.getLogger(PlcEntityManager.class);
+
+private final PlcDriverManager driverManager;
+
+public PlcEntityManager() {
+this.driverManager = new PlcDriverManager();
+}
+
+public PlcEntityManager(PlcDriverManager driverManager) {
+this.driverManager = driverManager;
+}
+
+public  T read(Class clazz) throws OPMException {
+PlcEntity annotation = getPlcEntityAndCheckPreconditions(clazz);
+String source = annotation.value();
+
+try (PlcConnection connection = driverManager.getConnection(source)) {
+
+if (!connection.getReader().isPresent()) {
+throw new OPMException("Unable to get Reader for connection 
with url '" + source + "'");
+}
+
+PlcReader reader = connection.getReader().get();
+
+PlcReadRequest.Builder requestBuilder = 
reader.readRequestBuilder();
+
+  

[GitHub] sruehl commented on a change in pull request #29: Opm plcentitymanager

2018-10-25 Thread GitBox
sruehl commented on a change in pull request #29: Opm plcentitymanager
URL: https://github.com/apache/incubator-plc4x/pull/29#discussion_r228230640
 
 

 ##
 File path: 
plc4j/utils/opm/src/main/java/org/apache/plc4x/java/opm/PlcEntityManager.java
 ##
 @@ -0,0 +1,380 @@
+/*
+ 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.plc4x.java.opm;
+
+import net.bytebuddy.ByteBuddy;
+import net.bytebuddy.implementation.MethodDelegation;
+import net.bytebuddy.implementation.bind.annotation.*;
+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.exceptions.PlcConnectionException;
+import org.apache.plc4x.java.api.exceptions.PlcInvalidFieldException;
+import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
+import org.apache.plc4x.java.api.messages.PlcReadRequest;
+import org.apache.plc4x.java.api.messages.PlcReadResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import static net.bytebuddy.matcher.ElementMatchers.any;
+
+/**
+ * Plc4x equivalent of Jpas EntityManager for implementing Object-Plc-Mapping.
+ * This means that calls to a plc can be done by using plain POJOs with 
Annotations.
+ * 
+ * First, the necessary annotations are {@link PlcEntity} and {@link PlcField}.
+ * For a class to be usable as PlcEntity it needs
+ * 
+ * be non-final (as proxiing has to be used in case of {@link 
#connect(Class)}
+ * a public no args constructor for instanciation
+ * Needs to be annotated with {@link PlcEntity} and has a valid value 
which is the connection string
+ * 
+ * 
+ * Basically, the {@link PlcEntityManager} has to operation "modes" 
represented by the methods {@link #read(Class)} and
+ * {@link #connect(Class)}.
+ * 
+ * For a field to get Values from the Plc Injected it needs to be annotated 
with the {@link PlcField} annotation.
+ * The value has to be the plc fields string (which is inserted in the {@link 
PlcReadRequest}).
+ * The connection string is taken from the value of the {@link PlcEntity} 
annotation on the class.
+ * 
+ * The {@link #read(Class)} method has no direkt equivalent in JPA (as far as 
I know) as it only returns a "detached"
+ * entity. This means it fetches all values from the plc that are annotated 
wiht the {@link PlcField} annotations.
+ * 
+ * The {@link #connect(Class)} method is more JPA-like as it returns a 
"connected" entity. This means, that each
+ * time one of the getters on the returned entity is called a call is made to 
the plc (and the field value is changed
+ * for this specific field).
+ * Furthermore, if a method which is no getter is called, then all {@link 
PlcField}s are refreshed before doing the call.
+ * Thus, all operations on fields that are annotated with {@link PlcField} are 
always done against the "live" values
+ * from the PLC.
+ * 
+ * // TODO Add detach method
+ */
+public class PlcEntityManager {
+
+private static final Logger LOGGER = 
LoggerFactory.getLogger(PlcEntityManager.class);
+
+private final PlcDriverManager driverManager;
+
+public PlcEntityManager() {
+this.driverManager = new PlcDriverManager();
+}
+
+public PlcEntityManager(PlcDriverManager driverManager) {
+this.driverManager = driverManager;
+}
+
+public  T read(Class clazz) throws OPMException {
+PlcEntity annotation = getPlcEntityAndCheckPreconditions(clazz);
+String source = annotation.value();
+
+try (PlcConnection connection = driverManager.getConnection(source)) {
+
+if (!connection.getReader().isPresent()) {
+throw new OPMException("Unable to get Reader for connection 
with url '" + source + "'");
+}
+
+PlcReader reader = connection.getReader().get();
+
+PlcReadRequest.Builder requestBuilder = 
reader.readRequestBuilder();
+
+  

[GitHub] sruehl commented on issue #29: Opm plcentitymanager

2018-10-25 Thread GitBox
sruehl commented on issue #29: Opm plcentitymanager
URL: https://github.com/apache/incubator-plc4x/pull/29#issuecomment-433106003
 
 
   looks good to me :)


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #29: Opm plcentitymanager

2018-10-25 Thread GitBox
sruehl commented on a change in pull request #29: Opm plcentitymanager
URL: https://github.com/apache/incubator-plc4x/pull/29#discussion_r228231802
 
 

 ##
 File path: 
plc4j/utils/opm/src/main/java/org/apache/plc4x/java/opm/PlcEntityManager.java
 ##
 @@ -0,0 +1,380 @@
+/*
+ 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.plc4x.java.opm;
+
+import net.bytebuddy.ByteBuddy;
+import net.bytebuddy.implementation.MethodDelegation;
+import net.bytebuddy.implementation.bind.annotation.*;
+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.exceptions.PlcConnectionException;
+import org.apache.plc4x.java.api.exceptions.PlcInvalidFieldException;
+import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
+import org.apache.plc4x.java.api.messages.PlcReadRequest;
+import org.apache.plc4x.java.api.messages.PlcReadResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import static net.bytebuddy.matcher.ElementMatchers.any;
+
+/**
+ * Plc4x equivalent of Jpas EntityManager for implementing Object-Plc-Mapping.
+ * This means that calls to a plc can be done by using plain POJOs with 
Annotations.
+ * 
+ * First, the necessary annotations are {@link PlcEntity} and {@link PlcField}.
+ * For a class to be usable as PlcEntity it needs
+ * 
+ * be non-final (as proxiing has to be used in case of {@link 
#connect(Class)}
+ * a public no args constructor for instanciation
+ * Needs to be annotated with {@link PlcEntity} and has a valid value 
which is the connection string
+ * 
+ * 
+ * Basically, the {@link PlcEntityManager} has to operation "modes" 
represented by the methods {@link #read(Class)} and
+ * {@link #connect(Class)}.
+ * 
+ * For a field to get Values from the Plc Injected it needs to be annotated 
with the {@link PlcField} annotation.
+ * The value has to be the plc fields string (which is inserted in the {@link 
PlcReadRequest}).
+ * The connection string is taken from the value of the {@link PlcEntity} 
annotation on the class.
+ * 
+ * The {@link #read(Class)} method has no direkt equivalent in JPA (as far as 
I know) as it only returns a "detached"
+ * entity. This means it fetches all values from the plc that are annotated 
wiht the {@link PlcField} annotations.
+ * 
+ * The {@link #connect(Class)} method is more JPA-like as it returns a 
"connected" entity. This means, that each
+ * time one of the getters on the returned entity is called a call is made to 
the plc (and the field value is changed
+ * for this specific field).
+ * Furthermore, if a method which is no getter is called, then all {@link 
PlcField}s are refreshed before doing the call.
+ * Thus, all operations on fields that are annotated with {@link PlcField} are 
always done against the "live" values
+ * from the PLC.
+ * 
+ * // TODO Add detach method
+ */
+public class PlcEntityManager {
+
+private static final Logger LOGGER = 
LoggerFactory.getLogger(PlcEntityManager.class);
+
+private final PlcDriverManager driverManager;
+
+public PlcEntityManager() {
+this.driverManager = new PlcDriverManager();
+}
+
+public PlcEntityManager(PlcDriverManager driverManager) {
+this.driverManager = driverManager;
+}
+
+public  T read(Class clazz) throws OPMException {
+PlcEntity annotation = getPlcEntityAndCheckPreconditions(clazz);
+String source = annotation.value();
+
+try (PlcConnection connection = driverManager.getConnection(source)) {
+
+if (!connection.getReader().isPresent()) {
+throw new OPMException("Unable to get Reader for connection 
with url '" + source + "'");
+}
+
+PlcReader reader = connection.getReader().get();
+
+PlcReadRequest.Builder requestBuilder = 
reader.readRequestBuilder();
+
+  

[GitHub] sruehl commented on a change in pull request #29: Opm plcentitymanager

2018-10-25 Thread GitBox
sruehl commented on a change in pull request #29: Opm plcentitymanager
URL: https://github.com/apache/incubator-plc4x/pull/29#discussion_r228230727
 
 

 ##
 File path: 
plc4j/utils/opm/src/main/java/org/apache/plc4x/java/opm/PlcEntityManager.java
 ##
 @@ -0,0 +1,380 @@
+/*
+ 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.plc4x.java.opm;
+
+import net.bytebuddy.ByteBuddy;
+import net.bytebuddy.implementation.MethodDelegation;
+import net.bytebuddy.implementation.bind.annotation.*;
+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.exceptions.PlcConnectionException;
+import org.apache.plc4x.java.api.exceptions.PlcInvalidFieldException;
+import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
+import org.apache.plc4x.java.api.messages.PlcReadRequest;
+import org.apache.plc4x.java.api.messages.PlcReadResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import static net.bytebuddy.matcher.ElementMatchers.any;
+
+/**
+ * Plc4x equivalent of Jpas EntityManager for implementing Object-Plc-Mapping.
+ * This means that calls to a plc can be done by using plain POJOs with 
Annotations.
+ * 
+ * First, the necessary annotations are {@link PlcEntity} and {@link PlcField}.
+ * For a class to be usable as PlcEntity it needs
+ * 
+ * be non-final (as proxiing has to be used in case of {@link 
#connect(Class)}
+ * a public no args constructor for instanciation
+ * Needs to be annotated with {@link PlcEntity} and has a valid value 
which is the connection string
+ * 
+ * 
+ * Basically, the {@link PlcEntityManager} has to operation "modes" 
represented by the methods {@link #read(Class)} and
+ * {@link #connect(Class)}.
+ * 
+ * For a field to get Values from the Plc Injected it needs to be annotated 
with the {@link PlcField} annotation.
+ * The value has to be the plc fields string (which is inserted in the {@link 
PlcReadRequest}).
+ * The connection string is taken from the value of the {@link PlcEntity} 
annotation on the class.
+ * 
+ * The {@link #read(Class)} method has no direkt equivalent in JPA (as far as 
I know) as it only returns a "detached"
+ * entity. This means it fetches all values from the plc that are annotated 
wiht the {@link PlcField} annotations.
+ * 
+ * The {@link #connect(Class)} method is more JPA-like as it returns a 
"connected" entity. This means, that each
+ * time one of the getters on the returned entity is called a call is made to 
the plc (and the field value is changed
+ * for this specific field).
+ * Furthermore, if a method which is no getter is called, then all {@link 
PlcField}s are refreshed before doing the call.
+ * Thus, all operations on fields that are annotated with {@link PlcField} are 
always done against the "live" values
+ * from the PLC.
+ * 
+ * // TODO Add detach method
+ */
+public class PlcEntityManager {
+
+private static final Logger LOGGER = 
LoggerFactory.getLogger(PlcEntityManager.class);
+
+private final PlcDriverManager driverManager;
+
+public PlcEntityManager() {
+this.driverManager = new PlcDriverManager();
+}
+
+public PlcEntityManager(PlcDriverManager driverManager) {
+this.driverManager = driverManager;
+}
+
+public  T read(Class clazz) throws OPMException {
+PlcEntity annotation = getPlcEntityAndCheckPreconditions(clazz);
+String source = annotation.value();
+
+try (PlcConnection connection = driverManager.getConnection(source)) {
+
+if (!connection.getReader().isPresent()) {
+throw new OPMException("Unable to get Reader for connection 
with url '" + source + "'");
+}
+
+PlcReader reader = connection.getReader().get();
+
+PlcReadRequest.Builder requestBuilder = 
reader.readRequestBuilder();
+
+  

[GitHub] sruehl commented on a change in pull request #29: Opm plcentitymanager

2018-10-25 Thread GitBox
sruehl commented on a change in pull request #29: Opm plcentitymanager
URL: https://github.com/apache/incubator-plc4x/pull/29#discussion_r228230145
 
 

 ##
 File path: 
plc4j/utils/opm/src/main/java/org/apache/plc4x/java/opm/PlcEntity.java
 ##
 @@ -0,0 +1,34 @@
+/*
+ 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.plc4x.java.opm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Marks a class as plc entity.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface PlcEntity {
+String value();
 
 Review comment:
   maybe we can add a additional String connectionUrl() method that is 
semantical the same as value() but haven't found a elegant way to achieve this.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #29: Opm plcentitymanager

2018-10-25 Thread GitBox
sruehl commented on a change in pull request #29: Opm plcentitymanager
URL: https://github.com/apache/incubator-plc4x/pull/29#discussion_r228230930
 
 

 ##
 File path: 
plc4j/utils/opm/src/main/java/org/apache/plc4x/java/opm/PlcEntityManager.java
 ##
 @@ -0,0 +1,380 @@
+/*
+ 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.plc4x.java.opm;
+
+import net.bytebuddy.ByteBuddy;
+import net.bytebuddy.implementation.MethodDelegation;
+import net.bytebuddy.implementation.bind.annotation.*;
+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.exceptions.PlcConnectionException;
+import org.apache.plc4x.java.api.exceptions.PlcInvalidFieldException;
+import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
+import org.apache.plc4x.java.api.messages.PlcReadRequest;
+import org.apache.plc4x.java.api.messages.PlcReadResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import static net.bytebuddy.matcher.ElementMatchers.any;
+
+/**
+ * Plc4x equivalent of Jpas EntityManager for implementing Object-Plc-Mapping.
+ * This means that calls to a plc can be done by using plain POJOs with 
Annotations.
+ * 
+ * First, the necessary annotations are {@link PlcEntity} and {@link PlcField}.
+ * For a class to be usable as PlcEntity it needs
+ * 
+ * be non-final (as proxiing has to be used in case of {@link 
#connect(Class)}
+ * a public no args constructor for instanciation
+ * Needs to be annotated with {@link PlcEntity} and has a valid value 
which is the connection string
+ * 
+ * 
+ * Basically, the {@link PlcEntityManager} has to operation "modes" 
represented by the methods {@link #read(Class)} and
+ * {@link #connect(Class)}.
+ * 
+ * For a field to get Values from the Plc Injected it needs to be annotated 
with the {@link PlcField} annotation.
+ * The value has to be the plc fields string (which is inserted in the {@link 
PlcReadRequest}).
+ * The connection string is taken from the value of the {@link PlcEntity} 
annotation on the class.
+ * 
+ * The {@link #read(Class)} method has no direkt equivalent in JPA (as far as 
I know) as it only returns a "detached"
+ * entity. This means it fetches all values from the plc that are annotated 
wiht the {@link PlcField} annotations.
+ * 
+ * The {@link #connect(Class)} method is more JPA-like as it returns a 
"connected" entity. This means, that each
+ * time one of the getters on the returned entity is called a call is made to 
the plc (and the field value is changed
+ * for this specific field).
+ * Furthermore, if a method which is no getter is called, then all {@link 
PlcField}s are refreshed before doing the call.
+ * Thus, all operations on fields that are annotated with {@link PlcField} are 
always done against the "live" values
+ * from the PLC.
+ * 
+ * // TODO Add detach method
+ */
+public class PlcEntityManager {
+
+private static final Logger LOGGER = 
LoggerFactory.getLogger(PlcEntityManager.class);
+
+private final PlcDriverManager driverManager;
+
+public PlcEntityManager() {
+this.driverManager = new PlcDriverManager();
+}
+
+public PlcEntityManager(PlcDriverManager driverManager) {
+this.driverManager = driverManager;
+}
+
+public  T read(Class clazz) throws OPMException {
+PlcEntity annotation = getPlcEntityAndCheckPreconditions(clazz);
+String source = annotation.value();
+
+try (PlcConnection connection = driverManager.getConnection(source)) {
+
+if (!connection.getReader().isPresent()) {
+throw new OPMException("Unable to get Reader for connection 
with url '" + source + "'");
+}
+
+PlcReader reader = connection.getReader().get();
+
+PlcReadRequest.Builder requestBuilder = 
reader.readRequestBuilder();
+
+  

[GitHub] sruehl commented on a change in pull request #29: Opm plcentitymanager

2018-10-25 Thread GitBox
sruehl commented on a change in pull request #29: Opm plcentitymanager
URL: https://github.com/apache/incubator-plc4x/pull/29#discussion_r228231315
 
 

 ##
 File path: 
plc4j/utils/opm/src/main/java/org/apache/plc4x/java/opm/PlcEntityManager.java
 ##
 @@ -0,0 +1,380 @@
+/*
+ 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.plc4x.java.opm;
+
+import net.bytebuddy.ByteBuddy;
+import net.bytebuddy.implementation.MethodDelegation;
+import net.bytebuddy.implementation.bind.annotation.*;
+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.exceptions.PlcConnectionException;
+import org.apache.plc4x.java.api.exceptions.PlcInvalidFieldException;
+import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
+import org.apache.plc4x.java.api.messages.PlcReadRequest;
+import org.apache.plc4x.java.api.messages.PlcReadResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import static net.bytebuddy.matcher.ElementMatchers.any;
+
+/**
+ * Plc4x equivalent of Jpas EntityManager for implementing Object-Plc-Mapping.
+ * This means that calls to a plc can be done by using plain POJOs with 
Annotations.
+ * 
+ * First, the necessary annotations are {@link PlcEntity} and {@link PlcField}.
+ * For a class to be usable as PlcEntity it needs
+ * 
+ * be non-final (as proxiing has to be used in case of {@link 
#connect(Class)}
+ * a public no args constructor for instanciation
+ * Needs to be annotated with {@link PlcEntity} and has a valid value 
which is the connection string
+ * 
+ * 
+ * Basically, the {@link PlcEntityManager} has to operation "modes" 
represented by the methods {@link #read(Class)} and
+ * {@link #connect(Class)}.
+ * 
+ * For a field to get Values from the Plc Injected it needs to be annotated 
with the {@link PlcField} annotation.
+ * The value has to be the plc fields string (which is inserted in the {@link 
PlcReadRequest}).
+ * The connection string is taken from the value of the {@link PlcEntity} 
annotation on the class.
+ * 
+ * The {@link #read(Class)} method has no direkt equivalent in JPA (as far as 
I know) as it only returns a "detached"
+ * entity. This means it fetches all values from the plc that are annotated 
wiht the {@link PlcField} annotations.
+ * 
+ * The {@link #connect(Class)} method is more JPA-like as it returns a 
"connected" entity. This means, that each
+ * time one of the getters on the returned entity is called a call is made to 
the plc (and the field value is changed
+ * for this specific field).
+ * Furthermore, if a method which is no getter is called, then all {@link 
PlcField}s are refreshed before doing the call.
+ * Thus, all operations on fields that are annotated with {@link PlcField} are 
always done against the "live" values
+ * from the PLC.
+ * 
+ * // TODO Add detach method
+ */
+public class PlcEntityManager {
+
+private static final Logger LOGGER = 
LoggerFactory.getLogger(PlcEntityManager.class);
+
+private final PlcDriverManager driverManager;
+
+public PlcEntityManager() {
+this.driverManager = new PlcDriverManager();
+}
+
+public PlcEntityManager(PlcDriverManager driverManager) {
+this.driverManager = driverManager;
+}
+
+public  T read(Class clazz) throws OPMException {
+PlcEntity annotation = getPlcEntityAndCheckPreconditions(clazz);
+String source = annotation.value();
+
+try (PlcConnection connection = driverManager.getConnection(source)) {
+
+if (!connection.getReader().isPresent()) {
+throw new OPMException("Unable to get Reader for connection 
with url '" + source + "'");
+}
+
+PlcReader reader = connection.getReader().get();
+
+PlcReadRequest.Builder requestBuilder = 
reader.readRequestBuilder();
+
+  

[GitHub] asfgit closed pull request #29: Opm plcentitymanager

2018-10-25 Thread GitBox
asfgit closed pull request #29: Opm plcentitymanager
URL: https://github.com/apache/incubator-plc4x/pull/29
 
 
   


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl closed pull request #26: connection manager for connection pool initial version

2018-10-25 Thread GitBox
sruehl closed pull request #26: connection manager for connection pool initial 
version
URL: https://github.com/apache/incubator-plc4x/pull/26
 
 
   

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/plc4j/core/src/main/java/org/apache/plc4x/java/PlcDriverManager.java 
b/plc4j/core/src/main/java/org/apache/plc4x/java/PlcDriverManager.java
index 8539a61e8..5eb10d024 100644
--- a/plc4j/core/src/main/java/org/apache/plc4x/java/PlcDriverManager.java
+++ b/plc4j/core/src/main/java/org/apache/plc4x/java/PlcDriverManager.java
@@ -29,7 +29,7 @@ Licensed to the Apache Software Foundation (ASF) under one
 import java.util.Map;
 import java.util.ServiceLoader;
 
-public class PlcDriverManager {
+public class PlcDriverManager implements PlcDriverManagerInterface {
 
 private Map driverMap = null;
 
@@ -57,6 +57,7 @@ public PlcDriverManager(ClassLoader classLoader) {
  * @return PlcConnection object.
  * @throws PlcConnectionException an exception if the connection attempt 
failed.
  */
+@Override
 public PlcConnection getConnection(String url) throws 
PlcConnectionException {
 PlcDriver driver = getDriver(url);
 PlcConnection connection = driver.connect(url);
@@ -72,6 +73,7 @@ public PlcConnection getConnection(String url) throws 
PlcConnectionException {
  * @return PlcConnection object.
  * @throws PlcConnectionException an exception if the connection attempt 
failed.
  */
+@Override
 public PlcConnection getConnection(String url, PlcAuthentication 
authentication) throws PlcConnectionException {
 PlcDriver driver = getDriver(url);
 PlcConnection connection = driver.connect(url, authentication);
diff --git 
a/plc4j/core/src/main/java/org/apache/plc4x/java/PlcDriverManagerInterface.java 
b/plc4j/core/src/main/java/org/apache/plc4x/java/PlcDriverManagerInterface.java
new file mode 100644
index 0..c9b8ef261
--- /dev/null
+++ 
b/plc4j/core/src/main/java/org/apache/plc4x/java/PlcDriverManagerInterface.java
@@ -0,0 +1,29 @@
+/*
+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.plc4x.java;
+
+import org.apache.plc4x.java.api.authentication.PlcAuthentication;
+import org.apache.plc4x.java.api.connection.PlcConnection;
+import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
+
+public interface PlcDriverManagerInterface {
+PlcConnection getConnection(String url) throws PlcConnectionException;
+
+PlcConnection getConnection(String url, PlcAuthentication authentication) 
throws PlcConnectionException;
+}
diff --git 
a/plc4j/core/src/main/java/org/apache/plc4x/java/connectionpool/ConnectionProxy.java
 
b/plc4j/core/src/main/java/org/apache/plc4x/java/connectionpool/ConnectionProxy.java
new file mode 100644
index 0..b1188d5c9
--- /dev/null
+++ 
b/plc4j/core/src/main/java/org/apache/plc4x/java/connectionpool/ConnectionProxy.java
@@ -0,0 +1,24 @@
+/*
+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.plc4x.java.connectionpool;
+
+import org.apache.plc4x.java.api.connection.PlcConnection;
+
+public interface ConnectionProxy extends PlcConnection {
+}
\ No newline at end of file
diff --git 
a/plc4j/core/src/main/java/org/apache/plc4x/java/connectionpool/PlcConnectionManager.java
 

  1   2   3   4   5   6   7   8   9   10   >