chirino 2003/09/06 06:52:12
Modified: modules/core/src/java/org/apache/geronimo/remoting/transport
BytesMsg.java TransportFactory.java
modules/core/src/java/org/apache/geronimo/remoting/transport/async
ChannelPool.java Registry.java
Added:
modules/core/src/java/org/apache/geronimo/remoting/transport/async
TransportFactory.java
Removed:
modules/core/src/java/org/apache/geronimo/remoting/transport/async
AsyncTransportFactory.java
Log:
Changed the abstract TransportFactory so that it can load TransportFactory
implementations dynamicly if the implementations follow a package naming
convention. A few more helper methods were added to BytesMsg.
Revision Changes Path
1.2 +23 -1
incubator-geronimo/modules/core/src/java/org/apache/geronimo/remoting/transport/BytesMsg.java
Index: BytesMsg.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/remoting/transport/BytesMsg.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BytesMsg.java 22 Aug 2003 02:23:26 -0000 1.1
+++ BytesMsg.java 6 Sep 2003 13:52:11 -0000 1.2
@@ -55,8 +55,12 @@
*/
package org.apache.geronimo.remoting.transport;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.DataInput;
+import java.io.DataInputStream;
import java.io.DataOutput;
+import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
@@ -84,6 +88,10 @@
throw new ArrayIndexOutOfBoundsException("Object stack is
empty.");
return (MarshalledObject) objectStack.remove(objectStack.size() - 1);
}
+
+ public int getStackSize() {
+ return objectStack.size();
+ }
/**
* @see org.apache.geronimo.remoting.transport.Msg#createMsg()
@@ -113,5 +121,19 @@
mo.setBytes(t);
objectStack.add(mo);
}
+ }
+
+ public byte[] getAsBytes() throws IOException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ DataOutputStream os = new DataOutputStream(baos);
+ writeExternal(os);
+ os.close();
+ return baos.toByteArray();
+ }
+
+ public void setFromBytes(byte data[]) throws IOException {
+ ByteArrayInputStream bais = new ByteArrayInputStream(data);
+ DataInputStream is = new DataInputStream(bais);
+ readExternal(is);
}
}
1.2 +17 -4
incubator-geronimo/modules/core/src/java/org/apache/geronimo/remoting/transport/TransportFactory.java
Index: TransportFactory.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/remoting/transport/TransportFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TransportFactory.java 22 Aug 2003 02:23:26 -0000 1.1
+++ TransportFactory.java 6 Sep 2003 13:52:11 -0000 1.2
@@ -59,8 +59,6 @@
import java.util.ArrayList;
import java.util.Iterator;
-import org.apache.geronimo.remoting.transport.async.AsyncTransportFactory;
-
/**
* @version $Revision$ $Date$
*/
@@ -71,10 +69,15 @@
// Try our best to add a few known TransportFactory objects.
// We may not be able to load due to ClassNotFound problems.
try {
- addFactory(AsyncTransportFactory.instance);
+ addFactory(loadFactory("async"));
} catch (Throwable ignore) {
}
}
+
+ static private TransportFactory loadFactory(String type) throws
InstantiationException, IllegalAccessException, ClassNotFoundException {
+ String className =
"org.apache.geronimo.remoting.transport."+type+".TransportFactory";
+ return (TransportFactory)
Thread.currentThread().getContextClassLoader().loadClass(className).newInstance();
+ }
public static TransportFactory getTransportFactory(URI uri) {
Iterator iterator = factories.iterator();
@@ -82,6 +85,16 @@
TransportFactory i = (TransportFactory) iterator.next();
if (i.handles(uri))
return i;
+ }
+
+ // Not found.. see if we can dynamicly load a new Factory for it
based on scheme.
+ try {
+ TransportFactory factory = loadFactory(uri.getScheme());
+ if (factory.handles(uri)) {
+ addFactory(factory);
+ return factory;
+ }
+ } catch (Throwable ignore) {
}
return null;
1.3 +2 -2
incubator-geronimo/modules/core/src/java/org/apache/geronimo/remoting/transport/async/ChannelPool.java
Index: ChannelPool.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/remoting/transport/async/ChannelPool.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ChannelPool.java 29 Aug 2003 19:16:53 -0000 1.2
+++ ChannelPool.java 6 Sep 2003 13:52:11 -0000 1.3
@@ -293,7 +293,7 @@
try {
log.debug("channel connecting to: " + uri);
- PooledAsynchChannel c = new
PooledAsynchChannel(AsyncTransportFactory.instance.createAsynchChannel());
+ PooledAsynchChannel c = new
PooledAsynchChannel(TransportFactory.instance.createAsynchChannel());
c.open(uri);
return c;
1.2 +2 -2
incubator-geronimo/modules/core/src/java/org/apache/geronimo/remoting/transport/async/Registry.java
Index: Registry.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/remoting/transport/async/Registry.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Registry.java 22 Aug 2003 02:23:26 -0000 1.1
+++ Registry.java 6 Sep 2003 13:52:11 -0000 1.2
@@ -160,7 +160,7 @@
return dynamicServer;
}
- dynamicServer = (AbstractServer)
AsyncTransportFactory.instance.createSever();
+ dynamicServer = (AbstractServer)
TransportFactory.instance.createSever();
// TODO: find a way to get a dispatcher to pass to the bind call.
dynamicServer.bind(new URI("async://0.0.0.0:0"), null);
1.1
incubator-geronimo/modules/core/src/java/org/apache/geronimo/remoting/transport/async/TransportFactory.java
Index: TransportFactory.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.geronimo.remoting.transport.async;
import java.net.URI;
import org.apache.geronimo.remoting.transport.TransportClient;
import org.apache.geronimo.remoting.transport.TransportServer;
import org.apache.geronimo.remoting.transport.async.bio.BlockingChannel;
import org.apache.geronimo.remoting.transport.async.bio.BlockingServer;
import org.apache.geronimo.remoting.transport.async.nio.NonBlockingChannel;
import org.apache.geronimo.remoting.transport.async.nio.NonBlockingServer;
/**
* @version $Revision: 1.1 $ $Date: 2003/09/06 13:52:11 $
*/
public class TransportFactory extends
org.apache.geronimo.remoting.transport.TransportFactory {
/**
* Should we used Blocking IO instead of Non-blocking IO. We default
* to using Non-blocking IO
*/
static public final boolean USE_BLOCKING_IO =
new
Boolean(System.getProperty("org.apache.geronimo.remoting.transport.async.use_blocking_io",
"true"))
.booleanValue();
static final public TransportFactory instance = new TransportFactory();
public TransportFactory() {
}
/**
* @see
org.apache.geronimo.remoting.transport.TransportFactory#handles(java.net.URI)
*/
protected boolean handles(URI uri) {
return "async".equals(uri.getScheme());
}
/**
* @see
org.apache.geronimo.remoting.transport.TransportFactory#createClient()
*/
public TransportClient createClient() {
return new AsyncClient();
}
/**
* @see
org.apache.geronimo.remoting.transport.TransportFactory#createSever()
*/
public TransportServer createSever() {
if (USE_BLOCKING_IO)
return new BlockingServer();
return new NonBlockingServer();
}
/**
* Factory method to create AsynchChannel instances.
*/
public Channel createAsynchChannel() {
if (USE_BLOCKING_IO)
return new BlockingChannel();
return new NonBlockingChannel();
}
}