Package org.osgi.service.event

Examples of org.osgi.service.event.EventAdmin


     * @param bundle The bundle hosting the web application.
     * @param contextPath
     *               The contextPath information from the bundle.
     */
    private void dispatch(String topic, Bundle bundle, String contextPath) {
        EventAdmin eventAdmin = getEventAdmin();
        if (eventAdmin == null) {
            return;
        }
        Dictionary<String, Object> props = createDefaultProperties(bundle, contextPath);
        eventAdmin.postEvent(new Event(topic, 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

            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

        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

        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.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<EventAdmin, EventAdmin>(bundleContext, EventAdmin.class.getName(), null);
        setIgnoreExchangeEvents(true);
    }

    public void notify(EventObject event) throws Exception {
        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

        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

    configListenerRegistration = null;
    eventAdminTracker.close();
  }

  public void configurationEvent(ConfigurationEvent event) {
    EventAdmin eventAdmin = (EventAdmin) eventAdminTracker.getService();
    if (eventAdmin == null) {
      return;
    }
    String typename = null;
    switch (event.getType()) {
      case ConfigurationEvent.CM_UPDATED :
        typename = CM_UPDATED;
        break;
      case ConfigurationEvent.CM_DELETED :
        typename = CM_DELETED;
        break;
      default : // do nothing
        return;
    }
    String topic = TOPIC + TOPIC_SEPARATOR + typename;
    ServiceReference ref = event.getReference();
    if (ref == null) {
      throw new RuntimeException("ServiceEvent.getServiceReference() is null"); //$NON-NLS-1$
    }
    Hashtable properties = new Hashtable();
    properties.put(CM_PID, event.getPid());
    if (event.getFactoryPid() != null) {
      properties.put(CM_FACTORY_PID, event.getFactoryPid());
    }
    putServiceReferenceProperties(properties, ref);
    Event convertedEvent = new Event(topic, (Dictionary) properties);
    eventAdmin.postEvent(convertedEvent);
  }
View Full Code Here

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

    public void featureEvent(FeatureEvent 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.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.