Package org.osgi.service.event

Examples of org.osgi.service.event.EventAdmin


        tracker = new ServiceTracker(bundleContext, EventAdmin.class.getName(), null);
        tracker.open();
    }

    public void beforeExecute(CommandSession session, CharSequence command) {
        EventAdmin admin = (EventAdmin) tracker.getService();
        if (admin != null) {
            Properties props = new Properties();
            props.setProperty("command", command.toString());
            Event event = new Event("org/apache/felix/service/command/EXECUTING", props);
            admin.postEvent(event);
        }
    }
View Full Code Here


        final ServiceReference ref = m_context
            .getServiceReference(EventAdmin.class.getName());

        if(null != ref)
        {
            final EventAdmin eventAdmin = (EventAdmin) m_context
                .getService(ref);

            if(null != eventAdmin)
            {
                final String topic;

                switch(event.getType())
                {
                    case ConfigurationEvent.CM_UPDATED:
                        topic = "org/osgi/service/cm/ConfigurationEvent/CM_UPDATED";
                        break;
                    case ConfigurationEvent.CM_DELETED:
                        topic = "org/osgi/service/cm/ConfigurationEvent/CM_DELETED";
                        break;
                    default:
                        m_context.ungetService(ref);
                        return;
                }
               
                final Hashtable properties = new Hashtable();
               
                if(null != event.getFactoryPid())
                {
                    properties.put("cm.factoryPid", event.getFactoryPid());
                }
               
                properties.put("cm.pid", event.getPid());
               
                final ServiceReference eventRef = event.getReference();

                if(null == eventRef)
                {
                    throw new IllegalArgumentException(
                        "ConfigurationEvent.getReference() may not be null");
                }

                properties.put(EventConstants.SERVICE, eventRef);

                properties.put(EventConstants.SERVICE_ID, eventRef.getProperty(
                    EventConstants.SERVICE_ID));

                final Object objectClass = eventRef.getProperty(
                    Constants.OBJECTCLASS);

                if(!(objectClass instanceof String[])
                    || !Arrays.asList((String[]) objectClass).contains(
                    ConfigurationAdmin.class.getName()))
                {
                    throw new IllegalArgumentException(
                        "Bad objectclass: " + objectClass);
                }

                properties.put(EventConstants.SERVICE_OBJECTCLASS, objectClass);

                properties.put(EventConstants.SERVICE_PID, eventRef.getProperty(
                    EventConstants.SERVICE_PID));
               
                eventAdmin.postEvent(new Event(topic, properties));

                m_context.ungetService(ref);
            }
        }
    }
View Full Code Here

        final ServiceReference ref = m_context
            .getServiceReference(EventAdmin.class.getName());

        if(null != ref)
        {
            final EventAdmin eventAdmin = (EventAdmin) m_context
                .getService(ref);

            if(null != eventAdmin)
            {
                final Dictionary immutableEvents = new Dictionary()
                {
                    public int size()
                    {
                        return events.size();
                    }

                    public boolean isEmpty()
                    {
                        return events.isEmpty();
                    }

                    public Enumeration keys()
                    {
                        return events.keys();
                    }

                    public Enumeration elements()
                    {
                        return events.elements();
                    }

                    public Object get(Object arg0)
                    {
                        return events.get(arg0);
                    }

                    public Object put(Object arg0, Object arg1)
                    {
                        throw new IllegalStateException(
                            "Event Properties may not be changed");
                    }

                    public Object remove(Object arg0)
                    {
                        throw new IllegalStateException(
                            "Event Properties may not be changed");
                    }

                    public boolean equals(Object arg0)
                    {
                        return events.equals(arg0);
                    }

                    public int hashCode()
                    {
                        return events.hashCode();
                    }

                    public String toString()
                    {
                        return events.toString();
                    }
                };

                final Hashtable properties = new Hashtable();
               
                properties.put(UPnPDevice.ID, deviceId);
                properties.put(UPnPService.ID, serviceId);
                properties.put("upnp.serviceId", serviceId);
                properties.put("upnp.deviceId", deviceId);
                properties.put("upnp.events", immutableEvents);
               
                eventAdmin.postEvent(
                    new Event("org/osgi/service/upnp/UPnPEvent", properties));

                m_context.ungetService(ref);
            }
        }
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

        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

        this.tracker = new ServiceTracker(bundleContext, EventAdmin.class.getName(), null);
        setIgnoreExchangeEvents(true);
    }

    public void notify(EventObject event) throws Exception {
        EventAdmin eventAdmin = (EventAdmin) tracker.getService();
        if (eventAdmin == null) {
            return;
        }

        Dictionary<String, Object> props = new Hashtable<String, Object>();
        props.put(TYPE, getType(event));
        props.put(EVENT, event);
        props.put(TIMESTAMP, System.currentTimeMillis());
        props.put(BUNDLE, bundleContext.getBundle());
        props.put(BUNDLE_SYMBOLICNAME, bundleContext.getBundle().getSymbolicName());
        props.put(BUNDLE_ID, bundleContext.getBundle().getBundleId());
        props.put(BUNDLE_VERSION, getBundleVersion(bundleContext.getBundle()));
        try {
            props.put(CAUSE, event.getClass().getMethod("getCause").invoke(event));
        } catch (Throwable t) {
            // ignore
        }
        eventAdmin.postEvent(new Event(getTopic(event), props));
    }
View Full Code Here

            tracker.open();
        }

        @SuppressWarnings({"ThrowableResultOfMethodCallIgnored"})
        public void blueprintEvent(BlueprintEvent 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, event.getTimestamp());
            props.put(EventConstants.BUNDLE, event.getBundle());
            props.put(EventConstants.BUNDLE_SYMBOLICNAME, event.getBundle().getSymbolicName());
            props.put(EventConstants.BUNDLE_ID, event.getBundle().getBundleId());
            props.put(EventConstants.BUNDLE_VERSION, JavaUtils.getBundleVersion(event.getBundle()));
            props.put(EventConstants.EXTENDER_BUNDLE, event.getExtenderBundle());
            props.put(EventConstants.EXTENDER_BUNDLE_ID, event.getExtenderBundle().getBundleId());
            props.put(EventConstants.EXTENDER_BUNDLE_SYMBOLICNAME, event.getExtenderBundle().getSymbolicName());
            props.put(EventConstants.EXTENDER_BUNDLE_VERSION, JavaUtils.getBundleVersion(event.getExtenderBundle()));

            if (event.getCause() != null) {
                props.put(EventConstants.CAUSE, event.getCause());
            }
            if (event.getDependencies() != null) {
                props.put(EventConstants.DEPENDENCIES, event.getDependencies());
            }
            String topic;
            switch (event.getType()) {
                case BlueprintEvent.CREATING:
                    topic = EventConstants.TOPIC_CREATING;
                    break;
                case BlueprintEvent.CREATED:
                    topic = EventConstants.TOPIC_CREATED;
                    break;
                case BlueprintEvent.DESTROYING:
                    topic = EventConstants.TOPIC_DESTROYING;
                    break;
                case BlueprintEvent.DESTROYED:
                    topic = EventConstants.TOPIC_DESTROYED;
                    break;
                case BlueprintEvent.FAILURE:
                    topic = EventConstants.TOPIC_FAILURE;
                    break;
                case BlueprintEvent.GRACE_PERIOD:
                    topic = EventConstants.TOPIC_GRACE_PERIOD;
                    break;
                case BlueprintEvent.WAITING:
                    topic = EventConstants.TOPIC_WAITING;
                    break;
                default:
                    throw new IllegalStateException("Unknown blueprint event type: " + event.getType());
            }
            eventAdmin.postEvent(new Event(topic, props));
        }
View Full Code Here

     * @param bundle The bundle we're attempting to deploy
     * @param contextPath
     *               The context path information from the bundle.
     */
    public void failed(Bundle bundle, String contextPath, Throwable cause) {
        EventAdmin eventAdmin = getEventAdmin();
        if (eventAdmin == null) {
            return;
        }
        Dictionary<String, Object> props = createDefaultProperties(bundle, contextPath);
        if (cause != null) {
            props.put(EventConstants.EXCEPTION, cause);
        }
        eventAdmin.postEvent(new Event(WebContainerConstants.TOPIC_FAILED, props));
    }
View Full Code Here

     * @param bundle The bundle we're attempting to deploy
     * @param contextPath
     *               The context path information from the bundle.
     */
    public void collision(Bundle bundle, String contextPath, Collection<Long> bundleId) {
        EventAdmin eventAdmin = getEventAdmin();
        if (eventAdmin == null) {
            return;
        }
        Dictionary<String, Object> props = createDefaultProperties(bundle, contextPath);
        props.put(WebContainerConstants.COLLISION, contextPath);
        props.put(WebContainerConstants.COLLISION_BUNDLES, bundleId);
        eventAdmin.postEvent(new Event(WebContainerConstants.TOPIC_FAILED, 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.