You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2018/06/13 12:39:18 UTC

[incubator-plc4x] branch master updated (ef96140 -> 067cf7a)

This is an automated email from the ASF dual-hosted git repository.

sruehl pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git.


    from ef96140  switch from link to code as the handlers are not a current dependency
     new dff0d41  set interrupt flag where necessary.
     new 067cf7a  try to fix wobbily test by avoid using the thread if no message is on the way

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../protocol/util/SingleMessageRateLimiter.java    | 10 +++++---
 .../ads/adslib/ADSClientNotificationExample.java   |  1 +
 .../org/apache/plc4x/java/ads/adslib/AdsLib.java   | 30 ++++++++++++++++++----
 .../apache/plc4x/java/ads/adslib/AmsRouter.java    | 18 ++++++++++---
 4 files changed, 48 insertions(+), 11 deletions(-)

-- 
To stop receiving notification emails like this one, please contact
sruehl@apache.org.

[incubator-plc4x] 02/02: try to fix wobbily test by avoid using the thread if no message is on the way

Posted by sr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sruehl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git

commit 067cf7a775c72449637dc99ba9567b3869a18c11
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed Jun 13 14:39:12 2018 +0200

    try to fix wobbily test by avoid using the thread if no message is on
    the way
---
 .../plc4x/java/ads/protocol/util/SingleMessageRateLimiter.java | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/util/SingleMessageRateLimiter.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/util/SingleMessageRateLimiter.java
index ad4a6ce..7b159a5 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/util/SingleMessageRateLimiter.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/util/SingleMessageRateLimiter.java
@@ -66,21 +66,25 @@ public class SingleMessageRateLimiter extends ChannelDuplexHandler {
                 pop.channelHandlerContext.writeAndFlush(pop.toSend, pop.promise);
                 LOGGER.debug("Send {}", pop);
             }
-        }, 0, 10, TimeUnit.MILLISECONDS);
+        }, 100, 10, TimeUnit.MILLISECONDS);
         super.connect(ctx, remoteAddress, localAddress, promise);
     }
 
     @Override
     public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
         LOGGER.debug("disconnect({}, {}, {}, {})", ctx, promise);
-        sender.cancel(true);
+        sender.cancel(false);
         super.disconnect(ctx, promise);
     }
 
     @Override
     public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
         LOGGER.trace("(<--OUT): {}, {}, {}", ctx, msg, promise);
-        messagesQueue.add(new ToSend(ctx, msg, promise));
+        if (messageOnTheWay.compareAndSet(false, true)) {
+            ctx.write(msg, promise);
+        } else {
+            messagesQueue.add(new ToSend(ctx, msg, promise));
+        }
     }
 
     @Override

-- 
To stop receiving notification emails like this one, please contact
sruehl@apache.org.

[incubator-plc4x] 01/02: set interrupt flag where necessary.

Posted by sr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sruehl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git

commit dff0d4180a590a84898a7337d04322a649b5e19f
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed Jun 13 14:17:23 2018 +0200

    set interrupt flag where necessary.
---
 .../ads/adslib/ADSClientNotificationExample.java   |  1 +
 .../org/apache/plc4x/java/ads/adslib/AdsLib.java   | 30 ++++++++++++++++++----
 .../apache/plc4x/java/ads/adslib/AmsRouter.java    | 18 ++++++++++---
 3 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/adslib/ADSClientNotificationExample.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/adslib/ADSClientNotificationExample.java
index 126d011..67bf68c 100644
--- a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/adslib/ADSClientNotificationExample.java
+++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/adslib/ADSClientNotificationExample.java
@@ -264,6 +264,7 @@ public class ADSClientNotificationExample {
                 TimeUnit.SECONDS.sleep(timeout);
                 System.out.println("Timeout reached enter pressed");
             } catch (InterruptedException e) {
+                Thread.currentThread().interrupt();
                 throw new RuntimeException(e);
             }
         }
diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/adslib/AdsLib.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/adslib/AdsLib.java
index 0aff88e..08a31da 100644
--- a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/adslib/AdsLib.java
+++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/adslib/AdsLib.java
@@ -163,8 +163,12 @@ public class AdsLib {
             buffer.value = bytes;
             bytesRead.value = bytes.length;
             return response.getResult();
-        } catch (InterruptedException | ExecutionException | TimeoutException e) {
+        } catch (ExecutionException | TimeoutException e) {
+            e.printStackTrace();
+            return Result.of(AdsReturnCode.ADS_CODE_1);
+        } catch (InterruptedException e) {
             e.printStackTrace();
+            Thread.currentThread().interrupt();
             return Result.of(AdsReturnCode.ADS_CODE_1);
         }
     }
@@ -239,9 +243,13 @@ public class AdsLib {
             adsState.value = response.getAdsState().getAsInt();
             devState.value = response.getDeviceState().getAsInt();
             return response.getResult();
-        } catch (InterruptedException | ExecutionException | TimeoutException e) {
+        } catch (ExecutionException | TimeoutException e) {
             e.printStackTrace();
             return Result.of(AdsReturnCode.ADS_CODE_1);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+            Thread.currentThread().interrupt();
+            return Result.of(AdsReturnCode.ADS_CODE_1);
         }
     }
 
@@ -341,9 +349,13 @@ public class AdsLib {
         try {
             AdsWriteResponse response = request.getResponseFuture().get(3, TimeUnit.SECONDS);
             return response.getResult();
-        } catch (InterruptedException | ExecutionException | TimeoutException e) {
+        } catch (ExecutionException | TimeoutException e) {
             e.printStackTrace();
             return Result.of(AdsReturnCode.ADS_CODE_1);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+            Thread.currentThread().interrupt();
+            return Result.of(AdsReturnCode.ADS_CODE_1);
         }
     }
 
@@ -443,8 +455,12 @@ public class AdsLib {
         try {
             AdsAddDeviceNotificationResponse response = request.getResponseFuture().get(3, TimeUnit.SECONDS);
             return response.getResult();
-        } catch (InterruptedException | ExecutionException | TimeoutException e) {
+        } catch (ExecutionException | TimeoutException e) {
+            e.printStackTrace();
+            return Result.of(AdsReturnCode.ADS_CODE_1);
+        } catch (InterruptedException e) {
             e.printStackTrace();
+            Thread.currentThread().interrupt();
             return Result.of(AdsReturnCode.ADS_CODE_1);
         }
     }
@@ -479,8 +495,12 @@ public class AdsLib {
         try {
             AdsDeleteDeviceNotificationResponse response = request.getResponseFuture().get(3, TimeUnit.SECONDS);
             return response.getResult();
-        } catch (InterruptedException | ExecutionException | TimeoutException e) {
+        } catch (ExecutionException | TimeoutException e) {
+            e.printStackTrace();
+            return Result.of(AdsReturnCode.ADS_CODE_1);
+        } catch (InterruptedException e) {
             e.printStackTrace();
+            Thread.currentThread().interrupt();
             return Result.of(AdsReturnCode.ADS_CODE_1);
         }
     }
diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/adslib/AmsRouter.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/adslib/AmsRouter.java
index 5e1d768..ba0bf79 100644
--- a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/adslib/AmsRouter.java
+++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/adslib/AmsRouter.java
@@ -203,9 +203,13 @@ public class AmsRouter {
             PlcProprietaryResponse<R> response = completableFuture.get(3, TimeUnit.SECONDS);
             request.getResponseFuture().complete(response.getResponse());
             return response.getResponse().getAmsHeader().getCode();
-        } catch (InterruptedException | ExecutionException | TimeoutException e) {
+        } catch (ExecutionException | TimeoutException e) {
             e.printStackTrace();
             return AmsError.of(AdsReturnCode.ADS_CODE_1864);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+            Thread.currentThread().interrupt();
+            return AmsError.of(AdsReturnCode.ADS_CODE_1864);
         }
     }
 
@@ -231,8 +235,12 @@ public class AmsRouter {
             port.AddNotification(pNotification.value, notify);
             request.getResponseFuture().complete(response.getResponse());
             return response.getResponse().getAmsHeader().getCode();
-        } catch (InterruptedException | ExecutionException | TimeoutException e) {
+        } catch (ExecutionException | TimeoutException e) {
+            e.printStackTrace();
+            return AmsError.of(AdsReturnCode.ADS_CODE_1);
+        } catch (InterruptedException e) {
             e.printStackTrace();
+            Thread.currentThread().interrupt();
             return AmsError.of(AdsReturnCode.ADS_CODE_1);
         }
     }
@@ -253,8 +261,12 @@ public class AmsRouter {
             adsLibPort.DelNotification(pAddr, plcProprietaryRequest.getRequest().getNotificationHandle());
             request.getResponseFuture().complete(response.getResponse());
             return response.getResponse().getAmsHeader().getCode();
-        } catch (InterruptedException | ExecutionException | TimeoutException e) {
+        } catch (ExecutionException | TimeoutException e) {
+            e.printStackTrace();
+            return AmsError.of(AdsReturnCode.ADS_CODE_1);
+        }catch (InterruptedException e) {
             e.printStackTrace();
+            Thread.currentThread().interrupt();
             return AmsError.of(AdsReturnCode.ADS_CODE_1);
         }
     }

-- 
To stop receiving notification emails like this one, please contact
sruehl@apache.org.