Package org.apache.tuscany.sca.assembly

Examples of org.apache.tuscany.sca.assembly.Endpoint


                                                      ComponentService service,
                                                      String bindingName,
                                                      Class<?> businessInterface) throws CloneNotSupportedException,
        InvalidInterfaceException {

        Endpoint endpoint = getEndpoint(service, bindingName);
        return createEndpointReference(endpoint, businessInterface);
    }
View Full Code Here


            // message in thread context could be null if the user has
            // spun up a new thread inside their component implementation
            return null;
        }
       
        Endpoint to = msgContext.getTo();
        RuntimeComponentService service = (RuntimeComponentService) to.getService();
        RuntimeComponentReference callbackReference = (RuntimeComponentReference)service.getCallbackReference();
        if (callbackReference == null) {
            return null;
        }
        JavaInterface javaInterface = (JavaInterface) callbackReference.getInterfaceContract().getInterface();
View Full Code Here

        return resolvedEndpoint;
    }

    private RuntimeEndpointReference selectCallbackEPR(Message msgContext) {
        // look for callback binding with same name as service binding
        Endpoint to = msgContext.getTo();
        if (to == null) {
            //FIXME: need better exception
            throw new ServiceRuntimeException("Destination for forward call is not available");
        }
        for (EndpointReference epr : callbackEPRs) {
            if (epr.getBinding().getName().equals(to.getBinding().getName())) {
                return (RuntimeEndpointReference) epr;
            }
        }

        // if no match, look for callback binding with same type as service binding
        for (EndpointReference epr : callbackEPRs) {
            if (epr.getBinding().getType().equals(to.getBinding().getType())) {
                return (RuntimeEndpointReference) epr;
            }
        }

        // no suitable callback wire was found
View Full Code Here

            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;
    } // end isAsyncInvocation
View Full Code Here

                                        componentReference
                                                .getInterfaceContract(),
                                        targetComponentService
                                                .getInterfaceContract())) {

                            Endpoint endpoint = endpointFactory
                                    .createEndpoint();
                            endpoint.setTargetName(targetComponent.getName());
                            endpoint.setSourceComponent(null); // TODO - fixed
                                                               // up at start
                            endpoint
                                    .setSourceComponentReference(componentReference);
                            endpoint.setInterfaceContract(componentReference
                                    .getInterfaceContract());
                            endpoint.setTargetComponent(targetComponent);
                            endpoint
                                    .setTargetComponentService(targetComponentService);
                            endpoint.getCandidateBindings().addAll(
                                    componentReference.getBindings());
                            endpoints.add(endpoint);

                            if (multiplicity == Multiplicity.ZERO_ONE
                                    || multiplicity == Multiplicity.ONE_ONE) {
                                break;
                            }
                        }
                    }
                }
            }

            if (multiplicity == Multiplicity.ONE_N
                    || multiplicity == Multiplicity.ONE_ONE) {
                if (endpoints.size() == 0) {
                    warning(monitor, "NoComponentReferenceTarget",
                            componentReference, componentReference.getName());
                }
            }

        } else if (!componentReference.getTargets().isEmpty()) {

            // Check if the component reference does not mix the use of
            // endpoints specified via
            // binding elements with target endpoints specified via the target
            // attribute
            for (Binding binding : componentReference.getBindings()) {
                if (binding.getURI() != null) {
                    warning(monitor, "ReferenceEndPointMixWithTarget",
                            composite, componentReference.getName());
                }
            }

            // Resolve targets specified on the component reference
            for (ComponentService componentService : componentReference
                    .getTargets()) {

                // Resolve the target component and service
                String name = componentService.getName();
                ComponentService targetComponentService = componentServices
                        .get(name);
                Component targetComponent;
                int s = name.indexOf('/');
                if (s == -1) {
                    targetComponent = components.get(name);
                } else {
                    targetComponent = components.get(name.substring(0, s));
                }

                if (targetComponentService != null) {

                    // Check that the target component service provides
                    // a superset of the component reference interface
                    if (componentReference.getInterfaceContract() == null
                            || interfaceContractMapper.isCompatible(
                                    componentReference.getInterfaceContract(),
                                    targetComponentService
                                            .getInterfaceContract())) {

                        Endpoint endpoint = endpointFactory.createEndpoint();
                        endpoint.setTargetName(targetComponent.getName());
                        endpoint.setSourceComponent(null); // TODO - fixed up at
                                                           // start
                        endpoint
                                .setSourceComponentReference(componentReference);
                        endpoint.setInterfaceContract(componentReference
                                .getInterfaceContract());
                        endpoint.setTargetComponent(targetComponent);
                        endpoint
                                .setTargetComponentService(targetComponentService);
                        endpoint.getCandidateBindings().addAll(
                                componentReference.getBindings());
                        endpoints.add(endpoint);

                        // mark the reference target as resolved. Used later
                        // when we are looking to
                        // see if an sca binding is associated with a resolved
                        // target or not
                        componentService.setUnresolved(false);
                    } else {
                        warning(monitor, "ReferenceIncompatibleInterface",
                                composite, composite.getName().toString(),
                                componentReference.getName(), componentService
                                        .getName());
                    }
                } else {
                    // add all the reference bindings into the target so that
                    // they
                    // can be used for comparison when the target is resolved at
                    // runtime
                    componentService.getBindings().addAll(
                            componentReference.getBindings());

                    Endpoint endpoint = endpointFactory.createEndpoint();
                    endpoint.setTargetName(name);
                    endpoint.setSourceComponent(null); // TODO - fixed up at
                                                       // start
                    endpoint.setSourceComponentReference(componentReference);
                    endpoint.setInterfaceContract(componentReference
                            .getInterfaceContract());
                    endpoint.getCandidateBindings().addAll(
                            componentReference.getBindings());
                    endpoints.add(endpoint);

                    // The bindings will be cloned back into the reference when
                    // the
                    // target is finally resolved.
                    warning(monitor, "ComponentReferenceTargetNotFound",
                            composite, composite.getName().toString(),
                            componentService.getName());
                }
            }
        } else if ((componentReference.getReference() != null)
                && (!componentReference.getReference().getTargets().isEmpty())) {

            // Resolve targets from the corresponding reference in the
            // componentType
            for (ComponentService componentService : componentReference
                    .getReference().getTargets()) {

                // Resolve the target component and service
                String name = componentService.getName();
                ComponentService targetComponentService = componentServices
                        .get(name);
                Component targetComponent;
                int s = name.indexOf('/');
                if (s == -1) {
                    targetComponent = components.get(name);
                } else {
                    targetComponent = components.get(name.substring(0, s));
                }

                if (targetComponentService != null) {

                    // Check that the target component service provides
                    // a superset of
                    // the component reference interface
                    if (componentReference.getInterfaceContract() == null
                            || interfaceContractMapper.isCompatible(
                                    componentReference.getInterfaceContract(),
                                    targetComponentService
                                            .getInterfaceContract())) {

                        Endpoint endpoint = endpointFactory.createEndpoint();
                        endpoint.setTargetName(targetComponent.getName());
                        endpoint.setSourceComponent(null); // TODO - fixed up at
                                                           // start
                        endpoint
                                .setSourceComponentReference(componentReference);
                        endpoint.setInterfaceContract(componentReference
                                .getInterfaceContract());
                        endpoint.setTargetComponent(targetComponent);
                        endpoint
                                .setTargetComponentService(targetComponentService);
                        endpoint.getCandidateBindings().addAll(
                                componentReference.getBindings());
                        endpoints.add(endpoint);

                        // mark the reference target as resolved. Used later
                        // when we are looking to
                        // see if an sca binding is associated with a resolved
                        // target or not
                        componentService.setUnresolved(false);
                    } else {
                        warning(monitor, "ComponentIncompatibleInterface",
                                composite, componentReference.getName(),
                                componentService.getName());
                    }
                } else {
                    // add all the reference bindings into the target so that
                    // they
                    // can be used for comparison when the target is resolved at
                    // runtime
                    componentService.getBindings().addAll(
                            componentReference.getBindings());

                    // The bindings will be cloned back into the reference when
                    // the
                    // target is finally resolved.

                    Endpoint endpoint = endpointFactory.createEndpoint();
                    endpoint.setTargetName(name);
                    endpoint.setSourceComponent(null); // TODO - fixed up at
                                                       // start
                    endpoint.setSourceComponentReference(componentReference);
                    endpoint.setInterfaceContract(componentReference
                            .getInterfaceContract());
                    endpoint.getCandidateBindings().addAll(
                            componentReference.getBindings());
                    endpoints.add(endpoint);

                    warning(monitor, "ComponentReferenceTargetNotFound",
                            composite, composite.getName().toString(),
                            componentService.getName());
                }
            }
        } else if (componentReference.getAutowire() == Boolean.TRUE) {

            // Find suitable targets in the current composite for an
            // autowired reference
            Multiplicity multiplicity = componentReference.getMultiplicity();
            for (Component targetComponent : composite.getComponents()) {
                // prevent autowire connecting to self
                boolean skipSelf = false;
                for (ComponentReference targetComponentReference : targetComponent
                        .getReferences()) {
                    if (componentReference == targetComponentReference) {
                        skipSelf = true;
                    }
                }

                if (!skipSelf) {
                    for (ComponentService targetComponentService : targetComponent
                            .getServices()) {
                        if (componentReference.getInterfaceContract() == null
                                || interfaceContractMapper.isCompatible(
                                        componentReference
                                                .getInterfaceContract(),
                                        targetComponentService
                                                .getInterfaceContract())) {

                            Endpoint endpoint = endpointFactory
                                    .createEndpoint();
                            endpoint.setTargetName(targetComponent.getName());
                            endpoint.setSourceComponent(null); // TODO - fixed
                                                               // up at start
                            endpoint
                                    .setSourceComponentReference(componentReference);
                            endpoint.setInterfaceContract(componentReference
                                    .getInterfaceContract());
                            endpoint.setTargetComponent(targetComponent);
                            endpoint
                                    .setTargetComponentService(targetComponentService);
                            endpoint.getCandidateBindings().addAll(
                                    componentReference.getBindings());
                            endpoints.add(endpoint);

                            if (multiplicity == Multiplicity.ZERO_ONE
                                    || multiplicity == Multiplicity.ONE_ONE) {
                                break;
                            }
                        }
                    }
                }
            }

            if (multiplicity == Multiplicity.ONE_N
                    || multiplicity == Multiplicity.ONE_ONE) {
                if (endpoints.size() == 0) {
                    warning(monitor, "NoComponentReferenceTarget",
                            componentReference, componentReference.getName());
                }
            }
        }

        // if no endpoints have found so far retrieve any target names that are
        // in binding URIs
        if (endpoints.isEmpty()) {
            for (Binding binding : componentReference.getBindings()) {

                String uri = binding.getURI();

                // user hasn't put a uri on the binding so it's not a target
                // name
                if (uri == null) {
                    continue;
                }

                // user might have put a local target name in the uri so get
                // the path part and see if it refers to a target we know about
                // - if it does the reference binding will be matched with a
                // service binding
                // - if it doesn't it is assumed to be an external reference
                Component targetComponent = null;
                ComponentService targetComponentService = null;
                String path = null;

                try {
                    path = URI.create(uri).getPath();
                } catch (Exception ex) {
                    // just assume that no target is identified if
                    // a URI related exception is thrown
                }

                if (path != null) {
                    if (path.startsWith("/")) {
                        path = path.substring(1);
                    }

                    // Resolve the target component and service
                    targetComponentService = componentServices.get(path);
                    int s = path.indexOf('/');
                    if (s == -1) {
                        targetComponent = components.get(path);
                    } else {
                        targetComponent = components.get(path.substring(0, s));
                    }
                }

                // if the path of the binding URI matches a component in the
                // composite then configure an endpoint with this component as
                // the target
                // if not then the binding URI will be assumed to reference an
                // external service
                if (targetComponentService != null) {

                    // Check that the target component service provides
                    // a superset of the component reference interface
                    if (componentReference.getInterfaceContract() == null
                            || interfaceContractMapper.isCompatible(
                                    componentReference.getInterfaceContract(),
                                    targetComponentService
                                            .getInterfaceContract())) {

                        Endpoint endpoint = endpointFactory.createEndpoint();
                        endpoint.setTargetName(targetComponent.getName());
                        endpoint.setSourceComponent(null); // TODO - fixed up at
                                                           // start
                        endpoint
                                .setSourceComponentReference(componentReference);
                        endpoint.setInterfaceContract(componentReference
                                .getInterfaceContract());
                        endpoint.setTargetComponent(targetComponent);
                        endpoint
                                .setTargetComponentService(targetComponentService);
                        endpoint.getCandidateBindings().add(binding);
                        endpoints.add(endpoint);
                    } else {
                        warning(monitor, "ReferenceIncompatibleInterface",
                                composite, composite.getName().toString(),
                                componentReference.getName(), uri);
                    }
                } else {

                    // create endpoints for manually configured bindings
                    Endpoint endpoint = endpointFactory.createEndpoint();
                    endpoint.setTargetName(uri);
                    endpoint.setSourceComponent(null); // TODO - fixed up at
                                                       // start
                    endpoint.setSourceComponentReference(componentReference);
                    endpoint.setInterfaceContract(componentReference
                            .getInterfaceContract());
                    endpoint.setSourceBinding(binding);
                    endpoints.add(endpoint);
                }
            }
        }
View Full Code Here

           
            ComponentReference ref = (composite.getComponents().get(0).getReferences().get(0));
           
            Assert.assertEquals(1, ref.getEndpoints().size());
           
            Endpoint endpoint = ref.getEndpoints().get(0);
           
            EndpointResolverFactory<Endpoint> factory = new EndpointResolverFactoryImpl(extensionPoints);
           
            EndpointResolver endpointResolver = factory.createEndpointResolver(endpoint, null);
           
View Full Code Here

        }

        // TODO: TUSCANY-2580: before returning null see if a candidate binding matches
        for (RuntimeWire wire : getRuntimeWires()) {
            if (wire instanceof EndpointWireImpl) {
                Endpoint endpoint = ((EndpointWireImpl)wire).getEndpoint();
                for (Binding b : endpoint.getCandidateBindings()) {
                    if (b == binding) {
                        return wire;
                    }
                }
            }
View Full Code Here

                                    break;
                                }
                            }
                        } else {
                            // create a new endpoint to represent this promoted binding
                            Endpoint endpoint = endpointFactory.createEndpoint();
                            endpoint.setTargetName(binding.getURI());
                            endpoint.setSourceComponent(null); // TODO - fixed up at start
                            endpoint.setSourceComponentReference(promotedReference)
                            endpoint.setInterfaceContract(reference.getInterfaceContract());
                            endpoint.setSourceBinding(binding);
                            endpointsToCopyDown.add(endpoint);
                        }
                    }
                }
               
                if (bindingsToCopyDown.size() > 0) {
                    promotedReference.getBindings().clear();
                    promotedReference.getBindings().addAll(bindingsToCopyDown);
                   
                    promotedReference.getEndpoints().clear();
                    promotedReference.getEndpoints().addAll(endpointsToCopyDown);
                }
            }
           
            if (promotedReference.getBindings().size() > 1) {
                warning(monitor, "ComponentReferenceMoreWire", promotedReference, promotedReference.getName());               
            }
        } else {
            // if necessary merge the promoted endpoints (and bindings) with the top level bindings
            if (reference.getBindings().size() > 0 ){
               
                for (Binding binding : reference.getBindings()) {
                    if ((!(binding instanceof OptimizableBinding)) || binding.getURI() != null) {
                        promotedReference.getBindings().add(binding);
                       
                        if (reference instanceof ComponentReference){
                            for (Endpoint endpoint : ((ComponentReference)reference).getEndpoints()){
                                if ( endpoint.getSourceBinding() == binding){
                                    promotedReference.getEndpoints().add(endpoint);
                                    break;
                                }
                            }
                        } else {
                            // create a new endpoint to represent this promoted binding
                            Endpoint endpoint = endpointFactory.createEndpoint();
                            endpoint.setTargetName(binding.getURI());
                            endpoint.setSourceComponent(null); // TODO - fixed up at start
                            endpoint.setSourceComponentReference(promotedReference);
                            endpoint.setInterfaceContract(reference.getInterfaceContract());
                            endpoint.setSourceBinding(binding);
                            promotedReference.getEndpoints().add(endpoint);
                        }
                    }
                }               
            }           
View Full Code Here

            List<Endpoint> eps = endpointRegistry.findEndpoint(serviceName);
            if (eps == null || eps.size() < 1) {
                throw new NoSuchServiceException(serviceName);
            }
            Endpoint endpoint = eps.get(0); // TODO: what should be done with multiple endpoints?
          
            RuntimeEndpointReference epr;
            try {
                epr = createEndpointReference(javaInterfaceFactory, compositeContext, assemblyFactory, endpoint, serviceInterface);
            } catch (Exception e) {
View Full Code Here

   
    public Message invokeRequest(Message msg) {
//        try {                 

            EndpointReference from = assemblyFactory.createEndpointReference();
            Endpoint fromEndpoint = assemblyFactory.createEndpoint();
            from.setTargetEndpoint(fromEndpoint);
            from.setStatus(EndpointReference.Status.WIRED_TARGET_FOUND_AND_MATCHED);
            msg.setFrom(from);
            Endpoint callbackEndpoint = assemblyFactory.createEndpoint();
//            callbackEndpoint.setURI(callbackAddress); // TODO: is this needed? Seems to work without it
            callbackEndpoint.setUnresolved(true);
            from.setCallbackEndpoint(callbackEndpoint);

            return msg;
//        } catch (JMSException e) {
//            throw new JMSBindingException(e);
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.assembly.Endpoint

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.