Package org.osgi.service.event

Examples of org.osgi.service.event.EventAdmin


        }
        eventAdmin.postEvent(new Event(topic, props));
    }

    public void repositoryEvent(RepositoryEvent event) {
        EventAdmin eventAdmin = (EventAdmin) tracker.getService();
        if (eventAdmin == null) {
            return;
        }
        Dictionary<String, Object> props = new Hashtable<String, Object>();
        props.put(EventConstants.TYPE, event.getType());
        props.put(EventConstants.EVENT, event);
        props.put(EventConstants.TIMESTAMP, System.currentTimeMillis());
        props.put(EventConstants.REPOSITORY_NAME, event.getRepository().getName());
        props.put(EventConstants.REPOSITORY_URI, event.getRepository().getURI().toString());
        String topic;
        switch (event.getType()) {
            case RepositoryAdded:
                topic = EventConstants.TOPIC_REPOSITORY_ADDED;
                break;
            case RepositoryRemoved:
                topic = EventConstants.TOPIC_REPOSITORY_REMOVED;
                break;
            default:
                throw new IllegalStateException("Unknown repository event type: " + event.getType());
        }
        eventAdmin.postEvent(new Event(topic, props));
    }
View Full Code Here


    }

    private void sendAdminEvent() {
        ServiceReference eaRef = bc.getServiceReference(EventAdmin.class.getName());
        if (eaRef != null) {
            EventAdmin ea = (EventAdmin) bc.getService(eaRef);
            ea.sendEvent(new Event("jersey/test/DEPLOYED", new HashMap<String, String>() {
                {
                    put("context-path", "/");
                }
            }));
            bc.ungetService(eaRef);
View Full Code Here

        Set<String> expectedIntents = new HashSet<String>(Arrays.asList(new String [] {"A", "B"}));
        assertEquals(expectedIntents, effectiveIntents);
    }
   
    public void testServiceExposedAdminEvent() throws Exception {
        EventAdmin ea = EasyMock.createMock(EventAdmin.class);
        ea.postEvent((Event) EasyMock.anyObject());
        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                Event e = (Event) EasyMock.getCurrentArguments()[0];
                assertEquals("org/osgi/service/distribution/DistributionProvider/service/exposed", e.getTopic());               
                List<String> keys = Arrays.asList(e.getPropertyNames());
View Full Code Here

        p.createServer(sr, dswContext, callingContext, sd, String.class, myService);
        EasyMock.verify(ea);
    }

    public void testServiceUnsatisfiedAdminEvent() throws Exception {
        EventAdmin ea = EasyMock.createMock(EventAdmin.class);
        ea.postEvent((Event) EasyMock.anyObject());
        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                Event e = (Event) EasyMock.getCurrentArguments()[0];
                assertEquals("org/osgi/service/distribution/DistributionProvider/service/unsatisfied", e.getTopic());               
                return null;
View Full Code Here

    private void fireExportEvents(Bundle source, List<ExportRegistration> exportRegistrations) {
        for (ExportRegistration registration : exportRegistrations) {
            RemoteServiceAdminEvent rsaEvent =
                new RemoteServiceAdminEvent(RemoteServiceAdminEvent.EXPORT_REGISTRATION, source, registration
                    .getExportReference(), registration.getException());
            EventAdmin eventAdmin = getEventAdmin();
            if (eventAdmin != null) {
                eventAdmin.postEvent(wrap(rsaEvent));
            }
            for (Object listener : listeners.getServices()) {
                RemoteServiceAdminListener rsaListener = (RemoteServiceAdminListener)listener;
                rsaListener.remoteAdminEvent(rsaEvent);
            }
View Full Code Here

    private void fireImportEvents(Bundle source, ImportRegistration registration) {
        RemoteServiceAdminEvent rsaEvent =
            new RemoteServiceAdminEvent(RemoteServiceAdminEvent.IMPORT_REGISTRATION, source, registration
                .getImportReference(), registration.getException());
        EventAdmin eventAdmin = getEventAdmin();
        if (eventAdmin != null) {
            eventAdmin.postEvent(wrap(rsaEvent));
        }
        for (Object listener : listeners.getServices()) {
            RemoteServiceAdminListener rsaListener = (RemoteServiceAdminListener)listener;
            rsaListener.remoteAdminEvent(rsaEvent);
        }
View Full Code Here

        this.tracker.close();
        super.doStop();
    }

    public void process(Exchange exchange) throws Exception {
        EventAdmin admin = (EventAdmin) this.tracker.getService();
        if (admin != null) {
            Event event = getEvent(exchange);
            if (endpoint.isSend()) {
                admin.sendEvent(event);
            } else {
                admin.postEvent(event);
            }
        } else {
            throw new CamelExchangeException("EventAdmin service not present", exchange);
        }
    }
View Full Code Here

    }

    private void sendAdminEvent() {
        ServiceReference eaRef = bc.getServiceReference(EventAdmin.class.getName());
        if (eaRef != null) {
            EventAdmin ea = (EventAdmin) bc.getService(eaRef);
            ea.sendEvent(new Event("jersey/test/DEPLOYED", new HashMap<String, String>() {

                {
                    put("context-path", "/");
                }
            }));
View Full Code Here

    }

    private void sendAdminEvent() {
        ServiceReference eaRef = bc.getServiceReference(EventAdmin.class.getName());
        if (eaRef != null) {
            EventAdmin ea = (EventAdmin) bc.getService(eaRef);
            ea.sendEvent(new Event("jersey/test/DEPLOYED", new HashMap<String, String>() {

                {
                    put("context-path", "/");
                }
            }));
View Full Code Here

        tracker = new ServiceTracker<EventAdmin, EventAdmin>(context, EventAdmin.class.getName(), null);
        tracker.open();
    }

    public void featureEvent(FeatureEvent event) {
        EventAdmin eventAdmin = tracker.getService();
        if (eventAdmin == null) {
            return;
        }
        Dictionary<String, Object> props = new Hashtable<String, Object>();
        props.put(EventConstants.TYPE, event.getType());
        props.put(EventConstants.EVENT, event);
        props.put(EventConstants.TIMESTAMP, System.currentTimeMillis());
        props.put(EventConstants.FEATURE_NAME, event.getFeature().getName());
        props.put(EventConstants.FEATURE_VERSION, event.getFeature().getVersion());
        String topic;
        switch (event.getType()) {
        case FeatureInstalled:
            topic = EventConstants.TOPIC_FEATURES_INSTALLED;
            break;
        case FeatureUninstalled:
            topic = EventConstants.TOPIC_FEATURES_UNINSTALLED;
            break;
        default:
            throw new IllegalStateException("Unknown features event type: " + event.getType());
        }
        eventAdmin.postEvent(new Event(topic, props));
    }
View Full Code Here

TOP

Related Classes of org.osgi.service.event.EventAdmin

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.