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
   * 
  *   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 java.util.UUID;
 
Invoker for a endpoint or endpoint reference

Version:
$Rev: 1061855 $ $Date: 2011-01-21 17:41:26 +0200 (Fri, 21 Jan 2011) $
 
 public class RuntimeInvoker implements InvokerInvokerAsyncRequest {
     protected ExtensionPointRegistry registry;
     protected MessageFactory messageFactory;
     protected Invocable invocable;
     
     // Run async service invocations using a ThreadPoolExecutor
     private ExecutorService theExecutor;
 
     public RuntimeInvoker(ExtensionPointRegistry registryInvocable invocable) {
         this. = registry;
         this. = registry.getExtensionPoint(FactoryExtensionPoint.class).getFactory(MessageFactory.class);
         this. = invocable;
         
         UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class);
         WorkScheduler scheduler = utilities.getUtility(WorkScheduler.class);
          = scheduler.getExecutorService();
     }
 
     public Message invokeBinding(Message msg) {
         Message context = ThreadMessageContext.setMessageContext(msg);
         try {
             return .getBindingInvocationChain().getHeadInvoker().invoke(msg);
         } finally {
             ThreadMessageContext.setMessageContext(context);
         }
     } // end method invokeBinding
     
    
Async Invoke of the Binding Chain

Parameters:
msg - the message to use in the invocation
 
     public void invokeBindingAsync(Message msg) {
         Message context = ThreadMessageContext.setMessageContext(msg);
         try {
         } catch (Throwable t ) {
         	// TODO - consider what best to do with exception
         } finally {
             ThreadMessageContext.setMessageContext(context);
         } // end try
     } // end method invokeBindingAsync
     
     public Message invoke(Message msg) {
         return invoke(msg.getOperation(), msg);
     }
 
     public Object invoke(Operation operationObject[] argsthrows InvocationTargetException {
         Message msg = .createMessage();
         msg.setBody(args);
         Message resp = invoke(operationmsg);
         Object body = resp.getBody();
         if (resp.isFault()) {
            throw new InvocationTargetException((Throwable)body);
        }
        return body;
    }
    public Message invoke(Operation operationMessage msg) {
        InvocationChain chain = .getInvocationChain(operation);
        return invoke(chainmsg);
    }
    public Message invoke(InvocationChain chainMessage msg) {
        if ( instanceof Endpoint) {
            msg.setTo((Endpoint));
        } else if ( instanceof EndpointReference) {
            msg.setFrom((EndpointReference));
        }
        Invoker headInvoker = chain.getHeadInvoker();
        Operation operation = chain.getTargetOperation();
        msg.setOperation(operation);
        Message msgContext = ThreadMessageContext.setMessageContext(msg);
        try {
            return headInvoker.invoke(msg);
        } finally {
            ThreadMessageContext.setMessageContext(msgContext);
        }
    }
    
    
Initiate the sending of the forward part of an asynchronous exchange along the request part of the wire.

Parameters:
msg the request message
    public void invokeAsync(Message msg) {
        if ( instanceof Endpoint) {
            Endpoint ep = (Endpoint);
            msg.setTo(ep);
            if (!ep.isAsyncInvocation()){
                throw new ServiceRuntimeException("Calling invokeAsync on a non-async endpoint - " + 
                                                  ep);
            }
        } else if ( instanceof EndpointReference) {
            if (!epr.isAsyncInvocation()){
                throw new ServiceRuntimeException("Calling invokeAsync on a non-async endpoint reference - " + 
                                                  epr);
            }
            if (epr.isOutOfDate()) {
                epr.rebuild();
            }
            msg.setFrom(epr);
            msg.setTo(epr.getTargetEndpoint());
        }
        
        Operation operation = msg.getOperation();
        InvocationChain chain = .getInvocationChain(operation);
        if (chain == null) {
            throw new IllegalArgumentException("No matching operation is found: " + operation.getName());
        }
        
        // create an async message ID if there isn't one there already
        if (!msg.getHeaders().containsKey(.)){
            msg.getHeaders().put(., UUID.randomUUID().toString());UUID.randomUUID().toString();
        }
        // Perform the async invocation
        Invoker headInvoker = chain.getHeadInvoker();
        Message msgContext = ThreadMessageContext.setMessageContext(msg);
        try {
            try {
                ((InvokerAsyncRequest)headInvoker).invokeAsyncRequest(msg);
            } catch (ServiceRuntimeException ex) {
                throw ex;
            } catch (Throwable ex) {                
                // temporary fix to swallow the dummy exception that's
                // thrown back to get past the response chain processing. 
                if (!(ex instanceof AsyncResponseException)){
                    throw new ServiceRuntimeException(ex);
                }
            }
        } finally {
            ThreadMessageContext.setMessageContext(msgContext);
        }
        return;
    }
    
    
Initiate the sending of the response part of an asynchronous exchange along the response part of the wire.

Parameters:
msg the response message
    public void invokeAsyncResponse(Message msg) {  
        Invoker tailInvoker = chain.getTailInvoker();
        ((InvokerAsyncResponse)tailInvoker).invokeAsyncResponse(msg);       
    } // end method invokeAsyncResponse
	public void invokeAsyncRequest(Message msgthrows Throwable {
// end method invokeAsyncRequest
New to GrepCode? Check out our FAQ X