Package org.apache.tuscany.sca.runtime

Examples of org.apache.tuscany.sca.runtime.RuntimeEndpointReference


    // TODO - this only works for the local case!
    @SuppressWarnings("unchecked")
  public void invokeAsyncResponse(Message msg) {
      AsyncResponseInvoker<RuntimeEndpointReference> asyncInvoker =
        (AsyncResponseInvoker<RuntimeEndpointReference>)msg.getHeaders().get("ASYNC_RESPONSE_INVOKER");
      RuntimeEndpointReference epr;
      if( asyncInvoker != null ) {
        epr = asyncInvoker.getResponseTargetAddress();
      } else {
        epr = (RuntimeEndpointReference)msg.getFrom();
      } // end if
      if( epr != null ) {
        epr.invokeAsyncResponse(msg);
      } else {
        throw new ServiceRuntimeException("SCABindingAsyncResponseInvoker - invokeAsyncResponse has null epr");
      } // end if
       
    } // end method invokeAsyncResponse
View Full Code Here


        @SuppressWarnings("unchecked")
    AsyncResponseInvoker<?> respInvoker =
          (AsyncResponseInvoker<?>)msg.getHeaders().get("ASYNC_RESPONSE_INVOKER");
        if( respInvoker != null && "SCA_LOCAL".equals(respInvoker.getBindingType()) ) {
          // Handle the locally optimised case
          RuntimeEndpointReference responseEPR = (RuntimeEndpointReference)respInvoker.getResponseTargetAddress();
          msg.setFrom(responseEPR);
          // Handle async response Relates_To message ID value
          String msgID = respInvoker.getRelatesToMsgID();
          msg.getHeaders().put("RELATES_TO", msgID);
         
          // Call the processing on the reference chain directly
          responseEPR.invokeAsyncResponse(msg);
         
          // Prevent the response being processed by the rest of the service chain
          return;
        } else {
          // Carry on processing the response by the rest of the service chain
View Full Code Here

      // Deal with async callback
      // Ensure invocation chains are built...
      getInvocationChains();
      // async callback handling
      if( this.isAsyncInvocation() && !this.getCallbackEndpointReferences().isEmpty() ) {
        RuntimeEndpointReference asyncEPR = (RuntimeEndpointReference) this.getCallbackEndpointReferences().get(0);
        // Place a link to the callback EPR into the message headers...
        msg.getHeaders().put(Constants.ASYNC_CALLBACK, asyncEPR );
      }
      // end of async callback handling
        return invoker.invokeBinding(msg);
View Full Code Here

      if( hasNativeAsyncBinding(this) ) return;
     
      // Check to see if the callback already exists
      if( asyncCallbackExists( this ) ) return;
     
      RuntimeEndpointReference asyncEPR = createAsyncEPR( this );
     
      // Store the new callback EPR into the Endpoint
      this.getCallbackEndpointReferences().add(asyncEPR);
     
      // Also store the callback EPR into the EndpointRegistry
View Full Code Here

     * @return the EndpointReference object representing the callback
     */
    private RuntimeEndpointReference createAsyncEPR( RuntimeEndpoint endpoint ){
      CompositeContext compositeContext = endpoint.getCompositeContext();
      RuntimeAssemblyFactory assemblyFactory = getAssemblyFactory( compositeContext );
        RuntimeEndpointReference epr = (RuntimeEndpointReference)assemblyFactory.createEndpointReference();
        epr.bind( compositeContext );
       
        // Create pseudo-component
        epr.setComponent(component);
       
        // Create pseudo-reference
        ComponentReference reference = assemblyFactory.createComponentReference();
        ExtensionPointRegistry registry = compositeContext.getExtensionPointRegistry();
        FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class);
        JavaInterfaceFactory javaInterfaceFactory = (JavaInterfaceFactory)modelFactories.getFactory(JavaInterfaceFactory.class);
        JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
        try {
      interfaceContract.setInterface(javaInterfaceFactory.createJavaInterface(AsyncResponseService.class));
    } catch (InvalidInterfaceException e1) {
      // Nothing to do here - will not happen
    } // end try
    reference.setInterfaceContract(interfaceContract);
        String referenceName = endpoint.getService().getName() + "_asyncCallback";
        reference.setName(referenceName);
        reference.setForCallback(true);
        // Add in "implementation" reference (really a dummy, but with correct interface)
        Reference implReference = assemblyFactory.createReference();
        implReference.setInterfaceContract(interfaceContract);
        implReference.setName(referenceName);
        implReference.setForCallback(true);
       
        reference.setReference(implReference);
        // Set the created ComponentReference into the EPR
        epr.setReference(reference);
       
        // Create a binding
    Binding binding = createMatchingBinding( endpoint.getBinding(), (RuntimeComponent)endpoint.getComponent(), reference, registry );     
    epr.setBinding(binding);
   
    // Need to establish policies here (binding has some...)
    epr.getRequiredIntents().addAll( endpoint.getRequiredIntents() );
    epr.getPolicySets().addAll( endpoint.getPolicySets() );
   
    // Attach a dummy endpoint to the epr
    RuntimeEndpoint ep = (RuntimeEndpoint)assemblyFactory.createEndpoint();
    ep.setUnresolved(false);
    epr.setTargetEndpoint(ep);
    //epr.setStatus(EndpointReference.Status.RESOLVED_BINDING);
    epr.setStatus(EndpointReference.Status.WIRED_TARGET_FOUND_AND_MATCHED);
    epr.setUnresolved(false);
   
    // Set the URI for the EPR
    String eprURI = endpoint.getComponent().getName() + "#reference-binding(" + referenceName + "/" + referenceName + ")";
    epr.setURI(eprURI);
       
      return epr;
    } // end method RuntimeEndpointReference
View Full Code Here

        if (source == null) {
            throw new ServiceRuntimeException("No runtime source is available");
        }

        if (source instanceof RuntimeEndpointReference) {
            RuntimeEndpointReference epr = (RuntimeEndpointReference)source;
            if (epr.isOutOfDate()) {
                epr.rebuild();
                chains.clear();
            }
        } // end if

        InvocationChain chain = getInvocationChain(method, source);
View Full Code Here

     * @return - the RuntimeEndpoint of the async callback
     */
    private RuntimeEndpoint getAsyncCallback(Invocable source) {
        if (!(source instanceof RuntimeEndpointReference))
            return null;
        RuntimeEndpointReference epr = (RuntimeEndpointReference)source;
        if (!isAsyncInvocation(epr)) return null;
       
        // Check to see if the binding supports async invocation natively
        ReferenceBindingProvider eprProvider = epr.getBindingProvider();
        if( eprProvider instanceof EndpointReferenceAsyncProvider) {
          if( ((EndpointReferenceAsyncProvider)eprProvider).supportsNativeAsync() ) return null;
        } // end if
       
        RuntimeEndpoint endpoint;
        synchronized (epr) {
            endpoint = (RuntimeEndpoint)epr.getCallbackEndpoint();
            // If the async callback endpoint is already created, return it...
            if (endpoint != null)
                return endpoint;
            // Create the endpoint for the async callback
            endpoint = createAsyncCallbackEndpoint(epr);
            epr.setCallbackEndpoint(endpoint);
        } // end synchronized

        // Activate the new callback endpoint
        startEndpoint(epr.getCompositeContext(), endpoint);
        endpoint.getInvocationChains();

        return endpoint;
    } // end method setupAsyncCallback
View Full Code Here

     * @return - true if the invocation is async
     */
    private boolean isAsyncInvocation(Invocable source) {
        if (!(source instanceof RuntimeEndpointReference))
            return false;
        RuntimeEndpointReference epr = (RuntimeEndpointReference)source;
        // First check is to see if the EPR itself has the asyncInvocation intent marked
        for (Intent intent : epr.getRequiredIntents()) {
            if (intent.getName().equals(ASYNC_INVOKE))
                return true;
        } // end for

        // Second check is to see if the target service has the asyncInvocation intent marked
        Endpoint ep = epr.getTargetEndpoint();
        for (Intent intent : ep.getRequiredIntents()) {
            if (intent.getName().equals(ASYNC_INVOKE))
                return true;
        } // end for
        return false;
View Full Code Here

    } // end isAsyncInvocation
   
    private boolean supportsNativeAsync(Invocable source) {
      if (!(source instanceof RuntimeEndpointReference))
            return false;
        RuntimeEndpointReference epr = (RuntimeEndpointReference)source;
       
        // TODO - need to update this once BindingProvider interface is refactored to contain
        // supportsNativeAsync directly...
        ReferenceBindingProvider provider = epr.getBindingProvider();
        if( provider instanceof EndpointReferenceAsyncProvider ) {
          return ((EndpointReferenceAsyncProvider)provider).supportsNativeAsync();
        } else {
          return false;
        } // end if
View Full Code Here

                                RuntimeComponent tuscanyRuntimeComponent = _server.getTuscanyRuntimeComponent(channel.getProcessName());

                                // Fetching the reference based on the data held in the PRC / Endpoint
                                String refName = channel.getEndpoint().serviceName.getLocalPart();
                                RuntimeComponentReference runtimeComponentReference = getReferenceByName( tuscanyRuntimeComponent, refName );
                                RuntimeEndpointReference epr = getEndpointReference( runtimeComponentReference, partnerRoleMessageExchange );
                                // convert operations
                                Operation operation =
                                    findOperation(partnerRoleMessageExchange.getOperation().getName(), epr);

                                /*
                                 This is how a request looks like (payload is wrapped with extra info)
                                   <?xml version="1.0" encoding="UTF-8"?>
                                   <message>
                                     <parameters>
                                       <getGreetings xmlns="http://greetings">
                                         <message xmlns="http://helloworld">Luciano</message>
                                       </getGreetings>
                                     </parameters>
                                   </message>
                                 */
                                Element msg = partnerRoleMessageExchange.getRequest().getMessage();
                                if (msg != null) {
   
                                    if(__log.isDebugEnabled()) {
                                        String xml = DOMUtils.domToString(msg);
                                        String payload = DOMUtils.domToString(getPayload(partnerRoleMessageExchange.getRequest()));
                                        __log.debug("Starting invocation of SCA Reference");
                                        __log.debug(">>> Original message: " + xml);
                                        __log.debug(">>> Payload: " + payload);
                                    } // end if
                                   
                                    Object[] args = new Object[] {getPayload(partnerRoleMessageExchange.getRequest())};

                                    Object result = null;
                                    boolean success = false;

                                    try {
                                        result = epr.invoke(operation, args);
                                        success = true;
                                    } catch (Exception e) {
                                      e.printStackTrace();
                                        partnerRoleMessageExchange.replyWithFailure(MessageExchange.FailureType.OTHER,
                                                                                    e.getMessage(),
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.runtime.RuntimeEndpointReference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.