Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * 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
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.    
Class which handles the asynchronous response message from an async service back to the client Java component This class provides a registration function which permits the reference invoking code to register the Future which is used to return the response to the Java component code
     // Map used to link between async requests and async responses
 	} // end constructor
Deal with the asynchronous response message

msg - the response message The response message must contain a RELATES_TO id, which is used to identify the Future that represents the operation yet to complete. The Future is then completed with the content of the message. The Future either calls back to the application code, or it is expected that the application is polling the Future for its completion.
 	@SuppressWarnings({ "rawtypes""unchecked" })
 	public void invokeAsyncResponse(Message msg) {
 		// Obtain the Message ID for this message
 		String relatesID = getMessageRelatesIDmsg );
 		ifrelatesID == null ) 
 			throw new ServiceRuntimeException("JavaAsyncResponseInvoker - response message has no RELATES_TO id");
 		// Look up the response object & remove it from the Map
 		Object responseHandler = .remove(relatesID);
 		ifresponseHandler == null ) 
 			throw new ServiceRuntimeException("JavaAsyncResponseInvoker - no Future matches the RELATES_TO id: " + relatesID);
 		// Invoke the response handler with the content of the message 
 		// - in the case of a Java implementation, the response handler is a Future...
 		AsyncResponseHandler future = (AsyncResponseHandlerresponseHandler;
 		Object payload = msg.getBody();
 		Object response;
 		ifpayload == null ) {
 			..println("Returned response message was null");
 		} else {
             if (payload.getClass().isArray()) {
                 response = ((Object[])payload)[0];
             } else {
                 response = payload;
             } // end if
             ifresponse.getClass().equals(AsyncFaultWrapper.class)) {
             	future.setWrappedFault((AsyncFaultWrapperresponse );
             } else if ( response instanceof Throwable ) {
             	future.setFault( (Throwable)response );
             } else {
             } // end if
 		} // end if
 	} // end method invokeAsyncResponse
Registers an Async response, which provides an ID which identifies a given response and an object which can handle the response

id - the ID
responseHandler - the response handler object
 	public void registerAsyncResponseString idObject responseHandler ) {
		// Add the ID/response handler mapping into the table
		ifid != null && responseHandler != null ) .put(idresponseHandler);
// end method registerAsyncResponse
Extracts the RELATES_TO header from the message

msg - the Tuscany message
- the value of the RELATES_TO header as a String
	private String getMessageRelatesIDMessage msg ) {
		return (String)msg.getHeaders().get("RELATES_TO");
// end method getMessageRelatesID
// end class JavaAsyncResponseInvoker
New to GrepCode? Check out our FAQ X