tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r702546 - in /openejb/trunk/openejb3/server: openejb-client/src/main/java/org/apache/openejb/client/ openejb-multicast/src/main/java/org/apache/openejb/server/discovery/
Date Tue, 07 Oct 2008 17:05:48 GMT
Author: dblevins
Date: Tue Oct  7 10:05:47 2008
New Revision: 702546

URL: http://svn.apache.org/viewvc?rev=702546&view=rev
Log:
Fixed client-side connection leak in failover leading to inability for client to reconnect
after situations where where all servers go down.
Stomped out multicast issues preventing it from working between machines.
Added a multicast diagnostic/test tool for clients.
Improved failover logic to more aggressively add servers to the failed list and fallback to
the multicast server address if specified.

Added:
    openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/MulticastTool.java
Modified:
    openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/MulticastConnectionFactory.java
    openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/MulticastSearch.java
    openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/SocketConnectionFactory.java
    openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/StickyConnectionStrategy.java
    openejb/trunk/openejb3/server/openejb-multicast/src/main/java/org/apache/openejb/server/discovery/MulticastSearch.java

Modified: openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/MulticastConnectionFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/MulticastConnectionFactory.java?rev=702546&r1=702545&r2=702546&view=diff
==============================================================================
--- openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/MulticastConnectionFactory.java
(original)
+++ openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/MulticastConnectionFactory.java
Tue Oct  7 10:05:47 2008
@@ -62,11 +62,17 @@
 
         URI serviceURI = search.search(new Filter(group, schemes), timeout, TimeUnit.MILLISECONDS);
 
+        if (serviceURI == null) {
+            throw new IllegalArgumentException("Unable to find an ejb server via the multicast
URI: " + uri);
+        }
+
         try {
             serviceURI = unwrap(serviceURI); // cut group:
             serviceURI = unwrap(serviceURI); // cut ejb:
         } catch (URISyntaxException e) {
             throw new IllegalArgumentException("Invalid ejb service uri " + serviceURI.toString(),
e);
+        } catch (Exception e) {
+            throw new IllegalArgumentException("Invalid ejb service uri " + serviceURI.toString(),
e);
         }
 
         return ConnectionManager.getConnection(serviceURI);

Modified: openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/MulticastSearch.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/MulticastSearch.java?rev=702546&r1=702545&r2=702546&view=diff
==============================================================================
--- openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/MulticastSearch.java
(original)
+++ openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/MulticastSearch.java
Tue Oct  7 10:05:47 2008
@@ -21,6 +21,8 @@
 import java.net.InetAddress;
 import java.net.DatagramPacket;
 import java.net.SocketException;
+import java.net.SocketTimeoutException;
+import java.net.URISyntaxException;
 import java.util.concurrent.TimeUnit;
 import java.io.IOException;
 
@@ -34,7 +36,7 @@
     private final MulticastSocket multicast;
 
     public MulticastSearch() throws IOException {
-        this("239.255.2.3", 6142);
+        this("239.255.3.2", 6142);
     }
 
     public MulticastSearch(String host, int port) throws IOException {
@@ -70,13 +72,18 @@
                 multicast.receive(packet);
                 if (packet.getLength() > 0) {
                     String str = new String(packet.getData(), packet.getOffset(), packet.getLength());
-                    URI service = URI.create(str);
-                    if (service != null && filter.accept(service)) {
-                        return service;
+                    try {
+                        URI service = new URI(str);
+                        if (service != null && filter.accept(service)) {
+                            return service;
+                        }
+                    } catch (URISyntaxException e) {
+                        // not a service URI
                     }
                 }
+            } catch (SocketTimeoutException e) {
             } catch (SocketException e) {
-                
+                System.out.println(e.getClass().getName() + ": " + e.getMessage());
             } finally {
                 long stop = System.currentTimeMillis();
                 waited += stop - start;

Added: 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=702546&view=auto
==============================================================================
--- openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/MulticastTool.java
(added)
+++ openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/MulticastTool.java
Tue Oct  7 10:05:47 2008
@@ -0,0 +1,161 @@
+/**
+ * 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.openejb.client;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+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.Timer;
+import java.util.TimerTask;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MulticastTool {
+
+    private static final int BUFF_SIZE = 8192;
+
+    public static void main(String[] array) throws Exception {
+
+        SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
+
+        String send = null;
+
+        long rate = 1000;
+
+        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);
+            }
+        }
+
+        InetAddress inetAddress = InetAddress.getByName(host);
+
+        InetSocketAddress address = new InetSocketAddress(inetAddress, port);
+
+        MulticastSocket multicast = new MulticastSocket(port);
+        multicast.joinGroup(inetAddress);
+
+        if (ttl != null) {
+            multicast.setTimeToLive(ttl);
+        }
+
+        if (socketTimeout != null) {
+            multicast.setSoTimeout(socketTimeout);
+        }
+
+        if (loopbackmode != null) {
+            multicast.setLoopbackMode(loopbackmode);
+        }
+
+        System.out.print("Connecting to multicast group: ");
+        System.out.print(host);
+        System.out.print(":");
+        System.out.println(multicast.getLocalPort());
+
+        print("LoopbackMode", multicast.getLoopbackMode());
+        print("TimeToLive", multicast.getTimeToLive());
+        print("SoTimeout", multicast.getSoTimeout());
+
+        System.out.println("-------------------------------");
+
+        if (send != null) {
+            Timer timer = new Timer("Multicast Send", true);
+            timer.scheduleAtFixedRate(new Send(address, multicast, send), 0, rate);
+        }
+
+        byte[] buf = new byte[BUFF_SIZE];
+        DatagramPacket packet = new DatagramPacket(buf, 0, buf.length);
+
+        while (true) {
+            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(" - ");
+                    String str = new String(packet.getData(), packet.getOffset(), packet.getLength());
+                    System.out.println(str);
+                }
+            } catch (SocketTimeoutException e) {
+            }
+        }
+    }
+
+    private static void print(String name, Object value) {
+        System.out.print(name);
+        System.out.print(":");
+        System.out.println(value);
+    }
+
+    static class Send extends TimerTask {
+        private final MulticastSocket multicast;
+        private final String text;
+        private final SocketAddress address;
+
+        public Send(SocketAddress address, MulticastSocket multicast, String text) {
+            this.address = address;
+            this.multicast = multicast;
+            this.text = text;
+        }
+
+        public void run() {
+            try {
+                byte[] data = text.getBytes();
+                DatagramPacket packet = new DatagramPacket(data, 0, data.length, address);
+                multicast.send(packet);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+
+    }
+
+}

Modified: openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/SocketConnectionFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/SocketConnectionFactory.java?rev=702546&r1=702545&r2=702546&view=diff
==============================================================================
--- openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/SocketConnectionFactory.java
(original)
+++ openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/SocketConnectionFactory.java
Tue Oct  7 10:05:47 2008
@@ -67,8 +67,13 @@
 
         SocketConnection conn = pool.get();
         if (conn == null) {
-            conn = new SocketConnection(uri, pool);
-            conn.open(uri);
+            try {
+                conn = new SocketConnection(uri, pool);
+                conn.open(uri);
+            } catch (IOException e) {
+                pool.put(null);
+                throw e;
+            }
         }
 
         try {

Modified: openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/StickyConnectionStrategy.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/StickyConnectionStrategy.java?rev=702546&r1=702545&r2=702546&view=diff
==============================================================================
--- openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/StickyConnectionStrategy.java
(original)
+++ openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/StickyConnectionStrategy.java
Tue Oct  7 10:05:47 2008
@@ -59,12 +59,16 @@
             try {
                 return connect(uri);
             } catch (IOException e) {
+                failed.add(uri);
                 LOGGER.log(Level.WARNING, "Failover: Cannot connect to server(s): " + uri.toString()
+ " Exception: " + e.getMessage()+".  Trying next.");
             } catch (Throwable e) {
+                failed.add(uri);
                 throw new RemoteException("Failover: Cannot connect to server: " +  uri.toString()
+ " due to an unkown exception in the OpenEJB client: ", e);
             }
         }
 
+        remaining.removeAll(failed);
+
         if (remaining.size() == 0 && !failed.contains(server.getLocation())){
             return connect(server.getLocation());
         }

Modified: openejb/trunk/openejb3/server/openejb-multicast/src/main/java/org/apache/openejb/server/discovery/MulticastSearch.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-multicast/src/main/java/org/apache/openejb/server/discovery/MulticastSearch.java?rev=702546&r1=702545&r2=702546&view=diff
==============================================================================
--- openejb/trunk/openejb3/server/openejb-multicast/src/main/java/org/apache/openejb/server/discovery/MulticastSearch.java
(original)
+++ openejb/trunk/openejb3/server/openejb-multicast/src/main/java/org/apache/openejb/server/discovery/MulticastSearch.java
Tue Oct  7 10:05:47 2008
@@ -33,7 +33,7 @@
     private final MulticastSocket multicast;
 
     public MulticastSearch() throws IOException {
-        this("239.255.2.3", 6142);
+        this("239.255.3.2", 6142);
     }
 
     public MulticastSearch(String host, int port) throws IOException {



Mime
View raw message