Package org.apache.tuscany.sca.runtime

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


        } catch (CloneNotSupportedException e) {
            throw new IOException(e.toString());
        }

        // Setup the reference on the cloned wire
        final RuntimeComponentReference ref = new RuntimeComponentReferenceImpl();
        ref.setComponent((RuntimeComponent) targetComponent);
        ref.setInterfaceContract(targetServiceIfaceContract);
        ((EndpointReferenceImpl) this.wire.getSource()).setContract(ref);
    }
View Full Code Here


        return new OSGiTargetInvoker(operation, this, service);
    }

    public void start() {
        for (ComponentReference ref : component.getReferences()) {
            RuntimeComponentReference reference = (RuntimeComponentReference)ref;
            InterfaceContract interfaceContract = reference.getInterfaceContract();
            JavaInterface javaInterface = (JavaInterface)interfaceContract.getInterface();
            final Class<?> interfaceClass = javaInterface.getJavaClass();

            final Hashtable<String, Object> osgiProps = getOSGiProperties(reference);
            osgiProps.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE);
            osgiProps.put("sca.reference", component.getURI() + "#reference(" + ref.getName() + ")");
            osgiProps.put(OSGiProperty.OSGI_REMOTE, "true");
            osgiProps.put(OSGiProperty.OSGI_REMOTE_CONFIGURATION_TYPE, "sca");
            osgiProps.put(OSGiProperty.OSGI_REMOTE_INTERFACES, interfaceClass.getName());

            ProxyFactory proxyService = proxyFactoryExtensionPoint.getInterfaceProxyFactory();
            if (!interfaceClass.isInterface()) {
                proxyService = proxyFactoryExtensionPoint.getClassProxyFactory();
            }

            for (RuntimeWire wire : reference.getRuntimeWires()) {
                final Object proxy = proxyService.createProxy(interfaceClass, wire);
                AccessController.doPrivileged(new PrivilegedAction<ServiceRegistration>() {
                    public ServiceRegistration run() {
                        return osgiBundle.getBundleContext().registerService(interfaceClass.getName(),
                                                                             proxy,
View Full Code Here

        }
        for (ComponentReference reference : component.getReferences()) {
            if (logger.isLoggable(Level.FINE)) {
                logger.fine("Starting component reference: " + component.getURI() + "#" + reference.getName());
            }
            RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)reference);
           
            for (EndpointReference2 endpointReference : reference.getEndpointReferences()) {
                final ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(endpointReference.getBinding());
                if (bindingProvider != null) {
                    // Allow bindings to read properties. Requires PropertyPermission read in security policy.
                    AccessController.doPrivileged(new PrivilegedAction<Object>() {
                        public Object run() {
                            bindingProvider.stop();
View Full Code Here

                if (endpointReference.getBinding() != null){
                   
                    // add the binding provider. This is apparently a repeat
                    // of previous configuration as self references are created
                    // on the fly and miss the previous point where providers are added
                    RuntimeComponentReference runtimeRef = (RuntimeComponentReference)componentReference;
                   
                    if (runtimeRef.getBindingProvider(endpointReference.getBinding()) == null) {
                        addReferenceBindingProvider(component, componentReference, endpointReference.getBinding());
                    }
                   
                    // start the binding provider  
                    final ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(endpointReference.getBinding());
                   
                    if (bindingProvider != null) {
                        // Allow bindings to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy.
                        AccessController.doPrivileged(new PrivilegedAction<Object>() {
                            public Object run() {
View Full Code Here

    public void stop(Component component, ComponentReference reference) {
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("Stopping component reference: " + component.getURI() + "#" + reference.getName());
        }
        RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)reference);
        for ( EndpointReference2 endpointReference : runtimeRef.getEndpointReferences()){
            ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(endpointReference.getBinding());
            if (bindingProvider != null) {
                bindingProvider.stop();
            }
        }
    }
View Full Code Here

            }
        }
    }
   
    private void addReferenceWire(Component component, ComponentReference reference, EndpointReference2 endpointReference) {
        RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference;
       
        // Use the interface contract of the reference on the component type and if there
        // isn't one then use the one from the reference itself
        Reference componentTypeRef = reference.getReference();

        InterfaceContract sourceContract;
        if (componentTypeRef == null || componentTypeRef.getInterfaceContract() == null) {
            sourceContract = reference.getInterfaceContract();
        } else {
            sourceContract = componentTypeRef.getInterfaceContract();
        }
      
        // TODO - EPR - interface contract seems to be null in the implementation.web
        //              case. Not introspecting the CT properly?
        if (sourceContract == null){
            // take the contract from the service to which the reference is connected
            sourceContract = endpointReference.getTargetEndpoint().getInterfaceContract();
            reference.setInterfaceContract(sourceContract);
        }
       
        endpointReference.setInterfaceContract(sourceContract.makeUnidirectional(false));

/* TODO - EPR should have been done previously during matching
        ComponentService callbackService = reference.getCallbackService();
        if (callbackService != null) {
            // select a reference callback binding to pass with invocations on this wire
            Binding callbackBinding = null;
            for (Binding binding : callbackService.getBindings()) {
                // first look for a callback binding whose name matches the reference binding name
                if (refBinding.getName().startsWith(binding.getName())) {
                    callbackBinding = binding;
                    break;
                }
            }
            // if no callback binding found, try again based on reference binding type
            if (callbackBinding == null) {
                callbackBinding = callbackService.getBinding(refBinding.getClass());
            }
            InterfaceContract callbackContract = callbackService.getInterfaceContract();
            EndpointReference callbackEndpoint =
                new EndpointReferenceImpl((RuntimeComponent)refComponent, callbackService, callbackBinding,
                                          callbackContract);
            wireSource.setCallbackEndpoint(callbackEndpoint);
        }
*/

        InterfaceContract bindingContract = getInterfaceContract(reference, endpointReference.getBinding());
        Endpoint2 endpoint = endpointReference.getTargetEndpoint();
        endpoint.setInterfaceContract(bindingContract);
   
/* TODO - EPR review in the light of new matching code       
        // TUSCANY-2029 - We should use the URI of the serviceBinding because the target may be a Component in a
        // nested composite.
        if (serviceBinding != null) {
            wireTarget.setURI(serviceBinding.getURI());
        }
*/       

        // create the wire
        RuntimeWire wire = new RuntimeWireImpl2(true,
                                                endpointReference,
                                                endpoint,
                                                interfaceContractMapper,
                                                workScheduler,
                                                wireProcessor,
                                                messageFactory,
                                                conversationManager);
        runtimeRef.getRuntimeWires().add(wire);
       
    }
View Full Code Here

    void start() {
        if (!instanceFactoryProvider.getImplementation().getCallbackMembers().isEmpty()) {
            Map<String, List<RuntimeWire>> callbackWires = new HashMap<String, List<RuntimeWire>>();
            for (ComponentService service : component.getServices()) {

                RuntimeComponentReference callbackReference = (RuntimeComponentReference)service.getCallbackReference();
                if (callbackReference != null) {
                    List<RuntimeWire> wires = callbackReference.getRuntimeWires();
                    if (!wires.isEmpty()) {
                        callbackWires.put(wires.get(0).getSource().getInterfaceContract().getInterface().toString(),
                                          wires);
                    }
                }
View Full Code Here

       
        if (!instanceFactoryProvider.getImplementation().getCallbackMembers().isEmpty()) {
            Map<String, List<EndpointReference>> callbackWires = new HashMap<String, List<EndpointReference>>();
            for (ComponentService service : component.getServices()) {

                RuntimeComponentReference callbackReference = (RuntimeComponentReference)service.getCallbackReference();
                if (callbackReference != null) {
                    List<EndpointReference> wires = callbackReference.getEndpointReferences();
                    if (!wires.isEmpty()) {
                        RuntimeEndpointReference epr = (RuntimeEndpointReference) wires.get(0);
                        callbackWires.put(epr.getComponentTypeReferenceInterfaceContract().getInterface().toString(),
                                          wires);
                    }
View Full Code Here

        try {
            InterfaceContract interfaceContract = endpointReference.getComponentTypeReferenceInterfaceContract();
            if (businessInterface == null) {
                businessInterface = (Class<B>)((JavaInterface)interfaceContract.getInterface()).getJavaClass();
            }
            RuntimeComponentReference ref = (RuntimeComponentReference)endpointReference.getReference();
            InterfaceContract refInterfaceContract = getInterfaceContract(interfaceContract, businessInterface);
            if (refInterfaceContract != null) {
              if (refInterfaceContract != interfaceContract) {
                  ref = (RuntimeComponentReference)ref.clone();
                  if (interfaceContract != null) {
                      ref.setInterfaceContract(interfaceContract);
                  } else {
                      ref.setInterfaceContract(refInterfaceContract);
                  }
              }
              ref.setComponent(component);
              result = new ServiceReferenceImpl<B>(businessInterface, endpointReference, component.getComponentContext().getCompositeContext());
            }
        } catch (IllegalArgumentException iae ) {
          throw iae;
        } catch (Exception e) {
View Full Code Here

       
        validateReferenceInterfaceCompatibility();

        List<InvocationChain> chainList = new ArrayList<InvocationChain>();
        if(sourceContract != null && targetContract != null) {
            RuntimeComponentReference reference = (RuntimeComponentReference)getReference();
            for (Operation operation : sourceContract.getInterface().getOperations()) {
                Operation targetOperation = interfaceContractMapper.map(targetContract.getInterface(), operation);
                if (targetOperation == null) {
                    throw new ServiceRuntimeException("No matching operation for " + operation.getName()
                        + " is found in reference "
                        + getComponent().getURI()
                        + "#"
                        + reference.getName());
                }
                InvocationChain chain = new InvocationChainImpl(operation, targetOperation, true, phaseManager);
                if (operation.isNonBlocking()) {
                    addNonBlockingInterceptor(chain);
                }
View Full Code Here

TOP

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

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.