Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 3CF3C200D3E for ; Thu, 16 Nov 2017 15:49:08 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 3BBE1160BF4; Thu, 16 Nov 2017 14:49:08 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 59985160BE5 for ; Thu, 16 Nov 2017 15:49:07 +0100 (CET) Received: (qmail 4530 invoked by uid 500); 16 Nov 2017 14:49:06 -0000 Mailing-List: contact issues-help@karaf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@karaf.apache.org Delivered-To: mailing list issues@karaf.apache.org Received: (qmail 4519 invoked by uid 99); 16 Nov 2017 14:49:06 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Nov 2017 14:49:06 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id B25261A1151 for ; Thu, 16 Nov 2017 14:49:05 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.202 X-Spam-Level: X-Spam-Status: No, score=-99.202 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id H4SUsSKZp7hg for ; Thu, 16 Nov 2017 14:49:03 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id B032D60E5E for ; Thu, 16 Nov 2017 14:49:02 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 7C157E259D for ; Thu, 16 Nov 2017 14:49:01 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id E4A4B2410A for ; Thu, 16 Nov 2017 14:49:00 +0000 (UTC) Date: Thu, 16 Nov 2017 14:49:00 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: issues@karaf.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (KARAF-5454) Collector socket - Add UDP protocol support MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Thu, 16 Nov 2017 14:49:08 -0000 [ https://issues.apache.org/jira/browse/KARAF-5454?page=3Dcom.atlassian= .jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D1625= 5439#comment-16255439 ]=20 ASF GitHub Bot commented on KARAF-5454: --------------------------------------- jbonofre closed pull request #18: [KARAF-5454] - Collector socket - Add UDP= protocol support URL: https://github.com/apache/karaf-decanter/pull/18 =20 =20 =20 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/collector/socket/src/main/cfg/org.apache.karaf.decanter.collec= tor.socket.cfg b/collector/socket/src/main/cfg/org.apache.karaf.decanter.co= llector.socket.cfg index b9a04b2..ed67ea7 100644 --- a/collector/socket/src/main/cfg/org.apache.karaf.decanter.collector.soc= ket.cfg +++ b/collector/socket/src/main/cfg/org.apache.karaf.decanter.collector.soc= ket.cfg @@ -4,4 +4,7 @@ #port=3D34343 =20 # Number of worker threads to deal with -#workers=3D10 \ No newline at end of file +#workers=3D10 + +# Protocol tcp(default) or udp +#protocol=3Dtcp diff --git a/collector/socket/src/main/java/org/apache/karaf/decanter/colle= ctor/socket/SocketCollector.java b/collector/socket/src/main/java/org/apach= e/karaf/decanter/collector/socket/SocketCollector.java index 49ddb63..3c1e48e 100644 --- a/collector/socket/src/main/java/org/apache/karaf/decanter/collector/so= cket/SocketCollector.java +++ b/collector/socket/src/main/java/org/apache/karaf/decanter/collector/so= cket/SocketCollector.java @@ -17,6 +17,8 @@ package org.apache.karaf.decanter.collector.socket; =20 import java.io.*; +import java.net.DatagramPacket; +import java.net.DatagramSocket; import java.net.InetAddress; import java.net.ServerSocket; import java.net.Socket; @@ -49,6 +51,8 @@ private static final Logger LOGGER =3D LoggerFactory.getLogger(SocketC= ollector.class); =20 private ServerSocket serverSocket; + private DatagramSocket datagramSocket; + private Protocol protocol; private EventAdmin eventAdmin; private boolean open; private ExecutorService executor; @@ -56,6 +60,11 @@ private String eventAdminTopic; private EventAdmin dispatcher; private Unmarshaller unmarshaller; + =20 + private enum Protocol { + TCP, + UDP; + } =20 @SuppressWarnings("unchecked") @Activate @@ -63,8 +72,24 @@ public void activate(ComponentContext context) throws IO= Exception { this.properties =3D context.getProperties(); int port =3D Integer.parseInt(getProperty(this.properties, "port",= "34343")); int workers =3D Integer.parseInt(getProperty(this.properties, "wor= kers", "10")); + =20 + this.protocol =3D Protocol.valueOf(getProperty(this.properties, "p= rotocol", "tcp").toUpperCase()); + // force TCP protocol if value not in Enum + if (this.protocol =3D=3D null) { + this.protocol =3D Protocol.TCP; + } + =20 eventAdminTopic =3D getProperty(this.properties, EventConstants.EV= ENT_TOPIC, "decanter/collect/socket"); - this.serverSocket =3D new ServerSocket(port); + =20 + switch (protocol) { + case TCP: + this.serverSocket =3D new ServerSocket(port); + break; + case UDP: + this.datagramSocket =3D new DatagramSocket(port); + break; + } + =20 // adding 1 for serverSocket handling this.executor =3D Executors.newFixedThreadPool(workers + 1); this.executor.execute(this); @@ -79,9 +104,21 @@ private String getProperty(Dictionary p= roperties, String key, St public void run() { while (open) { try { - Socket socket =3D serverSocket.accept(); - LOGGER.debug("Connected to client at {}", socket.getInetAd= dress()); - this.executor.execute(new SocketRunnable(socket)); + switch (protocol) { + case TCP: + Socket socket =3D serverSocket.accept(); + LOGGER.debug("Connected to TCP client at {}", sock= et.getInetAddress()); + this.executor.execute(new SocketRunnable(socket)); + break; + =20 + case UDP: + byte[] buffer =3D new byte[1024]; + DatagramPacket packet =3D new DatagramPacket(buffe= r, buffer.length); + LOGGER.debug("Connected to UDP client at {}", data= gramSocket.getLocalSocketAddress()); + datagramSocket.receive(packet); + this.executor.execute(new DatagramRunnable(packet)= ); + break; + } } catch (IOException e) { LOGGER.warn("Exception receiving log.", e); } @@ -103,7 +140,15 @@ public void close() throws IOException { } catch (Exception e) { // nothing to do } - serverSocket.close(); + switch (protocol) { + case TCP: + serverSocket.close(); + break; + =20 + case UDP: + datagramSocket.close(); + break; + } } =20 @Reference @@ -148,6 +193,41 @@ public void run() { } } } + =20 + private class DatagramRunnable implements Runnable { + + private DatagramPacket packet; + + public DatagramRunnable(DatagramPacket packet) { + this.packet =3D packet; + } + + public void run() { + =20 + try (ByteArrayInputStream bais =3D new ByteArrayInputStream(pa= cket.getData())) { + Map data =3D new HashMap<>(); + data.put("hostAddress", InetAddress.getLocalHost().getHost= Address()); + data.put("hostName", InetAddress.getLocalHost().getHostNam= e()); + data.put("type", "socket"); + String karafName =3D System.getProperty("karaf.name"); + if (karafName !=3D null) { + data.put("karafName", karafName); + } + try { + data.putAll(unmarshaller.unmarshal(bais)); + } catch (Exception e) { + // nothing to do + } + Event event =3D new Event(eventAdminTopic, data); + dispatcher.postEvent(event); + datagramSocket.send(packet); + } catch (EOFException e) { + LOGGER.warn("Client closed the connection", e); + } catch (IOException e) { + LOGGER.warn("Exception receiving data", e); + } + } + } =20 @Reference public void setDispatcher(EventAdmin dispatcher) { diff --git a/manual/src/main/asciidoc/user-guide/collectors.adoc b/manual/s= rc/main/asciidoc/user-guide/collectors.adoc index c236409..8a8980d 100644 --- a/manual/src/main/asciidoc/user-guide/collectors.adoc +++ b/manual/src/main/asciidoc/user-guide/collectors.adoc @@ -469,10 +469,14 @@ This feature installs a default `etc/org.apache.karaf= .decanter.collector.socket. =20 # Number of worker threads to deal with #workers=3D10 + +# Protocol tcp(default) or udp +#protocol=3Dtcp ---- =20 * the `port` property contains the port number where the network socket co= llector is listening * the `workers` property contains the number of worker thread the socket c= ollector is using for connection +* the `protocol` property contains the protocol used by the collector for = transferring data with the client =20 =3D=3D=3D=3D JMS =20 =20 ---------------------------------------------------------------- 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. =20 For queries about this service, please contact Infrastructure at: users@infra.apache.org > Collector socket - Add UDP protocol support > ------------------------------------------- > > Key: KARAF-5454 > URL: https://issues.apache.org/jira/browse/KARAF-5454 > Project: Karaf > Issue Type: Improvement > Components: decanter > Reporter: Francois Papon > Assignee: Jean-Baptiste Onofr=C3=A9 > Priority: Minor > Fix For: decanter-1.5.0 > > > Syslog send data with the UDP protocol and actually, it doesn't work > with the collector-socket version. > We could use a DatagramServer instead of a ServerSocket for UDP. > Modifications : > - Add a new properties in the collector cfg file to define the protocol : > # Protocol tcp(default) or udp > #protocol=3Dtcp > - Instanciate a DatagramServer in the case of udp protocol is define in > the cfg (org.apache.karaf.decanter.collector.socket.SocketCollector) -- This message was sent by Atlassian JIRA (v6.4.14#64029)