From: <fc...@us...> - 2010-12-06 23:36:04
|
Revision: 3154 http://openutils.svn.sourceforge.net/openutils/?rev=3154&view=rev Author: fcarone Date: 2010-12-06 23:35:56 +0000 (Mon, 06 Dec 2010) Log Message: ----------- working rmi callback example Modified Paths: -------------- sandbox/trunk/openutils-spring-remote-callback/pom.xml sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/Callback.java sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/manager/CallbackHolder.java sandbox/trunk/openutils-spring-remote-callback/src/test/java/it/openutils/spring/remote/callback/test/ClientTest.java sandbox/trunk/openutils-spring-remote-callback/src/test/java/it/openutils/spring/remote/callback/test/server/DummyManagerImpl.java sandbox/trunk/openutils-spring-remote-callback/src/test/resources/spring-client.xml sandbox/trunk/openutils-spring-remote-callback/src/test/resources/spring-services.xml sandbox/trunk/openutils-spring-remote-callback/src/test/resources/spring-tests.xml Added Paths: ----------- sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/TLCallbackRemoteInvocation.java sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/TLRMIServiceExporter.java sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/TLRemoteInvocationFactory.java sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/WlcfgRmiCallbackExporter.java sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/WlcfgRmiCallbackProxyFactory.java Removed Paths: ------------- sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/interceptor/ sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/manager/CallbackManager.java sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/manager/impl/ sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/rmi/ sandbox/trunk/openutils-spring-remote-callback/src/test/java/it/openutils/spring/remote/callback/test/ClientCallback.java sandbox/trunk/openutils-spring-remote-callback/src/test/resources/spring-jms.xml Modified: sandbox/trunk/openutils-spring-remote-callback/pom.xml =================================================================== --- sandbox/trunk/openutils-spring-remote-callback/pom.xml 2010-12-04 14:52:03 UTC (rev 3153) +++ sandbox/trunk/openutils-spring-remote-callback/pom.xml 2010-12-06 23:35:56 UTC (rev 3154) @@ -1,158 +1,148 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-parent</artifactId> - <version>1.0</version> - </parent> - <modelVersion>4.0.0</modelVersion> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-spring-remote-callback</artifactId> - <name>openutils spring remote callback</name> - <version>0.0.1-SNAPSHOT</version> - <description>Openutils Spring Remote Callback classes</description> - <properties> - <spring.version>3.0.0.RELEASE</spring.version> - <aspectj.version>1.5.3</aspectj.version> - </properties> - <dependencies> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-core</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-context</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-aop</artifactId> - <version>${spring.version}</version> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.logicblaze.lingo</groupId> - <artifactId>lingo</artifactId> - <version>1.3</version> - <exclusions> - <exclusion> - <groupId>incubator-activemq</groupId> - <artifactId>activeio-core</artifactId> - </exclusion> - <exclusion> - <groupId>incubator-activemq</groupId> - <artifactId>activemq-core</artifactId> - </exclusion> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>spring</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>activemq-core</artifactId> - <version>5.2.0</version> - </dependency> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>activemq-core</artifactId> - <version>4.1.1</version> - </dependency> - <dependency> - <groupId>aspectj</groupId> - <artifactId>aspectjrt</artifactId> - <version>${aspectj.version}</version> - </dependency> - <dependency> - <groupId>aspectj</groupId> - <artifactId>aspectjweaver</artifactId> - <version>${aspectj.version}</version> - </dependency> - <dependency> - <groupId>cglib</groupId> - <artifactId>cglib-nodep</artifactId> - <version>2.1_3</version> - </dependency> - <dependency> - <groupId>asm</groupId> - <artifactId>asm</artifactId> - <version>2.2.3</version> - </dependency> - <dependency> - <groupId>asm</groupId> - <artifactId>asm-attrs</artifactId> - <version>2.2.3</version> - </dependency> - <dependency> - <groupId>asm</groupId> - <artifactId>asm-commons</artifactId> - <version>2.2.3</version> - </dependency> - <dependency> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - <version>1.1.1</version> - <scope>compile</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.5.6</version> - </dependency> - <dependency> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-testing-junit</artifactId> - <version>2.0.2</version> - <scope>test</scope> - <exclusions> - <exclusion> - <groupId>org.slf4j</groupId> - <artifactId>jcl104-over-slf4j</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.4</version> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.4</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.xbean</groupId> - <artifactId>xbean-spring-v2c</artifactId> - <version>2.8</version> - <scope>test</scope> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-parent</artifactId> + <version>1.0</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-spring-remote-callback</artifactId> + <name>openutils spring remote callback</name> + <version>0.0.1-SNAPSHOT</version> + <description>Openutils Spring Remote Callback classes</description> + <properties> + <spring.version>3.0.0.RELEASE</spring.version> + <aspectj.version>1.5.3</aspectj.version> + </properties> + <dependencies> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>${spring.version}</version> <exclusions> <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-aop</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.logicblaze.lingo</groupId> + <artifactId>lingo</artifactId> + <version>1.3</version> + <exclusions> + <exclusion> + <groupId>incubator-activemq</groupId> + <artifactId>activeio-core</artifactId> + </exclusion> + <exclusion> + <groupId>incubator-activemq</groupId> + <artifactId>activemq-core</artifactId> + </exclusion> + <exclusion> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> </exclusion> - </exclusions> - </dependency> - </dependencies> + </exclusions> + </dependency> + <dependency> + <groupId>aspectj</groupId> + <artifactId>aspectjrt</artifactId> + <version>${aspectj.version}</version> + </dependency> + <dependency> + <groupId>aspectj</groupId> + <artifactId>aspectjweaver</artifactId> + <version>${aspectj.version}</version> + </dependency> + <dependency> + <groupId>cglib</groupId> + <artifactId>cglib-nodep</artifactId> + <version>2.1_3</version> + </dependency> + <dependency> + <groupId>asm</groupId> + <artifactId>asm</artifactId> + <version>2.2.3</version> + </dependency> + <dependency> + <groupId>asm</groupId> + <artifactId>asm-attrs</artifactId> + <version>2.2.3</version> + </dependency> + <dependency> + <groupId>asm</groupId> + <artifactId>asm-commons</artifactId> + <version>2.2.3</version> + </dependency> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + <version>1.1.1</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.5.6</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-testing-junit</artifactId> + <version>2.0.2</version> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>jcl104-over-slf4j</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.4</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.4</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.xbean</groupId> + <artifactId>xbean-spring-v2c</artifactId> + <version>2.8</version> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> </project> \ No newline at end of file Modified: sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/Callback.java =================================================================== --- sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/Callback.java 2010-12-04 14:52:03 UTC (rev 3153) +++ sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/Callback.java 2010-12-06 23:35:56 UTC (rev 3154) @@ -25,13 +25,9 @@ */ public interface Callback extends EventListener { + /** * Invocation for the remote callback */ void invoke(); - - /** - * @return The callback UID. - */ - String getUID(); } Added: sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/TLCallbackRemoteInvocation.java =================================================================== --- sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/TLCallbackRemoteInvocation.java (rev 0) +++ sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/TLCallbackRemoteInvocation.java 2010-12-06 23:35:56 UTC (rev 3154) @@ -0,0 +1,43 @@ +/* + * Copyright (c) Energeya. All rights reserved. http://www.energeya.com + */ +package it.openutils.spring.remote.callback; + +import it.openutils.spring.remote.callback.manager.CallbackHolder; + +import java.lang.reflect.InvocationTargetException; + +import org.aopalliance.intercept.MethodInvocation; +import org.springframework.remoting.support.RemoteInvocation; + + +/** + * @author carone + * @version $Id: $ + */ +public class TLCallbackRemoteInvocation extends RemoteInvocation +{ + + private Callback callback; + + /** + * + */ + public TLCallbackRemoteInvocation(MethodInvocation methodInvocation) + { + super(methodInvocation); + callback = CallbackHolder.getCallback(); + } + + /** + * {@inheritDoc} + */ + @Override + public Object invoke(Object targetObject) throws NoSuchMethodException, IllegalAccessException, + InvocationTargetException + { + CallbackHolder.setCallback(callback); + return super.invoke(targetObject); + } + +} Added: sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/TLRMIServiceExporter.java =================================================================== --- sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/TLRMIServiceExporter.java (rev 0) +++ sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/TLRMIServiceExporter.java 2010-12-06 23:35:56 UTC (rev 3154) @@ -0,0 +1,40 @@ +/* + * Copyright (c) Energeya. All rights reserved. http://www.energeya.com + */ +package it.openutils.spring.remote.callback; + +import it.openutils.spring.remote.callback.manager.CallbackHolder; + +import java.lang.reflect.InvocationTargetException; + +import org.springframework.remoting.rmi.RmiServiceExporter; +import org.springframework.remoting.support.RemoteInvocation; + + +/** + * @author carone + * @version $Id: $ + */ +public class TLRMIServiceExporter extends RmiServiceExporter +{ + + /** + * {@inheritDoc} + */ + @Override + protected Object invoke(RemoteInvocation invocation, Object targetObject) throws NoSuchMethodException, + IllegalAccessException, InvocationTargetException + { + Object[] args = invocation.getArguments(); + for (Object arg : args) + { + if (arg instanceof Callback) + { + CallbackHolder.setCallback((Callback) arg); + break; + } + } + return super.invoke(invocation, targetObject); + } + +} Added: sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/TLRemoteInvocationFactory.java =================================================================== --- sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/TLRemoteInvocationFactory.java (rev 0) +++ sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/TLRemoteInvocationFactory.java 2010-12-06 23:35:56 UTC (rev 3154) @@ -0,0 +1,26 @@ +/* + * Copyright (c) Energeya. All rights reserved. http://www.energeya.com + */ +package it.openutils.spring.remote.callback; + +import org.aopalliance.intercept.MethodInvocation; +import org.springframework.remoting.support.RemoteInvocation; +import org.springframework.remoting.support.RemoteInvocationFactory; + + +/** + * @author carone + * @version $Id: $ + */ +public class TLRemoteInvocationFactory implements RemoteInvocationFactory +{ + + /** + * {@inheritDoc} + */ + public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) + { + return new TLCallbackRemoteInvocation(methodInvocation); + } + +} Added: sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/WlcfgRmiCallbackExporter.java =================================================================== --- sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/WlcfgRmiCallbackExporter.java (rev 0) +++ sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/WlcfgRmiCallbackExporter.java 2010-12-06 23:35:56 UTC (rev 3154) @@ -0,0 +1,39 @@ +package it.openutils.spring.remote.callback; + +import java.rmi.Remote; +import java.rmi.RemoteException; +import java.rmi.server.UnicastRemoteObject; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.remoting.rmi.RmiBasedExporter; +import org.springframework.remoting.rmi.RmiInvocationHandler; + + +public class WlcfgRmiCallbackExporter extends RmiBasedExporter +{ + + private static Log log = LogFactory.getLog(WlcfgRmiCallbackExporter.class); + + public RmiInvocationHandler getRmiInvocationHandler(Object callback, Class callbackInterface) + { + this.setService(callback); + this.setServiceInterface(callbackInterface); + this.setRegisterTraceInterceptor(false); + + // wrap non-RMI service into a remote object + Remote exportedObject = getObjectToExport(); + + try + { + UnicastRemoteObject.exportObject(exportedObject, 0); + } + catch (RemoteException e) + { + log.error("Failed to export " + getServiceInterface().getName(), e); + } + + log.info("Export object " + getServiceInterface().getName()); + return (RmiInvocationHandler) exportedObject; + } +} \ No newline at end of file Added: sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/WlcfgRmiCallbackProxyFactory.java =================================================================== --- sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/WlcfgRmiCallbackProxyFactory.java (rev 0) +++ sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/WlcfgRmiCallbackProxyFactory.java 2010-12-06 23:35:56 UTC (rev 3154) @@ -0,0 +1,64 @@ +package it.openutils.spring.remote.callback; + +import java.io.Serializable; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Proxy; +import java.rmi.RemoteException; + +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; +import org.springframework.aop.framework.ProxyFactory; +import org.springframework.remoting.rmi.RmiClientInterceptorUtils; +import org.springframework.remoting.rmi.RmiInvocationHandler; +import org.springframework.remoting.support.RemoteInvocationBasedAccessor; +import org.springframework.remoting.support.RemoteInvocationUtils; +import org.springframework.util.ClassUtils; + + +public class WlcfgRmiCallbackProxyFactory extends RemoteInvocationBasedAccessor + implements + MethodInterceptor, + Serializable +{ + + private static final long serialVersionUID = 5685339356048366732L; + + private Class callbackInterface; + + private RmiInvocationHandler invocationHandler; + + public WlcfgRmiCallbackProxyFactory(Object callback, Class callbackInterface) + { + this.callbackInterface = callbackInterface; + WlcfgRmiCallbackExporter exporter = new WlcfgRmiCallbackExporter(); + this.invocationHandler = exporter.getRmiInvocationHandler(callback, callbackInterface); + } + + public Proxy getProxy() + { + Proxy proxy = (Proxy) ProxyFactory.getProxy(callbackInterface, this); + return proxy; + } + + public Object invoke(MethodInvocation invocation) throws Throwable + { + try + { + return invocationHandler.invoke(createRemoteInvocation(invocation)); + } + catch (RemoteException re) + { + throw RmiClientInterceptorUtils.convertRmiAccessException( + invocation.getMethod(), + re, + RmiClientInterceptorUtils.isConnectFailure(re), + ClassUtils.getShortName(callbackInterface)); + } + catch (InvocationTargetException ex) + { + Throwable targetEx = ex.getTargetException(); + RemoteInvocationUtils.fillInClientStackTraceIfPossible(targetEx); + throw targetEx; + } + } +} Modified: sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/manager/CallbackHolder.java =================================================================== --- sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/manager/CallbackHolder.java 2010-12-04 14:52:03 UTC (rev 3153) +++ sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/manager/CallbackHolder.java 2010-12-06 23:35:56 UTC (rev 3154) @@ -16,8 +16,7 @@ package it.openutils.spring.remote.callback.manager; -import org.apache.commons.lang.StringUtils; -import org.springframework.util.Assert; +import it.openutils.spring.remote.callback.Callback; /** @@ -27,32 +26,20 @@ public final class CallbackHolder { - private static ThreadLocal<String> callbackUID; + private static ThreadLocal<Callback> localCallback = new ThreadLocal<Callback>(); private CallbackHolder() { // } - /** - * @param uid The callback uid - */ - public static void setCallbackUID(String uid) + public static void setCallback(Callback callback) { - Assert.notNull(uid, "Only non-null UID instances are permitted"); - callbackUID.set(uid); + localCallback.set(callback); } - public static String getCallbackUID() + public static Callback getCallback() { - return callbackUID.get(); + return localCallback.get(); } - - /** - * Clears the callback UID - */ - public static void clearCallback() - { - callbackUID.set(StringUtils.EMPTY); - } } Deleted: sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/manager/CallbackManager.java =================================================================== --- sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/manager/CallbackManager.java 2010-12-04 14:52:03 UTC (rev 3153) +++ sandbox/trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/manager/CallbackManager.java 2010-12-06 23:35:56 UTC (rev 3154) @@ -1,44 +0,0 @@ -/* - * Copyright Openmind http://www.openmindonline.it - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package it.openutils.spring.remote.callback.manager; - -import it.openutils.spring.remote.callback.Callback; - - -/** - * @author fcarone - * @version $Id: $ - */ -public interface CallbackManager -{ - - /** - * @param callback The callback to register - */ - void installCallback(Callback callback); - - /** - * @param callback The callback to unregister - */ - void uninstallCallback(Callback callback); - - /** - * Invokes the current callback - */ - void invokeCallback(); - -} Deleted: sandbox/trunk/openutils-spring-remote-callback/src/test/java/it/openutils/spring/remote/callback/test/ClientCallback.java =================================================================== --- sandbox/trunk/openutils-spring-remote-callback/src/test/java/it/openutils/spring/remote/callback/test/ClientCallback.java 2010-12-04 14:52:03 UTC (rev 3153) +++ sandbox/trunk/openutils-spring-remote-callback/src/test/java/it/openutils/spring/remote/callback/test/ClientCallback.java 2010-12-06 23:35:56 UTC (rev 3154) @@ -1,53 +0,0 @@ -/* - * Copyright Openmind http://www.openmindonline.it - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package it.openutils.spring.remote.callback.test; - -import it.openutils.spring.remote.callback.Callback; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -/** - * @author fcarone - * @version $Id: $ - */ -public class ClientCallback implements Callback -{ - - /** - * Logger. - */ - private Logger log = LoggerFactory.getLogger(ClientCallback.class); - - /** - * {@inheritDoc} - */ - public String getUID() - { - return "1"; - } - - /** - * {@inheritDoc} - */ - public void invoke() - { - log.info("Callback invoked"); - } - -} Modified: sandbox/trunk/openutils-spring-remote-callback/src/test/java/it/openutils/spring/remote/callback/test/ClientTest.java =================================================================== --- sandbox/trunk/openutils-spring-remote-callback/src/test/java/it/openutils/spring/remote/callback/test/ClientTest.java 2010-12-04 14:52:03 UTC (rev 3153) +++ sandbox/trunk/openutils-spring-remote-callback/src/test/java/it/openutils/spring/remote/callback/test/ClientTest.java 2010-12-06 23:35:56 UTC (rev 3154) @@ -16,6 +16,9 @@ package it.openutils.spring.remote.callback.test; +import it.openutils.spring.remote.callback.Callback; +import it.openutils.spring.remote.callback.WlcfgRmiCallbackProxyFactory; +import it.openutils.spring.remote.callback.manager.CallbackHolder; import it.openutils.spring.remote.callback.test.shared.DummyManager; import org.junit.Before; @@ -34,23 +37,44 @@ private DummyManager dummyManager; - /** * Get the RMI version of the manager */ @Before public void setupTest() { - this.dummyManager = (DummyManager) applicationContext.getBean("dummyManager"); + this.dummyManager = (DummyManager) applicationContext.getBean("dummyManagerRMI"); } @Test public void clientTest() { + Callback cb = new Callback() + { + + /** + * {@inheritDoc} + */ + public String getUID() + { + return "UID"; + } + + /** + * {@inheritDoc} + */ + public void invoke() + { + System.out.println("Callback on the client invoked"); + } + + }; + + WlcfgRmiCallbackProxyFactory factory = new WlcfgRmiCallbackProxyFactory(cb, Callback.class); + CallbackHolder.setCallback((Callback) factory.getProxy()); dummyManager.findAll(); } - /** * Sets the dummyManager. * @param dummyManager the dummyManager to set Modified: sandbox/trunk/openutils-spring-remote-callback/src/test/java/it/openutils/spring/remote/callback/test/server/DummyManagerImpl.java =================================================================== --- sandbox/trunk/openutils-spring-remote-callback/src/test/java/it/openutils/spring/remote/callback/test/server/DummyManagerImpl.java 2010-12-04 14:52:03 UTC (rev 3153) +++ sandbox/trunk/openutils-spring-remote-callback/src/test/java/it/openutils/spring/remote/callback/test/server/DummyManagerImpl.java 2010-12-06 23:35:56 UTC (rev 3154) @@ -16,13 +16,18 @@ package it.openutils.spring.remote.callback.test.server; -import it.openutils.spring.remote.callback.manager.CallbackManager; +import it.openutils.spring.remote.callback.Callback; +import it.openutils.spring.remote.callback.manager.CallbackHolder; import it.openutils.spring.remote.callback.test.dataobject.DummyDataobject; import it.openutils.spring.remote.callback.test.shared.DummyManager; +import java.util.ArrayList; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * @author fcarone * @version $Id: $ @@ -30,15 +35,24 @@ public class DummyManagerImpl implements DummyManager { - private CallbackManager callbackManager; + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(DummyManagerImpl.class); /** * {@inheritDoc} */ public List<DummyDataobject> findAll() { - callbackManager.invokeCallback(); - return null; + Callback callback = CallbackHolder.getCallback(); + if (callback != null) + { + log.info("On server, before the call to the client callback"); + callback.invoke(); + log.info("On server, after the call to the client callback"); + } + return new ArrayList<DummyDataobject>(); } /** @@ -48,15 +62,4 @@ { return null; } - - - /** - * Sets the callbackManager. - * @param callbackManager the callbackManager to set - */ - public void setCallbackManager(CallbackManager callbackManager) - { - this.callbackManager = callbackManager; - } - } Modified: sandbox/trunk/openutils-spring-remote-callback/src/test/resources/spring-client.xml =================================================================== --- sandbox/trunk/openutils-spring-remote-callback/src/test/resources/spring-client.xml 2010-12-04 14:52:03 UTC (rev 3153) +++ sandbox/trunk/openutils-spring-remote-callback/src/test/resources/spring-client.xml 2010-12-06 23:35:56 UTC (rev 3154) @@ -3,31 +3,18 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd"> <!-- RMI CONFIG --> - <bean id="dummyManager" class="org.springframework.aop.framework.ProxyFactoryBean"> - <property name="targetName" value="dummyManagerRMI" /> - <property name="interceptorNames"> - <list> - <value>serverMethodInterceptor</value> - </list> - </property> - </bean> + + <bean id="remoteInvocationFactory" class="it.openutils.spring.remote.callback.TLRemoteInvocationFactory" /> + + <bean id="dummyManagerRMI" class="org.springframework.remoting.rmi.RmiProxyFactoryBean" lazy-init="true"> - <property name="serviceUrl" value="rmi://localhost:1099/dummyManagerRmi" /> + <property name="serviceUrl" value="rmi://localhost:1299/dummyManagerRMI" /> <property name="serviceInterface" value="it.openutils.spring.remote.callback.test.shared.DummyManager" /> <property name="cacheStub" value="true" /> <property name="lookupStubOnStartup" value="false" /> <property name="refreshStubOnConnectFailure" value="true" /> + <property name="remoteInvocationFactory"> + <ref local="remoteInvocationFactory" /> + </property> </bean> - <bean id="serverMethodInterceptor" class="it.openutils.spring.remote.callback.interceptor.CallbackInstallerInterceptor"> - <property name="callbackManager" ref="callbackManagerJMS" /> - <property name="callback" ref="clientCallback" /> - </bean> - <bean id="clientCallback" class="it.openutils.spring.remote.callback.test.ClientCallback" /> - <!-- JMS CONFIG --> - <bean id="callbackManagerJMS" class="org.logicblaze.lingo.jms.JmsProxyFactoryBean"> - <property name="serviceInterface" value="it.openutils.spring.remote.callback.manager.CallbackManager" /> - <property name="connectionFactory" ref="jmsFactory" /> - <property name="destination" ref="callbackDestination" /> - </bean> - </beans> Deleted: sandbox/trunk/openutils-spring-remote-callback/src/test/resources/spring-jms.xml =================================================================== --- sandbox/trunk/openutils-spring-remote-callback/src/test/resources/spring-jms.xml 2010-12-04 14:52:03 UTC (rev 3153) +++ sandbox/trunk/openutils-spring-remote-callback/src/test/resources/spring-jms.xml 2010-12-06 23:35:56 UTC (rev 3154) @@ -1,9 +0,0 @@ -<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:util="http://www.springframework.org/schema/util" xmlns:amq="http://activemq.org/config/1.0" - xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd - http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd - http://activemq.org/config/1.0 http://activemq.apache.org/schema/core/activemq-core-5.0.0.xsd"> - - - -</beans> \ No newline at end of file Modified: sandbox/trunk/openutils-spring-remote-callback/src/test/resources/spring-services.xml =================================================================== --- sandbox/trunk/openutils-spring-remote-callback/src/test/resources/spring-services.xml 2010-12-04 14:52:03 UTC (rev 3153) +++ sandbox/trunk/openutils-spring-remote-callback/src/test/resources/spring-services.xml 2010-12-06 23:35:56 UTC (rev 3154) @@ -4,42 +4,11 @@ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd http://activemq.org/config/1.0 http://activemq.apache.org/schema/core/activemq-core-5.0.0.xsd"> <!-- MANAGERS CONFIG --> - <bean id="dummyManager" class="it.openutils.spring.remote.callback.test.server.DummyManagerImpl"> - <property name="callbackManager" ref="callbackManager" /> - </bean> - <bean id="callbackManager" class="it.openutils.spring.remote.callback.manager.impl.CallbackManagerImpl" /> - <!-- RMI CONFIG --> - <bean id="dummyManagerRMI" class="org.springframework.remoting.rmi.RmiServiceExporter" lazy-init="true"> - <property name="serviceUrl" value="rmi://localhost:1099/dummyManagerRmi" /> + <bean id="dummyManager" class="it.openutils.spring.remote.callback.test.server.DummyManagerImpl" /> + <bean name="/dummyManagerRMI" class="org.springframework.remoting.rmi.RmiServiceExporter" lazy-init="false"> + <property name="service" ref="dummyManager" /> + <property name="serviceName" value="dummyManagerRMI" /> <property name="serviceInterface" value="it.openutils.spring.remote.callback.test.shared.DummyManager" /> - <property name="cacheStub" value="true" /> - <property name="lookupStubOnStartup" value="false" /> - <property name="refreshStubOnConnectFailure" value="true" /> + <property name="registryPort" value="1299" /> </bean> - <!-- JMS CONFIG --> - <!-- lets create an embedded ActiveMQ Broker --> - <amq:broker useJmx="false" persistent="false"> - <amq:transportConnectors> - <amq:transportConnector uri="tcp://localhost:61616"> - </amq:transportConnector> - </amq:transportConnectors> - </amq:broker> - - <!-- ActiveMQ destinations to use --> - <amq:queue id="callbackDestination" physicalName="org.apache.activemq.spring.Test.spring.embedded"/> - - <!-- JMS ConnectionFactory to use, configuring the embedded broker using XML --> - <amq:connectionFactory id="jmsFactory" brokerURL="tcp://localhost:61616"/> - - <bean id="callbackManagerListener" class="org.logicblaze.lingo.jms.JmsServiceExporterMessageListener"> - <property name="service" ref="callbackManager" /> - <property name="serviceInterface" value="it.openutils.spring.remote.callback.manager.CallbackManager" /> - <property name="connectionFactory" ref="jmsFactory" /> - </bean> - <bean id="callbackManagerJMS" class="org.springframework.jms.listener.DefaultMessageListenerContainer"> - <property name="concurrentConsumers" value="20" /> - <property name="destination" ref="callbackDestination" /> - <property name="messageListener" ref="callbackManagerListener" /> - <property name="connectionFactory" ref="jmsFactory" /> - </bean> </beans> \ No newline at end of file Modified: sandbox/trunk/openutils-spring-remote-callback/src/test/resources/spring-tests.xml =================================================================== --- sandbox/trunk/openutils-spring-remote-callback/src/test/resources/spring-tests.xml 2010-12-04 14:52:03 UTC (rev 3153) +++ sandbox/trunk/openutils-spring-remote-callback/src/test/resources/spring-tests.xml 2010-12-06 23:35:56 UTC (rev 3154) @@ -3,9 +3,6 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd"> - <!-- any side --> - <import resource="classpath:spring-jms.xml" /> - <!-- server side --> <import resource="classpath:spring-services.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |