tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r1023153 - in /openejb/trunk/openejb3: ./ container/openejb-core/src/test/java/org/apache/openejb/config/ examples/alternate-descriptors/src/main/resources/META-INF/ server/openejb-client/src/main/java/org/apache/openejb/client/
Date Sat, 16 Oct 2010 00:21:14 GMT
Author: dblevins
Date: Sat Oct 16 00:21:13 2010
New Revision: 1023153

URL: http://svn.apache.org/viewvc?rev=1023153&view=rev
Log:
svn merge -r 1021954:1021955 https://svn.apache.org/repos/asf/openejb/branches/openejb-3.1.x

http://svn.apache.org/viewvc?view=revision&revision=1021955
------------------------------------------------------------------------
r1021955 | dblevins | 2010-10-12 16:57:57 -0700 (Tue, 12 Oct 2010) | 2 lines

OPENEJB-1369: Help, expanded options and cleaner output for MulticastTool

------------------------------------------------------------------------

Added:
    openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/CommandParser.java
      - copied unchanged from r1021955, openejb/branches/openejb-3.1.x/server/openejb-client/src/main/java/org/apache/openejb/client/CommandParser.java
    openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/Options.java
      - copied unchanged from r1021955, openejb/branches/openejb-3.1.x/server/openejb-client/src/main/java/org/apache/openejb/client/Options.java
Modified:
    openejb/trunk/openejb3/   (props changed)
    openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/BusinessInterfacesTest.java
  (props changed)
    openejb/trunk/openejb3/examples/alternate-descriptors/src/main/resources/META-INF/test.ejb-jar.xml
  (props changed)
    openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/MulticastTool.java

Propchange: openejb/trunk/openejb3/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Oct 16 00:21:13 2010
@@ -1,3 +1,3 @@
 /openejb/branches/openejb-3.1.1:779593
-/openejb/branches/openejb-3.1.x:945409,945448,1004381,1005322,1021880,1021903
+/openejb/branches/openejb-3.1.x:945409,945448,1004381,1005322,1021880,1021903,1021955
 /openejb/branches/openejb-jcdi:984659-985270

Propchange: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/BusinessInterfacesTest.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Oct 16 00:21:13 2010
@@ -1,3 +1,3 @@
 /openejb/branches/openejb-3.1.1/container/openejb-core/src/test/java/org/apache/openejb/config/UberInterfaceTest.java:779593
-/openejb/branches/openejb-3.1.x/container/openejb-core/src/test/java/org/apache/openejb/config/BusinessInterfacesTest.java:945409,945448,1005322,1021880,1021903
+/openejb/branches/openejb-3.1.x/container/openejb-core/src/test/java/org/apache/openejb/config/BusinessInterfacesTest.java:945409,945448,1005322,1021880,1021903,1021955
 /openejb/branches/openejb-jcdi/container/openejb-core/src/test/java/org/apache/openejb/config/BusinessInterfacesTest.java:984659-985270

Propchange: openejb/trunk/openejb3/examples/alternate-descriptors/src/main/resources/META-INF/test.ejb-jar.xml
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Oct 16 00:21:13 2010
@@ -1,3 +1,3 @@
 /openejb/branches/openejb-3.1.1/examples/alternate-descriptors/src/main/resources/META-INF/ejb-jar.xml:779593
-/openejb/branches/openejb-3.1.x/examples/alternate-descriptors/src/main/resources/META-INF/test.ejb-jar.xml:945409,945448,1005322,1021880,1021903
+/openejb/branches/openejb-3.1.x/examples/alternate-descriptors/src/main/resources/META-INF/test.ejb-jar.xml:945409,945448,1005322,1021880,1021903,1021955
 /openejb/branches/openejb-jcdi/examples/alternate-descriptors/src/main/resources/META-INF/test.ejb-jar.xml:984659-985270

Modified: openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/MulticastTool.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/MulticastTool.java?rev=1023153&r1=1023152&r2=1023153&view=diff
==============================================================================
--- openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/MulticastTool.java
(original)
+++ openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/MulticastTool.java
Sat Oct 16 00:21:13 2010
@@ -24,9 +24,8 @@ import java.net.MulticastSocket;
 import java.net.SocketAddress;
 import java.net.SocketTimeoutException;
 import java.text.SimpleDateFormat;
-import java.util.Arrays;
 import java.util.Date;
-import java.util.Iterator;
+import java.util.List;
 import java.util.Timer;
 import java.util.TimerTask;
 
@@ -35,80 +34,126 @@ import java.util.TimerTask;
  */
 public class MulticastTool {
 
-    private static final int BUFF_SIZE = 8192;
+    private static final CommandParser cmd = new CommandParser() {
+        @Override
+        protected void init() {
+            category("Options");
+            opt('h', "host").type(String.class).value("239.255.3.2")
+                    .description("Address of the multicast channel");
 
-    public static void main(String[] array) throws Exception {
+            opt('p', "port").type(int.class).value(6142)
+                    .description("Port of the multicast channel");
 
-        SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
+            opt("date-format").type(String.class).value("HH:mm:ss")
+                    .description("Date format to use for log lines");
 
-        String send = null;
+            category("Sending");
 
-        long rate = 1000;
+            opt('s', "send").type(String.class)
+                    .description("Optional message to broadcast to the channel");
+            opt('r', "rate").type(long.class).value(1000)
+                    .description("Resend every N milliseconds. Zero sends just once");
 
-        String host = "239.255.3.2";
-        int port = 6142;
-        Integer ttl = null;
-        Boolean loopbackmode = null;
-        Integer socketTimeout = null;
-
-        Iterator<String> args = Arrays.asList(array).iterator();
-        while (args.hasNext()) {
-            String arg = args.next();
-
-            if (arg.equals("--host") || arg.equals("-h")) {
-                host = args.next();
-            } else if (arg.equals("--port") || arg.equals("-p")) {
-                port = Integer.parseInt(args.next());
-            } else if (arg.equals("--rate") || arg.equals("-r")) {
-                rate = new Long(args.next());
-            } else if (arg.equals("--ttl")) {
-                ttl = new Integer(args.next());
-            } else if (arg.equals("--send") || arg.equals("-s")) {
-                send = args.next();
-            } else if (arg.equals("--timeout") || arg.equals("-t")) {
-                socketTimeout = new Integer(args.next());
-            } else if (arg.equals("--loopback") || arg.equals("-l")) {
-                loopbackmode = new Boolean(args.next());
-            } else {
-                throw new IllegalArgumentException(arg);
-            }
+            category("Advanced");
+
+            opt("broadcast").type(boolean.class).description("java.net.MulticastSocket#setBroadcast");
+            opt("loopback-mode").type(boolean.class).description("java.net.MulticastSocket#setLoopbackMode");
+            opt("receive-buffer-size").type(int.class).description("java.net.MulticastSocket#setReceiveBufferSize");
+            opt("reuse-address").type(boolean.class).description("java.net.MulticastSocket#setReuseAddress");
+            opt("send-buffer-size").type(int.class).description("java.net.MulticastSocket#setSendBufferSize");
+            opt("so-timeout").type(int.class).description("java.net.MulticastSocket#setSoTimeout");
+            opt("time-to-live").type(int.class).description("java.net.MulticastSocket#setTimeToLive");
+            opt("traffic-class").type(int.class).description("java.net.MulticastSocket#setTrafficClass");
         }
 
-        InetAddress inetAddress = InetAddress.getByName(host);
+        @Override
+        protected List<String> validate(Arguments arguments) {
+            return super.validate(arguments);
+        }
 
-        InetSocketAddress address = new InetSocketAddress(inetAddress, port);
+        @Override
+        protected List<String> usage() {
+            return super.usage();
+        }
+    };
 
-        MulticastSocket multicast = new MulticastSocket(port);
-        multicast.joinGroup(inetAddress);
+    private static final int BUFF_SIZE = 8192;
 
-        if (ttl != null) {
-            multicast.setTimeToLive(ttl);
-        }
+    public static void main(String[] array) throws Exception {
 
-        if (socketTimeout != null) {
-            multicast.setSoTimeout(socketTimeout);
+        final CommandParser.Arguments arguments;
+        try {
+            arguments = cmd.parse(array);
+        } catch (CommandParser.HelpException e) {
+            System.exit(0);
+            throw new Exception(); // never reached, but keeps compiler happy
+        } catch (CommandParser.InvalidOptionsException e) {
+            System.exit(1);
+            throw new Exception(); // never reached, but keeps compiler happy
         }
 
-        if (loopbackmode != null) {
-            multicast.setLoopbackMode(loopbackmode);
-        }
+        final Options options = arguments.options();
+
+        SimpleDateFormat format = new SimpleDateFormat(options.get("date-format", "HH:mm:ss"));
+
+        final String host = options.get("host", "239.255.3.2");
+        final int port = options.get("port", 6142);
+
+        InetAddress inetAddress = InetAddress.getByName(host);
 
-        System.out.print("Connecting to multicast group: ");
-        System.out.print(host);
-        System.out.print(":");
-        System.out.println(multicast.getLocalPort());
+        InetSocketAddress address = new InetSocketAddress(inetAddress, port);
 
-        print("LoopbackMode", multicast.getLoopbackMode());
-        print("TimeToLive", multicast.getTimeToLive());
-        print("SoTimeout", multicast.getSoTimeout());
+        MulticastSocket multicast = new MulticastSocket(port);
+        multicast.joinGroup(inetAddress);
 
-        System.out.println("-------------------------------");
 
-        if (send != null) {
-            Timer timer = new Timer("Multicast Send", true);
-            timer.scheduleAtFixedRate(new Send(address, multicast, send), 0, rate);
+        final MulticastSocket s = multicast;
+        if (options.has("reuse-address")) s.setReuseAddress(options.get("reuse-address",
false));
+        if (options.has("broadcast")) s.setBroadcast(options.get("broadcast", false));
+        if (options.has("loopback-mode")) s.setLoopbackMode(options.get("loopback-mode",
false));
+        if (options.has("send-buffer-size")) s.setSendBufferSize(options.get("send-buffer-size",
0));
+        if (options.has("receive-buffer-size")) s.setReceiveBufferSize(options.get("receive-buffer-size",
0));
+        if (options.has("so-timeout")) s.setSoTimeout(options.get("so-timeout", 0));
+        if (options.has("time-to-live")) s.setTimeToLive(options.get("time-to-live", 0));
+        if (options.has("traffic-class")) s.setTrafficClass(options.get("traffic-class",
0));
+
+        System.out.println("Connected");
+        print("host", host);
+        print("port", port);
+        System.out.println();
+
+        System.out.println("Socket");
+        print("broadcast", s.getBroadcast());
+        print("loopback-mode", s.getLoopbackMode());
+        print("receive-buffer-size", s.getReceiveBufferSize());
+        print("reuse-address", s.getReuseAddress());
+        print("send-buffer-size", s.getSendBufferSize());
+        print("so-timeout", s.getSoTimeout());
+        print("time-to-live", s.getTimeToLive());
+        print("traffic-class", s.getTrafficClass());
+        System.out.println();
+
+        if (options.has("send")) {
+            String send = options.get("send", "");
+            long rate = options.get("rate", 1000);
+
+            System.out.println("Sending");
+            print("send", send);
+            print("rate", rate);
+            System.out.println();
+
+            final Send message = new Send(address, multicast, send);
+
+            if (rate >0) {
+                Timer timer = new Timer("Multicast Send", true);
+                timer.scheduleAtFixedRate(message, 0, rate);
+            } else {
+                message.run();
+            }
         }
 
+        System.out.println("Listening....");
+
         byte[] buf = new byte[BUFF_SIZE];
         DatagramPacket packet = new DatagramPacket(buf, 0, buf.length);
 
@@ -116,23 +161,30 @@ public class MulticastTool {
             try {
                 multicast.receive(packet);
                 if (packet.getLength() > 0) {
-                    InetAddress a = packet.getAddress();
-                    System.out.print(format.format(new Date()));
-                    System.out.print(" - ");
-                    System.out.print(a.getHostAddress());
-                    System.out.print(" - ");
+                    final StringBuilder sb = new StringBuilder();
+                    sb.append(format.format(new Date()));
+                    sb.append(" - ");
+                    sb.append(packet.getAddress().getHostAddress());
+                    sb.append(" - ");
                     String str = new String(packet.getData(), packet.getOffset(), packet.getLength());
-                    System.out.println(str);
+                    sb.append(str);
+                    System.out.println(sb.toString());
                 }
             } catch (SocketTimeoutException e) {
+                final StringBuilder sb = new StringBuilder();
+                sb.append(format.format(new Date()));
+                sb.append(" - ");
+                sb.append("ERROR");
+                sb.append(" - ");
+                sb.append(e.getMessage());
+                System.out.println(sb.toString());
             }
         }
     }
 
     private static void print(String name, Object value) {
-        System.out.print(name);
-        System.out.print(":");
-        System.out.println(value);
+        System.out.printf(" %-20s: %s", name, value);
+        System.out.println();
     }
 
     static class Send extends TimerTask {



Mime
View raw message