hammant 2003/09/04 14:24:25
Modified: client/impl project.xml
. maven.xml
Added:
client/impl/src/java/org/apache/altrmi/client/impl/callback/socket
CallbackEnabledSocketCustomStreamHostContext.java
CallbackEnabledSocketCustomStreamInvocationHandler.java
client/impl/src/java/org/apache/altrmi/client/impl/callback/stream
CallbackEnabledClientCustomStreamReadWriter.java
client/impl/src/java/org/apache/altrmi/client/impl/direct
AbstractDirectInvocationHandler.java
DirectHostContext.java DirectInvocationHandler.java
DirectMarshalledHostContext.java
DirectMarshalledInvocationHandler.java
common/src/java/org/apache/altrmi/common ClassFoo.java
Log:
Start of adding back of Direct and Callback
Revision Changes Path
1.2 +5 -0 incubator-altrmi/client/impl/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/incubator-altrmi/client/impl/project.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- project.xml 28 Aug 2003 18:10:34 -0000 1.1
+++ project.xml 4 Sep 2003 21:24:24 -0000 1.2
@@ -26,6 +26,11 @@
<version>${pom.currentVersion}</version>
</dependency>
<dependency>
+ <groupId>altrmi</groupId>
+ <artifactId>altrmi-server-api</artifactId>
+ <version>${pom.currentVersion}</version>
+ </dependency>
+ <dependency>
<groupId>avalon-framework</groupId>
<artifactId>avalon-framework-api</artifactId>
<version>4.1.5-dev</version>
1.3 +1 -1 incubator-altrmi/maven.xml
Index: maven.xml
===================================================================
RCS file: /home/cvs/incubator-altrmi/maven.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- maven.xml 31 Aug 2003 11:02:12 -0000 1.2
+++ maven.xml 4 Sep 2003 21:24:24 -0000 1.3
@@ -51,7 +51,7 @@
<goal name="clean-all">
<maven:reactor
basedir="${basedir}"
-
includes="common/project.xml,client/api/project.xml,client/impl/project.xml,server/api/project.xml,server/impl/project.xml,tools/project.xml,integrationtests/project.xml"
+
includes="common/project.xml,client/api/project.xml,server/api/project.xml,client/impl/project.xml,server/impl/project.xml,tools/project.xml,integrationtests/project.xml"
goals="clean"
banner="Cleaning subproject:"
ignoreFailures="true"/>
1.1
incubator-altrmi/client/impl/src/java/org/apache/altrmi/client/impl/callback/socket/CallbackEnabledSocketCustomStreamHostContext.java
Index: CallbackEnabledSocketCustomStreamHostContext.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 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 "Incubator", "AltRMI", 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. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.altrmi.client.impl.callback.socket;
import org.apache.altrmi.client.ClientMonitor;
import org.apache.altrmi.client.ConnectionPinger;
import org.apache.altrmi.client.impl.AbstractHostContext;
import org.apache.altrmi.client.impl.DumbClientMonitor;
import org.apache.altrmi.client.impl.NeverConnectionPinger;
import org.apache.altrmi.client.impl.socket.SocketObjectStreamHostContext;
import org.apache.altrmi.common.CallbackException;
import org.apache.altrmi.common.ConnectionException;
import org.apache.altrmi.common.ThreadPool;
import org.apache.altrmi.common.DefaultThreadPool;
/**
* Class CallbackEnabledSocketCustomStreamHostContext
* @author <a href="mailto:[EMAIL PROTECTED]">Vinay Chandran</a>
* @version $Revision: 1.1 $
*/
public class CallbackEnabledSocketCustomStreamHostContext extends
AbstractHostContext
{
public CallbackEnabledSocketCustomStreamHostContext( ThreadPool
threadPool, ClientMonitor clientMonitor,
ConnectionPinger connectionPinger, ClassLoader
classLoader, String host, int port)
throws ConnectionException
{
super( new CallbackEnabledSocketCustomStreamInvocationHandler(
threadPool, clientMonitor, connectionPinger,
classLoader, host, port ) );
}
public static class WithSimpleDefaults extends
CallbackEnabledSocketCustomStreamHostContext
{
/**
*
* @param host
* @param port
* @throws ConnectionException
*/
public WithSimpleDefaults(String host, int port) throws
ConnectionException
{
super(new DefaultThreadPool(),
new DumbClientMonitor(),
new NeverConnectionPinger(),
SocketObjectStreamHostContext.class.getClassLoader(),
host, port);
}
}
public static class WithCurrentClassLoader extends
CallbackEnabledSocketCustomStreamHostContext
{
/**
*
* @param threadPool
* @param clientMonitor
* @param connectionPinger
* @param host
* @param port
* @throws ConnectionException
*/
public WithCurrentClassLoader(ThreadPool threadPool, ClientMonitor
clientMonitor, ConnectionPinger connectionPinger, String host, int port) throws
ConnectionException
{
super(threadPool,
clientMonitor,
connectionPinger,
CallbackEnabledSocketCustomStreamHostContext.class.getClassLoader(),
host, port);
}
}
public boolean exposeObject( Object tobeExposedObject, Class
tobeExposedInterface ) throws CallbackException
{
return ( getInvocationHandler() ).exposeObject( tobeExposedObject,
tobeExposedInterface );
}
}
1.1
incubator-altrmi/client/impl/src/java/org/apache/altrmi/client/impl/callback/socket/CallbackEnabledSocketCustomStreamInvocationHandler.java
Index: CallbackEnabledSocketCustomStreamInvocationHandler.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 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 "Incubator", "AltRMI", 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. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.altrmi.client.impl.callback.socket;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.altrmi.client.ClientInvocationHandler;
import org.apache.altrmi.client.ClientMonitor;
import org.apache.altrmi.client.ConnectionPinger;
import org.apache.altrmi.client.ConnectionRefusedException;
import
org.apache.altrmi.client.impl.callback.stream.CallbackEnabledClientCustomStreamReadWriter;
import
org.apache.altrmi.client.impl.socket.AbstractSocketStreamInvocationHandler;
import org.apache.altrmi.client.impl.ClientStreamReadWriter;
import org.apache.altrmi.common.CallbackException;
import org.apache.altrmi.common.ConnectionException;
import org.apache.altrmi.common.ExposedObjectProxy;
import org.apache.altrmi.common.ThreadPool;
import org.apache.altrmi.common.BadConnectionException;
/**
* Class CallbackEnabledSocketCustomStreamInvocationHandler
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vinay Chandran</a>
* @version $Revision: 1.1 $
*/
public final class CallbackEnabledSocketCustomStreamInvocationHandler
extends AbstractSocketStreamInvocationHandler implements
ClientInvocationHandler
{
private CallbackEnabledClientCustomStreamReadWriter
m_callbackEnabledClientCustomStreamReadWriter;
/**
*
* @param threadPool
* @param clientMonitor
* @param connectionPinger
* @param interfacesClassLoader
* @param host
* @param port
* @throws ConnectionRefusedException
* @throws BadConnectionException
*/
public CallbackEnabledSocketCustomStreamInvocationHandler(ThreadPool
threadPool, ClientMonitor clientMonitor, ConnectionPinger connectionPinger,
ClassLoader interfacesClassLoader, String host, int port) throws
ConnectionRefusedException, BadConnectionException
{
super(threadPool, clientMonitor, connectionPinger,
interfacesClassLoader, host, port);
}
/*
* @see
AbstractSocketStreamInvocationHandler#createClientStreamReadWriter(InputStream,
OutputStream)
*/
protected ClientStreamReadWriter createClientStreamReadWriter(
InputStream in, OutputStream out ) throws ConnectionException
{
if( m_callbackEnabledClientCustomStreamReadWriter == null )
{
m_callbackEnabledClientCustomStreamReadWriter = new
CallbackEnabledClientCustomStreamReadWriter( m_threadPool, in, out,
m_interfacesClassLoader );
}
return m_callbackEnabledClientCustomStreamReadWriter;
}
public boolean exposeObject( Object tobeExposedObject, Class
tobeExposedInterface ) throws CallbackException
{
return m_callbackEnabledClientCustomStreamReadWriter.exposeObject(
tobeExposedObject, tobeExposedInterface );
}
public String getPublishedName( Object tobeExposedObject )
{
return
m_callbackEnabledClientCustomStreamReadWriter.getPublishedName(
tobeExposedObject );
}
/**
* <pre>
* <code>resolveArgument</code> override here handles the passage of
references
* of client to the server ,so that the server
* can issue callbacks back to the client using
* those references.
* </pre>
* @see
org.apache.altrmi.client.ClientInvocationHandler#resolveArgument(String, Class,
Object)
*/
public Object resolveArgument(
String methodSignature,
Class inputArgumentClass,
Object inputArgumentInstance)
{
//System.out.println("callback class["+inputArgumentClass+"]
obj["+inputArgumentInstance+"]");
if( inputArgumentClass != null)
{
String publishedName =getPublishedName( inputArgumentInstance );
if( publishedName != null ) //already published
{
ExposedObjectProxy exposedObjectProxy = new
ExposedObjectProxy( publishedName );
inputArgumentInstance= exposedObjectProxy;
}
else //check whether its
Publish'able
{
if( !inputArgumentClass.isInterface() ) //We handle only
Interface's to be exposed
{
return inputArgumentInstance;
}
if( inputArgumentClass.isAssignableFrom(
inputArgumentInstance.getClass() ) )
{
try
{
exposeObject( inputArgumentInstance,
inputArgumentClass );
}
catch( CallbackException ace )
{
ace.printStackTrace();
}
ExposedObjectProxy exposedObjectProxy =
new ExposedObjectProxy( getPublishedName(
inputArgumentInstance ) );
inputArgumentInstance =exposedObjectProxy;
}
}
}
return inputArgumentInstance;
}
public boolean isCallBackEnabled()
{
return true;
}
}
1.1
incubator-altrmi/client/impl/src/java/org/apache/altrmi/client/impl/callback/stream/CallbackEnabledClientCustomStreamReadWriter.java
Index: CallbackEnabledClientCustomStreamReadWriter.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 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 "Incubator", "AltRMI", 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. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.altrmi.client.impl.callback.stream;
import org.apache.altrmi.client.InvocationException;
import org.apache.altrmi.client.impl.ClientStreamReadWriter;
import org.apache.altrmi.common.CallbackException;
import org.apache.altrmi.common.ClientInvocationAbendReply;
import org.apache.altrmi.common.ConnectionException;
import org.apache.altrmi.common.ExceptionReply;
import org.apache.altrmi.common.Reply;
import org.apache.altrmi.common.ReqRepBytes;
import org.apache.altrmi.common.Request;
import org.apache.altrmi.common.RequestConstants;
import org.apache.altrmi.common.SerializationHelper;
import org.apache.altrmi.common.ThreadContext;
import org.apache.altrmi.common.ThreadPool;
import org.apache.altrmi.common.ClassFoo;
import org.apache.altrmi.server.PublicationException;
import org.apache.altrmi.server.Server;
import org.apache.altrmi.server.ServerException;
import org.apache.altrmi.server.ServerMonitor;
import org.apache.altrmi.server.ServerSideClientContextFactory;
import org.apache.altrmi.server.Authenticator;
import org.apache.altrmi.server.ClassRetriever;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.SocketException;
import java.util.HashMap;
/**
* Class CallbackEnabledClientCustomStreamReadWriter
* This class embedds within itself a Server which holds the
* exposedObjects for the client and upon which the Server can make
* callbacks.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vinay Chandran</a>
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public class CallbackEnabledClientCustomStreamReadWriter
implements ClientStreamReadWriter, Runnable {
//Mutex to block the client till a reply reaches back from server
private Object m_replyLock = new Object();
private boolean m_replyLockSyncedOn;
private Reply m_reply = null;
private ThreadContext m_messageLoopThreadContext = null;
private boolean m_isStopped = false;
private DataInputStream m_dataInputStream;
private DataOutputStream m_dataOutputStream;
private ClassLoader m_interfacesClassLoader;
private HashMap m_exposedObjPublishNameHash_ = new HashMap();
private Server m_clientServerHostingExposedObjects;
private static int m_random = 0;
private final ThreadPool m_threadPool;
/**
* Constructor ClientCustomStreamReadWriter
*
*
* @param inputStream The input stream
* @param outputStream The output stream
*
* @throws ConnectionException The IO Exception
*
*/
public CallbackEnabledClientCustomStreamReadWriter(ThreadPool threadPool,
InputStream inputStream, OutputStream outputStream, ClassLoader
interfacesClassLoader)
throws ConnectionException {
this.m_threadPool = threadPool;
m_dataOutputStream = new DataOutputStream(new
BufferedOutputStream(outputStream));
m_dataInputStream = new DataInputStream(inputStream);
m_interfacesClassLoader = interfacesClassLoader;
//start the internal Server which holds the exposed Objects
// for the server to make callbacks upon.
ServerMonitor serverMonitor = (ServerMonitor)
ClassFoo.instantiate("org.apache.altrmi.server.impl.NullServerMonitor");
ServerSideClientContextFactory serverSideClientContextFactory =
(ServerSideClientContextFactory)
ClassFoo.instantiate("org.apache.altrmi.server.impl.DefaultServerSideClientContextFactory");
Authenticator authenticator = (Authenticator)
ClassFoo.instantiate("org.apache.altrmi.server.impl.DefaultAuthenticator");
ClassRetriever classRetriever = (ClassRetriever)
ClassFoo.instantiate("org.apache.altrmi.server.impl.classretrievers.PlainClassRetriever",
ClassLoader.class.getName(), this.getClass().getClassLoader());
m_clientServerHostingExposedObjects = (Server)
ClassFoo.instantiate("org.apache.altrmi.server.impl.direct.DirectServer",
new String[]{ClassRetriever.class.getName(),
Authenticator.class.getName(), ServerMonitor.class.getName(),
ThreadPool.class.getName(), ServerSideClientContextFactory.class.getName()},
new Object[]{classRetriever, authenticator, serverMonitor,
threadPool, serverSideClientContextFactory});
try {
m_clientServerHostingExposedObjects.start();
} catch (ServerException e) {
throw new ConnectionException("Error Starting Internal Server");
}
//This thread recv's all the messages sent from the server
m_messageLoopThreadContext = m_threadPool.getThreadContext(this);
m_messageLoopThreadContext.start();
}
/*
* @see Runnable#run()
*/
public void run() {
while (!m_isStopped) {
ReqRepBytes reqRepBytes =
ReqRepBytes.getRequestReplyBytesFromDataStream(m_dataInputStream);
if (reqRepBytes.getIOException() != null &&
reqRepBytes.ioeDuringReadInt()) {
IOException ioe = reqRepBytes.getIOException();
if ((ioe instanceof EOFException &&
reqRepBytes.ioeDuringReadInt())
|| ioe instanceof SocketException) {
if (m_replyLockSyncedOn) {
m_reply = new ClientInvocationAbendReply(ioe);
synchronized (m_replyLock) {
m_replyLock.notify();
}
}
m_isStopped = true;
// restart ?
return;
}
System.out.println("--> ##1 " + reqRepBytes.getIOException());
}
// Is a reply.
if (!(reqRepBytes.isRequest())) {
if (reqRepBytes.hadIOE()) {
m_reply = new ExceptionReply(new
InvocationException("IOException", reqRepBytes.getIOException()));
} else {
try {
m_reply = (Reply)
SerializationHelper.getInstanceFromBytes(reqRepBytes.getBytes(),
m_interfacesClassLoader);
} catch (ClassNotFoundException e) {
m_reply = new ExceptionReply(new
InvocationException("ClassNotFoundException", e));
}
}
synchronized (m_replyLock) {
m_replyLock.notify();
}
}
// Is a request.
else if (reqRepBytes.isRequest()) {
Object obj = null;
Reply reply = null;
if (reqRepBytes.hadIOE()) {
reply = new
ClientInvocationAbendReply(reqRepBytes.getIOException());
try {
postReply(reply);
} catch (IOException e) {
// ?
}
} else {
try {
try {
obj =
SerializationHelper.getInstanceFromBytes(reqRepBytes.getBytes(),
m_interfacesClassLoader);
reply =
m_clientServerHostingExposedObjects.handleInvocation((Request) obj, "callback");
} catch (ClassNotFoundException e) {
reply = new ExceptionReply(new
InvocationException("ClassNotFoundException", e));
}
postReply(reply);
} catch (IOException ioe) {
if (ioe instanceof EOFException) {
m_isStopped = true;
return;
}
}
}
}
}
}
/**
* Method getReplyFromMessageLoop.
* Returns the reply recevied from the server
* @return Reply
*/
public Reply getReplyFromMessageLoop() {
if (m_reply == null) {
synchronized (m_replyLock) {
m_replyLockSyncedOn = true;
try {
m_replyLock.wait();
} catch (InterruptedException e) {
System.out.println("--> InterrupedException ");
e.printStackTrace();
}
m_replyLockSyncedOn = false;
}
}
return m_reply;
}
/*
* @see ClientStreamReadWriter#postRequest(Request)
*/
public Reply postRequest(Request request)
throws IOException, ClassNotFoundException {
if (m_isStopped && request.getRequestCode() !=
RequestConstants.GCREQUEST)
throw new IOException("Server Stoppped ? " +
request.getClass().getName());
writeRequest(request);
Reply r = readReply();
m_reply = null;
return r;
}
/**
* Method writeRequest.
* @param request
* @throws IOException
*/
private void writeRequest(Request request) throws IOException {
byte[] aBytes = SerializationHelper.getBytesFromInstance(request);
m_dataOutputStream.writeInt(aBytes.length);
m_dataOutputStream.writeBoolean(true);
m_dataOutputStream.write(aBytes);
m_dataOutputStream.flush();
}
/**
* Method readReply.
* @return Reply
*/
private Reply readReply() {
return getReplyFromMessageLoop();
}
/**
* Method postReply.
* @param reply
* @throws IOException
*/
public void postReply(Reply reply) throws IOException {
byte[] aBytes = SerializationHelper.getBytesFromInstance(reply);
m_dataOutputStream.writeInt(aBytes.length);
m_dataOutputStream.writeBoolean(false);
m_dataOutputStream.write(aBytes);
m_dataOutputStream.flush();
}
/**
* Method exposeObject.
* Expose the Object by adding it to the internal Server
* and by assigning a unique PublishedName for the same.
* @param tobeExposedObject
* @param tobeExposedInterface
* @return boolean
* @throws CallbackException
*/
public boolean exposeObject(Object tobeExposedObject, Class
tobeExposedInterface) throws CallbackException {
if (m_exposedObjPublishNameHash_.get(tobeExposedObject) != null)
return false;
String _uniquePublishedName =
getUniqueNameForExposedObject(tobeExposedObject);
m_exposedObjPublishNameHash_.put(tobeExposedObject,
_uniquePublishedName);
try {
m_clientServerHostingExposedObjects.publish(tobeExposedObject,
_uniquePublishedName, tobeExposedInterface);
} catch (PublicationException pce) {
throw new CallbackException(pce.getMessage());
}
return true;
}
/**
* Method getUniqueNameForExposedObject.
* Generate Unqiue name for the exposedObject.
* Right now its as simple as ClassName_1,ClassName_2 etc....
* @param tobeExposedObject
* @return String
*/
private String getUniqueNameForExposedObject(Object tobeExposedObject) {
m_random++;
return
tobeExposedObject.getClass().getName().substring(tobeExposedObject.getClass().getName().lastIndexOf(".")
+ 1) + "_" + m_random;
}
/**
* Method getPublishedName.
* Use while marshalling the exposedObject as an argument
* to the server.
* @param tobeExposedObject
* @return String
*/
public String getPublishedName(Object tobeExposedObject) {
return (String) m_exposedObjPublishNameHash_.get(tobeExposedObject);
}
}
1.1
incubator-altrmi/client/impl/src/java/org/apache/altrmi/client/impl/direct/AbstractDirectInvocationHandler.java
Index: AbstractDirectInvocationHandler.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 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 "Incubator", "AltRMI", 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. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.altrmi.client.impl.direct;
import java.io.IOException;
import org.apache.altrmi.client.ClientMonitor;
import org.apache.altrmi.client.impl.AbstractClientInvocationHandler;
import org.apache.altrmi.client.InvocationException;
import org.apache.altrmi.common.Reply;
import org.apache.altrmi.common.Request;
import org.apache.altrmi.common.MethodRequest;
import org.apache.altrmi.client.NoSuchReferenceException;
import org.apache.altrmi.common.NoSuchReferenceReply;
import org.apache.altrmi.client.NotPublishedException;
import org.apache.altrmi.client.ConnectionPinger;
import org.apache.altrmi.common.NotPublishedReply;
import org.apache.altrmi.common.PublishedNameRequest;
import org.apache.altrmi.common.TryLaterReply;
import org.apache.altrmi.common.RequestConstants;
import org.apache.altrmi.common.ThreadPool;
/**
* Class DirectInvocationHandler
*
*
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public abstract class AbstractDirectInvocationHandler extends
AbstractClientInvocationHandler
{
protected boolean m_methodLogging = false;
protected long m_lastRealRequest = System.currentTimeMillis();
public AbstractDirectInvocationHandler(ThreadPool threadPool,
ClientMonitor clientMonitor, ConnectionPinger connectionPinger)
{
super(threadPool, clientMonitor, connectionPinger);
}
/**
* Method handleInvocation
*
*
* @param request
*
* @return
*
*/
public Reply handleInvocation( Request request )
{
if( request.getRequestCode() != RequestConstants.PINGREQUEST )
{
m_lastRealRequest = System.currentTimeMillis();
}
boolean again = true;
Reply reply = null;
int tries = 0;
long start = 0;
if( m_methodLogging )
{
start = System.currentTimeMillis();
}
while( again )
{
tries++;
again = false;
try
{
reply = performInvocation( request );
}
catch( IOException ioe )
{
ioe.printStackTrace();
}
//if ((reply instanceof ProblemReply)) // slower by 11%
if( reply.getReplyCode() >= 100 )
{
if( reply instanceof TryLaterReply )
{
int millis = ( (TryLaterReply)reply
).getSuggestedDelayMillis();
m_clientMonitor.serviceSuspended(this.getClass(),
request, tries, millis );
again = true;
}
else if( reply instanceof NoSuchReferenceReply )
{
throw new NoSuchReferenceException( (
(NoSuchReferenceReply)reply )
.getReferenceID() );
}
else if( reply instanceof NotPublishedReply )
{
PublishedNameRequest pnr = (PublishedNameRequest)request;
throw new NotPublishedException(
pnr.getPublishedServiceName(),
pnr.getObjectName() );
}
}
}
if( m_methodLogging )
{
if( request instanceof MethodRequest )
{
m_clientMonitor.methodCalled(
this.getClass(), ( (MethodRequest)request
).getMethodSignature(),
System.currentTimeMillis() - start, "" );
}
}
return reply;
}
protected boolean tryReconnect()
{
// blimey how do we reconnect this?
throw new InvocationException( "Direct connection broken, unable to
reconnect." );
}
/**
* Method getLastRealRequest
*
*
* @return
*
*/
public long getLastRealRequest()
{
return m_lastRealRequest;
}
protected abstract Reply performInvocation( Request request ) throws
IOException;
}
1.1
incubator-altrmi/client/impl/src/java/org/apache/altrmi/client/impl/direct/DirectHostContext.java
Index: DirectHostContext.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 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 "Incubator", "AltRMI", 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. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.altrmi.client.impl.direct;
import org.apache.altrmi.client.impl.AbstractHostContext;
import org.apache.altrmi.client.impl.DumbClientMonitor;
import org.apache.altrmi.client.impl.NeverConnectionPinger;
import org.apache.altrmi.client.impl.socket.SocketObjectStreamHostContext;
import org.apache.altrmi.client.ConnectionPinger;
import org.apache.altrmi.client.ClientMonitor;
import org.apache.altrmi.common.ConnectionException;
import org.apache.altrmi.common.ThreadPool;
import org.apache.altrmi.common.DefaultThreadPool;
import org.apache.altrmi.server.ServerInvocationHandler;
import org.apache.altrmi.server.ServerMarshalledInvocationHandler;
/**
* Class DirectHostContext
*
*
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public class DirectHostContext extends AbstractHostContext
{
/**
* Constructor DirectHostContext
*
* @param threadPool
* @param clientMonitor
* @param connectionPinger
* @param invocationHandler
*/
public DirectHostContext( ThreadPool threadPool, ClientMonitor
clientMonitor,
ConnectionPinger connectionPinger,
ServerInvocationHandler invocationHandler )
{
super( new DirectInvocationHandler( threadPool, clientMonitor,
connectionPinger, invocationHandler ) );
}
public static class WithSimpleDefaults extends DirectHostContext
{
/**
*
* @param invocationHandler
*/
public WithSimpleDefaults(ServerInvocationHandler invocationHandler)
{
super(new DefaultThreadPool(),
new DumbClientMonitor(),
new NeverConnectionPinger(),
invocationHandler);
}
}
}
1.1
incubator-altrmi/client/impl/src/java/org/apache/altrmi/client/impl/direct/DirectInvocationHandler.java
Index: DirectInvocationHandler.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 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 "Incubator", "AltRMI", 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. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.altrmi.client.impl.direct;
import java.io.IOException;
import org.apache.altrmi.common.ConnectionException;
import org.apache.altrmi.common.Reply;
import org.apache.altrmi.common.Request;
import org.apache.altrmi.common.ThreadPool;
import org.apache.altrmi.server.ServerInvocationHandler;
import org.apache.altrmi.client.ClientMonitor;
import org.apache.altrmi.client.ConnectionPinger;
/**
* Class DirectInvocationHandler
*
*
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public final class DirectInvocationHandler extends
AbstractDirectInvocationHandler
{
private ServerInvocationHandler m_invocationHandler;
/**
* Constructor DirectInvocationHandler
*
*
* @param threadPool
* @param clientMonitor
* @param connectionPinger
* @param invocationHandler
*/
public DirectInvocationHandler(ThreadPool threadPool, ClientMonitor
clientMonitor, ConnectionPinger connectionPinger, ServerInvocationHandler
invocationHandler)
{
super(threadPool, clientMonitor, connectionPinger);
m_invocationHandler = invocationHandler;
}
protected Reply performInvocation( Request request ) throws IOException
{
return m_invocationHandler.handleInvocation( request, "" );
}
}
1.1
incubator-altrmi/client/impl/src/java/org/apache/altrmi/client/impl/direct/DirectMarshalledHostContext.java
Index: DirectMarshalledHostContext.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 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 "Incubator", "AltRMI", 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. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.altrmi.client.impl.direct;
import org.apache.altrmi.client.ClientMonitor;
import org.apache.altrmi.client.ConnectionPinger;
import org.apache.altrmi.client.impl.AbstractHostContext;
import org.apache.altrmi.client.impl.DumbClientMonitor;
import org.apache.altrmi.client.impl.NeverConnectionPinger;
import org.apache.altrmi.common.DefaultThreadPool;
import org.apache.altrmi.common.ThreadPool;
import org.apache.altrmi.server.ServerMarshalledInvocationHandler;
/**
* Class DirectMarshalledHostContext
*
*
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public class DirectMarshalledHostContext extends AbstractHostContext
{
/**
* Constructor DirectMarshalledHostContext
*
* @param threadPool
* @param clientMonitor
* @param connectionPinger
* @param interfacesClassLoader
* @param invocationHandler
*/
public DirectMarshalledHostContext(ThreadPool threadPool,
ClientMonitor clientMonitor,
ConnectionPinger connectionPinger,
ClassLoader interfacesClassLoader,
ServerMarshalledInvocationHandler
invocationHandler)
{
super(
new DirectMarshalledInvocationHandler(
threadPool,
clientMonitor,
connectionPinger,
invocationHandler,
interfacesClassLoader)
);
}
public static class WithSimpleDefaults extends DirectMarshalledHostContext
{
/**
*
* @param invocationHandler
*/
public WithSimpleDefaults(ServerMarshalledInvocationHandler
invocationHandler)
{
super(
new DefaultThreadPool(),
new DumbClientMonitor(),
new NeverConnectionPinger(),
DirectMarshalledHostContext.class.getClassLoader(),
invocationHandler
);
}
}
}
1.1
incubator-altrmi/client/impl/src/java/org/apache/altrmi/client/impl/direct/DirectMarshalledInvocationHandler.java
Index: DirectMarshalledInvocationHandler.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 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 "Incubator", "AltRMI", 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. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.altrmi.client.impl.direct;
import java.io.IOException;
import org.apache.altrmi.common.ConnectionException;
import org.apache.altrmi.common.Reply;
import org.apache.altrmi.common.Request;
import org.apache.altrmi.common.RequestFailedReply;
import org.apache.altrmi.common.SerializationHelper;
import org.apache.altrmi.common.ThreadPool;
import org.apache.altrmi.server.ServerMarshalledInvocationHandler;
import org.apache.altrmi.client.ClientMonitor;
import org.apache.altrmi.client.ConnectionPinger;
/**
* Class DirectInvocationHandler
*
*
* @author Paul Hammant
* @version $Revision: 1.1 $
*/
public final class DirectMarshalledInvocationHandler extends
AbstractDirectInvocationHandler
{
private ServerMarshalledInvocationHandler m_invocationHandler;
private ClassLoader m_interfacesClassLoader;
/**
* Constructor DirectInvocationHandler
*
* @param threadPool
* @param clientMonitor
* @param connectionPinger
* @param invocationHandler
*/
public DirectMarshalledInvocationHandler(ThreadPool threadPool,
ClientMonitor clientMonitor,
ConnectionPinger
connectionPinger,
ServerMarshalledInvocationHandler invocationHandler,
ClassLoader classLoader)
{
super(threadPool, clientMonitor, connectionPinger);
m_invocationHandler = invocationHandler;
m_interfacesClassLoader = classLoader;
}
protected Reply performInvocation( Request request ) throws IOException
{
try
{
byte[] serRequest = SerializationHelper.getBytesFromInstance(
request );
byte[] serReply = m_invocationHandler.handleInvocation(
serRequest, null );
return (Reply)SerializationHelper.getInstanceFromBytes( serReply,
m_interfacesClassLoader );
}
catch( ClassNotFoundException e )
{
e.printStackTrace();
return new RequestFailedReply( "Some Class not found Exception on
server side : "
+ e.getMessage() );
}
}
/**
* Method getInterfacesClassLoader
*
*
* @return
*
*/
public ClassLoader getInterfacesClassLoader()
{
return m_interfacesClassLoader;
}
}
1.1
incubator-altrmi/common/src/java/org/apache/altrmi/common/ClassFoo.java
Index: ClassFoo.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 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 "Incubator", "AltRMI", 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. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.altrmi.common;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
public class ClassFoo {
public static Object instantiate(String className) {
try {
Class clazz = Class.forName(className);
return clazz.newInstance();
} catch (ClassNotFoundException e) {
throw new AltrmiRuntimeException("Class Not Found",e);
} catch (InstantiationException e) {
throw new AltrmiRuntimeException("InstantiationException",e);
} catch (IllegalAccessException e) {
throw new AltrmiRuntimeException("IllegalAccessException",e);
}
}
public static Object instantiate(String className, String param, Object
arg) {
return instantiate(className, new String[] {param}, new Object[]
{arg});
}
public static Object instantiate(String className, String[] params,
Object[] args) {
Class[] paramz = new Class[params.length];
try {
for (int i = 0; i < params.length; i++) {
paramz[i] = Class.forName(params[i]);
}
Class clazz = Class.forName(className);
Constructor ctor = clazz.getConstructor(paramz);
return ctor.newInstance(args);
} catch (ClassNotFoundException e) {
throw new AltrmiRuntimeException("Class Not Found",e);
} catch (InstantiationException e) {
throw new AltrmiRuntimeException("InstantiationException",e);
} catch (IllegalAccessException e) {
throw new AltrmiRuntimeException("IllegalAccessException",e);
} catch (NoSuchMethodException e) {
throw new AltrmiRuntimeException("NoSuchMethodException",e);
} catch (InvocationTargetException e) {
throw new AltrmiRuntimeException("InvocationTargetException",e);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]