You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ol...@apache.org on 2018/09/22 19:12:52 UTC

[sling-org-apache-sling-commons-clam] branch master updated (aa22774 -> 33fdfb7)

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

olli pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-clam.git.


    from aa22774  trivial: added license header to *.md files
     new d231c45  SLING-7947 Play ping-pong with clam daemon after configuration of ClamdService
     new 33fdfb7  set version of package org.apache.sling.commons.clam to 1.0.0

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:
 .../sling/commons/clam/internal/ClamdService.java  | 37 +++++++++++++++++++++-
 .../apache/sling/commons/clam/package-info.java    |  2 +-
 2 files changed, 37 insertions(+), 2 deletions(-)


[sling-org-apache-sling-commons-clam] 02/02: set version of package org.apache.sling.commons.clam to 1.0.0

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

olli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-clam.git

commit 33fdfb7ebc91a035de3fa8f384bc32a8acefe938
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Sat Sep 22 21:12:13 2018 +0200

    set version of package org.apache.sling.commons.clam to 1.0.0
---
 src/main/java/org/apache/sling/commons/clam/package-info.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/commons/clam/package-info.java b/src/main/java/org/apache/sling/commons/clam/package-info.java
index 18154be..4417140 100644
--- a/src/main/java/org/apache/sling/commons/clam/package-info.java
+++ b/src/main/java/org/apache/sling/commons/clam/package-info.java
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-@Version("0.0.1")
+@Version("1.0.0")
 package org.apache.sling.commons.clam;
 
 import org.osgi.annotation.versioning.Version;


[sling-org-apache-sling-commons-clam] 01/02: SLING-7947 Play ping-pong with clam daemon after configuration of ClamdService

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

olli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-clam.git

commit d231c45df7aa215f9564cc343a8ec5d4cb793eba
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Sat Sep 22 21:10:43 2018 +0200

    SLING-7947 Play ping-pong with clam daemon after configuration of ClamdService
---
 .../sling/commons/clam/internal/ClamdService.java  | 37 +++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/commons/clam/internal/ClamdService.java b/src/main/java/org/apache/sling/commons/clam/internal/ClamdService.java
index ef23eb8..581dc0d 100644
--- a/src/main/java/org/apache/sling/commons/clam/internal/ClamdService.java
+++ b/src/main/java/org/apache/sling/commons/clam/internal/ClamdService.java
@@ -25,6 +25,7 @@ import java.io.OutputStream;
 import java.net.Socket;
 import java.nio.ByteBuffer;
 import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.sling.commons.clam.ClamService;
@@ -53,6 +54,10 @@ public class ClamdService implements ClamService {
 
     private ClamdServiceConfiguration configuration;
 
+    private static final byte[] PING_COMMAND = "nPING\n".getBytes(StandardCharsets.US_ASCII);
+
+    private static final byte[] PONG_REPLY = "PONG\n".getBytes(StandardCharsets.US_ASCII);
+
     private static final byte[] INSTREAM_COMMAND = "nINSTREAM\n".getBytes(StandardCharsets.US_ASCII);
 
     private static final String OK_REPLY_PATTERN = "stream: OK";
@@ -85,7 +90,7 @@ public class ClamdService implements ClamService {
 
     private void configure(final ClamdServiceConfiguration configuration) {
         this.configuration = configuration;
-        // TODO play ping pong on configuration change
+        playPingPong();
     }
 
     @Override
@@ -100,6 +105,36 @@ public class ClamdService implements ClamService {
         }
     }
 
+    private byte[] doPing() throws IOException {
+        logger.info("pinging clam daemon at {}:{}", configuration.clamd_host(), configuration.clamd_port());
+        try (final Socket socket = new Socket(configuration.clamd_host(), configuration.clamd_port());
+             final OutputStream out = new BufferedOutputStream(socket.getOutputStream());
+             final InputStream in = socket.getInputStream()) {
+
+            socket.setSoTimeout(configuration.connection_timeout());
+
+            // send command
+            out.write(PING_COMMAND);
+            out.flush();
+
+            return IOUtils.toByteArray(in);
+        }
+    }
+
+    private void playPingPong() {
+        try {
+            final byte[] reply = doPing();
+            if (Arrays.equals(reply, PONG_REPLY)) {
+                logger.info("clam daemon replied with PONG");
+            } else {
+                final String message = new String(reply, StandardCharsets.US_ASCII);
+                logger.error("clam daemon replied with unknown message: {}", message);
+            }
+        } catch (IOException e) {
+            logger.error("pinging clam daemon failed: {}", e.getMessage());
+        }
+    }
+
     /**
      * man (8) clamd
      * INSTREAM