You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by vi...@apache.org on 2002/11/01 17:35:43 UTC
cvs commit: jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/impl DefaultMethodInvocationHandler.java
vinayc 2002/11/01 08:35:43
Modified: altrmi/src/java/org/apache/excalibur/altrmi/common
AltrmiRequestConstants.java
AltrmiReplyConstants.java
altrmi/src/java/org/apache/excalibur/altrmi/server/impl/adapters
InvocationHandlerAdapter.java
altrmi/src/java/org/apache/excalibur/altrmi/server/impl
DefaultMethodInvocationHandler.java
Added: altrmi/src/java/org/apache/excalibur/altrmi/common
ListMethodsRequest.java ListMethodsReply.java
altrmi/src/java/org/apache/excalibur/altrmi/client/impl
DynamicStub.java DynamicInvoker.java
DynamicClassAltrmiFactory.java
Log:
Initial commit on providing Stub-less invocation within Altrmi.
This form of invocation removes the need for presence of any
generated stubs at the client(or server) for remote invocation.
Revision Changes Path
1.2 +5 -1 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/common/AltrmiRequestConstants.java
Index: AltrmiRequestConstants.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/common/AltrmiRequestConstants.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AltrmiRequestConstants.java 23 May 2002 21:37:19 -0000 1.1
+++ AltrmiRequestConstants.java 1 Nov 2002 16:35:42 -0000 1.2
@@ -47,4 +47,8 @@
* A request for garbage collection for a finished with proxy
*/
int GCREQUEST = 308;
+ /**
+ * A request for listing the methods within the publishedName
+ */
+ int LISTMETHODSREQUEST=309;
}
1.3 +5 -1 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/common/AltrmiReplyConstants.java
Index: AltrmiReplyConstants.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/common/AltrmiReplyConstants.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AltrmiReplyConstants.java 13 Oct 2002 11:54:26 -0000 1.2
+++ AltrmiReplyConstants.java 1 Nov 2002 16:35:42 -0000 1.3
@@ -96,4 +96,8 @@
* The proxy class could not be retrieved.
*/
int CLASSRETRIEVALFAILEDREPLY = 107;
+ /**
+ * The list of remote methods within the published Object
+ */
+ int LISTMETHODSREPLY=108;
}
1.1 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/common/ListMethodsRequest.java
Index: ListMethodsRequest.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 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 acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", 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 apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* 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.excalibur.altrmi.common;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
/**
* Request the list of remote methods within the published Object.
* @author <a href="mailto:vinayc@apache.org">Vinay Chandrasekharan</a>
*/
public final class ListMethodsRequest extends AltrmiRequest
{
//--------Variables----------//
static final long serialVersionUID = -6277904408381799644L;
/** Name of the published object whose remote methods is sought*/
private String m_publishedName;
//--------Constructors-------//
/**
* Constructor .
* @param publishedName
*/
public ListMethodsRequest(String publishedName)
{
m_publishedName = publishedName;
}
/**
* default constructor needed for externalization
*/
public ListMethodsRequest()
{
}
//--------Methods---------------//
/**
* Get the published objects name
*/
public String getPublishedName()
{
return m_publishedName;
}
//----AltrmiRequest Override--//
/**
* Gets number that represents type for this class.
* This is quicker than instanceof for type checking.
*
* @return the representative code
* @see AltrmiRequestConstants
*
*/
public int getRequestCode()
{
return AltrmiRequestConstants.LISTMETHODSREQUEST;
}
//----Externalizable Overrides---//
/**
* @see java.io.Externalizable#writeExternal(ObjectOutput)
*/
public void writeExternal(ObjectOutput out) throws IOException
{
out.writeObject(m_publishedName);
}
/**
* @see java.io.Externalizable#readExternal(ObjectInput)
*/
public void readExternal(ObjectInput in)
throws IOException, ClassNotFoundException
{
m_publishedName = (String) in.readObject();
}
}
1.1 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/common/ListMethodsReply.java
Index: ListMethodsReply.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 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 acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", 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 apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* 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.excalibur.altrmi.common;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
/**
* Class ListReply
*
*
* @author Vinay Chandrasekharan
* @version $Revision: 1.1 $
*/
public final class ListMethodsReply extends AltrmiReply
{
//-------variables-----------//
static final long serialVersionUID = 42199248686498983L;
/** String array of the methods list of the request publishedObject*/
private String[] m_listOfMethods;
//------Constructors----------//
/**
* Constructor initialized with remote method list of the publishedObject
* @param listOfMethods : list of remote methods exposed by the published Obj
*/
public ListMethodsReply( String[] listOfMethods )
{
m_listOfMethods = listOfMethods;
}
/**
* Default Constructor needed for Externalization
*/
public ListMethodsReply()
{
}
//------Methods--------------//
/**
* Get the list of methods of the publishedObject.
*
* @return the list of methods
*
*/
public String[] getListOfMethods()
{
return m_listOfMethods;
}
//-----AltrmiReply override---//
/**
* Gets number that represents type for this class.
* This is quicker than instanceof for type checking.
*
* @return the representative code
* @see AltrmiReplyConstants
*
*/
public int getReplyCode()
{
return AltrmiReplyConstants.LISTREPLY;
}
//----Externalizable Overrides--//
/**
* @see java.io.Externalizable#writeExternal(ObjectOutput)
*/
public void writeExternal( ObjectOutput out ) throws IOException
{
out.writeObject( m_listOfMethods );
}
/**
* @see java.io.Externalizable#readExternal(ObjectInput)
*/
public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
{
m_listOfMethods = (String[])in.readObject();
}
}
1.11 +57 -30 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/impl/adapters/InvocationHandlerAdapter.java
Index: InvocationHandlerAdapter.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/impl/adapters/InvocationHandlerAdapter.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- InvocationHandlerAdapter.java 20 Oct 2002 19:19:51 -0000 1.10
+++ InvocationHandlerAdapter.java 1 Nov 2002 16:35:42 -0000 1.11
@@ -7,47 +7,49 @@
*/
package org.apache.excalibur.altrmi.server.impl.adapters;
+import java.rmi.server.UID;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector;
-import java.rmi.server.UID;
-
-import org.apache.excalibur.altrmi.server.AltrmiAuthenticator;
-import org.apache.excalibur.altrmi.server.ClassRetrievalException;
-import org.apache.excalibur.altrmi.server.ClassRetriever;
-import org.apache.excalibur.altrmi.server.MethodInvocationHandler;
-import org.apache.excalibur.altrmi.server.impl.AltrmiSession;
-import org.apache.excalibur.altrmi.server.impl.DefaultAuthenticator;
-import org.apache.excalibur.altrmi.server.impl.classretrievers.NoClassRetriever;
+import org.apache.excalibur.altrmi.common.AltrmiAuthenticationException;
+import org.apache.excalibur.altrmi.common.AltrmiInvocationException;
import org.apache.excalibur.altrmi.common.AltrmiInvocationHandler;
import org.apache.excalibur.altrmi.common.AltrmiReply;
+import org.apache.excalibur.altrmi.common.AltrmiReplyConstants;
import org.apache.excalibur.altrmi.common.AltrmiRequest;
-import org.apache.excalibur.altrmi.common.SuspendedReply;
import org.apache.excalibur.altrmi.common.AltrmiRequestConstants;
-import org.apache.excalibur.altrmi.common.OpenConnectionRequest;
-import org.apache.excalibur.altrmi.common.PingReply;
-import org.apache.excalibur.altrmi.common.RequestFailedReply;
-import org.apache.excalibur.altrmi.common.MethodFacadeRequest;
-import org.apache.excalibur.altrmi.common.NotPublishedReply;
+import org.apache.excalibur.altrmi.common.ClassReply;
+import org.apache.excalibur.altrmi.common.ClassRequest;
+import org.apache.excalibur.altrmi.common.ClassRetrievalFailedReply;
import org.apache.excalibur.altrmi.common.ExceptionReply;
-import org.apache.excalibur.altrmi.common.AltrmiInvocationException;
-import org.apache.excalibur.altrmi.common.AltrmiReplyConstants;
-import org.apache.excalibur.altrmi.common.MethodReply;
-import org.apache.excalibur.altrmi.common.MethodFacadeReply;
+import org.apache.excalibur.altrmi.common.GarbageCollectionReply;
+import org.apache.excalibur.altrmi.common.GarbageCollectionRequest;
+import org.apache.excalibur.altrmi.common.ListMethodsReply;
+import org.apache.excalibur.altrmi.common.ListMethodsRequest;
+import org.apache.excalibur.altrmi.common.ListReply;
+import org.apache.excalibur.altrmi.common.LookupReply;
+import org.apache.excalibur.altrmi.common.LookupRequest;
import org.apache.excalibur.altrmi.common.MethodFacadeArrayReply;
+import org.apache.excalibur.altrmi.common.MethodFacadeReply;
+import org.apache.excalibur.altrmi.common.MethodFacadeRequest;
+import org.apache.excalibur.altrmi.common.MethodReply;
import org.apache.excalibur.altrmi.common.MethodRequest;
-import org.apache.excalibur.altrmi.common.LookupRequest;
-import org.apache.excalibur.altrmi.common.AltrmiAuthenticationException;
-import org.apache.excalibur.altrmi.common.LookupReply;
-import org.apache.excalibur.altrmi.common.ClassRequest;
-import org.apache.excalibur.altrmi.common.ClassReply;
-import org.apache.excalibur.altrmi.common.ClassRetrievalFailedReply;
-import org.apache.excalibur.altrmi.common.SameVMReply;
+import org.apache.excalibur.altrmi.common.NotPublishedReply;
import org.apache.excalibur.altrmi.common.OpenConnectionReply;
-import org.apache.excalibur.altrmi.common.ListReply;
-import org.apache.excalibur.altrmi.common.GarbageCollectionRequest;
-import org.apache.excalibur.altrmi.common.GarbageCollectionReply;
+import org.apache.excalibur.altrmi.common.OpenConnectionRequest;
+import org.apache.excalibur.altrmi.common.PingReply;
+import org.apache.excalibur.altrmi.common.RequestFailedReply;
+import org.apache.excalibur.altrmi.common.SameVMReply;
+import org.apache.excalibur.altrmi.common.SuspendedReply;
+import org.apache.excalibur.altrmi.server.AltrmiAuthenticator;
+import org.apache.excalibur.altrmi.server.ClassRetrievalException;
+import org.apache.excalibur.altrmi.server.ClassRetriever;
+import org.apache.excalibur.altrmi.server.MethodInvocationHandler;
+import org.apache.excalibur.altrmi.server.impl.AltrmiSession;
+import org.apache.excalibur.altrmi.server.impl.DefaultAuthenticator;
+import org.apache.excalibur.altrmi.server.impl.DefaultMethodInvocationHandler;
+import org.apache.excalibur.altrmi.server.impl.classretrievers.NoClassRetriever;
/**
* Class InvocationHandlerAdapter
@@ -152,6 +154,10 @@
{
return doListRequest();
}
+ else if(request.getRequestCode()== AltrmiRequestConstants.LISTMETHODSREQUEST)
+ {
+ return doListMethodsRequest(request);
+ }
else
{
return new RequestFailedReply( "Unknown request :" + request.getClass().getName() );
@@ -467,6 +473,27 @@
return new GarbageCollectionReply();
}
+ /**
+ * Do a ListMethods Request
+ * @param request The request
+ * @return The reply
+ */
+ private AltrmiReply doListMethodsRequest( AltrmiRequest request )
+ {
+ ListMethodsRequest lReq = (ListMethodsRequest)request;
+ String publishedThing = lReq.getPublishedName() + "_Main";
+
+ if( !isPublished( publishedThing ) )
+ {
+ return new NotPublishedReply();
+ }
+
+ DefaultMethodInvocationHandler methodInvocationHandler =
+ (DefaultMethodInvocationHandler)getMethodInvocationHandler( publishedThing );
+
+ return new ListMethodsReply(methodInvocationHandler.getListOfMethods());
+ }
+
/**
* Does a session exist
* @param session The session
1.1 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/DynamicStub.java
Index: DynamicStub.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 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 acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", 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 apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* 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.excalibur.altrmi.client.impl;
import org.apache.excalibur.altrmi.client.AltrmiProxy;
/**
* Implementation of AltrmiProxy(client stub) for dynamic invocation.
*
* @author <a href="mailto:vinayc@apache.org">Vinay Chandran</a>
*/
public class DynamicStub implements AltrmiProxy
{
//-------Variables-----------//
/** Name of the published obj for which this is a stub*/
private String m_publishedName;
/** ObjectName of the stub(facades have diff obj names)*/
private String m_objectName;
/** Proxy Helper*/
private DefaultProxyHelper m_proxyHelper;
//-------Constructor--------------//
/**
* Constructor
*/
public DynamicStub(
String publishedName,
String objectName,
DefaultProxyHelper proxyHelper)
{
m_publishedName = publishedName;
m_objectName = objectName;
m_proxyHelper = proxyHelper;
}
//------AltrmiProxy override---------------------//
/**
* @see org.apache.excalibur.altrmi.client.AltrmiProxy#altrmiGetReferenceID(Object)
*/
public Long altrmiGetReferenceID(Object factoryThatIsAsking)
{
return m_proxyHelper.getReferenceID(factoryThatIsAsking);
}
//--------Methods----------------//
/**
* Invoke the method with the given arguments
* (todo: passing the methodSingature is quite clumsy.
* Replace with method name).
* (todo: Remove the Class[] argument).
* (todo: More).
* @param methodSignature the method to invoke
* @param args Argument array
* @param argClasses Classes of the respec parameters
* @return the result of the invocation.
*/
public Object invoke(
String methodSingature,
Object[] args,
Class[] argClasses)
{
try
{
Object retVal =
m_proxyHelper.processObjectRequest(
methodSingature,
args,
argClasses);
return retVal;
}
catch (Throwable t)
{
if (t instanceof RuntimeException)
{
throw (RuntimeException) t;
}
else if (t instanceof Error)
{
throw (Error) t;
}
else
{
t.printStackTrace();
throw new org.apache.excalibur.altrmi.common.
AltrmiInvocationException(
"Should never get here: " + t.getMessage());
}
}
}
}
1.1 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/DynamicInvoker.java
Index: DynamicInvoker.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 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 acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", 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 apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* 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.excalibur.altrmi.client.impl;
import java.util.HashMap;
import java.util.Map;
import org.apache.excalibur.altrmi.client.AltrmiClientInvocationHandler;
import org.apache.excalibur.altrmi.client.AltrmiHostContext;
import org.apache.excalibur.altrmi.common.AltrmiConnectionException;
import org.apache.excalibur.altrmi.common.AltrmiReply;
import org.apache.excalibur.altrmi.common.ListMethodsReply;
import org.apache.excalibur.altrmi.common.ListMethodsRequest;
/**
* DynamicInvoker enables complete dynamic
* invocation of the remote methods ;Its a stubless execution working
* directly with the Altrmi defined request and response messages.
*.
* One creates a DynamicInvoker as follows:
* <code>
* //create custom altrmiHostContext for the specific transport
* AltrmiHostContext arhc;
* arhc = new SocketCustomStreamHostContext("127.0.0.1", 1235);
*
* //Initialize the dynamic invoker
* DynamicInvoker invoker = new DynamicInvoker(arhc);
*
* </code>
* Subsequently client can auto-magically query as well as execute the methods
* on the server without having to bother about the stubs.
* <code>
* //Get the list quotes listed on the stock exchange
* String[] quotes=(String[])invoker.invoke("StockExchange","getQuotes()",null,null);
* </code>
*
*
* @author <a href="mailto:vinayc@apache.org">Vinay Chandran</a>
*/
public class DynamicInvoker
{
//------Variables------------//
/** AltrmiFactory*/
private DynamicClassAltrmiFactory m_factory =
new DynamicClassAltrmiFactory(false);
/** AltrmiHostContext*/
private AltrmiHostContext m_hostContext;
/** AltrmiClientInvocationHandler */
private AltrmiClientInvocationHandler m_clientInvocationHandler;
/** Cache of stubs lookeup by the client*/
private Map m_stubs = new HashMap();
//-------Constructor---------//
/**
* Constructor
* @param altrmiFactory
* @param altrmiHostContext
* @throws Exception
*/
public DynamicInvoker(AltrmiHostContext altrmiHostContext) throws Exception
{
m_hostContext = altrmiHostContext;
//initialize the factory
m_factory.setHostContext(m_hostContext);
//cache the invocationhandler
m_clientInvocationHandler = m_hostContext.getClientInvocationHandler();
}
//--------Methods---------------//
/**
* Close the underlying transport
*/
public void close()
{
m_factory.close();
}
/**
* Retrieve the list of publishedObjects on the server.
* Re-uses the impl within AbstractAltrmiFactory.
*/
public String[] list()
{
return m_factory.list();
}
/** Retrieve the list of remote methods of the given published object
* @param String publishedObject name
* @return String[] list of remote methods
*/
public String[] listOfMethods(String publishedName)
{
AltrmiReply ar =
m_clientInvocationHandler.handleInvocation(
new ListMethodsRequest(publishedName));
if (ar instanceof ListMethodsReply)
{
return ((ListMethodsReply) ar).getListOfMethods();
}
else
{
return new String[0];
}
}
/**
* Invoke the remote method.
*
* Todo: Enable invocation given the ONLY the method name(now entire signature is needed)
* Todo: Remove the need to pass Class[] during invocation.
* Todo: Enable invocations with String array being passed as arguments.
* This would be resolved to their proper type on the server.(using BeanUtils.ConverterUtils)
*
* @param publishedName published objects name
* @param methodName signature of the method (this is quite clumsy)
* @param Object[] arguments to the function
* @param Class[] corresponding classes of the arguments.
* @return Object the return value of the remote call
*/
public Object invoke(
String publishedName,
String methodName,
Object[] args,
Class[] argClasses)
throws AltrmiConnectionException
{
//check the stub cache
DynamicStub stub = (DynamicStub) m_stubs.get(publishedName);
if (stub == null)
{
stub = (DynamicStub) m_factory.lookup(publishedName);
if (stub == null)
{
throw new AltrmiConnectionException(
publishedName + " is NOT published on the server");
}
m_stubs.put(publishedName, stub);
}
if (args == null)
{
args = new Object[0];
}
if (argClasses == null)
{
argClasses = new Class[0];
}
// Regenerate the methodSignature so that its conformant with whats expected
// on the server side.
//Right now the methodSignature that is passed to the server needs to
// be formatted with arguments spaced by commas and a space.
// e,g, hello4(float, double)
methodName = methodName.trim();
// if there are multiple arguments,the space them properly
StringBuffer buf = new StringBuffer(methodName);
for (int i = 0; i < buf.length(); i++)
{
char c = buf.charAt(i);
if (c == ' ')
{
buf.deleteCharAt(i);
i--; // acct for the deletion
}
if (c == ',')
{
buf.insert(i + 1, ' ');
i++;
}
}
methodName = buf.toString();
//invoke the operation on the stub
Object ret = stub.invoke(methodName, args, argClasses);
return ret;
}
}
1.1 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/DynamicClassAltrmiFactory.java
Index: DynamicClassAltrmiFactory.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 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 acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", 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 apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* 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.excalibur.altrmi.client.impl;
import org.apache.excalibur.altrmi.common.AltrmiConnectionException;
/**
* DynamicClassAltrmiFactory creates stubs(@see DynamicStub) for the given
* publishedName at the time of invocation.Using this factory removes the need
* for any compiled stubs corresponding to the remote interface
* to be present on the client side to invoke any remote method on the server.
*
* @author <a href="mailto:vinayc@apache.org">Vinay Chandran</a>
*/
public class DynamicClassAltrmiFactory extends AbstractAltrmiFactory
{
//-------Constructors---------//
/**
* Constructor DynamicClassAltrmiFactory
* @param beanOnly
*/
public DynamicClassAltrmiFactory(boolean beanOnly)
{
super(beanOnly);
}
//-------AbstractAltrmiFactory Overrides------//
/**
* @see org.apache.excalibur.altrmi.client.impl.AbstractAltrmiFactory#getFacadeClass(String, String, boolean)
*/
protected Class getFacadeClass(
String publishedServiceName,
String objectName,
boolean beanOnly)
throws AltrmiConnectionException, ClassNotFoundException
{
//NOT USED
return null;
}
/**
* @see org.apache.excalibur.altrmi.client.impl.AbstractAltrmiFactory#getInstance(String, String, DefaultProxyHelper, boolean)
*/
protected Object getInstance(
String publishedServiceName,
String objectName,
DefaultProxyHelper proxyHelper,
boolean beanOnly)
throws AltrmiConnectionException
{
return new DynamicStub(publishedServiceName,objectName,proxyHelper);
}
/**
* @see org.apache.excalibur.altrmi.client.AltrmiInterfaceLookup#close()
*/
public void close()
{
m_hostContext.getClientInvocationHandler().close();
}
}
1.9 +11 -1 jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/impl/DefaultMethodInvocationHandler.java
Index: DefaultMethodInvocationHandler.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/impl/DefaultMethodInvocationHandler.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- DefaultMethodInvocationHandler.java 20 Oct 2002 19:19:51 -0000 1.8
+++ DefaultMethodInvocationHandler.java 1 Nov 2002 16:35:43 -0000 1.9
@@ -324,4 +324,14 @@
{
return className.replace( '.', '$' );
}
+
+ /**
+ * Get the list of remote method names
+ */
+ public String[] getListOfMethods()
+ {
+ String[] methodNames=(String[])m_methodMap.keySet().toArray(new String[0]);
+ return methodNames;
+ }
+
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>