From: <fc...@us...> - 2008-03-20 15:14:20
|
Revision: 748 http://openutils.svn.sourceforge.net/openutils/?rev=748&view=rev Author: fcarone Date: 2008-03-20 08:13:45 -0700 (Thu, 20 Mar 2008) Log Message: ----------- initial impl for remote callbacks Added Paths: ----------- trunk/openutils-spring-remote-callback/ trunk/openutils-spring-remote-callback/pom.xml trunk/openutils-spring-remote-callback/src/ trunk/openutils-spring-remote-callback/src/main/ trunk/openutils-spring-remote-callback/src/main/java/ trunk/openutils-spring-remote-callback/src/main/java/it/ trunk/openutils-spring-remote-callback/src/main/java/it/openutils/ trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/ trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/ trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/ trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/Callback.java trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/interceptor/ trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/interceptor/CallbackInstallerInterceptor.java trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/manager/ trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/manager/CallbackHolder.java trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/manager/CallbackManager.java trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/manager/impl/ trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/manager/impl/CallbackManagerImpl.java trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/rmi/ trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/rmi/CallbackRemoteInvocation.java trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/rmi/CallbackRemoteInvocationFactory.java trunk/openutils-spring-remote-callback/src/main/resources/ Added: trunk/openutils-spring-remote-callback/pom.xml =================================================================== --- trunk/openutils-spring-remote-callback/pom.xml (rev 0) +++ trunk/openutils-spring-remote-callback/pom.xml 2008-03-20 15:13:45 UTC (rev 748) @@ -0,0 +1,144 @@ +<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> + <artifactId>openutils</artifactId> + <groupId>net.sourceforge.openutils</groupId> + <version>7</version> + <relativePath>..</relativePath> + </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>2.5.1</spring.version> + <aspectj.version>1.5.3</aspectj.version> + </properties> + <dependencies> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring</artifactId> + <version>${spring.version}</version> + <scope>provided</scope> + </dependency> + <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> + </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.4.1</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-testing-junit</artifactId> + <version>2.0.2</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-testing</artifactId> + <version>2.0.3</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.2</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.4</version> + <scope>test</scope> + </dependency> + </dependencies> + <repositories> + <repository> + <id>http://repository.codehaus.org</id> + <name>codehaus repository</name> + <url>http://repository.codehaus.org</url> + <snapshots> + <enabled>false</enabled> + </snapshots> + </repository> + </repositories> +</project> \ No newline at end of file Added: trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/Callback.java =================================================================== --- trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/Callback.java (rev 0) +++ trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/Callback.java 2008-03-20 15:13:45 UTC (rev 748) @@ -0,0 +1,37 @@ +/* + * 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; + +import java.util.EventListener; + + +/** + * @author fcarone + * @version $Id: $ + */ +public interface Callback extends EventListener +{ + /** + * Invocation for the remote callback + */ + void invoke(); + + /** + * @return The callback UID. + */ + String getUID(); +} Property changes on: trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/Callback.java ___________________________________________________________________ Name: svn:executable + * Added: trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/interceptor/CallbackInstallerInterceptor.java =================================================================== --- trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/interceptor/CallbackInstallerInterceptor.java (rev 0) +++ trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/interceptor/CallbackInstallerInterceptor.java 2008-03-20 15:13:45 UTC (rev 748) @@ -0,0 +1,65 @@ +/* + * 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.interceptor; + +import it.openutils.spring.remote.callback.Callback; +import it.openutils.spring.remote.callback.manager.CallbackManager; + +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; + + +/** + * @author fcarone + * @version $Id: $ + */ +public class CallbackInstallerInterceptor implements MethodInterceptor +{ + + private CallbackManager callbackManager; + + private Callback callback; + + /** + * {@inheritDoc} + */ + public Object invoke(MethodInvocation invocation) throws Throwable + { + callbackManager.installCallback(callback); + Object result = invocation.proceed(); + callbackManager.uninstallCallback(callback); + return result; + } + + /** + * Sets the callback. + * @param callback the callback to set + */ + public void setCallback(Callback callback) + { + this.callback = callback; + } + + /** + * Sets the callbackManager. + * @param callbackManager the callbackManager to set + */ + public void setCallbackManager(CallbackManager callbackManager) + { + this.callbackManager = callbackManager; + } +} Property changes on: trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/interceptor/CallbackInstallerInterceptor.java ___________________________________________________________________ Name: svn:executable + * Added: trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/manager/CallbackHolder.java =================================================================== --- trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/manager/CallbackHolder.java (rev 0) +++ trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/manager/CallbackHolder.java 2008-03-20 15:13:45 UTC (rev 748) @@ -0,0 +1,58 @@ +/* + * 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 org.apache.commons.lang.StringUtils; +import org.springframework.util.Assert; + + +/** + * @author fcarone + * @version $Id: $ + */ +public final class CallbackHolder +{ + + private static ThreadLocal<String> callbackUID; + + private CallbackHolder() + { + // + } + + /** + * @param uid The callback uid + */ + public static void setCallbackUID(String uid) + { + Assert.notNull(uid, "Only non-null UID instances are permitted"); + callbackUID.set(uid); + } + + public static String getCallbackUID() + { + return callbackUID.get(); + } + + /** + * Clears the callback UID + */ + public static void clearCallback() + { + callbackUID.set(StringUtils.EMPTY); + } +} Property changes on: trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/manager/CallbackHolder.java ___________________________________________________________________ Name: svn:executable + * Added: trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/manager/CallbackManager.java =================================================================== --- trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/manager/CallbackManager.java (rev 0) +++ trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/manager/CallbackManager.java 2008-03-20 15:13:45 UTC (rev 748) @@ -0,0 +1,44 @@ +/* + * 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(); + +} Property changes on: trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/manager/CallbackManager.java ___________________________________________________________________ Name: svn:executable + * Added: trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/manager/impl/CallbackManagerImpl.java =================================================================== --- trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/manager/impl/CallbackManagerImpl.java (rev 0) +++ trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/manager/impl/CallbackManagerImpl.java 2008-03-20 15:13:45 UTC (rev 748) @@ -0,0 +1,66 @@ +/* + * 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.impl; + +import it.openutils.spring.remote.callback.Callback; +import it.openutils.spring.remote.callback.manager.CallbackHolder; +import it.openutils.spring.remote.callback.manager.CallbackManager; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + + +/** + * @author fcarone + * @version $Id: $ + */ +public class CallbackManagerImpl implements CallbackManager +{ + + private Set<Callback> callbacks = new HashSet<Callback>(); + private Map<String, Callback> callbacksMap = new HashMap<String, Callback>(); + + /** + * {@inheritDoc} + */ + public void invokeCallback() + { + Callback callback = callbacksMap.get(CallbackHolder.getCallbackUID()); + callback.invoke(); + } + + /** + * {@inheritDoc} + */ + public void installCallback(Callback callback) + { + callbacks.add(callback); + callbacksMap.put(callback.getUID(), callback); + } + + /** + * {@inheritDoc} + */ + public void uninstallCallback(Callback callback) + { + callbacks.remove(callback); + callbacksMap.remove(callback.getUID()); + } + +} Property changes on: trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/manager/impl/CallbackManagerImpl.java ___________________________________________________________________ Name: svn:executable + * Added: trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/rmi/CallbackRemoteInvocation.java =================================================================== --- trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/rmi/CallbackRemoteInvocation.java (rev 0) +++ trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/rmi/CallbackRemoteInvocation.java 2008-03-20 15:13:45 UTC (rev 748) @@ -0,0 +1,66 @@ +/* + * 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.rmi; + +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 fcarone + * @version $Id: $ + */ +public class CallbackRemoteInvocation extends RemoteInvocation +{ + /** + * + */ + private static final long serialVersionUID = 5093459466178643546L; + + private String callbackUID; + + /** + * @param methodInvocation The methodInvocation + */ + public CallbackRemoteInvocation(MethodInvocation methodInvocation) + { + super(methodInvocation); + this.callbackUID = CallbackHolder.getCallbackUID(); + } + + /** + * {@inheritDoc} + */ + @Override + public Object invoke(Object targetObject) throws NoSuchMethodException, IllegalAccessException, + InvocationTargetException + { + CallbackHolder.setCallbackUID(callbackUID); + try + { + return super.invoke(targetObject); + } + finally + { + CallbackHolder.clearCallback(); + } + } +} Property changes on: trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/rmi/CallbackRemoteInvocation.java ___________________________________________________________________ Name: svn:executable + * Added: trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/rmi/CallbackRemoteInvocationFactory.java =================================================================== --- trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/rmi/CallbackRemoteInvocationFactory.java (rev 0) +++ trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/rmi/CallbackRemoteInvocationFactory.java 2008-03-20 15:13:45 UTC (rev 748) @@ -0,0 +1,45 @@ +/* + * 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.rmi; + +import org.aopalliance.intercept.MethodInvocation; +import org.springframework.remoting.support.RemoteInvocation; +import org.springframework.remoting.support.RemoteInvocationFactory; + + + +/** + * @author fcarone + * @version $Id: $ + */ +public class CallbackRemoteInvocationFactory implements RemoteInvocationFactory +{ + /** + * + */ + private static final long serialVersionUID = 5093459466178643546L; + + /** + * {@inheritDoc} + */ + public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) + { + return new CallbackRemoteInvocation(methodInvocation); + } + + +} Property changes on: trunk/openutils-spring-remote-callback/src/main/java/it/openutils/spring/remote/callback/rmi/CallbackRemoteInvocationFactory.java ___________________________________________________________________ Name: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |