You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ha...@apache.org on 2002/04/06 11:59:59 UTC
cvs commit: jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/callback CallBackTest.java CallBackTestClient.java CallBackTestImpl.java CallBackTestListener.java CallBackTestListenerImpl.java CallBackTestServer.java
hammant 02/04/06 01:59:59
Added: altrmi callback.xml
altrmi/src/test/org/apache/excalibur/altrmi/test/callback
CallBackTest.java CallBackTestClient.java
CallBackTestImpl.java CallBackTestListener.java
CallBackTestListenerImpl.java
CallBackTestServer.java
Log:
Tests for AltRMI callback
Revision Changes Path
1.1 jakarta-avalon-excalibur/altrmi/callback.xml
Index: callback.xml
===================================================================
<project name="Alt (to) RMI" default="generate" basedir=".">
<!-- ========== Initialize Properties ===================================== -->
<property file="ant.properties"/> <!-- Component local -->
<property file="${user.home}/ant.properties"/> <!-- User local -->
<!-- ========== Component Declarations ==================================== -->
<!-- The base directory for compilation targets -->
<property name="build.home" value="build"/>
<!-- Construct compile classpath -->
<path id="compile.classpath">
<pathelement location="${build.home}/classes"/>
</path>
<!-- For running of tests -->
<path id="test.classpath">
<pathelement location="${build.home}/classes"/>
<pathelement location="${build.home}/genclasses"/>
<pathelement location="${avalon-framework.jar}"/>
</path>
<taskdef name="altrmiproxies" classname="org.apache.excalibur.altrmi.generator.ant.AltrmiProxyTask">
<classpath refid="compile.classpath" />
</taskdef>
<!-- ========== Executable Targets ======================================== -->
<target name="prepare"
description="Prepare build directory">
<mkdir dir="${build.home}"/>
<mkdir dir="${build.home}/genclasses"/>
<delete>
<fileset dir="${build.home}/genclasses" includes="*" defaultexcludes="no"/>
</delete>
<mkdir dir="${build.home}/genjava"/>
<delete>
<fileset dir="${build.home}/genjava" includes="*" defaultexcludes="no"/>
</delete>
</target>
<target name="generate" depends="prepare">
<altrmiproxies genname="EventServer" srcgendir="${build.home}/genjava"
classgendir="${build.home}/genclasses" verbose="true"
interfaces="org.apache.excalibur.altrmi.test.callback.EventGenerator">
<classpath>
<pathelement location="${build.home}/classes"/>
</classpath>
</altrmiproxies>
</target>
<target name="server" description="Callback test server">
<echo>Warning : This spawns a seperate process that is not killed by Ctrl-C on this process</echo>
<java classname="org.apache.excalibur.altrmi.test.callback.CallBackTestServer" maxmemory="10m" fork="true">
<classpath refid="test.classpath"/>
</java>
</target>
<target name="client" description="Callback test client" depends="generate">
<echo>Warning : This spawns a seperate process that is not killed by Ctrl-C on this process</echo>
<java classname="org.apache.excalibur.altrmi.test.callback.CallBackTestClient" maxmemory="10m" fork="true">
<classpath refid="test.classpath"/>
</java>
</target>
</project>
1.1 jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/callback/CallBackTest.java
Index: CallBackTest.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.excalibur.altrmi.test.callback;
/**
* Interface CallBackTest
*
* @author <a href="mailto:vinayc77@yahoo.com">Vinay Chandran</a>
*/
public interface CallBackTest
{
/**
* A plain-vanila remote method
*/
String getName();
/**
* Method adding a client-side exposed Object
*/
boolean addCallBackListener(CallBackTestListener callbackTestListener);
}
1.1 jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/callback/CallBackTestClient.java
Index: CallBackTestClient.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.excalibur.altrmi.test.callback;
import org.apache.excalibur.altrmi.client.AltrmiHostContext;
import org.apache.excalibur.altrmi.client.AltrmiFactory;
import org.apache.excalibur.altrmi.common.AltrmiConnectionException;
import org.apache.excalibur.altrmi.client.impl.ServerClassAltrmiFactory;
import org.apache.excalibur.altrmi.client.impl.ClientClassAltrmiFactory;
import org.apache.excalibur.altrmi.test.*;
import org.apache.excalibur.altrmi.client.impl.socket.*;
import java.io.IOException;
/**
* Class CallBackTestClient
*
* @author <a href="mailto:vinayc77@yahoo.com">Vinay Chandran</a>
*/
public class CallBackTestClient{
/**
* Method main
*
*
* @param args
*
* @throws Exception
*
*/
public static void main(String[] args) throws Exception {
System.out.println("Callback test Client");
AltrmiHostContext arhc;
arhc = new SocketCustomStreamHostContext("127.0.0.1", 1235);
AltrmiFactory af = null;
af = new ServerClassAltrmiFactory(false);
af.setHostContext(arhc);
//list
System.out.println("Listing Published Objects At Server...");
String[] listOfPublishedObjectsOnServer = af.list();
for (int i = 0; i < listOfPublishedObjectsOnServer.length; i++) {
System.out.println("..[" + i + "]:" + listOfPublishedObjectsOnServer[i]);
}
CallBackTest callbacktest = (CallBackTest) af.lookup("EventServer");
// Nothing from here on down is aware of AltRMI bridging two VMs.....
System.out.println("CallBackTest.getName["+callbacktest.getName()+"]");
System.out.println("Registering CallBackTestListenerImpls with the CallBackTest");
CallBackTestListenerImpl[] callBackTestListenerImpls = new CallBackTestListenerImpl[3];
callBackTestListenerImpls[0] = new CallBackTestListenerImpl(0);
callBackTestListenerImpls[1] = new CallBackTestListenerImpl(1);
callBackTestListenerImpls[2] = new CallBackTestListenerImpl(2);
callbacktest.addCallBackListener(callBackTestListenerImpls[0]);
callbacktest.addCallBackListener(callBackTestListenerImpls[1]);
callbacktest.addCallBackListener(callBackTestListenerImpls[2]);
//Sleep waiting for the event to occur
try
{
System.out.println("Ctrl-C to abort the program");
System.in.read();
}
catch(java.io.IOException ie)
{
ie.printStackTrace();
}
af.close();
}
}
1.1 jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/callback/CallBackTestImpl.java
Index: CallBackTestImpl.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.excalibur.altrmi.test.callback;
import java.util.ArrayList;
import java.util.List;
import org.apache.excalibur.altrmi.common.AltrmiConnectionClosedException;
/**
* Class CallBackTestImpl
*
* @author <a href="mailto:vinayc77@yahoo.com">Vinay Chandran</a>
*/
public class CallBackTestImpl implements CallBackTest
{
private List m_list = new ArrayList();
/*
* @see CallBackTest#getName()
*/
public String getName()
{
return "Test CallBackTest";
}
/*
* @see CallBackTest#addNotificationListener(CallBackTestListener)
*/
public boolean addCallBackListener(CallBackTestListener callBackTestListener)
{
System.out.println("NEW CallBack Test Listener Added:"+callBackTestListener);
m_list.add(callBackTestListener);
return true;
}
/*
* @see CallBackTest#generateEvent()
*/
public void generateEvent()
{
//while(true)
{
try
{
for(int i=0;i<m_list.size();i++)
{
CallBackTestListener notificationListenerInf = (CallBackTestListener)m_list.get(i);
try
{
((CallBackTestListener)m_list.get(i)).serverCallingClient("Hello to presumed instance ["+i+"]");
}
catch(AltrmiConnectionClosedException ace) //SHLD this be some other exception
{
System.out.println("Invalid Callback");
m_list.remove(i);
--i;
}
}
Thread.yield();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}
1.1 jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/callback/CallBackTestListener.java
Index: CallBackTestListener.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.excalibur.altrmi.test.callback;
/**
* Interface CallBackTestListener
*
* @author <a href="mailto:vinayc77@yahoo.com">Vinay Chandran</a>
*/
public interface CallBackTestListener
{
/**
* Callback methods invoked by the server
*/
public void serverCallingClient(String message);
}
1.1 jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/callback/CallBackTestListenerImpl.java
Index: CallBackTestListenerImpl.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.excalibur.altrmi.test.callback;
/**
* Class CallBackTestListenerImpl
*
* This class is exposed by the client for the server to make callbacks
* @author <a href="mailto:vinayc77@yahoo.com">Vinay Chandran</a>
*/
public class CallBackTestListenerImpl implements CallBackTestListener
{
private int instNbr = 0;
public CallBackTestListenerImpl(int instNbr) {
this.instNbr = instNbr;
}
/*
* @see CallBackTestListener#serverCallingClient(String)
*/
public void serverCallingClient(String message)
{
System.out.println("CallBackTestListenerImpl: Server message for instance number " + instNbr + " ["+message+"]");
}
}
1.1 jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/callback/CallBackTestServer.java
Index: CallBackTestServer.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.excalibur.altrmi.test.callback;
import org.apache.excalibur.altrmi.server.impl.classretrievers.JarFileClassRetriever;
import org.apache.excalibur.altrmi.server.impl.AbstractServer;
import org.apache.excalibur.altrmi.test.*;
import org.apache.excalibur.altrmi.server.impl.socket.*;
import org.apache.excalibur.altrmi.server.PublicationDescription;
import java.io.IOException;
/**
* Class CallBackTestServer
*
* @author <a href="mailto:vinayc77@yahoo.com">Vinay Chandran</a>
*/
public class CallBackTestServer{
/**
* Method main
*
*
* @param args
*
* @throws Exception
*
*/
public static void main(String[] args) throws Exception {
System.out.println("Stream over Socket Server");
AbstractServer as;
// CustomStream
System.out.println("(Custom Stream)");
as = new CompleteSocketCustomStreamServer(1235);
as.setClassRetriever(new JarFileClassRetriever("build/classes2"));
//CallBackTest
CallBackTestImpl callBackTest = new CallBackTestImpl();
as.publish(callBackTest, "EventServer", CallBackTest.class);
//start
as.start();
Thread thread = new Thread(new FireMan(callBackTest));
thread.start();
}
private static class FireMan implements Runnable
{
CallBackTestImpl callBackTest;
FireMan(CallBackTestImpl callBackTest)
{
this.callBackTest=callBackTest;
}
public void run()
{
try
{
Thread.sleep(5000); // wait five seconds forclient to register three callbacks.
}
catch (InterruptedException ie)
{
}
while(true)
{
callBackTest.generateEvent();
}
}
};
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>