Examples of EndpointListener


Examples of org.apache.servicemix.nmr.api.event.EndpointListener

    public void testEndpointListener() throws Exception {
        final CountDownLatch regLatch = new CountDownLatch(1);
        final CountDownLatch unregLatch = new CountDownLatch(1);
        Endpoint endpoint = new DummyEndpoint();
        nmr.getListenerRegistry().register(new EndpointListener() {
            public void endpointRegistered(InternalEndpoint endpoint) {
                regLatch.countDown();
            }
            public void endpointUnregistered(InternalEndpoint endpoint) {
                unregLatch.countDown();
View Full Code Here

Examples of org.apache.servicemix.nmr.api.event.EndpointListener

    @Test
    public void testEndpointListener() throws Exception {
        final CountDownLatch regLatch = new CountDownLatch(1);
        final CountDownLatch unregLatch = new CountDownLatch(1);
        Endpoint endpoint = new DummyEndpoint();
        nmr.getListenerRegistry().register(new EndpointListener() {
            public void endpointRegistered(InternalEndpoint endpoint) {
                regLatch.countDown();
            }
            public void endpointUnregistered(InternalEndpoint endpoint) {
                unregLatch.countDown();
View Full Code Here

Examples of org.apache.servicemix.nmr.api.event.EndpointListener

    public void testEndpointListener() throws Exception {
        final CountDownLatch regLatch = new CountDownLatch(1);
        final CountDownLatch unregLatch = new CountDownLatch(1);
        Endpoint endpoint = new DummyEndpoint();
        nmr.getListenerRegistry().register(new EndpointListener() {
            public void endpointRegistered(InternalEndpoint endpoint) {
                regLatch.countDown();
            }
            public void endpointUnregistered(InternalEndpoint endpoint) {
                unregLatch.countDown();
View Full Code Here

Examples of org.osgi.service.remoteserviceadmin.EndpointListener

       
        Bundle topMgrBundle = c.createMock(Bundle.class);
       
        RemoteServiceAdmin rsa = c.createMock(RemoteServiceAdmin.class);
        final ServiceReference rsaSref = c.createMock(ServiceReference.class);
        EndpointListener epl = c.createMock(EndpointListener.class);
        final ServiceReference eplSref = c.createMock(ServiceReference.class);
        EasyMock.expect(eplSref.getProperty(EasyMock.same(EndpointListener.ENDPOINT_LISTENER_SCOPE)))
            .andReturn(scope).anyTimes();
        EasyMock.expect(eplSref.getBundle()).andReturn(topMgrBundle).anyTimes();

        final ServiceReference sref = c.createMock(ServiceReference.class);
        EasyMock.expect(sref.getProperty(EasyMock.same(RemoteConstants.SERVICE_EXPORTED_INTERFACES)))
            .andReturn("*").anyTimes();
        Bundle srefBundle = c.createMock(Bundle.class);
        EasyMock.expect(sref.getBundle()).andReturn(srefBundle).anyTimes();
       
       
        EndpointDescription endpoint = c.createMock(EndpointDescription.class);
        {
            Map props = new HashMap();
            String[] objs = new String[1];
            objs[0] = "abc";
            props.put("objectClass", objs);
            EasyMock.expect(endpoint.getProperties()).andReturn(props).anyTimes();
        }

        ExportRegistration exportRegistration = c.createMock(ExportRegistration.class);
        ExportReference exportReference = c.createMock(ExportReference.class);

        EasyMock.expect(exportRegistration.getExportReference()).andReturn(exportReference).anyTimes();
        EasyMock.expect(exportReference.getExportedEndpoint()).andReturn(endpoint).anyTimes();
        {
            List ret = new ArrayList();
            ret.add(exportRegistration);
            EasyMock.expect(rsa.exportService(EasyMock.same(sref), (Map)EasyMock.anyObject())).andReturn(ret)
                .once();
        }

        epl.endpointAdded((EndpointDescription)EasyMock.anyObject(), (String)EasyMock.anyObject());
        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {

            public Object answer() throws Throwable {
                System.out.println("Call made !!!");
                sema.release();
View Full Code Here

Examples of org.osgi.service.remoteserviceadmin.EndpointListener

        BundleContext bc = c.createMock(BundleContext.class);
        ServiceReference sref = c.createMock(ServiceReference.class);
        ExportRegistration exReg = c.createMock(ExportRegistration.class);
        ExportRegistration exReg2 = c.createMock(ExportRegistration.class);
        EndpointListener epl = EasyMock.createMock(EndpointListener.class);
        EndpointDescription epd = c.createMock(EndpointDescription.class);
        EndpointDescription epd2 = c.createMock(EndpointDescription.class);
        ExportReference exRef = c.createMock(ExportReference.class);
        ExportReference exRef2 = c.createMock(ExportReference.class);
       
       
        Map props = new HashMap();
        String[] oc = new String[1];
        oc[0] = "myClass";
        props.put("objectClass", oc);
       
        Map props2 = new HashMap();
        oc = new String[1];
        oc[0] = "notMyClass";
        props2.put("objectClass", oc);
       
       
        EasyMock.expect(bc.getService(EasyMock.eq(sref))).andReturn(epl).anyTimes();
        EasyMock.expect(bc.createFilter((String)EasyMock.anyObject())).andAnswer(new IAnswer<Filter>() {
            public Filter answer() throws Throwable {
                return FrameworkUtil.createFilter((String)EasyMock.getCurrentArguments()[0]);
            }
        }).anyTimes();
        EasyMock.expect(sref.getProperty(EasyMock.eq(EndpointListener.ENDPOINT_LISTENER_SCOPE)))
            .andReturn("(objectClass=myClass)").anyTimes();

       
        EasyMock.expect(exReg.getExportReference()).andReturn(exRef).anyTimes();
        EasyMock.expect(exRef.getExportedEndpoint()).andReturn(epd).anyTimes();
        EasyMock.expect(epd.getProperties()).andReturn(props).anyTimes();
       
        EasyMock.expect(exReg2.getExportReference()).andReturn(exRef2).anyTimes();
        EasyMock.expect(exRef2.getExportedEndpoint()).andReturn(epd2).anyTimes();
        EasyMock.expect(epd2.getProperties()).andReturn(props2).anyTimes();
       
        // must only be called for the first EndpointDestription !
        epl.endpointRemoved(EasyMock.eq(epd), EasyMock.eq("(objectClass=myClass)"));
        EasyMock.expectLastCall().once();
       
        c.replay();
        EasyMock.replay(epl);
       
View Full Code Here

Examples of org.osgi.service.remoteserviceadmin.EndpointListener

        }
    }

    void registerTracker(ServiceReference reference, Object svc) {
        if (svc instanceof EndpointListener) {
            EndpointListener listener = (EndpointListener) svc;
            Collection<String> filters = addListener(reference, listener);
            triggerCallbacks(filters, listener);
        }
    }
View Full Code Here

Examples of org.osgi.service.remoteserviceadmin.EndpointListener

        }
    }

    void clearTracker(Object svc) {
        if (svc instanceof EndpointListener) {
            EndpointListener listener = (EndpointListener) svc;
            removeListener(listener);
            // If the tracker was removed or the scope was changed this doesn't require
            // additional callbacks on the tracker. Its the responsibility of the tracker
            // itself to clean up any orphans. See Remote Service Admin spec 122.6.3
        }
View Full Code Here

Examples of org.osgi.service.remoteserviceadmin.EndpointListener

                return props.get(EasyMock.getCurrentArguments()[0]);
            }
        }).anyTimes();               
        EasyMock.replay(sr);

        EndpointListener el = EasyMock.createMock(EndpointListener.class);
        el.endpointAdded((EndpointDescription) EasyMock.anyObject(), EasyMock.eq("(objectClass=*)"));
        EasyMock.expectLastCall();
        EasyMock.replay(el);
        ld.registerTracker(sr, el);
       
        // Start the bundle
        BundleEvent be = new BundleEvent(BundleEvent.STARTED, bundle);
        ld.bundleChanged(be);
        assertEquals(1, ld.endpointDescriptions.size());
        EndpointDescription ed = ld.endpointDescriptions.keySet().iterator().next();
        assertEquals("http://somewhere:12345", ed.getId());
        assertSame(bundle, ld.endpointDescriptions.get(ed));
       
        EasyMock.verify(el);

        // Stop the bundle
        EasyMock.reset(el);
        el.endpointRemoved((EndpointDescription) EasyMock.anyObject(), EasyMock.eq("(objectClass=*)"));
        EasyMock.expectLastCall();
        EasyMock.replay(el);
       
        BundleEvent be1 = new BundleEvent(BundleEvent.STOPPED, bundle);
        ld.bundleChanged(be1);
View Full Code Here

Examples of org.osgi.service.remoteserviceadmin.EndpointListener

        }).anyTimes();
               
        EasyMock.replay(sr);
       
        EasyMock.reset(ld.bundleContext);
        EndpointListener el = EasyMock.createMock(EndpointListener.class);
        EasyMock.expect(ld.bundleContext.getService(sr)).andReturn(el);
        EasyMock.expect(ld.bundleContext.ungetService(sr)).andReturn(true);
        EasyMock.expect(ld.bundleContext.createFilter((String) EasyMock.anyObject())).andAnswer(new IAnswer<Filter>() {
            public Filter answer() throws Throwable {
                return FrameworkUtil.createFilter((String) EasyMock.getCurrentArguments()[0]);
            }
        }).anyTimes();
        EasyMock.replay(ld.bundleContext);
       
        el.endpointAdded((EndpointDescription) EasyMock.anyObject(),
                EasyMock.eq("(objectClass=org.example.ClassA)"));
        EasyMock.expectLastCall();
        EasyMock.replay(el);
       
        // Add the EndpointListener Service
        assertEquals("Precondition failed", 0, ld.listenerToFilters.size());
        assertEquals("Precondition failed", 0, ld.filterToListeners.size());       
        assertSame(el, ld.listenerTracker.addingService(sr));
       
        assertEquals(1, ld.listenerToFilters.size());
        assertEquals(Collections.singletonList("(objectClass=org.example.ClassA)"), ld.listenerToFilters.get(el));
        assertEquals(1, ld.filterToListeners.size());
        assertEquals(Collections.singletonList(el), ld.filterToListeners.get("(objectClass=org.example.ClassA)"));

        EasyMock.verify(el);
       
        // Modify the EndpointListener Service
        // no need to reset the mock for this...
        props.put(EndpointListener.ENDPOINT_LISTENER_SCOPE, "(|(objectClass=org.example.ClassA)(objectClass=org.example.ClassB))");
       
        EasyMock.reset(el);
        final Set<String> actualEndpoints = new HashSet<String>();
        el.endpointAdded((EndpointDescription) EasyMock.anyObject(),
                EasyMock.eq("(|(objectClass=org.example.ClassA)(objectClass=org.example.ClassB))"));
        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                EndpointDescription ed = (EndpointDescription) EasyMock.getCurrentArguments()[0];
                actualEndpoints.addAll(ed.getInterfaces());
View Full Code Here

Examples of org.osgi.service.remoteserviceadmin.EndpointListener

                return props.get(EasyMock.getCurrentArguments()[0]);
            }
        }).anyTimes();               
        EasyMock.replay(sr);

        EndpointListener el = EasyMock.createMock(EndpointListener.class);
        EasyMock.replay(el);
       
        assertEquals("Precondition failed", 0, ld.listenerToFilters.size());
        assertEquals("Precondition failed", 0, ld.filterToListeners.size());
        ld.registerTracker(sr, el);
       
        assertEquals(1, ld.listenerToFilters.size());
        assertEquals(Collections.singletonList("(objectClass=Aaaa)"), ld.listenerToFilters.get(el));
        assertEquals(1, ld.filterToListeners.size());
        assertEquals(Collections.singletonList(el), ld.filterToListeners.get("(objectClass=Aaaa)"));
       
        // Add another one with the same scope filter
        ServiceReference sr2 = EasyMock.createMock(ServiceReference.class);
        EasyMock.expect(sr2.getPropertyKeys()).andReturn(props.keySet().toArray(new String [] {})).anyTimes();
        EasyMock.expect(sr2.getProperty((String) EasyMock.anyObject())).andAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                return props.get(EasyMock.getCurrentArguments()[0]);
            }
        }).anyTimes();               
        EasyMock.replay(sr2);

        EndpointListener el2 = EasyMock.createMock(EndpointListener.class);
        EasyMock.replay(el2);
        ld.registerTracker(sr2, el2);

        assertEquals(2, ld.listenerToFilters.size());
        assertEquals(Collections.singletonList("(objectClass=Aaaa)"), ld.listenerToFilters.get(el));
        assertEquals(Collections.singletonList("(objectClass=Aaaa)"), ld.listenerToFilters.get(el2));
       
        assertEquals(1, ld.filterToListeners.size());
        assertEquals(Arrays.asList(el, el2), ld.filterToListeners.get("(objectClass=Aaaa)"));
       
        // Add another listener with a multi-value scope
        final Hashtable<String, Object> props2 = new Hashtable<String, Object>();
        props2.put(EndpointListener.ENDPOINT_LISTENER_SCOPE, Arrays.asList("(objectClass=X)","(objectClass=Y)"));
        ServiceReference sr3 = EasyMock.createMock(ServiceReference.class);
        EasyMock.expect(sr3.getPropertyKeys()).andReturn(props2.keySet().toArray(new String [] {})).anyTimes();
        EasyMock.expect(sr3.getProperty((String) EasyMock.anyObject())).andAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                return props2.get(EasyMock.getCurrentArguments()[0]);
            }
        }).anyTimes();               
        EasyMock.replay(sr3);

        EndpointListener el3 = EasyMock.createMock(EndpointListener.class);
        EasyMock.replay(el3);
        ld.registerTracker(sr3, el3);

        assertEquals(3, ld.listenerToFilters.size());
        assertEquals(Collections.singletonList("(objectClass=Aaaa)"), ld.listenerToFilters.get(el));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.