You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ed...@apache.org on 2010/07/05 13:07:14 UTC

svn commit: r960540 - in /tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation: AsyncFaultWrapper.java AsyncResponseHandler.java impl/AsyncResponseHandlerImpl.java

Author: edwardsmj
Date: Mon Jul  5 11:07:14 2010
New Revision: 960540

URL: http://svn.apache.org/viewvc?rev=960540&view=rev
Log:
Adding Classes to handle asynchronous responses as part of Phase II of TUSCANY-3612

Added:
    tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AsyncFaultWrapper.java   (with props)
    tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AsyncResponseHandler.java   (with props)
    tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncResponseHandlerImpl.java   (with props)

Added: tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AsyncFaultWrapper.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AsyncFaultWrapper.java?rev=960540&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AsyncFaultWrapper.java (added)
+++ tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AsyncFaultWrapper.java Mon Jul  5 11:07:14 2010
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.tuscany.sca.core.invocation;
+
+/**
+ * A class which is used to wrap an Exception of any type thrown by an asynchronous service operation and
+ * which is returned through a separate one-way message sent asynchronously from the server to the client.
+ *
+ */
+public class AsyncFaultWrapper {
+	
+	private String faultClassName = null;
+	private Exception e = null;
+	
+	public AsyncFaultWrapper() {
+		super();
+	}
+	
+	public AsyncFaultWrapper( Exception e ) {
+		super();
+		storeFault( e );
+	}
+	
+	public void storeFault( Exception e ) {
+		faultClassName = e.getClass().getCanonicalName();
+		this.e = e;
+	}
+	
+	public Exception retrieveFault( ) {
+		if( e != null ) return e;
+		System.out.println( "Tried to retrieve Exception reom AsyncFaultWrapper: " + faultClassName);
+		return null;
+	}
+
+}

Propchange: tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AsyncFaultWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AsyncFaultWrapper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AsyncResponseHandler.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AsyncResponseHandler.java?rev=960540&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AsyncResponseHandler.java (added)
+++ tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AsyncResponseHandler.java Mon Jul  5 11:07:14 2010
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.tuscany.sca.core.invocation;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * An interface which describes a general response pattern for the asynchronous invocation of a service
+ *
+ * @param <V> - the type of the non-fault response
+ */
+@Remotable()
+public interface AsyncResponseHandler<V> {
+	
+	/**
+	 * Async process completed with a Fault.  Must only be invoked once
+	 * @param e - the wrapper containing the Fault to send
+	 * @throws IllegalStateException if either the setResponse method or the setFault method have been called previously
+	 */
+	public void setFault(AsyncFaultWrapper e);
+	
+	/**
+	 * Async process completed with a response message.  Must only be invoked once
+	 * @throws IllegalStateException if either the setResponse method or the setFault method have been called previously
+	 * @param res - the response message, which is of type V
+	 */
+	public void setResponse(V res);
+
+}

Propchange: tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AsyncResponseHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AsyncResponseHandler.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncResponseHandlerImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncResponseHandlerImpl.java?rev=960540&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncResponseHandlerImpl.java (added)
+++ tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncResponseHandlerImpl.java Mon Jul  5 11:07:14 2010
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.tuscany.sca.core.invocation.impl;
+
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.core.invocation.AsyncFaultWrapper;
+import org.apache.tuscany.sca.core.invocation.AsyncResponseHandler;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.policy.ExtensionType;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+
+/**
+ * A class intended to form the final link in the chain calling into a Future which represents
+ * the response to an asynchronous service invocation
+ * Most methods are dummies, required to fulfil the contracts for ImplementationProvider, Implementation
+ * and Invoker, since this class collapses together the functions of these separate interfaces, due to its
+ * specialized nature, where most of the function will never be used.
+ * 
+ * The class acts as the implementation object that terminates the chain - and also as the provider of the implementation.
+ * The class accepts Future objects which represent individual invocations of forward operations on the async service
+ * and expects that the responses it handles as invocations will carry the unique ID of one of the Future objects in the
+ * message header.  On receipt of each message, the class seeks out the Future with that unique ID and completes the future
+ * either with a response message or with a Fault.
+ *
+ * @param <V>
+ */
+public class AsyncResponseHandlerImpl<V> implements AsyncResponseHandler<V>,
+		ImplementationProvider, Implementation, Invoker {
+
+	private ConcurrentHashMap< String, AsyncInvocationFutureImpl<?> > table = 
+		new ConcurrentHashMap< String, AsyncInvocationFutureImpl<?> >();
+	
+	public Invoker createInvoker(RuntimeComponentService service,
+			Operation operation) {
+		return this;
+	}
+	
+	/**
+	 * Add a future to this response handler
+	 * @param future - the future
+	 */
+	public void addFuture( AsyncInvocationFutureImpl<?> future ) {
+		// The Future is stored in the table indexed by its unique ID
+		table.put(future.getUniqueID(), future);		
+	} // end method addFuture
+
+	public boolean supportsOneWayInvocation() {
+		return true;
+	}
+
+	public void start() {}
+
+	public void stop() {}
+
+	public List<Operation> getOperations() {
+		return null;
+	}
+
+	public QName getType() {
+		return null;
+	}
+
+	public List<Property> getProperties() {
+		return null;
+	}
+
+	public Property getProperty(String name) {
+		return null;
+	}
+
+	public Reference getReference(String name) {
+		return null;
+	}
+
+	public List<Reference> getReferences() {
+		return null;
+	}
+
+	public Service getService(String name) {
+		return null;
+	}
+
+	public List<Service> getServices() {
+		return null;
+	}
+
+	public String getURI() {
+		return null;
+	}
+
+	public void setURI(String uri) {}
+
+	public boolean isUnresolved() {
+		return false;
+	}
+
+	public void setUnresolved(boolean unresolved) {}
+
+	public ExtensionType getExtensionType() {
+		return null;
+	}
+
+	public List<PolicySet> getPolicySets() {
+		return null;
+	}
+
+	public List<Intent> getRequiredIntents() {
+		return null;
+	}
+
+	public void setExtensionType(ExtensionType type) {}
+
+	public void setFault(AsyncFaultWrapper e) {}
+
+	public void setResponse(V res) { }
+
+	public Message invoke(Message msg) {
+		// TODO Auto-generated method stub
+		// Get the unique ID from the message header
+		// Fetch the Future with that Unique ID
+		// Complete the Future with a Response message
+		// ...or complete the Future with a Fault
+		return null;
+	}
+
+} // end class 

Propchange: tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncResponseHandlerImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/AsyncResponseHandlerImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date