You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jg...@apache.org on 2006/12/21 22:02:30 UTC

svn commit: r489459 - in /incubator/openejb/trunk/openejb3/server: openejb-client/src/main/java/org/apache/openejb/client/ openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/

Author: jgenender
Date: Thu Dec 21 13:02:29 2006
New Revision: 489459

URL: http://svn.apache.org/viewvc?view=rev&rev=489459
Log:
OPENEJB-427 - Added multiple URIs and ConnectionFactories to use the multiple URIs when connecting to provide for clustering

Modified:
    incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java
    incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/ConnectionFactory.java
    incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/ConnectionManager.java
    incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
    incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
    incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/SocketConnectionFactory.java
    incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/ClientObjectFactory.java

Modified: incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java?view=diff&rev=489459&r1=489458&r2=489459
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java (original)
+++ incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java Thu Dec 21 13:02:29 2006
@@ -22,12 +22,14 @@
 import java.io.ObjectOutput;
 import java.io.ObjectOutputStream;
 import java.io.OutputStream;
+import java.net.URI;
 import java.rmi.RemoteException;
 
 public class Client {
 
     public static Response request(Request req, Response res, ServerMetaData server) throws RemoteException {
-        if (server == null) throw new IllegalArgumentException("Server instance cannot be null");
+        if (server == null)
+            throw new IllegalArgumentException("Server instance cannot be null");
 
         OutputStream out = null;
         ObjectOutput objectOut = null;
@@ -38,16 +40,22 @@
             /*----------------------------*/
             /* Get a connection to server */
             /*----------------------------*/
-            try {
-                conn = ConnectionManager.getConnection(server);
-            } catch (IOException e) {
-                throw new RemoteException("Cannot access server: " + server.getHost() + ":" + server.getPort() + " Exception: ", e);
-            } catch (Throwable e) {
-                throw new RemoteException("Cannot access server: " + server.getHost() + ":" + server.getPort() + " due to an unkown exception in the OpenEJB client: ", e);
+            URI[] uris = server.getLocations();
+            for (int i = 0; i < uris.length; i++) {
+                URI uri = uris[i];
+                try {
+                    conn = ConnectionManager.getConnection(uri);
+                } catch (IOException e) {
+                    throw new RemoteException("Cannot access server(s): " + uri.getHost() + ":" + uri.getPort() + " Exception: ",
+                            e);
+                } catch (Throwable e) {
+                    throw new RemoteException("Cannot access server: " + uri.getHost() + ":" + uri.getPort()
+                            + " due to an unkown exception in the OpenEJB client: ", e);
+                }
             }
 
             /*----------------------------------*/
-            /* Get output streams               */
+            /* Get output streams */
             /*----------------------------------*/
             try {
 
@@ -61,7 +69,7 @@
             }
 
             /*----------------------------------*/
-            /* Write request type               */
+            /* Write request type */
             /*----------------------------------*/
             try {
 
@@ -75,7 +83,7 @@
             }
 
             /*----------------------------------*/
-            /* Get output streams               */
+            /* Get output streams */
             /*----------------------------------*/
             try {
 
@@ -89,7 +97,7 @@
             }
 
             /*----------------------------------*/
-            /* Write request                    */
+            /* Write request */
             /*----------------------------------*/
             try {
 
@@ -108,7 +116,7 @@
             }
 
             /*----------------------------------*/
-            /* Get input streams               */
+            /* Get input streams */
             /*----------------------------------*/
             try {
 
@@ -121,13 +129,15 @@
             }
 
             /*----------------------------------*/
-            /* Read response                    */
+            /* Read response */
             /*----------------------------------*/
             try {
 
                 res.readExternal(objectIn);
             } catch (ClassNotFoundException e) {
-                throw new RemoteException("Cannot read the response from the server.  The class for an object being returned is not located in this system:", e);
+                throw new RemoteException(
+                        "Cannot read the response from the server.  The class for an object being returned is not located in this system:",
+                        e);
 
             } catch (IOException e) {
                 throw new RemoteException("Cannot read the response from the server.", e);
@@ -149,6 +159,4 @@
         }
         return res;
     }
-
 }
-

Modified: incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/ConnectionFactory.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/ConnectionFactory.java?view=diff&rev=489459&r1=489458&r2=489459
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/ConnectionFactory.java (original)
+++ incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/ConnectionFactory.java Thu Dec 21 13:02:29 2006
@@ -16,13 +16,14 @@
  */
 package org.apache.openejb.client;
 
+import java.net.URI;
 import java.util.Properties;
 
 public interface ConnectionFactory {
 
     public void init(Properties props);
 
-    public Connection getConnection(ServerMetaData server) throws java.io.IOException;
+    public Connection getConnection(URI uri) throws java.io.IOException;
 
 }
 

Modified: incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/ConnectionManager.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/ConnectionManager.java?view=diff&rev=489459&r1=489458&r2=489459
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/ConnectionManager.java (original)
+++ incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/ConnectionManager.java Thu Dec 21 13:02:29 2006
@@ -34,12 +34,11 @@
         }
     }
 
-    public static Connection getConnection(ServerMetaData server) throws IOException {
-        URI location = server.getLocation();
-        if (location.getScheme().equals("http")){
-            return new HttpConnectionFactory().getConnection(server);
+    public static Connection getConnection(URI uri) throws IOException {
+        if (uri.getScheme().equals("http")){
+            return new HttpConnectionFactory().getConnection(uri);
         } else {
-            return factory.getConnection(server);
+            return factory.getConnection(uri);
         }
     }
 

Modified: incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java?view=diff&rev=489459&r1=489458&r2=489459
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java (original)
+++ incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java Thu Dec 21 13:02:29 2006
@@ -17,12 +17,13 @@
  */
 package org.apache.openejb.client;
 
-import java.util.Properties;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.HttpURLConnection;
+import java.net.URI;
 import java.net.URL;
+import java.util.Properties;
 
 /**
  * @version $Revision$ $Date$
@@ -32,19 +33,19 @@
     public void init(Properties props) {
     }
 
-    public Connection getConnection(ServerMetaData server) throws IOException {
-        return new HttpConnection(server);
+    public Connection getConnection(URI uri) throws IOException {
+        return new HttpConnection(uri);
     }
 
     public static class HttpConnection implements Connection {
 
         private HttpURLConnection httpURLConnection;
 
-        public HttpConnection(ServerMetaData server) throws IOException {
+        public HttpConnection(URI uri) throws IOException {
             String host = "localhost";
 //            String host = server.getLocation().getHost();
             // TODO: Use the URI for making the URL
-            URL url = server.getLocation().toURL();
+            URL url = uri.toURL();
             httpURLConnection = (HttpURLConnection)url.openConnection();
             httpURLConnection.setDoOutput(true);
             httpURLConnection.connect();

Modified: incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java?view=diff&rev=489459&r1=489458&r2=489459
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java (original)
+++ incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java Thu Dec 21 13:02:29 2006
@@ -21,43 +21,28 @@
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.net.URI;
-import java.net.URISyntaxException;
 
 public class ServerMetaData implements Externalizable {
 
-    private transient URI location;
+    private transient URI[] locations;
 
     public ServerMetaData() {
     }
 
-    public ServerMetaData(URI location)  {
-        this.location = location;
+    public ServerMetaData(URI ... locations)  {
+        this.locations = locations;
     }
 
-    public int getPort() {
-        return location.getPort();
-    }
-
-    public String getHost() {
-        return location.getHost();
-    }
-
-
-    public URI getLocation() {
-        return location;
+    public URI[] getLocations() {
+        return locations;
     }
 
     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        String uri = (String) in.readObject();
-        try {
-            location = new URI(uri);
-        } catch (URISyntaxException e) {
-            throw (IOException)new IOException("cannot create uri from '"+uri+"'").initCause(e);
-        }
+        locations = (URI[]) in.readObject();
     }
 
     public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeObject(location.toString());
+        out.writeObject(locations);
     }
 
 }

Modified: incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/SocketConnectionFactory.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/SocketConnectionFactory.java?view=diff&rev=489459&r1=489458&r2=489459
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/SocketConnectionFactory.java (original)
+++ incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/SocketConnectionFactory.java Thu Dec 21 13:02:29 2006
@@ -21,6 +21,7 @@
 import java.io.OutputStream;
 import java.io.StreamCorruptedException;
 import java.net.Socket;
+import java.net.URI;
 import java.util.Properties;
 
 public class SocketConnectionFactory implements ConnectionFactory {
@@ -28,9 +29,9 @@
     public void init(Properties props) {
     }
 
-    public Connection getConnection(ServerMetaData server) throws java.io.IOException {
+    public Connection getConnection(URI uri) throws java.io.IOException {
         SocketConnection conn = new SocketConnection();
-        conn.open(server);
+        conn.open(uri);
         return conn;
     }
 
@@ -40,21 +41,21 @@
         OutputStream socketOut = null;
         InputStream socketIn = null;
 
-        protected void open(ServerMetaData server) throws IOException {
+        protected void open(URI uri) throws IOException {
             /*-----------------------*/
             /* Open socket to server */
             /*-----------------------*/
             try {
-                socket = new Socket(server.getHost(), server.getPort());
+                socket = new Socket(uri.getHost(), uri.getPort());
                 socket.setTcpNoDelay(true);
             } catch (IOException e) {
-                throw new IOException("Cannot access server: " + server.getHost() + ":" + server.getPort() + " Exception: " + e.getClass().getName() + " : " + e.getMessage());
+                throw new IOException("Cannot access server: " + uri.getHost() + ":" + uri.getPort() + " Exception: " + e.getClass().getName() + " : " + e.getMessage());
 
             } catch (SecurityException e) {
-                throw new IOException("Cannot access server: " + server.getHost() + ":" + server.getPort() + " due to security restrictions in the current VM: " + e.getClass().getName() + " : " + e.getMessage());
+                throw new IOException("Cannot access server: " + uri.getHost() + ":" + uri.getPort() + " due to security restrictions in the current VM: " + e.getClass().getName() + " : " + e.getMessage());
 
             } catch (Throwable e) {
-                throw new IOException("Cannot access server: " + server.getHost() + ":" + server.getPort() + " due to an unkown exception in the OpenEJB client: " + e.getClass().getName() + " : " + e.getMessage());
+                throw new IOException("Cannot access server: " + uri.getHost() + ":" + uri.getPort() + " due to an unkown exception in the OpenEJB client: " + e.getClass().getName() + " : " + e.getMessage());
             }
 
         }

Modified: incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/ClientObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/ClientObjectFactory.java?view=diff&rev=489459&r1=489458&r2=489459
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/ClientObjectFactory.java (original)
+++ incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/ClientObjectFactory.java Thu Dec 21 13:02:29 2006
@@ -36,7 +36,7 @@
     public ClientObjectFactory(EjbDaemon daemon) {
 
         try {
-            this.sMetaData = new ServerMetaData(new URI("foo://"+"127.0.0.1" +":"+4201));
+            this.sMetaData = new ServerMetaData(new URI[]{new URI("foo://"+"127.0.0.1" +":"+4201)});
         } catch (Exception e) {
 
             e.printStackTrace();



Re: Protocol commit

Posted by David Blevins <da...@visi.com>.
Short answer, hasn't been ported from 2.x yet :)

-David

On Dec 21, 2006, at 5:33 PM, Jeff Genender wrote:

> Doh!...where is the protocol version number?
>
> Jeff Genender wrote:
>> No problem...I got rid of line breaks and I will recheck in the fix.
>>
>> You want the PROTOCOL_VERSION bumped to 2.1 or 3.0?
>>
>> Jeff
>>
>> Dain Sundstrom wrote:
>>> Jeff,
>>>
>>> This is cool.  One thing, can you set your IDE to not break likes  
>>> like
>>> that?  It should be fine to have had that all on one line.
>>>
>>> Also, if you haven't done it already, we'll need bump the protocol
>>> version number.
>>>
>>> -dain
>>>
>


Re: Protocol commit

Posted by Jeff Genender <jg...@apache.org>.
Doh!...where is the protocol version number?

Jeff Genender wrote:
> No problem...I got rid of line breaks and I will recheck in the fix.
> 
> You want the PROTOCOL_VERSION bumped to 2.1 or 3.0?
> 
> Jeff
> 
> Dain Sundstrom wrote:
>> Jeff,
>>
>> This is cool.  One thing, can you set your IDE to not break likes like
>> that?  It should be fine to have had that all on one line.
>>
>> Also, if you haven't done it already, we'll need bump the protocol
>> version number.
>>
>> -dain
>>

Re: Protocol commit

Posted by Jeff Genender <jg...@apache.org>.
No problem...I got rid of line breaks and I will recheck in the fix.

You want the PROTOCOL_VERSION bumped to 2.1 or 3.0?

Jeff

Dain Sundstrom wrote:
> Jeff,
>
> This is cool.  One thing, can you set your IDE to not break likes like
> that?  It should be fine to have had that all on one line.
>
> Also, if you haven't done it already, we'll need bump the protocol
> version number.
>
> -dain
> 

Re: Protocol commit

Posted by Jeff Genender <jg...@apache.org>.
Disregard the last email I sent...i get what you are saying about the
IDE...I'll try to prevent it from breaking..period.

But I still need the protocol info ;-)

Thanks,

Jeff

Dain Sundstrom wrote:
> On Dec 21, 2006, at 1:02 PM, jgenender@apache.org wrote:
> 
>> -                throw new RemoteException("Cannot read the response
>> from the server.  The class for an object being returned is not
>> located in this system:", e);
>> +                throw new RemoteException(
>> +                        "Cannot read the response from the server. 
>> The class for an object being returned is not located in this system:",
>> +                        e);
> 
> Jeff,
> 
> This is cool.  One thing, can you set your IDE to not break likes like
> that?  It should be fine to have had that all on one line.
> 
> Also, if you haven't done it already, we'll need bump the protocol
> version number.
> 
> -dain

Re: Protocol commit

Posted by Jeff Genender <jg...@apache.org>.
Actually, it's the scm/diff that is showing the split...my IDE busted it
at the comma...I am pretty sure it's clean.

Look at:

http://svn.apache.org/repos/asf/incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java

and let me know if it looks ok.

Can you tell me where the protocol version number is and I will be happy
to bump it? ;-)

Thanks,

Jeff


Dain Sundstrom wrote:
> On Dec 21, 2006, at 1:02 PM, jgenender@apache.org wrote:
> 
>> -                throw new RemoteException("Cannot read the response
>> from the server.  The class for an object being returned is not
>> located in this system:", e);
>> +                throw new RemoteException(
>> +                        "Cannot read the response from the server. 
>> The class for an object being returned is not located in this system:",
>> +                        e);
> 
> Jeff,
> 
> This is cool.  One thing, can you set your IDE to not break likes like
> that?  It should be fine to have had that all on one line.
> 
> Also, if you haven't done it already, we'll need bump the protocol
> version number.
> 
> -dain

Protocol commit

Posted by Dain Sundstrom <da...@iq80.com>.
On Dec 21, 2006, at 1:02 PM, jgenender@apache.org wrote:

> -                throw new RemoteException("Cannot read the  
> response from the server.  The class for an object being returned  
> is not located in this system:", e);
> +                throw new RemoteException(
> +                        "Cannot read the response from the  
> server.  The class for an object being returned is not located in  
> this system:",
> +                        e);

Jeff,

This is cool.  One thing, can you set your IDE to not break likes  
like that?  It should be fine to have had that all on one line.

Also, if you haven't done it already, we'll need bump the protocol  
version number.

-dain