Package org.osgi.service.discovery

Examples of org.osgi.service.discovery.ServiceEndpointDescription


        Map<Collection<String>, String> eids = getEndpointIDs(lds.servicesInfo.keySet());

        Map<String, Object> sed1Props = new HashMap<String, Object>();
        sed1Props.put("osgi.remote.requires.intents", "confidentiality");
        setEndpointID(eids, sed1Props, "org.example.SomeService");
        ServiceEndpointDescription sed1 = new ServiceEndpointDescriptionImpl(
                Arrays.asList("org.example.SomeService"), sed1Props);
        Map<String, Object> sed2Props = new HashMap<String, Object>();
        setEndpointID(eids, sed2Props, "SomeOtherService", "WithSomeSecondInterface");      
        ServiceEndpointDescription sed2 = new ServiceEndpointDescriptionImpl(
                Arrays.asList("SomeOtherService", "WithSomeSecondInterface"), 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());
       
        Map<String, Object> sed3Props = new HashMap<String, Object>();
        setEndpointID(eids2, sed3Props, "org.example.SomeRelatedService", "org.example.SomeService");      
        ServiceEndpointDescription sed3 = new ServiceEndpointDescriptionImpl(
                Arrays.asList("org.example.SomeRelatedService", "org.example.SomeService"), 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


            // it should be prepopulated with the info from bundle b0
            assertEquals(2, lds.servicesInfo.size());
   
            Map<String, Object> sed1Props = new HashMap<String, Object>();
            sed1Props.put("osgi.remote.requires.intents", "confidentiality");
            ServiceEndpointDescription sed1 = new ServiceEndpointDescriptionImpl(
                    Arrays.asList("org.example.SomeService"), sed1Props);
            Map<String, Object> sed2Props = new HashMap<String, Object>();
            sed2Props.put("blah", "5");
            ServiceEndpointDescription sed2 = new ServiceEndpointDescriptionImpl(
                    Arrays.asList("SomeOtherService", "WithSomeSecondInterface"), 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);
           
            Map<String, Object> sed3Props = new HashMap<String, Object>();
            sed3Props.put("blah", "3");
            sed3Props.put("boo", "hello");
            ServiceEndpointDescription sed3 = new ServiceEndpointDescriptionImpl(
                    Arrays.asList("org.example.SomeRelatedService", "org.example.SomeService"), 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

           
            // it should be prepopulated with the info from bundle b0
            assertEquals(2, lds.servicesInfo.size());
            Map<String, Object> sed1Props = new HashMap<String, Object>();
            sed1Props.put("osgi.remote.requires.intents", "confidentiality");
            ServiceEndpointDescription sed1 = new ServiceEndpointDescriptionImpl(
                    Arrays.asList("org.example.SomeService"), 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

       
        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")));      
        ServiceEndpointDescription sed1 = new ServiceEndpointDescriptionImpl(
                Arrays.asList("SomeService"), sed1Props);

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

    }
       
    protected void processNotification(DiscoveredServiceNotification notification,
                                       BundleContext requestingContext) {
           
        ServiceEndpointDescription sd =
            notification.getServiceEndpointDescription();
        if (sd.getProperty(DistributionConstants.REMOTE_INTERFACES) == null) {
            LOG.info("not proxifying service, enabling property not set: "
                 + DistributionConstants.REMOTE_INTERFACES);
            return;
        }
           
View Full Code Here

        }
    }

    private class DiscoveryCallback implements DiscoveredServiceTracker {
        public void serviceChanged(DiscoveredServiceNotification notification) {
            ServiceEndpointDescription notified =
                notification.getServiceEndpointDescription();
            switch (notification.getType()) {

            case AVAILABLE:
               LOG.info("Notified - AVAILABLE: "
                         + notified.getProvidedInterfaces()
                         + " endpoint id: "
                         + notification.getServiceEndpointDescription().getProperty(ENDPOINT_ID));
                processNotification(notification, getContext());
                break;

            case UNAVAILABLE:
                LOG.info("Notified - UNAVAILABLE: " + notified.getProvidedInterfaces()
                         + notified.getProvidedInterfaces()
                         + " endpoint id: "
                         + notification.getServiceEndpointDescription().getProperty(ENDPOINT_ID));
                unCacheEndpointId(notified);
                break;

            case MODIFIED:
                LOG.info("Notified - MODIFIED: " + notified.getProvidedInterfaces());
                // we don't currently use this notification, but we could do
                // so to allow to support transparent service re-location
                break;
            }
        }
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

                                                String interfaceName,
                                                Filter filter,
                                                boolean matchAll) {
       
        for (Iterator<ServiceEndpointDescription> it = sds.iterator(); it.hasNext();) {
            ServiceEndpointDescription sd = it.next();
            
            if (filter != null && !OsgiUtils.matchAgainstFilter(sd, interfaceName, filter, matchAll)) {
                it.remove();
            }
        }
View Full Code Here

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof ServiceEndpointDescription)) {
            return false;
        }
        ServiceEndpointDescription other = (ServiceEndpointDescription)obj;
        if (this == other) {
            return true;
        }
       
       
        return interfaceNames.equals(other.getProvidedInterfaces())
               && properties.equals(other.getProperties());
    }
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.