[prev in list] [next in list] [prev in thread] [next in thread]
List: incubator-cvs
Subject: cvs commit: incubator-altrmi/src/test/org/apache/altrmi/test/clientcontext Account.java AccountImpl.
From: hammant () apache ! org
Date: 2003-05-05 21:11:21
[Download RAW message or body]
hammant 2003/05/05 14:11:20
Modified: . base.xml build.xml
src/java/org/apache/altrmi/client ProxyHelper.java
src/java/org/apache/altrmi/client/impl
DefaultProxyHelper.java
src/java/org/apache/altrmi/common MethodAsyncRequest.java
MethodRequest.java PublishedNameRequest.java
src/java/org/apache/altrmi/server Server.java
src/java/org/apache/altrmi/server/impl AbstractServer.java
src/java/org/apache/altrmi/server/impl/adapters
InvocationHandlerAdapter.java
src/test/org/apache/altrmi/test AbstractHelloTestCase.java
Added: src/java/org/apache/altrmi/client ClientContextFactory.java
src/java/org/apache/altrmi/client/impl
DefaultClientContextFactory.java
src/java/org/apache/altrmi/common ClientContext.java
Contextualizable.java DefaultClientContext.java
src/java/org/apache/altrmi/server
ServerSideClientContextFactory.java
src/java/org/apache/altrmi/server/impl
DefaultServerSideClientContext.java
DefaultServerSideClientContextFactory.java
src/test/org/apache/altrmi/test/clientcontext Account.java
AccountImpl.java AccountListener.java
AccountManager.java AccountManagerImpl.java
ClientContextTestCase.java CreditBarfed.java
DebitBarfed.java TestClientContext.java
TestClientContextFactory.java TransferBarfed.java
Log:
First cut of client context. This can be leveraged for TXN capability.
Revision Changes Path
1.3 +42 -23 incubator-altrmi/base.xml
Index: base.xml
===================================================================
RCS file: /home/cvs/incubator-altrmi/base.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- base.xml 22 Feb 2003 14:53:51 -0000 1.2
+++ base.xml 5 May 2003 21:11:19 -0000 1.3
@@ -12,14 +12,14 @@
<!-- The base directory for compilation targets -->
- <property name="build.home" value="build"/>
+ <property name="build.dir" value="build"/>
<!-- ========== Compiler Defaults ========================================= -->
<!-- Construct compile classpath -->
<path id="compile.classpath">
- <pathelement location="${build.home}/classes"/>
+ <pathelement location="${build.dir}/classes"/>
<pathelement location="${jakarta-commons-attributes.jar}"/>
<pathelement location="${jakarta-commons-logging.jar}"/>
<pathelement location="${jakarta-bcel.jar}"/>
@@ -34,64 +34,83 @@
<target name="prepare"
description="Prepare build directory">
- <mkdir dir="${build.home}"/>
- <mkdir dir="${build.home}/genclasses"/>
+ <mkdir dir="${build.dir}"/>
+ <mkdir dir="${build.dir}/genclasses"/>
<delete>
- <fileset dir="${build.home}/genclasses" includes="*" defaultexcludes="no"/>
+ <fileset dir="${build.dir}/genclasses" includes="*" defaultexcludes="no"/>
</delete>
- <mkdir dir="${build.home}/genjava"/>
+ <mkdir dir="${build.dir}/genjava"/>
<delete>
- <fileset dir="${build.home}/genjava" includes="*" defaultexcludes="no"/>
+ <fileset dir="${build.dir}/genjava" includes="*" defaultexcludes="no"/>
</delete>
</target>
<target name="generate" depends="prepare">
- <altrmiproxies genname="Hello" srcgendir="${build.home}/genjava"
- classgendir="${build.home}/genclasses" verbose="true"
+ <altrmiproxies genname="Hello" srcgendir="${build.dir}/genjava"
+ classgendir="${build.dir}/genclasses" verbose="true"
interfaces="org.apache.altrmi.test.TestInterface"
additionalfacades="org.apache.altrmi.test.TestInterface3,org.apache.altrmi.test.TestInterface2"
callbackfacades="org.apache.altrmi.test.TestCallBackListener">
<classpath>
- <pathelement location="${build.home}/classes"/>
- <pathelement location="${build.home}/testclasses"/>
+ <pathelement location="${build.dir}/classes"/>
+ <pathelement location="${build.dir}/testclasses"/>
</classpath>
</altrmiproxies>
- <altrmiproxies genname="CallbackEnabledCustomStreamTestCase" \
srcgendir="${build.home}/genjava"
- classgendir="${build.home}/genclasses" verbose="true"
+ <altrmiproxies genname="CallbackEnabledCustomStreamTestCase" \
srcgendir="${build.dir}/genjava" + classgendir="${build.dir}/genclasses" \
verbose="true" interfaces="org.apache.altrmi.test.TestCallBackListener">
<classpath>
- <pathelement location="${build.home}/classes"/>
- <pathelement location="${build.home}/testclasses"/>
+ <pathelement location="${build.dir}/classes"/>
+ <pathelement location="${build.dir}/testclasses"/>
</classpath>
</altrmiproxies>
+ <altrmiproxies genname="OurAccountManager" srcgendir="${build.dir}/genjava"
+ classgendir="${build.dir}/genclasses" verbose="true"
+ interfaces="org.apache.altrmi.test.clientcontext.AccountManager">
+ <classpath>
+ <pathelement location="${build.dir}/classes"/>
+ <pathelement location="${build.dir}/testclasses"/>
+ </classpath>
+ </altrmiproxies>
+
</target>
<target name="generate-bcel" depends="prepare">
<echo>-${jakarta-bcel.jar}-</echo>
- <altrmiproxies genname="Hello" srcgendir="${build.home}/genjava"
- classgendir="${build.home}/genclasses" verbose="true"
+ <altrmiproxies genname="Hello" srcgendir="${build.dir}/genjava"
+ classgendir="${build.dir}/genclasses" verbose="true"
interfaces="org.apache.altrmi.test.TestInterface"
additionalfacades="org.apache.altrmi.test.TestInterface3,org.apache.altrmi.test.TestInterface2"
callbackfacades="org.apache.altrmi.test.TestCallBackListener"
generatorclass="org.apache.altrmi.generator.BCELProxyGeneratorImpl">
<classpath>
- <pathelement location="${build.home}/classes"/>
- <pathelement location="${build.home}/testclasses"/>
+ <pathelement location="${build.dir}/classes"/>
+ <pathelement location="${build.dir}/testclasses"/>
</classpath>
</altrmiproxies>
- <altrmiproxies genname="CallbackEnabledCustomStreamTestCase" \
srcgendir="${build.home}/genjava"
- classgendir="${build.home}/genclasses" verbose="true"
+ <altrmiproxies genname="CallbackEnabledCustomStreamTestCase" \
srcgendir="${build.dir}/genjava" + classgendir="${build.dir}/genclasses" \
verbose="true" interfaces="org.apache.altrmi.test.TestCallBackListener"
generatorclass="org.apache.altrmi.generator.BCELProxyGeneratorImpl">
<classpath>
- <pathelement location="${build.home}/classes"/>
- <pathelement location="${build.home}/testclasses"/>
+ <pathelement location="${build.dir}/classes"/>
+ <pathelement location="${build.dir}/testclasses"/>
+ </classpath>
+ </altrmiproxies>
+
+ <altrmiproxies genname="OurAccountManager" srcgendir="${build.dir}/genjava"
+ classgendir="${build.dir}/genclasses" verbose="true"
+ interfaces="org.apache.altrmi.test.clientcontext.AccountManager"
+ generatorclass="org.apache.altrmi.generator.BCELProxyGeneratorImpl">
+ <classpath>
+ <pathelement location="${build.dir}/classes"/>
+ <pathelement location="${build.dir}/testclasses"/>
</classpath>
</altrmiproxies>
1.17 +1 -0 incubator-altrmi/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/incubator-altrmi/build.xml,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- build.xml 4 May 2003 17:40:25 -0000 1.16
+++ build.xml 5 May 2003 21:11:19 -0000 1.17
@@ -372,6 +372,7 @@
<include name="**/${test.filter}.class"/>
<exclude name="**/Abstract*"/>
<exclude name="**/JSXObjectStreamTestCase.class"/>
+ <exclude name="**/BetwixtTestCase.class"/>
</fileset>
</batchtest>
</junit>
1.3 +4 -1 \
incubator-altrmi/src/java/org/apache/altrmi/client/ProxyHelper.java
Index: ProxyHelper.java
===================================================================
RCS file: /home/cvs/incubator-altrmi/src/java/org/apache/altrmi/client/ProxyHelper.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ProxyHelper.java 17 Feb 2003 20:27:40 -0000 1.2
+++ ProxyHelper.java 5 May 2003 21:11:19 -0000 1.3
@@ -147,4 +147,7 @@
boolean isEquals(Object o1, Object o2);
+ void setClientContextClientFactory(ClientContextFactory \
clientContextClientFactory); +
+
}
1.1 \
incubator-altrmi/src/java/org/apache/altrmi/client/ClientContextFactory.java
Index: ClientContextFactory.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 apache@apache.org.
*
* 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;
import org.apache.altrmi.common.ClientContext;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public interface ClientContextFactory
{
ClientContext getClientContext();
}
1.4 +33 -11 \
incubator-altrmi/src/java/org/apache/altrmi/client/impl/DefaultProxyHelper.java
Index: DefaultProxyHelper.java
===================================================================
RCS file: /home/cvs/incubator-altrmi/src/java/org/apache/altrmi/client/impl/DefaultProxyHelper.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DefaultProxyHelper.java 20 Feb 2003 07:36:57 -0000 1.3
+++ DefaultProxyHelper.java 5 May 2003 21:11:19 -0000 1.4
@@ -54,27 +54,29 @@
*/
package org.apache.altrmi.client.impl;
-import org.apache.altrmi.client.ClientInvocationHandler;
-import org.apache.altrmi.client.Proxy;
import org.apache.altrmi.client.ProxyHelper;
+import org.apache.altrmi.client.ClientInvocationHandler;
+import org.apache.altrmi.client.ClientContextFactory;
import org.apache.altrmi.client.InvocationException;
+import org.apache.altrmi.client.Proxy;
import org.apache.altrmi.client.NoSuchSessionException;
import org.apache.altrmi.client.NoSuchReferenceException;
-import org.apache.altrmi.common.Reply;
+import org.apache.altrmi.common.MethodFacadeReply;
import org.apache.altrmi.common.ReplyConstants;
-import org.apache.altrmi.common.ExceptionReply;
-import org.apache.altrmi.common.GarbageCollectionReply;
-import org.apache.altrmi.common.GarbageCollectionRequest;
-import org.apache.altrmi.common.MethodAsyncRequest;
import org.apache.altrmi.common.MethodFacadeArrayReply;
-import org.apache.altrmi.common.MethodFacadeReply;
-import org.apache.altrmi.common.MethodFacadeRequest;
-import org.apache.altrmi.common.MethodReply;
import org.apache.altrmi.common.MethodRequest;
+import org.apache.altrmi.common.Reply;
+import org.apache.altrmi.common.MethodReply;
import org.apache.altrmi.common.RawRequest;
+import org.apache.altrmi.common.MethodAsyncRequest;
+import org.apache.altrmi.common.ExceptionReply;
import org.apache.altrmi.common.NoSuchSessionReply;
import org.apache.altrmi.common.NoSuchReferenceReply;
import org.apache.altrmi.common.InvocationExceptionReply;
+import org.apache.altrmi.common.GarbageCollectionRequest;
+import org.apache.altrmi.common.GarbageCollectionReply;
+import org.apache.altrmi.common.PublishedNameRequest;
+import org.apache.altrmi.common.MethodFacadeRequest;
import java.lang.reflect.Array;
import java.util.Vector;
@@ -96,6 +98,7 @@
private final transient String m_objectName;
private final transient Long m_referenceID;
private final transient Long m_session;
+ private ClientContextFactory m_clientContextClientFactory;
/**
@@ -189,6 +192,7 @@
m_session );
}
+ setContext(request);
Reply reply = m_clientInvocationHandler.handleInvocation( request );
if( reply.getReplyCode() == ReplyConstants.METHODFACADEREPLY )
@@ -302,6 +306,7 @@
MethodRequest request = new MethodRequest( m_publishedServiceName, \
m_objectName,
methodSignature, args, \
m_referenceID, m_session ); + setContext(request);
Reply reply = m_clientInvocationHandler.handleInvocation( request );
if( reply.getReplyCode() == ReplyConstants.METHODREPLY )
@@ -333,6 +338,7 @@
rawRequests, m_referenceID, \
m_session );
//debug(args);
+ setContext(request);
Reply reply = m_clientInvocationHandler.handleInvocation( request );
if( reply.getReplyCode() == ReplyConstants.METHODREPLY )
@@ -371,6 +377,7 @@
methodSignature, args, \
m_referenceID, m_session );
//debug(args);
+ setContext(request);
Reply reply = m_clientInvocationHandler.handleInvocation( request );
if( reply.getReplyCode() == ReplyConstants.METHODREPLY )
@@ -534,4 +541,19 @@
}
super.finalize();
}
+
+ public void setClientContextClientFactory(ClientContextFactory \
clientContextClientFactory) { + m_clientContextClientFactory = \
clientContextClientFactory; + }
+
+ private synchronized void setContext(PublishedNameRequest request) {
+
+ if (m_clientContextClientFactory == null) {
+ m_clientContextClientFactory = new DefaultClientContextFactory();
+ }
+ request.setContext(m_clientContextClientFactory.getClientContext());
+
+ }
+
+
}
1.1 \
incubator-altrmi/src/java/org/apache/altrmi/client/impl/DefaultClientContextFactory.java
Index: DefaultClientContextFactory.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 apache@apache.org.
*
* 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;
import org.apache.altrmi.client.ClientContextFactory;
import org.apache.altrmi.common.ClientContext;
import org.apache.altrmi.common.DefaultClientContext;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public class DefaultClientContextFactory implements ClientContextFactory
{
// The next serial number to be assigned
private static long nextSerialNum = 0;
private static ThreadLocal serialContext = new ThreadLocal()
{
protected synchronized Object initialValue()
{
return new DefaultClientContext( nextSerialNum++ );
}
};
public static ClientContext get()
{
return ( ClientContext ) ( serialContext.get() );
}
public ClientContext getClientContext()
{
return get();
}
}
1.3 +2 -2 \
incubator-altrmi/src/java/org/apache/altrmi/common/MethodAsyncRequest.java
Index: MethodAsyncRequest.java
===================================================================
RCS file: /home/cvs/incubator-altrmi/src/java/org/apache/altrmi/common/MethodAsyncRequest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MethodAsyncRequest.java 17 Feb 2003 20:28:07 -0000 1.2
+++ MethodAsyncRequest.java 5 May 2003 21:11:19 -0000 1.3
@@ -65,7 +65,7 @@
* @author Paul Hammant
* @version $Revision$
*/
-public class MethodAsyncRequest extends PublishedNameRequest implements \
Sessionable +public class MethodAsyncRequest extends PublishedNameRequest implements \
Contextualizable {
static final long serialVersionUID = -5928783250529633953L;
1.4 +2 -2 \
incubator-altrmi/src/java/org/apache/altrmi/common/MethodRequest.java
Index: MethodRequest.java
===================================================================
RCS file: /home/cvs/incubator-altrmi/src/java/org/apache/altrmi/common/MethodRequest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MethodRequest.java 17 Feb 2003 20:28:36 -0000 1.3
+++ MethodRequest.java 5 May 2003 21:11:19 -0000 1.4
@@ -65,7 +65,7 @@
* @author Paul Hammant
* @version $Revision$
*/
-public class MethodRequest extends PublishedNameRequest implements Sessionable
+public class MethodRequest extends PublishedNameRequest implements \
Contextualizable {
static final long serialVersionUID = -4850912985882914299L;
1.4 +13 -1 \
incubator-altrmi/src/java/org/apache/altrmi/common/PublishedNameRequest.java
Index: PublishedNameRequest.java
===================================================================
RCS file: /home/cvs/incubator-altrmi/src/java/org/apache/altrmi/common/PublishedNameRequest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PublishedNameRequest.java 17 Feb 2003 20:28:36 -0000 1.3
+++ PublishedNameRequest.java 5 May 2003 21:11:19 -0000 1.4
@@ -57,6 +57,7 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
+import java.io.Serializable;
/**
* Class PublishedNameRequest
@@ -71,6 +72,7 @@
private String m_publishedServiceName;
private String m_objectName;
+ private ClientContext m_context;
/**
* Constructor PublishedNameRequest
@@ -87,6 +89,14 @@
m_objectName = objectName;
}
+ public void setContext(ClientContext context) {
+ m_context = context;
+ }
+
+ public ClientContext getContext() {
+ return m_context;
+ }
+
/**
* Constructor PublishedNameRequest for Externalization
*
@@ -139,6 +149,7 @@
{
out.writeObject( m_publishedServiceName );
out.writeObject( m_objectName );
+ out.writeObject( m_context );
}
/**
@@ -157,5 +168,6 @@
{
m_publishedServiceName = (String)in.readObject();
m_objectName = (String)in.readObject();
+ m_context = (ClientContext) in.readObject();
}
}
1.1 \
incubator-altrmi/src/java/org/apache/altrmi/common/ClientContext.java
Index: ClientContext.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 apache@apache.org.
*
* 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.io.Serializable;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public interface ClientContext extends Serializable
{
}
1.1 \
incubator-altrmi/src/java/org/apache/altrmi/common/Contextualizable.java
Index: Contextualizable.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 apache@apache.org.
*
* 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;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public interface Contextualizable extends Sessionable
{
ClientContext getContext();
void setContext(ClientContext serializable);
}
1.1 \
incubator-altrmi/src/java/org/apache/altrmi/common/DefaultClientContext.java
Index: DefaultClientContext.java
===================================================================
package org.apache.altrmi.common;
import org.apache.altrmi.common.ClientContext;
import java.io.Externalizable;
import java.io.ObjectOutput;
import java.io.IOException;
import java.io.ObjectInput;
public class DefaultClientContext implements ClientContext, Externalizable
{
private long contextSeq;
private int hashCode;
public DefaultClientContext( long contextSeq )
{
this.contextSeq = contextSeq;
setConstants();
}
// for externalization.
public DefaultClientContext()
{
}
private void setConstants()
{
hashCode = new Long(contextSeq).hashCode();
}
public int hashCode()
{
return hashCode;
}
public boolean equals( Object obj )
{
if (!(obj instanceof DefaultClientContext))
{
return false;
}
else
{
return contextSeq == ((DefaultClientContext) obj).contextSeq;
}
}
public String toString()
{
return "DefaultClientContext:" + contextSeq;
}
public void writeExternal( ObjectOutput out ) throws IOException
{
out.writeLong(contextSeq);
}
public void readExternal( ObjectInput in ) throws IOException, \
ClassNotFoundException {
contextSeq = in.readLong();
setConstants();
}
}
1.4 +3 -1 incubator-altrmi/src/java/org/apache/altrmi/server/Server.java
Index: Server.java
===================================================================
RCS file: /home/cvs/incubator-altrmi/src/java/org/apache/altrmi/server/Server.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Server.java 17 Feb 2003 20:28:38 -0000 1.3
+++ Server.java 5 May 2003 21:11:19 -0000 1.4
@@ -135,4 +135,6 @@
*
*/
void stop();
+
+ void setClientContextFactory(ServerSideClientContextFactory \
clientContextFactory); }
1.1 \
incubator-altrmi/src/java/org/apache/altrmi/server/ServerSideClientContextFactory.java
Index: ServerSideClientContextFactory.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 apache@apache.org.
*
* 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.server;
import org.apache.altrmi.common.ClientContext;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public interface ServerSideClientContextFactory {
ClientContext get();
void set(Long session, ClientContext clientContext);
boolean isSet();
}
1.4 +13 -10 \
incubator-altrmi/src/java/org/apache/altrmi/server/impl/AbstractServer.java
Index: AbstractServer.java
===================================================================
RCS file: /home/cvs/incubator-altrmi/src/java/org/apache/altrmi/server/impl/AbstractServer.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AbstractServer.java 26 Mar 2003 20:23:03 -0000 1.3
+++ AbstractServer.java 5 May 2003 21:11:19 -0000 1.4
@@ -59,17 +59,9 @@
import org.apache.altrmi.common.Request;
import org.apache.altrmi.common.MethodRequest;
import org.apache.altrmi.common.ThreadPool;
-import org.apache.altrmi.common.ThreadContext;
import org.apache.altrmi.common.DefaultThreadPool;
import org.apache.altrmi.common.ThreadPoolAware;
-import org.apache.altrmi.server.Authenticator;
-import org.apache.altrmi.server.Server;
-import org.apache.altrmi.server.ServerConnection;
-import org.apache.altrmi.server.ClassRetriever;
-import org.apache.altrmi.server.MethodInvocationHandler;
-import org.apache.altrmi.server.PublicationDescription;
-import org.apache.altrmi.server.PublicationException;
-import org.apache.altrmi.server.ServerMonitor;
+import org.apache.altrmi.server.*;
import org.apache.altrmi.server.impl.adapters.InvocationHandlerAdapter;
/**
@@ -101,6 +93,7 @@
private ServerMonitor m_serverMonitor;
private ThreadPool m_threadPool;
+ private ServerSideClientContextFactory m_clientContextFactory;
/**
* Construct a AbstractServer
@@ -357,4 +350,14 @@
{
return m_state;
}
+
+ public void setClientContextFactory(ServerSideClientContextFactory \
clientContextFactory) { + m_clientContextFactory = clientContextFactory;
+ }
+
+ protected ServerSideClientContextFactory getClientContextFactory() {
+ return m_clientContextFactory;
+ }
+
+
}
1.1 \
incubator-altrmi/src/java/org/apache/altrmi/server/impl/DefaultServerSideClientContext.java
Index: DefaultServerSideClientContext.java
===================================================================
package org.apache.altrmi.server.impl;
import org.apache.altrmi.common.ClientContext;
public class DefaultServerSideClientContext implements ClientContext
{
private Long session;
private ClientContext clientSideClientContext;
private int hashCode;
public DefaultServerSideClientContext( Long session, ClientContext \
clientSideClientContext ) {
this.session = session;
this.clientSideClientContext = clientSideClientContext;
hashCode = session.hashCode() + clientSideClientContext.hashCode();
}
public int hashCode()
{
return hashCode;
}
public boolean equals( Object obj )
{
if (obj instanceof DefaultServerSideClientContext) {
DefaultServerSideClientContext other = ( DefaultServerSideClientContext \
) obj; if (!session.equals(other.session)) {
return false;
}
if (!clientSideClientContext.equals(other.clientSideClientContext)) {
return false;
}
return true;
}
return false;
}
public String toString()
{
return "DefaultServerSideClientContext["+ session + "," + \
clientSideClientContext.toString() +"]"; }
}
1.1 \
incubator-altrmi/src/java/org/apache/altrmi/server/impl/DefaultServerSideClientContextFactory.java
Index: DefaultServerSideClientContextFactory.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 apache@apache.org.
*
* 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.server.impl;
import org.apache.altrmi.server.ServerSideClientContextFactory;
import org.apache.altrmi.common.ClientContext;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public class DefaultServerSideClientContextFactory implements \
ServerSideClientContextFactory {
private static ThreadLocal c_contexts = new ThreadLocal();
public ClientContext get() {
return (ClientContext) c_contexts.get();
}
public void set(Long session, ClientContext clientContext) {
c_contexts.set(new DefaultServerSideClientContext(session, clientContext));
}
public boolean isSet() {
return c_contexts.get() != null;
}
}
1.5 +50 -59 \
incubator-altrmi/src/java/org/apache/altrmi/server/impl/adapters/InvocationHandlerAdapter.java
Index: InvocationHandlerAdapter.java
===================================================================
RCS file: /home/cvs/incubator-altrmi/src/java/org/apache/altrmi/server/impl/adapters/InvocationHandlerAdapter.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- InvocationHandlerAdapter.java 26 Mar 2003 20:23:03 -0000 1.4
+++ InvocationHandlerAdapter.java 5 May 2003 21:11:20 -0000 1.5
@@ -54,59 +54,16 @@
*/
package org.apache.altrmi.server.impl.adapters;
+import org.apache.altrmi.common.*;
+import org.apache.altrmi.server.*;
+import org.apache.altrmi.server.impl.*;
+import org.apache.altrmi.server.impl.classretrievers.NoClassRetriever;
+
import java.rmi.server.UID;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector;
-
-import org.apache.altrmi.server.Authenticator;
-import org.apache.altrmi.server.ClassRetrievalException;
-import org.apache.altrmi.server.ClassRetriever;
-import org.apache.altrmi.server.MethodInvocationHandler;
-import org.apache.altrmi.server.ServerInvocationHandler;
-import org.apache.altrmi.server.ServerMonitor;
-import org.apache.altrmi.server.impl.Session;
-import org.apache.altrmi.server.impl.DefaultAuthenticator;
-import org.apache.altrmi.server.impl.DefaultMethodInvocationHandler;
-import org.apache.altrmi.server.impl.ConsoleServerMonitor;
-import org.apache.altrmi.server.impl.classretrievers.NoClassRetriever;
-import org.apache.altrmi.common.Reply;
-import org.apache.altrmi.common.Request;
-import org.apache.altrmi.common.SuspendedReply;
-import org.apache.altrmi.common.RequestConstants;
-import org.apache.altrmi.common.MethodAsyncRequest;
-import org.apache.altrmi.common.OpenConnectionRequest;
-import org.apache.altrmi.common.PingReply;
-import org.apache.altrmi.common.RequestFailedReply;
-import org.apache.altrmi.common.MethodRequest;
-import org.apache.altrmi.common.MethodFacadeRequest;
-import org.apache.altrmi.common.ExceptionReply;
-import org.apache.altrmi.common.NotPublishedReply;
-import org.apache.altrmi.common.ReplyConstants;
-import org.apache.altrmi.common.MethodReply;
-import org.apache.altrmi.common.MethodFacadeReply;
-import org.apache.altrmi.common.MethodNameHelper;
-import org.apache.altrmi.common.MethodFacadeArrayReply;
-import org.apache.altrmi.common.RawRequest;
-import org.apache.altrmi.common.AuthenticationException;
-import org.apache.altrmi.common.LookupReply;
-import org.apache.altrmi.common.ClassRequest;
-import org.apache.altrmi.common.ClassReply;
-import org.apache.altrmi.common.ClassRetrievalFailedReply;
-import org.apache.altrmi.common.SameVMReply;
-import org.apache.altrmi.common.OpenConnectionReply;
-import org.apache.altrmi.common.ListReply;
-import org.apache.altrmi.common.GarbageCollectionRequest;
-import org.apache.altrmi.common.InvocationExceptionReply;
-import org.apache.altrmi.common.GarbageCollectionReply;
-import org.apache.altrmi.common.ListMethodsRequest;
-import org.apache.altrmi.common.ListMethodsReply;
-import org.apache.altrmi.common.LookupRequest;
-import org.apache.altrmi.common.NoSuchSessionReply;
-
-import javax.swing.*;
-
/**
* Class InvocationHandlerAdapter
*
@@ -127,6 +84,9 @@
private Authenticator m_altrmiAuthenticator = new DefaultAuthenticator();
private ServerMonitor m_serverMonitor;
+ private ServerSideClientContextFactory m_clientContextFactory;
+
+
/**
* Set a ClassRetriever
*
@@ -175,21 +135,28 @@
if( request.getRequestCode() == RequestConstants.METHODREQUEST )
{
- return doMethodRequest( request, connectionDetails );
+ MethodRequest methodRequest = (MethodRequest) request;
+ setClientContext(methodRequest);
+ return doMethodRequest( methodRequest, connectionDetails );
}
else if( request.getRequestCode() == \
RequestConstants.METHODFACADEREQUEST ) {
- return doMethodFacadeRequest( request, connectionDetails );
+ MethodFacadeRequest methodFacadeRequest = ( MethodFacadeRequest ) \
request; + setClientContext(methodFacadeRequest);
+ return doMethodFacadeRequest( methodFacadeRequest, \
connectionDetails );
}
else if( request.getRequestCode() == \
RequestConstants.METHODASYNCREQUEST ) {
- return doMethodAsyncRequest( (MethodAsyncRequest) request, \
connectionDetails ); + MethodAsyncRequest methodAsyncRequest = ( \
MethodAsyncRequest ) request; + setClientContext(methodAsyncRequest);
+ return doMethodAsyncRequest( methodAsyncRequest, connectionDetails \
);
}
else if( request.getRequestCode() == RequestConstants.GCREQUEST )
{
+
return doGarbageCollectionRequest( request );
}
@@ -230,11 +197,12 @@
}
catch (NullPointerException npe)
{
+ npe.printStackTrace();
if (request instanceof MethodRequest)
{
String methd = ((MethodRequest) request).getMethodSignature();
getServerMonitor().unexpectedException(InvocationHandlerAdapter.class,"InvocationHandlerAdapter.handleInvocation() \
NPE processing method " + methd,npe);
- throw new NullPointerException("Null pointer exception, processing \
method" + methd); + throw new NullPointerException("Null pointer \
exception, processing method " + methd); }
else
{
@@ -244,14 +212,38 @@
}
}
+ public void setClientContextFactory( ServerSideClientContextFactory \
clientContextFactory ) + {
+ m_clientContextFactory = clientContextFactory;
+ }
+
+ protected synchronized ServerSideClientContextFactory \
getClientContextFactory() + {
+ if (m_clientContextFactory == null) {
+ m_clientContextFactory = new DefaultServerSideClientContextFactory();
+ }
+ return m_clientContextFactory;
+ }
+
+ private void setClientContext( Contextualizable request )
+ {
+ Long session = request.getSession();
+ ClientContext clientSideClientContext = request.getContext();
+
+ // *always* happens before method invocations.
+ getClientContextFactory().set(session, clientSideClientContext);
+
+ }
+
+
+
/**
* Do a Method Facade Request
- * @param request the request
+ * @param facadeRequest the request
* @return The reply
*/
- private Reply doMethodFacadeRequest( Request request, Object connectionDetails \
) + private Reply doMethodFacadeRequest( MethodFacadeRequest facadeRequest, \
Object connectionDetails ) {
- MethodFacadeRequest facadeRequest = (MethodFacadeRequest)request;
if (!sessionExists(facadeRequest.getSession()))
{
@@ -414,12 +406,11 @@
/**
* Do a method request
- * @param request The request
+ * @param methodRequest The request
* @return The reply
*/
- private Reply doMethodRequest( Request request, Object connectionDetails )
+ private Reply doMethodRequest( MethodRequest methodRequest, Object \
connectionDetails ) {
- MethodRequest methodRequest = (MethodRequest) request;
if (!sessionExists(methodRequest.getSession()))
{
1.6 +1 -1 \
incubator-altrmi/src/test/org/apache/altrmi/test/AbstractHelloTestCase.java
Index: AbstractHelloTestCase.java
===================================================================
RCS file: /home/cvs/incubator-altrmi/src/test/org/apache/altrmi/test/AbstractHelloTestCase.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AbstractHelloTestCase.java 18 Apr 2003 12:57:15 -0000 1.5
+++ AbstractHelloTestCase.java 5 May 2003 21:11:20 -0000 1.6
@@ -299,7 +299,7 @@
testClient.testSpeed();
}
long end = System.currentTimeMillis();
- System.out.println("--> ST " + this.getClass().getName() + " " + \
iterations + " " + ((end - start)/1000) ); + //System.out.println("--> ST " + \
this.getClass().getName() + " " + iterations + " " + ((end - start)/1000) );
}
1.1 \
incubator-altrmi/src/test/org/apache/altrmi/test/clientcontext/Account.java
Index: Account.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 apache@apache.org.
*
* 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.test.clientcontext;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public interface Account
{
String getSymbolicKey();
void debit( int amt ) throws DebitBarfed;
void credit( int amt ) throws CreditBarfed;
}
1.1 \
incubator-altrmi/src/test/org/apache/altrmi/test/clientcontext/AccountImpl.java
Index: AccountImpl.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 apache@apache.org.
*
* 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.test.clientcontext;
import org.apache.altrmi.common.ClientContext;
import org.apache.altrmi.server.ServerSideClientContextFactory;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public class AccountImpl implements Account {
private ServerSideClientContextFactory m_clientContextFactory;
String m_symbolicKey;
private int m_balance = 123;
private AccountListener m_accountListener;
public AccountImpl(ServerSideClientContextFactory clientContextFactory, String \
symbolicKey, AccountListener accountListener) { m_clientContextFactory = \
clientContextFactory; m_symbolicKey = symbolicKey;
m_accountListener = accountListener;
}
public String getSymbolicKey() {
return m_symbolicKey;
}
public int getBalance() {
return m_balance;
}
public void debit(int amt) throws DebitBarfed
{
ClientContext cc = m_clientContextFactory.get();
m_balance = m_balance - amt;
m_accountListener.record(getSymbolicKey() + ":debit:" + amt, cc);
}
public void credit(int amt) throws CreditBarfed
{
ClientContext cc = m_clientContextFactory.get();
m_balance = m_balance + amt;
m_accountListener.record(getSymbolicKey() + ":credit:" + amt, cc);
}
}
1.1 \
incubator-altrmi/src/test/org/apache/altrmi/test/clientcontext/AccountListener.java
Index: AccountListener.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 apache@apache.org.
*
* 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.test.clientcontext;
import org.apache.altrmi.common.ClientContext;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public interface AccountListener
{
void record( String event, ClientContext clientContext );
}
1.1 \
incubator-altrmi/src/test/org/apache/altrmi/test/clientcontext/AccountManager.java
Index: AccountManager.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 apache@apache.org.
*
* 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.test.clientcontext;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public interface AccountManager
{
void transferAmount( String acct1, String acct2, int amt ) throws \
TransferBarfed;
}
1.1 \
incubator-altrmi/src/test/org/apache/altrmi/test/clientcontext/AccountManagerImpl.java
Index: AccountManagerImpl.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 apache@apache.org.
*
* 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.test.clientcontext;
import org.apache.altrmi.common.ClientContext;
import org.apache.altrmi.server.ServerSideClientContextFactory;
import java.util.HashMap;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public class AccountManagerImpl implements AccountManager
{
private HashMap m_accounts = new HashMap();
private ServerSideClientContextFactory m_clientContextFactory;
public AccountManagerImpl( ServerSideClientContextFactory clientContextFactory, \
Account one, Account two ) {
m_clientContextFactory = clientContextFactory;
m_accounts.put( one.getSymbolicKey(), one );
m_accounts.put( two.getSymbolicKey(), two );
}
public void transferAmount( String acct1, String acct2, int amt ) throws \
TransferBarfed {
Account from = ( Account ) m_accounts.get( acct1 );
Account to = ( Account ) m_accounts.get( acct2 );
ClientContext cc = m_clientContextFactory.get();
try
{
from.debit( amt );
to.credit( amt );
}
catch ( DebitBarfed debitBarfed )
{
throw new TransferBarfed();
}
catch ( CreditBarfed creditBarfed )
{
throw new TransferBarfed();
}
finally
{
// ?
}
}
}
1.1 \
incubator-altrmi/src/test/org/apache/altrmi/test/clientcontext/ClientContextTestCase.java
Index: ClientContextTestCase.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 apache@apache.org.
*
* 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.test.clientcontext;
import junit.framework.TestCase;
import org.apache.altrmi.server.impl.socket.CompleteSocketCustomStreamServer;
import org.apache.altrmi.server.impl.DefaultServerSideClientContextFactory;
import org.apache.altrmi.server.impl.DefaultServerSideClientContext;
import org.apache.altrmi.server.ServerSideClientContextFactory;
import org.apache.altrmi.server.PublicationDescription;
import org.apache.altrmi.server.Server;
import org.apache.altrmi.server.PublicationException;
import org.apache.altrmi.server.ServerException;
import org.apache.altrmi.client.impl.ClientSideClassFactory;
import org.apache.altrmi.client.impl.socket.SocketCustomStreamHostContext;
import org.apache.altrmi.client.Factory;
import org.apache.altrmi.common.ConnectionException;
import org.apache.altrmi.common.ClientContext;
import java.util.HashMap;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public class ClientContextTestCase extends TestCase
{
public ClientContextTestCase( String name )
{
super( name );
}
public void testSimple()
{
AccountListener al = new AccountListener()
{
public void record( String event, ClientContext clientContext )
{
}
};
ServerSideClientContextFactory clientContextFactory = new \
DefaultServerSideClientContextFactory();
AccountImpl one = new AccountImpl( clientContextFactory, "one", al );
AccountImpl two = new AccountImpl( clientContextFactory, "two", al );
final AccountManager accountManager = new AccountManagerImpl( \
clientContextFactory, one, two );
try
{
accountManager.transferAmount( "one", "two", 23 );
}
catch ( TransferBarfed transferBarfed )
{
fail( "Transfer should have worked" );
}
assertEquals( one.getBalance(), 100 );
assertEquals( two.getBalance(), 146 );
}
public void testWithCustomContextWithoutRPC() throws InterruptedException
{
final HashMap hashMap = new HashMap();
AccountListener al = makeAccountListener( hashMap );
ServerSideClientContextFactory clientContextFactory = new \
TestClientContextFactory();
AccountImpl one = new AccountImpl( clientContextFactory, "one", al );
AccountImpl two = new AccountImpl( clientContextFactory, "two", al );
final AccountManager accountManager = new AccountManagerImpl( \
clientContextFactory, one, two );
Thread threadOne = makeThread( accountManager, 11 );
Thread threadTwo = makeThread( accountManager, 22 );
threadOne.start();
threadTwo.start();
Thread.sleep( 2000 );
ClientContext debit11 = ( ClientContext ) hashMap.get( "one:debit:11" );
ClientContext credit11 = ( ClientContext ) hashMap.get( "two:credit:11" );
basicAsserts( debit11, credit11 );
ClientContext debit22 = ( ClientContext ) hashMap.get( "one:debit:22" );
ClientContext credit22 = ( ClientContext ) hashMap.get( "two:credit:22" );
basicAsserts( debit22, credit22 );
assertFalse( debit11 == credit22 );
}
public void testWithCustomContextWithRPC() throws InterruptedException, \
ServerException, PublicationException, ConnectionException {
final HashMap hashMap = new HashMap();
AccountListener al = makeAccountListener( hashMap );
ServerSideClientContextFactory clientContextFactory
= new DefaultServerSideClientContextFactory();
AccountImpl one = new AccountImpl( clientContextFactory, "one", al );
AccountImpl two = new AccountImpl( clientContextFactory, "two", al );
final AccountManager accountManager
= new AccountManagerImpl( clientContextFactory, one, two );
Server server = new CompleteSocketCustomStreamServer( 13333 );
PublicationDescription pd = new PublicationDescription( \
AccountManager.class ); server.publish( accountManager, "OurAccountManager", pd );
server.setClientContextFactory( clientContextFactory );
server.start();
Factory altrmiFactory = new ClientSideClassFactory();
altrmiFactory.setHostContext( new SocketCustomStreamHostContext( \
"127.0.0.1", 13333 ), false );
final AccountManager clientSideAccountManager = ( AccountManager ) \
altrmiFactory.lookup( "OurAccountManager" );
Thread threadOne = makeThread( clientSideAccountManager, 11 );
Thread threadTwo = makeThread( clientSideAccountManager, 22 );
threadOne.start();
threadTwo.start();
Thread.sleep( 2000 );
ClientContext debit11 = ( ClientContext ) hashMap.get( "one:debit:11" );
ClientContext credit11 = ( ClientContext ) hashMap.get( "two:credit:11" );
basicAsserts( debit11, credit11 );
assertTrue( "Wrong type of ClientContext", credit11 instanceof \
DefaultServerSideClientContext );
ClientContext debit22 = ( ClientContext ) hashMap.get( "one:debit:22" );
ClientContext credit22 = ( ClientContext ) hashMap.get( "two:credit:22" );
basicAsserts( debit22, credit22 );
assertFalse( debit11 == credit22 );
}
private void basicAsserts( ClientContext debitContext, ClientContext \
creditContext ) {
assertNotNull( "Debit should have been registered on server side", \
debitContext );
assertNotNull( "Credit should have been registered on server side", \
creditContext );
assertEquals( "Debit Context and Credit Context should be .equals()", \
debitContext, creditContext ); }
private AccountListener makeAccountListener( final HashMap hashMap )
{
AccountListener al = new AccountListener()
{
public void record( String event, ClientContext clientContext )
{
//System.out.println("EVENT-" + event + " " + clientContext);
hashMap.put( event, clientContext );
}
};
return al;
}
private Thread makeThread( final AccountManager accountManager, final int \
amount ) {
Thread thread = new Thread( new Runnable()
{
public void run()
{
try
{
accountManager.transferAmount( "one", "two", amount );
}
catch ( TransferBarfed transferBarfed )
{
fail( "Transfer should have worked" );
}
}
} );
return thread;
}
}
1.1 \
incubator-altrmi/src/test/org/apache/altrmi/test/clientcontext/CreditBarfed.java
Index: CreditBarfed.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 apache@apache.org.
*
* 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.test.clientcontext;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public class CreditBarfed extends Exception
{
}
1.1 \
incubator-altrmi/src/test/org/apache/altrmi/test/clientcontext/DebitBarfed.java
Index: DebitBarfed.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 apache@apache.org.
*
* 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.test.clientcontext;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public class DebitBarfed extends Exception
{
}
1.1 \
incubator-altrmi/src/test/org/apache/altrmi/test/clientcontext/TestClientContext.java \
Index: TestClientContext.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 apache@apache.org.
*
* 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.test.clientcontext;
import org.apache.altrmi.common.ClientContext;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public class TestClientContext implements ClientContext
{
private String ctx;
public TestClientContext()
{
ctx = "TestCCF:" + System.identityHashCode(Thread.currentThread());
}
public int hashCode()
{
return ctx.hashCode();
}
public String toString()
{
return ctx;
}
public boolean equals( Object obj )
{
return ctx.equals(((TestClientContext) obj).ctx);
}
}
1.1 \
incubator-altrmi/src/test/org/apache/altrmi/test/clientcontext/TestClientContextFactory.java
Index: TestClientContextFactory.java
===================================================================
package org.apache.altrmi.test.clientcontext;
import org.apache.altrmi.server.ServerSideClientContextFactory;
import org.apache.altrmi.common.ClientContext;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public class TestClientContextFactory implements ServerSideClientContextFactory
{
public TestClientContextFactory()
{
}
public ClientContext get()
{
return new TestClientContext();
}
//return "TestCCF:" + System.identityHashCode(Thread.currentThread());
public void set( Long session, ClientContext clientContext )
{
}
public boolean isSet()
{
return false;
}
}
1.1 \
incubator-altrmi/src/test/org/apache/altrmi/test/clientcontext/TransferBarfed.java
Index: TransferBarfed.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 apache@apache.org.
*
* 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.test.clientcontext;
/**
* @author Paul Hammant and Rune Johanessen (pairing for part)
* @version $Revision: 1.1 $
*/
public class TransferBarfed extends Exception
{
}
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@incubator.apache.org
For additional commands, e-mail: cvs-help@incubator.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic