Package org.apache.tuscany.spi.wire

Examples of org.apache.tuscany.spi.wire.InboundWire


        ServiceExtension service = new ServiceExtension(null, null, null, null);
        assertEquals(Scope.COMPOSITE, service.getScope());
    }

    public void testSetGetInterface() throws Exception {
        InboundWire wire = createMock(InboundWire.class);
        JavaServiceContract contract = new JavaServiceContract(getClass());
        expect(wire.getServiceContract()).andReturn(contract);
        replay(wire);
        ServiceExtension service = new ServiceExtension(null, null, null, null);
        service.setInboundWire(wire);
        service.getInterface();
    }
View Full Code Here


        expectLastCall();
        chain.getOperation();
        expectLastCall().andReturn(operation);
        chain.prepare();
        expectLastCall();
        InboundWire wire = createMock(InboundWire.class);
        wire.getInvocationChains();
        Map<Operation, InvocationChain> chains = new HashMap<Operation, InvocationChain>();
        chains.put(operation, chain);
        expectLastCall().andReturn(chains);
        OutboundWire outboundWire = createMock(OutboundWire.class);
        outboundWire.getTargetName();
View Full Code Here

     * @param serviceName the service name associated with the wire
     * @param interfaze   the interface associated with the wire
     */
    public static <T> InboundWire createInboundWire(String serviceName, Class<T> interfaze)
        throws InvalidServiceContractException {
        InboundWire wire = new InboundWireImpl();
        JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
        ServiceContract<?> contract = registry.introspect(interfaze);
        wire.setServiceContract(contract);
        wire.setServiceName(serviceName);
        wire.addInvocationChains(createInboundChains(interfaze));
        return wire;
    }
View Full Code Here

        // 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()));
            }
            component.register(service);
View Full Code Here

                    chain.prepare();
                }
            }
        } else if (source instanceof Reference) {
            Reference reference = (Reference) source;
            InboundWire inboundWire = reference.getInboundWire();
            Map<Operation<?>, InboundInvocationChain> inboundChains = inboundWire.getInvocationChains();
            for (InboundInvocationChain chain : inboundChains.values()) {
                //TODO handle async
                // add target invoker on inbound side
                ServiceContract contract = inboundWire.getServiceContract();
                Operation operation = chain.getOperation();
                TargetInvoker invoker = reference.createTargetInvoker(contract, operation);
                chain.setTargetInvoker(invoker);
                chain.prepare();
            }
            OutboundWire outboundWire = reference.getOutboundWire();
            // connect the reference's inbound and outbound wires
            connect(inboundWire, outboundWire, true);
           
            if (reference instanceof CompositeReference) {
                // 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
                parent = parent.getParent();
                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();
View Full Code Here

        assert sourceWire.getTargetName() != null : "Wire target name was null";
        QualifiedName targetName = sourceWire.getTargetName();

        if (target instanceof AtomicComponent) {
            AtomicComponent targetComponent = (AtomicComponent) target;
            InboundWire targetWire = targetComponent.getInboundWire(targetName.getPortName());
            if (targetWire == null) {
                String refName = sourceWire.getReferenceName();
                BuilderConfigException e = new BuilderConfigException("No target service for reference " + refName);
                e.setIdentifier(targetName.getPortName());
                throw e;
            }
            checkIfWireable(sourceWire, targetWire);
            boolean optimizable = isOptimizable(source.getScope(), target.getScope());
            connect(sourceWire, targetWire, optimizable);
        } else if (target instanceof Reference) {
            InboundWire targetWire = ((Reference) target).getInboundWire();
            assert targetWire != null;
            checkIfWireable(sourceWire, targetWire);
            boolean optimizable = isOptimizable(source.getScope(), target.getScope());
            connect(sourceWire, targetWire, optimizable);
        } else if (target instanceof CompositeComponent) {
            CompositeComponent composite = (CompositeComponent) target;
            InboundWire targetWire = null;
            if (source.isSystem()) {
                for (Object child : composite.getSystemChildren()) {
                    if (child instanceof CompositeService) {
                        CompositeService compServ = (CompositeService) child;
                        targetWire = compServ.getInboundWire();
                        assert targetWire != null;
                        Class<?> sourceInterface = sourceWire.getServiceContract().getInterfaceClass();
                        Class<?> targetInterface = targetWire.getServiceContract().getInterfaceClass();
                        if (sourceInterface.isAssignableFrom(targetInterface)) {
                            target = compServ;
                            break;
                        } else {
                            targetWire = null;
                        }
                    }
                }
            } else {
                for (Object child : composite.getChildren()) {
                    if (child instanceof CompositeService) {
                        CompositeService compServ = (CompositeService) child;
                        targetWire = compServ.getInboundWire();
                        assert targetWire != null;
                        Class<?> sourceInterface = sourceWire.getServiceContract().getInterfaceClass();
                        Class<?> targetInterface = targetWire.getServiceContract().getInterfaceClass();
                        if (sourceInterface.isAssignableFrom(targetInterface)) {
                            target = compServ;
                            break;
                        } else {
                            targetWire = null;
View Full Code Here

        return getServiceInstance(null);
    }

    @SuppressWarnings("unchecked")
    public Object getServiceInstance(String service) throws TargetException {
        InboundWire wire = getInboundWire(service);
        if (wire == null) {
            TargetException e = new TargetException("ServiceDefinition not found"); // TODO better error message
            e.setIdentifier(service);
            throw e;
        }
View Full Code Here

        Component target = (Component) parent.getSystemChild(targetName.getPartName());
        if (target == null) {
            throw new BuilderConfigException("Target not found: [" + targetName + ']');
        }
        String name = boundServiceDefinition.getName();
        InboundWire inboundWire =
            new SystemInboundWireImpl(name, interfaze, target);
        SystemOutboundWire outboundWire =
            new SystemOutboundWireImpl(name, targetName, interfaze);
        SystemService service = new SystemServiceImpl(boundServiceDefinition.getName(), parent);
        service.setInboundWire(inboundWire);
View Full Code Here

        Port port = wsdlService.getPort("SoapPort");

        WebServiceBinding wsBinding = new WebServiceBinding(wsdlDef, port, "uri", "portURI", wsdlService);

        //Create mocked InboundWire, for ServiceExtension.getInterface()
        InboundWire inboundWire = EasyMock.createNiceMock(InboundWire.class);
        JavaServiceContract contract = new JavaServiceContract(Greeter.class);
        EasyMock.expect(inboundWire.getServiceContract()).andReturn(contract).anyTimes();
        EasyMock.replay(inboundWire);

        //Create mocked WireService, for ServiceExtension.getServiceInstance()
        WireService wireService = EasyMock.createNiceMock(WireService.class);
        wireService.createProxy(EasyMock.isA(InboundWire.class));
View Full Code Here

    /**
     * Verifies system services in a CompositeComponentImpl are wired during the parent composite's prepare callback
     */
    public void testSystemServiceWire() {
        InboundWire inbound = EasyMock.createMock(InboundWire.class);
        EasyMock.expect(inbound.getServiceContract()).andReturn(new JavaServiceContract(Foo.class));
        inbound.getInvocationChains();
        EasyMock.expectLastCall().andReturn(Collections.emptyMap());

        List<Class<?>> services = new ArrayList<Class<?>>();
        services.add(Foo.class);
        QualifiedName qName = new QualifiedName("target/bar");
        OutboundWire outbound = EasyMock.createMock(OutboundWire.class);
        EasyMock.expect(outbound.getTargetName()).andReturn(qName).atLeastOnce();
        outbound.getInvocationChains();
        EasyMock.expectLastCall().andReturn(Collections.emptyMap());
        outbound.setTargetWire(EasyMock.eq(inbound));
        EasyMock.expect(outbound.getServiceContract()).andReturn(new JavaServiceContract(Foo.class)).atLeastOnce();
        List<OutboundWire> wires = new ArrayList<OutboundWire>();
        wires.add(outbound);
        Map<String, List<OutboundWire>> wireMap = new HashMap<String, List<OutboundWire>>();
        wireMap.put("ref", wires);
        CompositeComponent parent = new CompositeComponentImpl("foo", "foo", null, new ConnectorImpl(), null);
        SystemAtomicComponent source = EasyMock.createMock(SystemAtomicComponent.class);
        EasyMock.expect(source.getScope()).andReturn(Scope.MODULE).atLeastOnce();
        EasyMock.expect(source.getName()).andReturn("source").atLeastOnce();
        EasyMock.expect(source.getServiceInterfaces()).andReturn(services);
        EasyMock.expect(source.getOutboundWires()).andReturn(wireMap);
        source.getInboundWires();
        EasyMock.expectLastCall().andReturn(Collections.emptyMap());
        EasyMock.expect(source.isSystem()).andReturn(true).atLeastOnce();
        EasyMock.expect(source.getParent()).andReturn(parent).atLeastOnce();

        source.prepare();
        EasyMock.replay(source);

        EasyMock.expect(outbound.getContainer()).andReturn(source);
        EasyMock.replay(outbound);

        parent.register(source);

        SystemAtomicComponent target = EasyMock.createMock(SystemAtomicComponent.class);
        EasyMock.expect(target.getName()).andReturn("target").atLeastOnce();
        EasyMock.expect(target.getServiceInterfaces()).andReturn(services);
        EasyMock.expect(target.getInboundWire("bar")).andReturn(inbound).atLeastOnce();
        EasyMock.expect(target.getScope()).andReturn(Scope.MODULE).atLeastOnce();
        EasyMock.expect(target.getParent()).andReturn(parent).atLeastOnce();
        target.getInboundWires();
        EasyMock.expectLastCall().andReturn(Collections.emptyMap());

        target.prepare();
        target.getOutboundWires();
        EasyMock.expectLastCall().andReturn(Collections.emptyMap());
        EasyMock.expect(target.isSystem()).andReturn(true).atLeastOnce();
        EasyMock.replay(target);

        EasyMock.expect(inbound.getContainer()).andReturn(target);
        EasyMock.replay(inbound);

        parent.register(target);
        parent.prepare();
        EasyMock.verify(source);
View Full Code Here

TOP

Related Classes of org.apache.tuscany.spi.wire.InboundWire

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.