Package org.osgi.service.discovery

Examples of org.osgi.service.discovery.ServiceEndpointDescription


        List<String> intf1 = Arrays.asList("org.example.SomeService");
        Map<String, Object> sed1Props = new HashMap<String, Object>();
        sed1Props.put("osgi.remote.requires.intents", "confidentiality");
        sed1Props.put(ServicePublication.SERVICE_INTERFACE_NAME, intf1);
        setEndpointID(eids, sed1Props, "org.example.SomeService");
        ServiceEndpointDescription sed1 = new ServiceEndpointDescriptionImpl(intf1, sed1Props);
        List<String> intf2 = Arrays.asList("SomeOtherService", "WithSomeSecondInterface");
        Map<String, Object> sed2Props = new HashMap<String, Object>();
        sed2Props.put(ServicePublication.SERVICE_INTERFACE_NAME, intf2);
        setEndpointID(eids, sed2Props, "SomeOtherService", "WithSomeSecondInterface");      
        ServiceEndpointDescription sed2 = new ServiceEndpointDescriptionImpl(intf2, sed2Props);
        assertTrue(lds.servicesInfo.containsKey(sed1));
        assertTrue(lds.servicesInfo.containsKey(sed2));
       
        // should be pre-populated by now...
        // register a tracker, it should get called back instantly with sed1
        assertEquals("Precondition failed", 0, dst.notifications.size());
        lds.trackerTracker.addingService(sr);
        assertEquals(1, dst.notifications.size());
        DiscoveredServiceNotification dsn = dst.notifications.iterator().next();
        assertEquals(DiscoveredServiceNotification.AVAILABLE, dsn.getType());
        assertEquals(sed1, dsn.getServiceEndpointDescription());
        verifyNotification(dsn, 0, 1, "org.example.SomeService");
       
        // add a new bundle that also contains a someservice
        // we should get notified again...
        Bundle b1 = EasyMock.createNiceMock(Bundle.class);
        EasyMock.expect(b1.getState()).andReturn(Bundle.ACTIVE).anyTimes();
        EasyMock.expect(b1.findEntries("OSGI-INF/remote-service", "*.xml", false)).
                andReturn(rsBEnum).anyTimes();
        EasyMock.replay(b1);

        // Call back on the LDS just like what would have happened with the BundleListener
        BundleEvent be = new BundleEvent(BundleEvent.STARTED, b1);
        lds.bundleChanged(be);
        Map<Collection<String>, String> eids2 = getEndpointIDs(lds.servicesInfo.keySet());
       
        List<String> intf3 = Arrays.asList("org.example.SomeRelatedService", "org.example.SomeService");
        Map<String, Object> sed3Props = new HashMap<String, Object>();
        sed3Props.put(ServicePublication.SERVICE_INTERFACE_NAME, intf3);
        setEndpointID(eids2, sed3Props, "org.example.SomeRelatedService", "org.example.SomeService");      
        ServiceEndpointDescription sed3 = new ServiceEndpointDescriptionImpl(intf3, sed3Props);
        assertEquals(3, lds.servicesInfo.size());
        assertTrue(lds.servicesInfo.containsKey(sed1));
        assertTrue(lds.servicesInfo.containsKey(sed2));
        assertTrue(lds.servicesInfo.containsKey(sed3));
       
View Full Code Here


   
            List<String> intf1 = Arrays.asList("org.example.SomeService");
            Map<String, Object> sed1Props = new HashMap<String, Object>();
            sed1Props.put("osgi.remote.requires.intents", "confidentiality");
            sed1Props.put(ServicePublication.SERVICE_INTERFACE_NAME, intf1);
            ServiceEndpointDescription sed1 = new ServiceEndpointDescriptionImpl(intf1, sed1Props);
            List<String> intf2 = Arrays.asList("SomeOtherService", "WithSomeSecondInterface");
            Map<String, Object> sed2Props = new HashMap<String, Object>();
            sed2Props.put("blah", "5");
            sed2Props.put(ServicePublication.SERVICE_INTERFACE_NAME, intf2);
            ServiceEndpointDescription sed2 = new ServiceEndpointDescriptionImpl(intf2, sed2Props);
            assertTrue(lds.servicesInfo.containsKey(sed1));
            assertTrue(lds.servicesInfo.containsKey(sed2));
           
            // should be pre-populated by now...
            // register a tracker, it should get called back instantly with sed1
            assertEquals("Precondition failed", 0, dst.notifications.size());
            lds.trackerTracker.addingService(sr);
            assertEquals(1, dst.notifications.size());
            DiscoveredServiceNotification dsn = dst.notifications.iterator().next();
            assertEquals(DiscoveredServiceNotification.AVAILABLE, dsn.getType());
            assertEquals(sed2, dsn.getServiceEndpointDescription());
            verifyNotification(dsn, 1, 0, "(blah <= 5)");
           
            // add a new bundle that also contains a someservice
            // we should get notified again...
            Bundle b1 = EasyMock.createNiceMock(Bundle.class);
            EasyMock.expect(b1.getState()).andReturn(Bundle.ACTIVE).anyTimes();
            EasyMock.expect(b1.findEntries("OSGI-INF/remote-service", "*.xml", false)).
                    andReturn(rsBEnum).anyTimes();
            EasyMock.replay(b1);
   
            // Call back on the LDS just like what would have happened with the BundleListener
            BundleEvent be = new BundleEvent(BundleEvent.STARTED, b1);
            lds.bundleChanged(be);
           
            List<String> intf3 = Arrays.asList("org.example.SomeRelatedService", "org.example.SomeService");
            Map<String, Object> sed3Props = new HashMap<String, Object>();
            sed3Props.put("blah", "3");
            sed3Props.put("boo", "hello");
            sed3Props.put(ServicePublication.SERVICE_INTERFACE_NAME, intf3);
            ServiceEndpointDescription sed3 = new ServiceEndpointDescriptionImpl(intf3, sed3Props);
            assertEquals(3, lds.servicesInfo.size());
            assertTrue(lds.servicesInfo.containsKey(sed1));
            assertTrue(lds.servicesInfo.containsKey(sed2));
            assertTrue(lds.servicesInfo.containsKey(sed3));
           
View Full Code Here

            assertEquals(2, lds.servicesInfo.size());
            List<String> intf1 = Arrays.asList("org.example.SomeService");
            Map<String, Object> sed1Props = new HashMap<String, Object>();
            sed1Props.put(ServicePublication.SERVICE_INTERFACE_NAME, intf1);
            sed1Props.put("osgi.remote.requires.intents", "confidentiality");
            ServiceEndpointDescription sed1 = new ServiceEndpointDescriptionImpl(intf1, sed1Props);
            ServiceEndpointDescription sed2 = new ServiceEndpointDescriptionImpl(
                    Arrays.asList("SomeOtherService", "WithSomeSecondInterface"));
            assertTrue(lds.servicesInfo.containsKey(sed1));
            assertTrue(lds.servicesInfo.containsKey(sed2));
           
            // should be prepopulated by now...
View Full Code Here

            control.replay();
   
            // create the local discovery service
            LocalDiscoveryService lds = new LocalDiscoveryService(bc);
           
            ServiceEndpointDescription sed3 = new ServiceEndpointDescriptionImpl(
                    Arrays.asList("org.example.SomeRelatedService", "org.example.SomeService"));
            assertEquals(1, lds.servicesInfo.size());
            assertEquals(sed3, lds.servicesInfo.keySet().iterator().next());
        } finally {
            LocalDiscoveryUtils.addEndpointID = true;
View Full Code Here

                notifications.add(notification);
            }
        };
       
        LocalDiscoveryService lds = new LocalDiscoveryService(bc);
        ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl("org.acme.B");
       
        assertEquals("Precondition failed", 0, notifications.size());
        lds.triggerCallbacks(dst, filter, true, sd, DiscoveredServiceNotification.AVAILABLE);
        assertEquals(1, notifications.size());
    }
View Full Code Here

        Map<String, Object> sed1Props = new HashMap<String, Object>();
        sed1Props.put("osgi.remote.requires.intents", "confidentiality");
        sed1Props.put(ServicePublication.ENDPOINT_ID, eids.get(
                Collections.singleton("SomeService")));
        sed1Props.put(ServicePublication.SERVICE_INTERFACE_NAME, interfaces);
        ServiceEndpointDescription sed1 =
            new ServiceEndpointDescriptionImpl(interfaces, sed1Props);

        List<String> interfaces2 = Arrays.asList("SomeOtherService", "WithSomeSecondInterface");
        Map<String, Object> sed2Props = new HashMap<String, Object>();
        sed2Props.put(ServicePublication.ENDPOINT_ID, eids.get(
                new HashSet<String>(interfaces2)));
        sed2Props.put(ServicePublication.SERVICE_INTERFACE_NAME, interfaces2);
        ServiceEndpointDescription sed2 =
            new ServiceEndpointDescriptionImpl(interfaces2, sed2Props);
        assertTrue(seds.contains(sed1));
        assertTrue(seds.contains(sed2));
    }
View Full Code Here

        boolean s1Found = false, s2Found = false;
        for (DiscoveredServiceNotification dsn : notifications) {
            assertEquals(DiscoveredServiceNotification.AVAILABLE, dsn.getType());
            assertEquals(Collections.emptyList(), dsn.getFilters());
            assertEquals(Collections.singleton(String.class.getName()), dsn.getInterfaces());
            ServiceEndpointDescription sed = dsn.getServiceEndpointDescription();
            assertEquals(Collections.singleton(String.class.getName()), sed.getProvidedInterfaces());
            Map<?, ?> m = sed.getProperties();
            if (m.entrySet().containsAll(s1Props.entrySet())) {
                s1Found = true;
            }
           
            if (m.entrySet().containsAll(s2Props.entrySet())) {
                s2Found = true;
            }           
        }
        assertTrue(s1Found);
        assertTrue(s2Found);
       
        // Second time around, with same data
        notifications.clear();
        dm.processResult(Code.Ok, null, null, null);
        assertEquals("No changes, so should not get any new notifications", 0, notifications.size());
       
        // Third time around, removal
        EasyMock.reset(zk);
        zk.exists(Util.getZooKeeperPath(String.class.getName()), false);
        EasyMock.expectLastCall().andReturn(EasyMock.createMock(Stat.class));
        EasyMock.expect(zk.getChildren(Util.getZooKeeperPath(String.class.getName()), false))
            .andReturn(Arrays.asList("a#90#r")).anyTimes();
        EasyMock.expect(zk.getData(Util.getZooKeeperPath(String.class.getName()) + "/a#90#r", false, null))
            .andReturn(s1Bytes.toByteArray()).anyTimes();
        EasyMock.replay(zk);
        notifications.clear();
        dm.processResult(Code.Ok, null, null, null);
        DiscoveredServiceNotification dsn = notifications.iterator().next();
        assertEquals(1, notifications.size());
        assertEquals(DiscoveredServiceNotification.UNAVAILABLE, dsn.getType());
        assertEquals(Collections.emptyList(), dsn.getFilters());
        assertEquals(Collections.singleton(String.class.getName()), dsn.getInterfaces());
        ServiceEndpointDescription sed = dsn.getServiceEndpointDescription();
        assertEquals(Collections.singleton(String.class.getName()), sed.getProvidedInterfaces());
        assertTrue(sed.getProperties().entrySet().containsAll(s2Props.entrySet()));
    }
View Full Code Here

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof ServiceEndpointDescription)) {
            return false;
        }
        ServiceEndpointDescription other = (ServiceEndpointDescription)obj;
       
        return interfaceNames.equals(other.getProvidedInterfaces())
               && properties.equals(other.getProperties());
    }
View Full Code Here

    @SuppressWarnings("unchecked")
    public void testDSNImpl() {
        Collection filters = Collections.singleton("(some.property=some.value)");
        Collection interfaces = Arrays.asList(String.class.getName(), ArrayList.class.getName());
        int type = DiscoveredServiceNotification.AVAILABLE;
        ServiceEndpointDescription sed = new ServiceEndpointDescriptionImpl(String.class.getName());
        DiscoveredServiceNotification dsn =
            new DiscoveredServiceNotificationImpl(filters, interfaces, type, sed);
       
        assertEquals(filters, dsn.getFilters());
        assertEquals(interfaces, dsn.getInterfaces());
View Full Code Here

        EasyMock.replay(sr);
        EasyMock.replay(callingContext);

        Map<String, Object> props = new HashMap<String, Object>();
        props.put(Constants.WS_HTTP_SERVICE_CONTEXT, "/myRunnable");
        ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(Runnable.class.getName(), props);
       
        assertEquals("Precondition failed", 0, dp.getExposedServices().size());
        assertEquals("Precondition failed", "", sfb.getAddress());
        h.createServer(sr, dswContext, callingContext, sd, Runnable.class, myService);
        assertEquals("The address should be set to '/'. The Servlet context dictates the actual location.", "/", sfb.getAddress());
View Full Code Here

TOP

Related Classes of org.osgi.service.discovery.ServiceEndpointDescription

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.