Package org.osgi.service.discovery

Examples of org.osgi.service.discovery.DiscoveredServiceNotification


        // 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);
View Full Code Here


            // 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);
View Full Code Here

            // should be prepopulated 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");
           
            EasyMock.reset(sr);
            EasyMock.expect(sr.getProperty(DiscoveredServiceTracker.INTERFACE_MATCH_CRITERIA)).
                    andReturn(Arrays.asList("org.example.SomeService", "SomeOtherService")).anyTimes();
            EasyMock.replay(sr);
           
            lds.trackerTracker.modifiedService(sr, dst);
            assertEquals(2, dst.notifications.size());
            DiscoveredServiceNotification dsn0 = dst.notifications.get(0);
            assertEquals(DiscoveredServiceNotification.AVAILABLE, dsn0.getType());
            assertEquals(sed1, dsn0.getServiceEndpointDescription());
            DiscoveredServiceNotification dsn1 = dst.notifications.get(1);
            assertEquals(DiscoveredServiceNotification.AVAILABLE, dsn1.getType());
            assertEquals(sed2, dsn1.getServiceEndpointDescription());
            verifyNotification(dsn1, 0, 1, "SomeOtherService");
        } finally {
            LocalDiscoveryUtils.addEndpointID = true;
        }
    }
View Full Code Here

                newNodes.put(child, m);
                Map<String, Object> prevVal = prevNodes.remove(child);
                if (prevVal == null) {
                    // This guy is new
                    ServiceEndpointDescriptionImpl sed = new ServiceEndpointDescriptionImpl(Collections.singletonList(interFace), m);
                    DiscoveredServiceNotification dsn = new DiscoveredServiceNotificationImpl(Collections.emptyList(),
                        Collections.singleton(interFace), DiscoveredServiceNotification.AVAILABLE, sed);
                    discoveredServiceTracker.serviceChanged(dsn);                   
                } else if (!prevVal.equals(m)){
                    // There's been a modification
                    ServiceEndpointDescriptionImpl sed = new ServiceEndpointDescriptionImpl(Collections.singletonList(interFace), m);
                    DiscoveredServiceNotification dsn = new DiscoveredServiceNotificationImpl(Collections.emptyList(),
                        Collections.singleton(interFace), DiscoveredServiceNotification.MODIFIED, sed);
                    discoveredServiceTracker.serviceChanged(dsn);                   
                }               
            }

            for (Map<String, Object> props : prevNodes.values()) {
                // whatever's left in prevNodes now has been removed from Discovery
                ServiceEndpointDescriptionImpl sed = new ServiceEndpointDescriptionImpl(Collections.singletonList(interFace), props);
                DiscoveredServiceNotification dsn = new DiscoveredServiceNotificationImpl(Collections.emptyList(),
                        Collections.singleton(interFace), DiscoveredServiceNotification.UNAVAILABLE, sed);
                discoveredServiceTracker.serviceChanged(dsn);               
            }
        } catch (Exception e) {
            LOG.log(Level.SEVERE, "Problem processing Zookeeper callback", e);
View Full Code Here

        InterfaceDataMonitorListenerImpl dml = new InterfaceDataMonitorListenerImpl(zk, String.class.getName(), dst);
       
        assertEquals("Precondition failed", 0, dsnCallbacks.size());
        dml.change();
        assertEquals(1, dsnCallbacks.size());
        DiscoveredServiceNotification dsn = dsnCallbacks.iterator().next();
        assertEquals(Collections.singleton(String.class.getName()), dsn.getInterfaces());
        assertEquals(DiscoveredServiceNotification.AVAILABLE, dsn.getType());
        assertEquals(0, dsn.getFilters().size());
        ServiceEndpointDescription sed = dsn.getServiceEndpointDescription();
        assertEquals(Collections.singleton(String.class.getName()), sed.getProvidedInterfaces());   
       
        Properties expected = new Properties();
        expected.load(new ByteArrayInputStream(propBytes.toByteArray()));
        expected.put("service.exported.configs", "org.apache.cxf.ws");
        expected.put("org.apache.cxf.ws.address", "http://somehost:12345/some/context");
       
        assertEquals(expected, sed.getProperties());
        EasyMock.verify(zk);
       
        // Again with the same data
        EasyMock.reset(zk);
        EasyMock.expect(zk.getChildren(Util.getZooKeeperPath(String.class.getName()), false))
            .andReturn(Arrays.asList("x#y#z"));
        EasyMock.expect(zk.getData(Util.getZooKeeperPath(String.class.getName()) + "/x#y#z", false, null))
            .andReturn(propBytes.toByteArray());
        EasyMock.replay(zk);

        dsnCallbacks.clear();
        assertEquals("Precondition failed", 0, dsnCallbacks.size());
        dml.change();
        assertEquals(0, dsnCallbacks.size());
       
        EasyMock.verify(zk);
        //----------------------------------------------------------------
        // Test DiscoveredServiceNotification.MODIFIED
        //----------------------------------------------------------------
        Properties modified = new Properties();
        modified.put("c", "d");
        modified.put(ServicePublication.ENDPOINT_LOCATION, "http://somehost:999/some/context");
        modified.put("service.exported.configs", "org.apache.cxf.rs");
        ByteArrayOutputStream modBytes = new ByteArrayOutputStream();
        modified.store(modBytes, "");
       
        EasyMock.reset(zk);
        EasyMock.expect(zk.getChildren(Util.getZooKeeperPath(String.class.getName()), false))
            .andReturn(Arrays.asList("x#y#z"));
        EasyMock.expect(zk.getData(Util.getZooKeeperPath(String.class.getName()) + "/x#y#z", false, null))
            .andReturn(modBytes.toByteArray());
        EasyMock.replay(zk);

        dsnCallbacks.clear();
        assertEquals("Precondition failed", 0, dsnCallbacks.size());
        dml.change();
        assertEquals(1, dsnCallbacks.size());
        DiscoveredServiceNotification dsn2 = dsnCallbacks.iterator().next();
        assertEquals(Collections.singleton(String.class.getName()), dsn2.getInterfaces());
        assertEquals(DiscoveredServiceNotification.MODIFIED, dsn2.getType());
        assertEquals(0, dsn2.getFilters().size());
        ServiceEndpointDescription sed2 = dsn2.getServiceEndpointDescription();
        assertEquals(Collections.singleton(String.class.getName()), sed2.getProvidedInterfaces());       
        assertEquals(modified, sed2.getProperties());
       
        EasyMock.verify(zk);

        //----------------------------------------------------------------
        // Test DiscoveredServiceNotification.MODIFIED2
        //----------------------------------------------------------------
        Properties modified2 = new Properties();
        modified2.put("c", "d2");
        modified2.put(ServicePublication.ENDPOINT_LOCATION, "http://somehost:112/some/context");
        modified2.put("service.exported.configs", "org.apache.cxf.ws");
        modified2.put("org.apache.cxf.ws.address", "http://somewhereelse/123");
        ByteArrayOutputStream modBytes2 = new ByteArrayOutputStream();
        modified2.store(modBytes2, "");
       
        EasyMock.reset(zk);
        EasyMock.expect(zk.getChildren(Util.getZooKeeperPath(String.class.getName()), false))
            .andReturn(Arrays.asList("x#y#z"));
        EasyMock.expect(zk.getData(Util.getZooKeeperPath(String.class.getName()) + "/x#y#z", false, null))
            .andReturn(modBytes2.toByteArray());
        EasyMock.replay(zk);

        dsnCallbacks.clear();
        assertEquals("Precondition failed", 0, dsnCallbacks.size());
        dml.change();
        assertEquals(1, dsnCallbacks.size());
        DiscoveredServiceNotification dsn3 = dsnCallbacks.iterator().next();
        assertEquals(Collections.singleton(String.class.getName()), dsn3.getInterfaces());
        assertEquals(DiscoveredServiceNotification.MODIFIED, dsn3.getType());
        assertEquals(0, dsn3.getFilters().size());
        ServiceEndpointDescription sed3 = dsn3.getServiceEndpointDescription();
        assertEquals(Collections.singleton(String.class.getName()), sed3.getProvidedInterfaces());       
        assertEquals(modified2, sed3.getProperties());
       
        EasyMock.verify(zk);
        //----------------------------------------------------------------
        // Test DiscoveredServiceNotification.UNAVAILABLE
        //----------------------------------------------------------------
        EasyMock.reset(zk);
        EasyMock.expect(zk.getChildren(Util.getZooKeeperPath(String.class.getName()), false))
            .andReturn(Collections.<String>emptyList());
        EasyMock.replay(zk);

        dsnCallbacks.clear();
        assertEquals("Precondition failed", 0, dsnCallbacks.size());
        dml.change();
        assertEquals(1, dsnCallbacks.size());
        DiscoveredServiceNotification dsn4 = dsnCallbacks.iterator().next();
        assertEquals(Collections.singleton(String.class.getName()), dsn4.getInterfaces());
        assertEquals(DiscoveredServiceNotification.UNAVAILABLE, dsn4.getType());
        assertEquals(0, dsn4.getFilters().size());
        ServiceEndpointDescription sed4 = dsn4.getServiceEndpointDescription();
        assertEquals(Collections.singleton(String.class.getName()), sed4.getProvidedInterfaces());       
        assertEquals(modified2, sed4.getProperties());
       
        EasyMock.verify(zk);
       
View Full Code Here

        // 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);
View Full Code Here

            // 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);
View Full Code Here

            // should be prepopulated 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");
           
            EasyMock.reset(sr);
            EasyMock.expect(sr.getProperty(DiscoveredServiceTracker.INTERFACE_MATCH_CRITERIA)).
                    andReturn(Arrays.asList("org.example.SomeService", "SomeOtherService")).anyTimes();
            EasyMock.replay(sr);
           
            lds.trackerTracker.modifiedService(sr, dst);
            assertEquals(2, dst.notifications.size());
            DiscoveredServiceNotification dsn0 = dst.notifications.get(0);
            assertEquals(DiscoveredServiceNotification.AVAILABLE, dsn0.getType());
            assertEquals(sed1, dsn0.getServiceEndpointDescription());
            DiscoveredServiceNotification dsn1 = dst.notifications.get(1);
            assertEquals(DiscoveredServiceNotification.AVAILABLE, dsn1.getType());
            assertEquals(sed2, dsn1.getServiceEndpointDescription());
            verifyNotification(dsn1, 0, 1, "SomeOtherService");
        } finally {
            LocalDiscoveryUtils.addEndpointID = true;
        }
    }
View Full Code Here

        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

    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());
        assertEquals(type, dsn.getType());
        assertEquals(sed, dsn.getServiceEndpointDescription());
    }
View Full Code Here

TOP

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

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.