Package org.apache.tuscany.spi.component

Examples of org.apache.tuscany.spi.component.Service


                throw e;
            }
            children.put(child.getName(), child);
        }
        if (child instanceof Service) {
            Service service = (Service) child;
            synchronized (services) {
                if (service.isSystem()) {
                    systemServices.add(service);
                } else {
                    services.add(service);
                }
            }
View Full Code Here


        }
        return (Service) ctx;
    }

    public Object getServiceInstance() throws TargetException {
        Service service = services.get(0);
        if (service == null) {
            throw new TargetException("Component has no services");
        }
        return service.getServiceInstance();
    }
View Full Code Here

            }
        }
    }

    public <T> T resolveExternalInstance(Class<T> instanceInterface) throws AutowireResolutionException {
        Service service = autowireExternal.get(instanceInterface);
        if (service != null) {
            try {
                return instanceInterface.cast(service.getServiceInstance());
            } catch (CoreRuntimeException e) {
                e.addContextName(getName());
                throw e;
            }
        } else {
View Full Code Here

            return null;
        }
    }

    public <T> T resolveSystemExternalInstance(Class<T> instanceInterface) throws AutowireResolutionException {
        Service service = systemAutowireExternal.get(instanceInterface);
        if (service != null) {
            try {
                return instanceInterface.cast(service.getServiceInstance());
            } catch (CoreRuntimeException e) {
                e.addContextName(getName());
                throw e;
            }
        } else {
View Full Code Here

        // We still need to set the target invoker as opposed to having the connector do it since the
        // Spring context is "opaque" to the wiring fabric. In other words, the Spring context does not expose
        // its beans as SCA components to the connector to wire the services to
        for (BoundServiceDefinition<? extends Binding> serviceDefinition : componentType.getServices().values()) {
            // call back into builder registry to handle building of services
            Service service = (Service) builderRegistry.build(parent, serviceDefinition, deploymentContext);
            // wire serviceDefinition to bean invokers
            InboundWire wire = service.getInboundWire();
            QualifiedName targetName = new QualifiedName(serviceDefinition.getTarget().getPath());
            for (InboundInvocationChain chain : wire.getInvocationChains().values()) {
                // FIXME this should go to the connector and get policy and be invoked from SpringComposite.prepare()
                chain.addInterceptor(new SpringInterceptor());
                chain.setTargetInvoker(component.createTargetInvoker(targetName.getPartName(), chain.getOperation()));
View Full Code Here

                assert parent != null : "Parent of parent was null";
                SCAObject target = parent.getChild(outboundWire.getTargetName().getPartName());
                connect((Component)parent, outboundWire, target);
            }           
        } else if (source instanceof Service) {
            Service service = (Service) source;
            InboundWire inboundWire = service.getInboundWire();
            OutboundWire outboundWire = service.getOutboundWire();
            // For a composite reference only, since its outbound wire comes from its parent composite,
            // the corresponding target would not lie in its parent but rather in its parent's parent
            if (source instanceof CompositeReference) {
                parent = parent.getParent();
                assert parent != null : "Parent of parent was null";
            }
            SCAObject target;
            if (service.isSystem()) {
                target = parent.getSystemChild(outboundWire.getTargetName().getPartName());
            } else {
                target = parent.getChild(outboundWire.getTargetName().getPartName());
            }
            // connect the outbound service wire to the target
View Full Code Here

                    // if the target is a component and the operation is non-blocking
                    connect(outboundChain, inboundChain, null, true);
                } else {
                    connect(outboundChain, inboundChain, null, false);
                }
                Service service = (Service) source;
                InboundInvocationChain chain = service.getInboundWire().getInvocationChains().get(operation);
                chain.setTargetInvoker(invoker);
            } else {
                if (target instanceof Component && (isOneWayOperation || operationHasCallback)) {
                    // if the target is a component and the operation is non-blocking
                    connect(outboundChain, inboundChain, invoker, true);
                } else {
                    connect(outboundChain, inboundChain, invoker, false);
                }
            }
        }

        // create source callback chains and connect them if target callback chains exist
        Map<Operation<?>, OutboundInvocationChain> sourceCallbackChains =
            targetWire.getSourceCallbackInvocationChains(source.getName());
        for (InboundInvocationChain inboundChain : sourceWire.getTargetCallbackInvocationChains().values()) {
            Operation<?> operation = inboundChain.getOperation();
            if (sourceCallbackChains != null && sourceCallbackChains.get(operation) != null) {
                String name = operation.getName();
                BuilderConfigException e =
                    new BuilderConfigException("Source callback chain should not exist for operation [" + name + "]");
                e.setIdentifier(sourceWire.getReferenceName());
                throw e;
            }
           
            Operation targetOp =
                (Operation)targetWire.getServiceContract().getCallbackOperations().get(operation.getName());
            OutboundInvocationChain outboundChain = wireService.createOutboundChain(targetOp);
            targetWire.addSourceCallbackInvocationChain(source.getName(), targetOp, outboundChain);
            if (source instanceof Component) {
                Component component = (Component) source;
                TargetInvoker invoker = component.createTargetInvoker(null, operation);
                connect(outboundChain, inboundChain, invoker, false);
            } else if (source instanceof CompositeReference) {
                CompositeReference compRef = (CompositeReference) source;
                ServiceContract sourceContract = sourceWire.getServiceContract();
                TargetInvoker invoker = compRef.createCallbackTargetInvoker(sourceContract, operation);
                connect(outboundChain, inboundChain, invoker, false);
            } else if (source instanceof Service) {
                Service service = (Service) source;
                ServiceContract sourceContract = sourceWire.getServiceContract();
                TargetInvoker invoker = service.createCallbackTargetInvoker(sourceContract, operation);
                connect(outboundChain, inboundChain, invoker, false);
            }
        }
        if (postProcessorRegistry != null) {
            // run wire post-processors
View Full Code Here


    public void testGetService() throws NoSuchMethodException {
        CompositeComponent parent = new CompositeComponentImpl("foo", null, null, null);
        parent.start();
        Service service = EasyMock.createMock(Service.class);
        EasyMock.expect(service.getName()).andReturn("source").atLeastOnce();
        EasyMock.expect(service.isSystem()).andReturn(false).atLeastOnce();
        service.getInterface();
        EasyMock.expectLastCall().andReturn(Source.class);
        EasyMock.replay(service);
        parent.register(service);
        assertNotNull(parent.getService("source"));
        try {
View Full Code Here

    }

    public void testSystemGetService() throws NoSuchMethodException {
        CompositeComponent parent = new CompositeComponentImpl("foo", null, null, null);
        parent.start();
        Service service = EasyMock.createMock(Service.class);
        EasyMock.expect(service.getName()).andReturn("source").atLeastOnce();
        EasyMock.expect(service.isSystem()).andReturn(true).atLeastOnce();
        service.getInterface();
        EasyMock.expectLastCall().andReturn(Source.class);
        EasyMock.replay(service);
        parent.register(service);
        assertNotNull(parent.getSystemService("source"));
        try {
View Full Code Here

        EasyMock.expect(outboundWire.getServiceContract()).andReturn(contract).anyTimes();
        EasyMock.expect(outboundWire.getTargetName()).andReturn(new QualifiedName("target/FooService")).anyTimes();
        EasyMock.expect(outboundWire.getInvocationChains()).andReturn(outboundChains).anyTimes();

        // create the service
        Service service = EasyMock.createMock(Service.class);
        EasyMock.expect(service.getName()).andReturn("source");
        EasyMock.expect(service.isSystem()).andReturn(false).atLeastOnce();
        EasyMock.expect(service.getParent()).andReturn(parent).atLeastOnce();
        EasyMock.expect(service.getInboundWire()).andReturn(inboundWire).atLeastOnce();
        EasyMock.expect(service.getScope()).andReturn(Scope.COMPOSITE);
        EasyMock.expect(service.getOutboundWire()).andReturn(outboundWire);
        EasyMock.replay(service);

        EasyMock.expect(outboundWire.getContainer()).andReturn(service);
        EasyMock.replay(outboundWire);
View Full Code Here

TOP

Related Classes of org.apache.tuscany.spi.component.Service

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.