You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ha...@apache.org on 2002/01/29 11:05:00 UTC
cvs commit: jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test DirectTest.java
hammant 02/01/29 02:05:00
Modified: altrmi/src/java/org/apache/commons/altrmi/server
AltrmiPublisher.java
altrmi/src/java/org/apache/commons/altrmi/server/impl
AbstractServer.java
altrmi/src/java/org/apache/commons/altrmi/server/impl/adapters
InovcationHandlerAdapter.java
altrmi/src/java/org/apache/commons/altrmi/test
DirectTest.java
Added: altrmi/src/java/org/apache/commons/altrmi/server
MethodInvocationHandler.java
altrmi/src/java/org/apache/commons/altrmi/server/impl
DefaultMethodInvocationHandler.java
altrmi/src/java/org/apache/commons/altrmi/server/impl/adapters
PublicationAdapter.java
Removed: altrmi/src/java/org/apache/commons/altrmi/server
ServerInvocationHandler.java
altrmi/src/java/org/apache/commons/altrmi/server/impl
DefaultInvocationHandler.java
Log:
AbstractServer refactored into comps.
Revision Changes Path
1.4 +32 -11 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/AltrmiPublisher.java
Index: AltrmiPublisher.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/AltrmiPublisher.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AltrmiPublisher.java 25 Jan 2002 16:40:13 -0000 1.3
+++ AltrmiPublisher.java 29 Jan 2002 10:05:00 -0000 1.4
@@ -1,3 +1,4 @@
+
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -8,12 +9,16 @@
package org.apache.commons.altrmi.server;
+
+import org.apache.commons.altrmi.common.MethodRequest;
+
+
/**
* Interface AltrmiServer
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
- * @version * $Revision: 1.3 $
+ * @version * $Revision: 1.4 $
*/
public interface AltrmiPublisher {
@@ -26,7 +31,8 @@
* @param classOrInterfaceToExpose
*
*/
- void publish(Object impl, String asName, Class classOrInterfaceToExpose) throws PublicationException;
+ void publish(Object impl, String asName, Class classOrInterfaceToExpose)
+ throws PublicationException;
/**
* Method publish
@@ -38,7 +44,9 @@
* @param additionalFacade
*
*/
- void publish(Object impl, String asName, Class classOrInterfaceToExpose, Class additionalFacade) throws PublicationException;
+ void publish(
+ Object impl, String asName, Class classOrInterfaceToExpose, Class additionalFacade)
+ throws PublicationException;
/**
* Method publish
@@ -50,8 +58,9 @@
* @param additionalFacades
*
*/
- void publish(Object impl, String asName, Class classOrInterfaceToExpose, Class[] additionalFacades) throws PublicationException;
-
+ void publish(
+ Object impl, String asName, Class classOrInterfaceToExpose, Class[] additionalFacades)
+ throws PublicationException;
/**
* Method publish
@@ -62,7 +71,8 @@
* @param classesOrInterfacesToExpose
*
*/
- void publish(Object impl, String asName, Class[] classesOrInterfacesToExpose) throws PublicationException;
+ void publish(Object impl, String asName, Class[] classesOrInterfacesToExpose)
+ throws PublicationException;
/**
* Method publish
@@ -74,8 +84,9 @@
* @param additionalFacades
*
*/
- void publish(Object impl, String asName, Class[] classesOrInterfacesToExpose, Class[] additionalFacades) throws PublicationException;
-
+ void publish(
+ Object impl, String asName, Class[] classesOrInterfacesToExpose,
+ Class[] additionalFacades) throws PublicationException;
/**
* Method unPublish
@@ -96,8 +107,18 @@
* @param withImpl
*
*/
- void replacePublished(Object oldImpl, String asName, Object withImpl) throws PublicationException;
-
-
+ void replacePublished(Object oldImpl, String asName, Object withImpl)
+ throws PublicationException;
+ /**
+ * Method getMethodInvocationHandler
+ *
+ *
+ * @param mr
+ * @param objectName
+ *
+ * @return
+ *
+ */
+ MethodInvocationHandler getMethodInvocationHandler(MethodRequest mr, String objectName);
}
1.1 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/MethodInvocationHandler.java
Index: MethodInvocationHandler.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.commons.altrmi.server;
import org.apache.commons.altrmi.common.AltrmiInvocationHandler;
/**
* Class MethodInvocationHandler
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
* @version $Revision: 1.1 $
*/
public interface MethodInvocationHandler extends AltrmiInvocationHandler {
/**
* Method addImplementationBean
*
*
* @param referenceID
* @param beanImpl
*
*/
void addImplementationBean(Long referenceID, Object beanImpl);
/**
* Method replaceImplementationBean
*
*
* @param implBean
* @param withImplBean
*
*/
void replaceImplementationBean(Object implBean, Object withImplBean);
/**
* Method getOrMakeReferenceIDForBean
*
*
* @param implBean
*
*/
Long getOrMakeReferenceIDForBean(Object implBean);
}
1.17 +107 -215 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/AbstractServer.java
Index: AbstractServer.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/AbstractServer.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- AbstractServer.java 28 Jan 2002 14:19:08 -0000 1.16
+++ AbstractServer.java 29 Jan 2002 10:05:00 -0000 1.17
@@ -8,50 +8,20 @@
*/
package org.apache.commons.altrmi.server.impl;
-
-
-import org.apache.commons.altrmi.server.AltrmiServer;
-import org.apache.commons.altrmi.server.PublicationException;
-import org.apache.commons.altrmi.server.AltrmiServerConnection;
-import org.apache.commons.altrmi.common.AltrmiInvocationHandler;
-import org.apache.commons.altrmi.common.AltrmiRequest;
-import org.apache.commons.altrmi.common.AltrmiReply;
import org.apache.commons.altrmi.common.AbstractMethodHandler;
+import org.apache.commons.altrmi.common.AltrmiReply;
+import org.apache.commons.altrmi.common.AltrmiRequest;
import org.apache.commons.altrmi.common.MethodRequest;
-import org.apache.commons.altrmi.common.ExceptionReply;
-import org.apache.commons.altrmi.common.ClassRequest;
-import org.apache.commons.altrmi.common.AltrmiConnectionException;
-import org.apache.commons.altrmi.common.ClassReply;
-import org.apache.commons.altrmi.common.RequestFailedReply;
-import org.apache.commons.altrmi.common.TryLaterReply;
-import org.apache.commons.altrmi.common.NotPublishedReply;
-import org.apache.commons.altrmi.common.SuspendedReply;
-import org.apache.commons.altrmi.common.LookupRequest;
-import org.apache.commons.altrmi.common.LookupReply;
-import org.apache.commons.altrmi.common.MethodFacadeRequest;
-import org.apache.commons.altrmi.common.MethodFacadeReply;
-import org.apache.commons.altrmi.common.MethodReply;
-import org.apache.commons.altrmi.common.AltrmiAuthenticationException;
-import org.apache.commons.altrmi.common.AltrmiInvocationException;
-import org.apache.commons.altrmi.common.OpenConnectionReply;
-import org.apache.commons.altrmi.common.PingReply;
-import org.apache.commons.altrmi.common.ClassRetrievalFailedReply;
-import org.apache.commons.altrmi.server.ClassRetrievalException;
+import org.apache.commons.altrmi.server.AltrmiServer;
import org.apache.commons.altrmi.server.ClassRetriever;
-import org.apache.commons.altrmi.server.ServerInvocationHandler;
import org.apache.commons.altrmi.server.AltrmiAuthenticator;
-import org.apache.commons.altrmi.server.impl.classretrievers.NoClassRetriever;
+import org.apache.commons.altrmi.server.AltrmiServerConnection;
+import org.apache.commons.altrmi.server.PublicationException;
+import org.apache.commons.altrmi.server.MethodInvocationHandler;
import org.apache.commons.altrmi.server.impl.adapters.InovcationHandlerAdapter;
-import org.apache.commons.altrmi.generator.PrimarySourceGenerator;
-import org.apache.commons.altrmi.generator.SourceGenerationException;
-import org.apache.tools.ant.AntClassLoader;
-
-import java.lang.reflect.Method;
-import java.util.HashMap;
import java.util.Vector;
import java.util.Iterator;
-import java.io.File;
/**
@@ -59,14 +29,11 @@
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
- * @version $Revision: 1.16 $
+ * @version $Revision: 1.17 $
*/
public abstract class AbstractServer extends AbstractMethodHandler implements AltrmiServer {
-
- private HashMap mPublishedObjects = new HashMap();
-
private Vector mConnections = new Vector();
private InovcationHandlerAdapter mInovcationHandlerAdapter;
protected static final int SHUTTINGDOWN = 11;
@@ -76,11 +43,94 @@
protected int mState = UNSTARTED;
public AbstractServer() {
- mInovcationHandlerAdapter = new InovcationHandlerAdapter(mPublishedObjects);
+ mInovcationHandlerAdapter = new InovcationHandlerAdapter();
}
- public HashMap getPublishedObjects() {
- return mPublishedObjects;
+
+
+
+ /**
+ * Method setClassRetriever
+ *
+ *
+ * @param classRetriever
+ *
+ *
+ */
+ public final void setClassRetriever(ClassRetriever classRetriever) {
+ mInovcationHandlerAdapter.setClassRetriever(classRetriever);
+ }
+
+ /**
+ * Method setAuthenticator
+ *
+ *
+ * @param altrmiAuthenticator
+ *
+ *
+ */
+ public final void setAuthenticator(AltrmiAuthenticator altrmiAuthenticator) {
+ mInovcationHandlerAdapter.setAuthenticator(altrmiAuthenticator);
+ }
+
+ /**
+ * Method handleInvocation
+ *
+ *
+ * @param request
+ *
+ * @return
+ *
+ */
+ public AltrmiReply handleInvocation(AltrmiRequest request) {
+
+ return mInovcationHandlerAdapter.handleInvocation(request);
+
+ }
+
+
+
+ /**
+ * Method suspend
+ *
+ */
+ public void suspend() {
+ mInovcationHandlerAdapter.suspend();
+ }
+
+ /**
+ * Method resume
+ *
+ */
+ public void resume() {
+ mInovcationHandlerAdapter.resume();
+ }
+
+ /**
+ * Method connectionStart
+ *
+ */
+ protected void connectionStart(AltrmiServerConnection altrmiConnection) {
+ mConnections.add(altrmiConnection);
+ }
+
+ /**
+ * Method connectionCompleted
+ *
+ */
+ protected void connectionCompleted(AltrmiServerConnection altrmiConnection) {
+ mConnections.remove(altrmiConnection);
+ }
+
+ protected void killAllConnections() {
+
+ Iterator it = mConnections.iterator();
+
+ while (it.hasNext()) {
+ AltrmiServerConnection asc = (AltrmiServerConnection) it.next();
+
+ asc.endConnection();
+ }
}
/**
@@ -94,7 +144,7 @@
*/
public void publish(Object impl, String asName, Class classOrInterfaceToExpose)
throws PublicationException {
- publish(impl, asName, new Class[]{ classOrInterfaceToExpose }, new Class[0]);
+ mInovcationHandlerAdapter.publish(impl,asName,classOrInterfaceToExpose);
}
/**
@@ -109,9 +159,8 @@
*/
public void publish(
Object impl, String asName, Class classOrInterfaceToExpose, Class additionalFacade)
- throws PublicationException {
- publish(impl, asName, new Class[]{ classOrInterfaceToExpose },
- new Class[]{ additionalFacade });
+ throws PublicationException {
+ mInovcationHandlerAdapter.publish(impl,asName,classOrInterfaceToExpose, additionalFacade);
}
/**
@@ -126,8 +175,8 @@
*/
public void publish(
Object impl, String asName, Class classOrInterfaceToExpose, Class[] additionalFacades)
- throws PublicationException {
- publish(impl, asName, new Class[]{ classOrInterfaceToExpose }, additionalFacades);
+ throws PublicationException {
+ mInovcationHandlerAdapter.publish(impl,asName, classOrInterfaceToExpose, additionalFacades);
}
/**
@@ -141,7 +190,7 @@
*/
public void publish(Object impl, String asName, Class[] classesOrInterfacesToExpose)
throws PublicationException {
- publish(impl, asName, classesOrInterfacesToExpose, new Class[0]);
+ mInovcationHandlerAdapter.publish(impl,asName,classesOrInterfacesToExpose);
}
/**
@@ -155,61 +204,9 @@
*
*/
public void publish(
- Object impl, String asName, Class[] classesOrInterfacesToExpose, Class[] additionalFacades)
- throws PublicationException {
-
- if (mPublishedObjects.containsKey(asName + "_Main")) {
- throw new PublicationException("Service '" + asName + "' already published");
- }
-
- String[] interfaceNames = new String[classesOrInterfacesToExpose.length];
-
- for (int i = 0; i < classesOrInterfacesToExpose.length; i++) {
- interfaceNames[i] = classesOrInterfacesToExpose[i].getName();
- }
-
- // add method maps for main lookup-able service.
- HashMap mainMethodMap = new HashMap();
- ServerInvocationHandler mainAsih = new DefaultInvocationHandler(this,
- asName + "_Main", mainMethodMap);
-
- mainAsih.addImplementationBean(new Long(0), impl);
-
- for (int x = 0; x < classesOrInterfacesToExpose.length; x++) {
- Method methods[] = classesOrInterfacesToExpose[x].getMethods();
-
- for (int y = 0; y < methods.length; y++) {
- Method method = methods[y];
- String methodSignature = getMethodSignature(method);
-
- if (!mainMethodMap.containsKey(methodSignature.toString())) {
- mainMethodMap.put(methodSignature.toString(), methods[y]);
- }
- }
- }
-
- // as the main service is lookup-able, it has a prexisting impl.
- mPublishedObjects.put(asName + "_Main", mainAsih);
-
- // add method maps for all the additional facades.
- for (int x = 0; x < additionalFacades.length; x++) {
- Method methods[] = additionalFacades[x].getMethods();
- String encodedClassName = encodeClassName(additionalFacades[x].getName());
- HashMap methodMap = new HashMap();
- ServerInvocationHandler asih = new DefaultInvocationHandler(this,
- asName + "_" + encodedClassName, methodMap);
-
- for (int y = 0; y < methods.length; y++) {
- Method method = methods[y];
- String methodSignature = getMethodSignature(method);
-
- if (!methodMap.containsKey(methodSignature.toString())) {
- methodMap.put(methodSignature.toString(), methods[y]);
- }
- }
-
- mPublishedObjects.put(asName + "_" + encodedClassName, asih);
- }
+ Object impl, String asName, Class[] classesOrInterfacesToExpose,
+ Class[] additionalFacades) throws PublicationException {
+ mInovcationHandlerAdapter.publish(impl, asName, classesOrInterfacesToExpose, additionalFacades);
}
/**
@@ -221,12 +218,7 @@
*
*/
public void unPublish(Object impl, String asName) throws PublicationException {
-
- if (!mPublishedObjects.containsKey(asName + "_Main")) {
- throw new PublicationException("Service '" + asName + "' not published");
- }
-
- mPublishedObjects.remove(asName + "_Main");
+ mInovcationHandlerAdapter.unPublish(impl, asName);
}
/**
@@ -240,103 +232,11 @@
*/
public void replacePublished(Object oldImpl, String asName, Object withImpl)
throws PublicationException {
-
- if (!mPublishedObjects.containsKey(asName + "_Main")) {
- throw new PublicationException("Service '" + asName + "' not published");
- }
-
- ServerInvocationHandler asih =
- (ServerInvocationHandler) mPublishedObjects.get(asName + "_Main");
-
- asih.replaceImplementationBean(oldImpl, withImpl);
+ mInovcationHandlerAdapter.replacePublished(oldImpl, asName, withImpl);
}
/**
- * Method setClassRetriever
- *
- *
- * @param classRetriever
- *
- *
- */
- public final void setClassRetriever(ClassRetriever classRetriever) {
- mInovcationHandlerAdapter.setClassRetriever(classRetriever);
- }
-
- /**
- * Method setAuthenticator
- *
- *
- * @param altrmiAuthenticator
- *
- *
- */
- public final void setAuthenticator(AltrmiAuthenticator altrmiAuthenticator) {
- mInovcationHandlerAdapter.setAuthenticator(altrmiAuthenticator);
- }
-
- /**
- * Method handleInvocation
- *
- *
- * @param request
- *
- * @return
- *
- */
- public AltrmiReply handleInvocation(AltrmiRequest request) {
-
- return mInovcationHandlerAdapter.handleInvocation(request);
-
- }
-
-
-
- /**
- * Method suspend
- *
- */
- public void suspend() {
- mInovcationHandlerAdapter.suspend();
- }
-
- /**
- * Method resume
- *
- */
- public void resume() {
- mInovcationHandlerAdapter.resume();
- }
-
- /**
- * Method connectionStart
- *
- */
- protected void connectionStart(AltrmiServerConnection altrmiConnection) {
- mConnections.add(altrmiConnection);
- }
-
- /**
- * Method connectionCompleted
- *
- */
- protected void connectionCompleted(AltrmiServerConnection altrmiConnection) {
- mConnections.remove(altrmiConnection);
- }
-
- protected void killAllConnections() {
-
- Iterator it = mConnections.iterator();
-
- while (it.hasNext()) {
- AltrmiServerConnection asc = (AltrmiServerConnection) it.next();
-
- asc.endConnection();
- }
- }
-
- /**
- * Method getServerInvocationHandler
+ * Method getMethodInvocationHandler
*
*
* @param mr
@@ -345,15 +245,7 @@
* @return
*
*/
- public ServerInvocationHandler getServerInvocationHandler(MethodRequest mr,
- String objectName) {
- return (ServerInvocationHandler) mPublishedObjects.get(mr.getPublishedServiceName()
- + "_" + objectName);
+ public MethodInvocationHandler getMethodInvocationHandler(MethodRequest mr, String objectName) {
+ return mInovcationHandlerAdapter.getMethodInvocationHandler(mr, objectName);
}
-
-
-
-
-
-
}
1.1 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/DefaultMethodInvocationHandler.java
Index: DefaultMethodInvocationHandler.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.commons.altrmi.server.impl;
import org.apache.commons.altrmi.common.AltrmiReply;
import org.apache.commons.altrmi.common.AltrmiInvocationHandler;
import org.apache.commons.altrmi.common.MethodReply;
import org.apache.commons.altrmi.common.ExceptionReply;
import org.apache.commons.altrmi.common.MethodRequest;
import org.apache.commons.altrmi.common.AltrmiRequest;
import org.apache.commons.altrmi.common.AltrmiInvocationException;
import org.apache.commons.altrmi.common.NoSuchReferenceReply;
import org.apache.commons.altrmi.common.FacadeRefHolder;
import org.apache.commons.altrmi.server.MethodInvocationHandler;
import org.apache.commons.altrmi.server.AltrmiPublisher;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Collection;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import java.io.Serializable;
/**
* Class DefaultMethodInvocationHandler
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
* @version $Revision: 1.1 $
*/
public class DefaultMethodInvocationHandler implements MethodInvocationHandler {
private HashMap mRefBeans = new HashMap();
private HashMap mBeanRefs = new HashMap();
private HashMap mMethodMap;
private int mNextReference = 1;
private AltrmiPublisher mAltrmiPublisher;
private String mPublishedThing;
/**
* Constructor DefaultMethodInvocationHandler
*
*
* @param bean
* @param methodMap
*
*/
public DefaultMethodInvocationHandler(AltrmiPublisher altrmiPublisher, String publishedThing,
HashMap methodMap) {
mAltrmiPublisher = altrmiPublisher;
mPublishedThing = publishedThing;
mMethodMap = methodMap;
}
/**
* Method toString
*
*
* @return
*
*/
public String toString() {
return "DIH:" + mPublishedThing;
}
/**
* Method addImplementationBean
*
*
* @param referenceID
* @param beanImpl
*
*/
public void addImplementationBean(Long referenceID, Object beanImpl) {
mRefBeans.put(referenceID, beanImpl);
mBeanRefs.put(beanImpl, referenceID);
}
/**
* Method replaceImplementationBean
*
*
* @param implBean
* @param withImplBean
*
*/
public void replaceImplementationBean(Object implBean, Object withImplBean) {
Collection coll = mRefBeans.keySet();
for (Iterator iterator = coll.iterator(); iterator.hasNext(); ) {
Long ref = (Long) iterator.next();
if (mRefBeans.get(ref).equals(implBean)) {
mRefBeans.put(ref, withImplBean);
mBeanRefs.remove(implBean);
mBeanRefs.put(withImplBean, ref);
}
}
}
/**
* Method getOrMakeReferenceIDForBean
*
*
* @param implBean
*
*/
public Long getOrMakeReferenceIDForBean(Object implBean) {
Long ref = (Long) mBeanRefs.get(implBean);
if (ref == null) {
ref = new Long((long) ((long) mNextReference++ << 32)
+ (long) Math.round(Math.random()));
mBeanRefs.put(implBean, ref);
mRefBeans.put(ref, implBean);
}
return ref;
}
/**
* Method handleInvocation
*
*
* @param request
*
* @return
*
*/
public AltrmiReply handleInvocation(AltrmiRequest request) {
MethodRequest mr = (MethodRequest) request;
String methodSignature = mr.getMethodSignature();
if (!mMethodMap.containsKey(methodSignature)) {
return new ExceptionReply(
new AltrmiInvocationException("Method not present in impl"));
}
Method method = (Method) mMethodMap.get(methodSignature);
Object rv = null;
try {
Object beanImpl = mRefBeans.get(mr.getReferenceID());
if (beanImpl == null) {
return new NoSuchReferenceReply();
}
Object[] args = mr.getArgs();
correctArgs(mr, args);
return new MethodReply(method.invoke(beanImpl, mr.getArgs()));
} catch (InvocationTargetException ite) {
Throwable t = ite.getTargetException();
if (t instanceof Serializable) {
// NOTE Sever side stack traces will appear on the client side
return new ExceptionReply(t);
} else {
return new ExceptionReply(
new AltrmiInvocationException(
"Exception was not serializable :" + t.getClass().getName()));
}
} catch (Throwable t) {
return new ExceptionReply(
new AltrmiInvocationException(
"Some ServerSide exception problem :" + t.getMessage()));
}
}
private void correctArgs(MethodRequest mr, Object[] args) {
for (int i = 0; i < args.length; i++) {
// TODO find a faster way to do this....
if (args[i] instanceof FacadeRefHolder) {
FacadeRefHolder frh = (FacadeRefHolder) args[i];
DefaultMethodInvocationHandler asih =
(DefaultMethodInvocationHandler) mAltrmiPublisher.getMethodInvocationHandler(mr,
frh.getObjectName());
args[i] = asih.mRefBeans.get(frh.getReferenceID());
}
}
}
}
1.3 +7 -22 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/adapters/InovcationHandlerAdapter.java
Index: InovcationHandlerAdapter.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/adapters/InovcationHandlerAdapter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- InovcationHandlerAdapter.java 28 Jan 2002 14:19:08 -0000 1.2
+++ InovcationHandlerAdapter.java 29 Jan 2002 10:05:00 -0000 1.3
@@ -30,7 +30,7 @@
import org.apache.commons.altrmi.common.OpenConnectionReply;
import org.apache.commons.altrmi.common.PingReply;
import org.apache.commons.altrmi.server.AltrmiServer;
-import org.apache.commons.altrmi.server.ServerInvocationHandler;
+import org.apache.commons.altrmi.server.MethodInvocationHandler;
import org.apache.commons.altrmi.server.ClassRetrievalException;
import org.apache.commons.altrmi.server.ClassRetriever;
import org.apache.commons.altrmi.server.AltrmiAuthenticator;
@@ -47,9 +47,9 @@
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
-public class InovcationHandlerAdapter implements AltrmiInvocationHandler {
+public class InovcationHandlerAdapter extends PublicationAdapter implements AltrmiInvocationHandler {
private static int SESSION = 0;
private Long mLastSession = new Long(0);
@@ -58,22 +58,7 @@
private ClassRetriever mClassRetriever = new NoClassRetriever();
private AltrmiAuthenticator mAltrmiAuthenticator = new DefaultAuthenticator();
- private HashMap mPublishedObjects;
- /**
- * Constructor InovcationHandlerAdapter
- *
- *
- * @param publishedObjects
- *
- */
- public InovcationHandlerAdapter(HashMap publishedObjects) {
- mPublishedObjects = publishedObjects;
- }
-
- public InovcationHandlerAdapter(AbstractServer abstractServer) {
- this(abstractServer.getPublishedObjects());
- }
public final void setClassRetriever(ClassRetriever classRetriever) {
mClassRetriever = classRetriever;
@@ -125,8 +110,8 @@
new AltrmiInvocationException("TODO - you dirty rat/hacker"));
}
- ServerInvocationHandler asih =
- (ServerInvocationHandler) mPublishedObjects.get(publishedThing);
+ MethodInvocationHandler asih =
+ (MethodInvocationHandler) mPublishedObjects.get(publishedThing);
AltrmiReply ar = asih.handleInvocation(mr);
if (ar.getReplyCode() == AltrmiReply.EXCEPTIONREPLY) {
@@ -138,8 +123,8 @@
}
Object beanImpl = ((MethodReply) ar).getReplyObject();
- ServerInvocationHandler asih2 =
- (ServerInvocationHandler) mPublishedObjects
+ MethodInvocationHandler asih2 =
+ (MethodInvocationHandler) mPublishedObjects
.get(mr.getPublishedServiceName() + "_" + mr.getReturnClassNameEncoded());
if (asih2 == null) {
1.1 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/adapters/PublicationAdapter.java
Index: PublicationAdapter.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.commons.altrmi.server.impl.adapters;
import org.apache.commons.altrmi.server.AltrmiPublisher;
import org.apache.commons.altrmi.server.PublicationException;
import org.apache.commons.altrmi.server.MethodInvocationHandler;
import org.apache.commons.altrmi.server.impl.DefaultMethodInvocationHandler;
import org.apache.commons.altrmi.common.AbstractMethodHandler;
import org.apache.commons.altrmi.common.MethodRequest;
import java.util.HashMap;
import java.lang.reflect.Method;
public class PublicationAdapter extends AbstractMethodHandler implements AltrmiPublisher {
protected HashMap mPublishedObjects = new HashMap();
/**
* Method publish
*
*
* @param impl
* @param asName
* @param classOrInterfaceToExpose
*
*/
public void publish(Object impl, String asName, Class classOrInterfaceToExpose)
throws PublicationException {
publish(impl, asName, new Class[]{ classOrInterfaceToExpose }, new Class[0]);
}
/**
* Method publish
*
*
* @param impl
* @param asName
* @param classOrInterfaceToExpose
* @param additionalFacade
*
*/
public void publish(
Object impl, String asName, Class classOrInterfaceToExpose, Class additionalFacade)
throws PublicationException {
publish(impl, asName, new Class[]{ classOrInterfaceToExpose },
new Class[]{ additionalFacade });
}
/**
* Method publish
*
*
* @param impl
* @param asName
* @param classOrInterfaceToExpose
* @param additionalFacades
*
*/
public void publish(
Object impl, String asName, Class classOrInterfaceToExpose, Class[] additionalFacades)
throws PublicationException {
publish(impl, asName, new Class[]{ classOrInterfaceToExpose }, additionalFacades);
}
/**
* Method publish
*
*
* @param impl
* @param asName
* @param classesOrInterfacesToExpose
*
*/
public void publish(Object impl, String asName, Class[] classesOrInterfacesToExpose)
throws PublicationException {
publish(impl, asName, classesOrInterfacesToExpose, new Class[0]);
}
/**
* Method publish
*
*
* @param impl
* @param asName
* @param classesOrInterfacesToExpose
* @param additionalFacades
*
*/
public void publish(
Object impl, String asName, Class[] classesOrInterfacesToExpose, Class[] additionalFacades)
throws PublicationException {
if (mPublishedObjects.containsKey(asName + "_Main")) {
throw new PublicationException("Service '" + asName + "' already published");
}
String[] interfaceNames = new String[classesOrInterfacesToExpose.length];
for (int i = 0; i < classesOrInterfacesToExpose.length; i++) {
interfaceNames[i] = classesOrInterfacesToExpose[i].getName();
}
// add method maps for main lookup-able service.
HashMap mainMethodMap = new HashMap();
MethodInvocationHandler mainAsih = new DefaultMethodInvocationHandler(this, asName + "_Main", mainMethodMap);
mainAsih.addImplementationBean(new Long(0), impl);
for (int x = 0; x < classesOrInterfacesToExpose.length; x++) {
Method methods[] = classesOrInterfacesToExpose[x].getMethods();
for (int y = 0; y < methods.length; y++) {
Method method = methods[y];
String methodSignature = getMethodSignature(method);
if (!mainMethodMap.containsKey(methodSignature.toString())) {
mainMethodMap.put(methodSignature.toString(), methods[y]);
}
}
}
// as the main service is lookup-able, it has a prexisting impl.
mPublishedObjects.put(asName + "_Main", mainAsih);
// add method maps for all the additional facades.
for (int x = 0; x < additionalFacades.length; x++) {
Method methods[] = additionalFacades[x].getMethods();
String encodedClassName = encodeClassName(additionalFacades[x].getName());
HashMap methodMap = new HashMap();
MethodInvocationHandler asih = new DefaultMethodInvocationHandler(this, asName + "_" + encodedClassName, methodMap);
for (int y = 0; y < methods.length; y++) {
Method method = methods[y];
String methodSignature = getMethodSignature(method);
if (!methodMap.containsKey(methodSignature.toString())) {
methodMap.put(methodSignature.toString(), methods[y]);
}
}
mPublishedObjects.put(asName + "_" + encodedClassName, asih);
}
}
/**
* Method unPublish
*
*
* @param impl
* @param asName
*
*/
public void unPublish(Object impl, String asName) throws PublicationException {
if (!mPublishedObjects.containsKey(asName + "_Main")) {
throw new PublicationException("Service '" + asName + "' not published");
}
mPublishedObjects.remove(asName + "_Main");
}
/**
* Method replacePublished
*
*
* @param oldImpl
* @param asName
* @param withImpl
*
*/
public void replacePublished(Object oldImpl, String asName, Object withImpl)
throws PublicationException {
if (!mPublishedObjects.containsKey(asName + "_Main")) {
throw new PublicationException("Service '" + asName + "' not published");
}
MethodInvocationHandler asih =
(MethodInvocationHandler) mPublishedObjects.get(asName + "_Main");
asih.replaceImplementationBean(oldImpl, withImpl);
}
/**
* Method getServerInvocationHandler
*
*
* @param mr
* @param objectName
*
* @return
*
*/
public MethodInvocationHandler getMethodInvocationHandler(MethodRequest mr,
String objectName) {
return (MethodInvocationHandler) mPublishedObjects.get(mr.getPublishedServiceName()
+ "_" + objectName);
}
}
1.9 +3 -3 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/DirectTest.java
Index: DirectTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/DirectTest.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- DirectTest.java 28 Jan 2002 14:04:55 -0000 1.8
+++ DirectTest.java 29 Jan 2002 10:05:00 -0000 1.9
@@ -28,7 +28,7 @@
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
- * @version $Revision: 1.8 $
+ * @version $Revision: 1.9 $
*/
public class DirectTest {
@@ -58,7 +58,7 @@
ds.publish(ti, "Hello", TestInterface.class, TestInterface2.class);
ds.start();
- DirectTestClient dtc = new DirectTestClient(new InovcationHandlerAdapter(ds));
+ DirectTestClient dtc = new DirectTestClient(ds);
Thread thread = new Thread(dtc);
thread.start();
@@ -69,7 +69,7 @@
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
- * @version $Revision: 1.8 $
+ * @version $Revision: 1.9 $
*/
static class DirectTestClient implements Runnable {
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>