Package org.switchyard

Examples of org.switchyard.ServiceReference


    @Test
    public void testDispatchInOnly() throws Exception {
        QName name = new QName("testDispatchInOnly");
        ExchangeSink sink = new ExchangeSink();
        Service service = new MockService(name, new InOnlyService(), sink);
        ServiceReference reference = new ServiceReferenceImpl(name, new InOnlyService(), null, null);
        ExchangeDispatcher dispatch = _provider.createDispatcher(reference);

        Exchange exchange = new CamelExchange(dispatch, new DefaultExchange(_camelContext), sink);
        exchange.consumer(reference, reference.getInterface().getOperation(ServiceInterface.DEFAULT_OPERATION));
        exchange.provider(service, service.getInterface().getOperation(ServiceInterface.DEFAULT_OPERATION));
        Message message = exchange.createMessage();
        exchange.send(message);
        Thread.sleep(200);
View Full Code Here


    @Test
    public void throttle() throws Exception {
        QName name = new QName("testDispatchInOnly");
        final ExchangeSink sink = new ExchangeSink(1000);
        final Service service = new MockService(name, new InOnlyService(), sink);
        final ServiceReference reference = new ServiceReferenceImpl(name, new InOnlyService(), null, null);
        final ExchangeDispatcher dispatch = _provider.createDispatcher(reference);
       
        // Set throttling to 1 per second
        Throttling throttle = new Throttling().setMaxRequests(1);
        ServiceMetadataBuilder.update(reference.getServiceMetadata()).throttling(throttle);
               
        final int NUM_SENDS = 5;
        for (int i = 0; i < NUM_SENDS; i++) {
            new Thread(new Runnable() {
                public void run() {
                    Exchange exchange = dispatch.createExchange(sink, ExchangePattern.IN_ONLY);
                    exchange.consumer(reference, reference.getInterface().getOperation(ServiceInterface.DEFAULT_OPERATION));
                    exchange.provider(service, service.getInterface().getOperation(ServiceInterface.DEFAULT_OPERATION));
                    Message message = exchange.createMessage();
                    exchange.send(message);
                }
            }).start();
View Full Code Here

        initDomain(domain);
       
        QName name = new QName("testThrottleTimePeriod");
        final ExchangeSink sink = new ExchangeSink();
        final Service service = new MockService(name, new InOnlyService(), sink);
        final ServiceReference reference = new ServiceReferenceImpl(name, new InOnlyService(), null, null);
        // Set throttling to 1 per minute (60000 ms)
        Throttling throttle = new Throttling().setMaxRequests(1).setTimePeriod(60 * 1000);
        ServiceMetadataBuilder.update(reference.getServiceMetadata()).throttling(throttle);
       
        final ExchangeDispatcher dispatch = _provider.createDispatcher(reference);
               
        final int NUM_SENDS = 5;
        for (int i = 0; i < NUM_SENDS; i++) {
            new Thread(new Runnable() {
                public void run() {
                    Exchange exchange = dispatch.createExchange(sink, ExchangePattern.IN_ONLY);
                    exchange.consumer(reference, reference.getInterface().getOperation(ServiceInterface.DEFAULT_OPERATION));
                    exchange.provider(service, service.getInterface().getOperation(ServiceInterface.DEFAULT_OPERATION));
                    Message message = exchange.createMessage();
                    exchange.send(message);
                }
            }).start();
View Full Code Here

        ExchangeSink inHandler = new ExchangeSink(true);
        // consumer handler
        ExchangeSink outHandler = new ExchangeSink();

        Service service = new MockService(name, new InOutService(), inHandler);
        ServiceReference reference = new ServiceReferenceImpl(name, new InOutService(), null, null);
        Dispatcher dispatch = _provider.createDispatcher(reference);

        Exchange exchange = dispatch.createExchange(outHandler, ExchangePattern.IN_OUT);
        exchange.consumer(reference, reference.getInterface().getOperation(ServiceInterface.DEFAULT_OPERATION));
        exchange.provider(service, service.getInterface().getOperation(ServiceInterface.DEFAULT_OPERATION));
        Message message = exchange.createMessage();
        exchange.send(message.setContent(REQUEST));
        Thread.sleep(400);
View Full Code Here

        // set the timeout value to 5 seconds and start the camel context
        _domain.setProperty(CamelContextConfigurator.SHUTDOWN_TIMEOUT, "5");
        _camelContext.start();
       
        // register a service and send a message
        ServiceReference ref = registerInOutService("inOut", new TakesForeverHandler());
        sendMessage(ref, 120 * 1000);
       
        // Give the sending thread a chance to send the message
        Thread.sleep(1000);
       
View Full Code Here

        _domain = new MockDomain();
    }
   
    @Test
    public void testInMessageTrace() {
        ServiceReference service = _domain.createInOnlyService(new QName("InTrace"));
        Exchange exchange = service.createExchange();
        exchange.send(exchange.createMessage());
    }
View Full Code Here

        }
    }
  
    @Override
    public void registerServiceReference(ServiceReference reference) {
        ServiceReference ref = _references.putIfAbsent(reference.getName(), reference);

        if (_logger.isDebugEnabled()) {
            _logger.debug("Registered ServiceReference '" + reference.getName() + "', "
                    + "found previous map value of " + ref + ".");
        }
View Full Code Here

        }
    }

    @Override
    public void unregisterServiceReference(ServiceReference reference) {
        ServiceReference removed = _references.remove(reference.getName());
        if (removed != null && _logger.isDebugEnabled()) {
            _logger.debug("Unregistered ServiceReference '" + reference.getName() + "'.");
        }
    }
View Full Code Here

                new QName("urn:test:config-mock-binding:1.0", "TestReference")).get(0);
        Assert.assertNotNull(bindingService.getServiceMetadata().getRegistrant());
        List<BindingModel> svcBindings = bindingService.getServiceMetadata().getRegistrant().getConfig();
        Assert.assertEquals(1, svcBindings.size());
       
        ServiceReference implReference = deployment.getDomain().getServiceReference(
                new QName("urn:test:config-mock-binding:1.0", "TestService/TestReference"));
        Assert.assertNotNull(implReference.getServiceMetadata().getRegistrant());
        Assert.assertTrue(implReference.getServiceMetadata().getRegistrant().getConfig() instanceof ComponentImplementationModel);
       
        ServiceReference bindingReference = deployment.getDomain().getServiceReference(
                new QName("urn:test:config-mock-binding:1.0", "PromotedTestService"));
        Assert.assertNotNull(bindingReference.getServiceMetadata().getRegistrant());
        List<BindingModel> refBindings = bindingReference.getServiceMetadata().getRegistrant().getConfig();
        Assert.assertEquals(2, refBindings.size());

        // SWITCHYARD-1686
        ServiceReference compReference = deployment.getDomain().getServiceReference(
                new QName("urn:test:config-mock-binding:1.0", "NoService/TestReference"));
        Assert.assertNotNull(compReference.getServiceMetadata().getRegistrant());
        Assert.assertTrue(compReference.getServiceMetadata().getRegistrant().getConfig() instanceof ComponentImplementationModel);
       
        ServiceRegistry registry = ((DomainImpl) deployment.getDomain()).getServiceRegistry();
        deployment.stop();
        // ensure we're cleaning up after ourselves.
        Assert.assertEquals(0, registry.getServices().size());
View Full Code Here

        ServiceOperation op = iface.getOperation(ServiceInterface.DEFAULT_OPERATION);
        Assert.assertNotNull(op);
        Assert.assertEquals(ExchangePattern.IN_ONLY, op.getExchangePattern());
       
        // Test the reference
        ServiceReference reference = serviceDomain.getServiceReference(
                new QName("urn:switchyard-interface-esb", "HelloService/SomeOtherService"));
        Assert.assertNotNull(reference);
        Assert.assertEquals(EsbInterfaceModel.ESB, service.getInterface().getType());
        ServiceOperation rop = reference.getInterface().getOperation(ServiceInterface.DEFAULT_OPERATION);
        Assert.assertNotNull(rop);
        Assert.assertEquals(ExchangePattern.IN_OUT, rop.getExchangePattern());

        deployment.stop();
        deployment.destroy();
View Full Code Here

TOP

Related Classes of org.switchyard.ServiceReference

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.