Package org.switchyard.remote

Examples of org.switchyard.remote.RemoteEndpoint


                if (node.startsWith(serviceKey)) {
                    String epStr = _serviceCache.get(node);
                    // Catch a race condition where entry has been removed since keySet list was built
                    if (epStr != null) {
                        try {
                            RemoteEndpoint ep = _serializer.deserialize(epStr.getBytes(), RemoteEndpoint.class);
                            services.add(ep);
                        } catch (java.io.IOException ioEx) {
                            _log.warn("Failed to deserialize remote endpoint: " + epStr, ioEx);
                        }
                    }
View Full Code Here


    public RemoteEndpoint selectEndpoint(QName serviceName) {
        if (getRegistry() == null) {
            return null;
        }
       
        RemoteEndpoint selectedEp = null;
        List<RemoteEndpoint> eps = getRegistry().getEndpoints(serviceName);
        if (!eps.isEmpty()) {
            int idx = _random.nextInt(Integer.MAX_VALUE) % eps.size();
            selectedEp = eps.get(idx);
        }
View Full Code Here

    @Override
    public RemoteEndpoint selectEndpoint(QName serviceName) {
        if (getRegistry() == null) {
            return null;
        }
        RemoteEndpoint selectedEp = null;
        List<RemoteEndpoint> eps = getRegistry().getEndpoints(serviceName);
        if (!eps.isEmpty()) {
            _endpointIdxs.putIfAbsent(serviceName, new AtomicInteger(0));
            AtomicInteger idx = _endpointIdxs.get(serviceName);
            synchronized (idx) {
View Full Code Here

        _loadBalancer.setRegistry(registry);
    }
   
    @Override
    public RemoteMessage invoke(RemoteMessage request) throws IOException {
        RemoteEndpoint ep = _loadBalancer.selectEndpoint(request.getService());
        if (ep == null) {
            throw RemoteMessages.MESSAGES.noRemoteEndpointFound(request.getService().toString());
        }
        return new HttpInvoker(ep.getEndpoint()).invoke(request);
    }
View Full Code Here

        _cacheMgr.stop();
    }
   
    @Test
    public void addGetAndRemoveSingle() throws Exception {
        RemoteEndpoint ep1 = new RemoteEndpoint()
            .setDomainName(new QName("domain1"))
            .setServiceName(new QName("service1"));

        // nothing in the registry
        Assert.assertEquals(0, _registry.getEndpoints(ep1.getServiceName()).size());
        // add an endpoint
        _registry.addEndpoint(ep1);
        // should get one now
        Assert.assertEquals(1, _registry.getEndpoints(ep1.getServiceName()).size());
        // remove the endpoint
        _registry.removeEndpoint(ep1);
        // nothing in the registry
        Assert.assertEquals(0, _registry.getEndpoints(ep1.getServiceName()).size());
    }
View Full Code Here

        Assert.assertEquals(0, _registry.getEndpoints(ep1.getServiceName()).size());
    }
   
    @Test
    public void testNodeFailure() throws Exception {
        RemoteEndpoint ep1 = new RemoteEndpoint()
        .setDomainName(new QName("domain1"))
        .setServiceName(new QName("service1"));
        RemoteEndpoint ep2 = new RemoteEndpoint()
        .setDomainName(new QName("domain1"))
        .setServiceName(new QName("service2"));
       
        // nothing in the registry
        Assert.assertEquals(0, _registry.getEndpoints(ep1.getServiceName()).size());
        // add our endpoints on the same node
        _registry.addEndpoint(ep1);
        _registry.addEndpoint(ep2);
        // signal that the node has failed
        InfinispanRegistry.MemberDropListener dropListener = _registry.new MemberDropListener();
        dropListener.dropAllServices(new FakeAddress(ep1.getNode()));

        // check to make sure all endpoints were removed
        Assert.assertEquals(0, _registry.getEndpoints(ep1.getServiceName()).size());
        // check to make sure all endpoints were removed
        Assert.assertEquals(0, _registry.getEndpoints(ep2.getServiceName()).size());
       
    }
View Full Code Here

       
    }
   
    @Test
    public void addDuplicate() throws Exception {
        RemoteEndpoint ep1 = new RemoteEndpoint()
            .setDomainName(new QName("domain1"))
            .setServiceName(new QName("service1"));

        // add an endpoint
        _registry.addEndpoint(ep1);
        // should get one now
        Assert.assertEquals(1, _registry.getEndpoints(ep1.getServiceName()).size());
        // attempt to add again
        _registry.addEndpoint(ep1);
        // still just one in the registry
        Assert.assertEquals(1, _registry.getEndpoints(ep1.getServiceName()).size());
    }
View Full Code Here

        Assert.assertNull(random.selectEndpoint(TEST_SERVICE));
    }
   
    @Test
    public void oneEndpoint() {
        registry.addEndpoint(new RemoteEndpoint().setServiceName(TEST_SERVICE));
        Assert.assertNotNull(random.selectEndpoint(TEST_SERVICE));
    }
View Full Code Here

    }
   
    @Test
    public void multipleEndpoints() {
        // register two endpoints for the same service
        RemoteEndpoint ep1 = new RemoteEndpoint().setServiceName(TEST_SERVICE).setEndpoint("ep1");
        RemoteEndpoint ep2 = new RemoteEndpoint().setServiceName(TEST_SERVICE).setEndpoint("ep2");
        registry.addEndpoint(ep1);
        registry.addEndpoint(ep2);
       
        Map<String, AtomicInteger> epCounts = new HashMap<String, AtomicInteger>();
        epCounts.put(ep1.getEndpoint(), new AtomicInteger());
        epCounts.put(ep2.getEndpoint(), new AtomicInteger());
        for (int i = 0; i < 1000; i++) {
            RemoteEndpoint ep = random.selectEndpoint(TEST_SERVICE);
            epCounts.get(ep.getEndpoint()).incrementAndGet();
        }
       
        Assert.assertTrue(epCounts.get(ep1.getEndpoint()).get() > 0);
        Assert.assertTrue(epCounts.get(ep2.getEndpoint()).get() > 0);
    }
View Full Code Here

        Assert.assertNull(robin.selectEndpoint(TEST_SERVICE1));
    }
   
    @Test
    public void oneEndpoint() {
        registry.addEndpoint(new RemoteEndpoint().setServiceName(TEST_SERVICE1));
        Assert.assertNotNull(robin.selectEndpoint(TEST_SERVICE1));
    }
View Full Code Here

TOP

Related Classes of org.switchyard.remote.RemoteEndpoint

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.