Package org.osgi.service.event

Examples of org.osgi.service.event.EventAdmin


            if (event == null || event == TERMINATE_PROCESSING) {
                break;
            }

            try {
                final EventAdmin localEa = this.support.getEventAdmin();
                final ResourceResolver resolver = this.support.getResourceResolver();
                if (localEa != null && resolver != null ) {
                    final String topic = (String) event.remove(EventConstants.EVENT_TOPIC);
                    final String path = (String) event.get(SlingConstants.PROPERTY_PATH);
                    Resource resource = resolver.getResource(path);
                    boolean sendEvent = true;
                    if (!SlingConstants.TOPIC_RESOURCE_REMOVED.equals(topic)) {
                        if (resource != null) {
                            // check if this is a JCR backed resource, otherwise it is not visible!
                            final Node node = resource.adaptTo(Node.class);
                            if (node != null) {
                                // check for nt:file nodes
                                if (path.endsWith("/jcr:content")) {
                                    try {
                                        if (node.getParent().isNodeType("nt:file")) {
                                            final Resource parentResource = resource.getParent();
                                            if (parentResource != null) {
                                                resource = parentResource;
                                                event.put(SlingConstants.PROPERTY_PATH, resource.getPath());
                                            }
                                        }
                                    } catch (final RepositoryException re) {
                                        // ignore this
                                    }
                                }

                                final String resourceType = resource.getResourceType();
                                if (resourceType != null) {
                                    event.put(SlingConstants.PROPERTY_RESOURCE_TYPE, resource.getResourceType());
                                }
                                final String resourceSuperType = resource.getResourceSuperType();
                                if (resourceSuperType != null) {
                                    event.put(SlingConstants.PROPERTY_RESOURCE_SUPER_TYPE, resource.getResourceSuperType());
                                }
                            } else {
                                // this is not a jcr backed resource
                                sendEvent = false;
                            }

                        } else {
                            // take a quite silent note of not being able to
                            // resolve the resource
                            logger.debug(
                                "processOsgiEventQueue: Resource at {} not found, which is not expected for an added or modified node",
                                path);
                            sendEvent = false;
                        }
                    }

                    if ( sendEvent ) {
                        localEa.sendEvent(new org.osgi.service.event.Event(topic, new EventProperties(event)));
                    }
                }
            } catch (final Exception e) {
                logger.warn("processOsgiEventQueue: Unexpected problem processing event " + event, e);
            }
View Full Code Here


        logger.debug("bindResourceProvider: Binding {}", debugServiceName);

        final String[] roots = provider.getRoots();
        boolean foundRoot = false;
        if (roots != null) {
            final EventAdmin localEA = this.eventAdmin;
            for (final String root : roots) {
                foundRoot = true;

                this.addResourceProvider(root, provider);

                logger.debug("bindResourceProvider: {}={} ({})", new Object[] { root, provider, debugServiceName });
                if (localEA != null) {
                    final Dictionary<String, Object> eventProps = new Hashtable<String, Object>();
                    eventProps.put(SlingConstants.PROPERTY_PATH, root);
                    localEA.postEvent(new Event(SlingConstants.TOPIC_RESOURCE_PROVIDER_ADDED, eventProps));
                }
            }
        }
        if ( !foundRoot ) {
            logger.info("Ignoring ResourceProvider(Factory) {} : no configured roots.", provider.getName());
View Full Code Here

        logger.debug("unbindResourceProvider: Unbinding {}", debugServiceName);

        final String[] roots = provider.getRoots();
        if (roots != null) {

            final EventAdmin localEA = this.eventAdmin;

            for (final String root : roots) {

                this.removeResourceProvider(root, provider);

                logger.debug("unbindResourceProvider: root={} ({})", root, debugServiceName);
                if (localEA != null) {
                    final Dictionary<String, Object> eventProps = new Hashtable<String, Object>();
                    eventProps.put(SlingConstants.PROPERTY_PATH, root);
                    localEA.postEvent(new Event(SlingConstants.TOPIC_RESOURCE_PROVIDER_REMOVED, eventProps));
                }
            }
        }

        logger.debug("unbindResourceProvider: Unbound {}, current providers={}", debugServiceName, Arrays.asList(getResourceProviders()) );
View Full Code Here

            changePath = this.mountPrefix + path;
        }
        changes.put(PROPERTY_PATH, changePath);

        try {
            final EventAdmin localEa = this.support.getEventAdmin();
            if (localEa != null ) {
                boolean sendEvent = true;
                if (!TOPIC_RESOURCE_REMOVED.equals(topic)) {
                    String resourceType = properties.get("sling:resourceType");
                    String resourceSuperType = properties.get("sling:resourceSuperType");
                    String nodeType = properties.get("jcr:primaryType");

                    // check for nt:file nodes
                    if (path.endsWith("/jcr:content")) {
                        final ResourceResolver resolver = this.support.getResourceResolver();
                        if ( resolver == null ) {
                            sendEvent = false;
                            logger.debug("resource resolver is null");
                        } else {
                            final Resource rsrc = resolver.getResource(changePath);
                            if ( rsrc == null ) {
                                resolver.refresh();
                                sendEvent = false;
                                logger.debug("not able to get resource for changes path {}", changePath);
                            } else {
                                // check if this is a JCR backed resource, otherwise it is not visible!
                                final Node node = rsrc.adaptTo(Node.class);
                                if (node != null) {
                                    try {
                                        if (node.getParent().isNodeType("nt:file")) {
                                            final Resource parentResource = rsrc.getParent();
                                            if (parentResource != null) {
                                                // update resource type and path to parent node
                                                resourceType = parentResource.getResourceType();
                                                resourceSuperType = parentResource.getResourceSuperType();
                                                changes.put(PROPERTY_PATH, parentResource.getPath());
                                            }
                                        }
                                    } catch (RepositoryException re) {
                                        // ignore this
                                        logger.error(re.getMessage(), re);
                                    }

                                } else {
                                    // this is not a jcr backed resource
                                    sendEvent = false;
                                    logger.debug("not able to adapt resource {} to node", changePath);
                                }

                            }
                        }
                        if ( !sendEvent ) {
                            // take a quite silent note of not being able to
                            // resolve the resource
                            logger.debug(
                                "processOsgiEventQueue: Resource at {} not found, which is not expected for an added or modified node",
                                        changePath);
                        }
                    }

                    // update resource type properties
                    if ( sendEvent ) {
                        if ( resourceType == null ) {
                            changes.put(PROPERTY_RESOURCE_TYPE, nodeType);
                        } else {
                            changes.put(PROPERTY_RESOURCE_TYPE, resourceType);
                        }
                        if ( resourceSuperType != null ) {
                            changes.put(PROPERTY_RESOURCE_SUPER_TYPE, resourceSuperType);
                        }
                    }
                }

                if ( sendEvent ) {
                    localEa.sendEvent(new org.osgi.service.event.Event(topic, new EventProperties(changes)));
                }
            }
        } catch (final Exception e) {
            logger.warn("sendOsgiEvent: Unexpected problem processing event " + topic + " at " + path + " with " + changes, e);
        }
View Full Code Here

    /**
     * Post a notification with the EventAdmin
     */
    private void postEvent(final String topic, final ScriptEngineFactory scriptEngineFactory) {
        final EventAdmin localEA = this.getEventAdmin();
        if (localEA != null) {
            final Dictionary<String, Object> props = new Hashtable<String, Object>();
            props.put(SlingScriptConstants.PROPERTY_SCRIPT_ENGINE_FACTORY_NAME, scriptEngineFactory.getEngineName());
            props.put(SlingScriptConstants.PROPERTY_SCRIPT_ENGINE_FACTORY_VERSION, scriptEngineFactory.getEngineVersion());
            props.put(SlingScriptConstants.PROPERTY_SCRIPT_ENGINE_FACTORY_EXTENSIONS, toArray(scriptEngineFactory.getExtensions()));
            props.put(SlingScriptConstants.PROPERTY_SCRIPT_ENGINE_FACTORY_LANGUAGE_NAME, scriptEngineFactory.getLanguageName());
            props.put(SlingScriptConstants.PROPERTY_SCRIPT_ENGINE_FACTORY_LANGUAGE_VERSION, scriptEngineFactory.getLanguageVersion());
            props.put(SlingScriptConstants.PROPERTY_SCRIPT_ENGINE_FACTORY_MIME_TYPES, toArray(scriptEngineFactory.getMimeTypes()));
            localEA.postEvent(new Event(topic, props));
        }
    }
View Full Code Here

            PrivateAccessor.setField(resFac, "mangleNamespacePrefixes", true);

            // setup mapping root
            PrivateAccessor.setField(resFac, "mapRoot", "/etc/map");
           
            final EventAdmin mockVoidEA = new EventAdmin() {

                public void postEvent(Event event) {
                    // nothing to do
                }
View Full Code Here

     * @throws NullPointerException if eventName or props is <code>null</code>.
     */
    public void fireEvent(Bundle sourceBundle, String eventName) {

        // check event admin service, return if not available
        EventAdmin ea = eventAdmin;
        BundleMapper mapper = this.mapper;
        if (ea == null || mapper == null) {
            return;
        }

        // only fire, if there is a (new) mapper
        Map<String, Object> props = new HashMap<String, Object>();
        props.put(MAPPING_CLASS, mapper.getMappedClasses());
        props.put(MAPPING_NODE_TYPE, mapper.getMappedNodeTypes());

        // create and fire the event
        Event event = OsgiUtil.createEvent(sourceBundle, null, eventName, props);
        ea.postEvent(event);
    }
View Full Code Here

    @Override
    public void execute(final JobContext context) {
        final String topic = (String) context.getConfiguration().get(JOB_TOPIC);
        @SuppressWarnings("unchecked")
        final Dictionary<String, Object> properties = (Dictionary<String, Object>) context.getConfiguration().get(JOB_CONFIG);
        final EventAdmin ea = this.eventAdmin;
        if ( ea != null ) {
            try {
                ea.postEvent(new Event(topic, properties));
            } catch (IllegalArgumentException iae) {
                this.logger.error("Scheduled event has illegal topic: " + topic, iae);
            }
        } else {
            this.logger.warn("Unable to send timed event as no event admin service is available.");
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 UserAdminEvent.ROLE_CHANGED:
                        topic = "org/osgi/service/useradmin/UserAdmin/ROLE_CHANGED";
                        break;
                    case UserAdminEvent.ROLE_CREATED:
                        topic = "org/osgi/service/useradmin/UserAdmin/ROLE_CREATED";
                        break;
                    case UserAdminEvent.ROLE_REMOVED:
                        topic = "org/osgi/service/useradmin/UserAdmin/ROLE_REMOVED";
                        break;
                    default:
                        m_context.ungetService(ref);
                        return;
                }

                final Hashtable properties = new Hashtable();
               
                properties.put(EventConstants.EVENT, event);

                properties.put("role", event.getRole());

                properties.put("role.name", event.getRole().getName());

                properties.put("role.type", new Integer(event.getRole().getType()));

                final ServiceReference eventRef = event
                    .getServiceReference();

                if(null == eventRef)
                {
                    throw new IllegalArgumentException(
                        "UserAdminEvent.getServiceReference() 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(
                        UserAdmin.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 String topic;

                switch(event.getType())
                {
                    case WireAdminEvent.WIRE_CREATED:
                        topic = "org/osgi/service/wireadmin/WireAdminEvent/WIRE_CREATED";
                        break;
                    case WireAdminEvent.WIRE_CONNECTED:
                        topic = "org/osgi/service/wireadmin/WireAdminEvent/WIRE_CONNECTED";
                        break;
                    case WireAdminEvent.WIRE_UPDATED:
                        topic = "org/osgi/service/wireadmin/WireAdminEvent/WIRE_UPDATED";
                        break;
                    case WireAdminEvent.WIRE_TRACE:
                        topic = "org/osgi/service/wireadmin/WireAdminEvent/WIRE_TRACE";
                        break;
                    case WireAdminEvent.WIRE_DISCONNECTED:
                        topic = "org/osgi/service/wireadmin/WireAdminEvent/WIRE_DISCONNECTED";
                        break;
                    case WireAdminEvent.WIRE_DELETED:
                        topic = "org/osgi/service/wireadmin/WireAdminEvent/WIRE_DELETED";
                        break;
                    case WireAdminEvent.PRODUCER_EXCEPTION:
                        topic = "org/osgi/service/wireadmin/WireAdminEvent/PRODUCER_EXCEPTION";
                        break;
                    case WireAdminEvent.CONSUMER_EXCEPTION:
                        topic = "org/osgi/service/wireadmin/WireAdminEvent/CONSUMER_EXCEPTION";
                        break;
                    default:
                        m_context.ungetService(ref);
                        return;
                }

                final Hashtable properties = new Hashtable();
               
                properties.put(EventConstants.EVENT, event);

                properties.put("wire", event.getWire());

                properties.put("wire.flavors", event.getWire().getFlavors());

                properties.put("wire.scope", event.getWire().getScope());

                properties.put("wire.connected", (event.getWire().isConnected()) ?
                    Boolean.TRUE : Boolean.FALSE);

                properties.put("wire.valid", (event.getWire().isValid()) ?
                    Boolean.TRUE : Boolean.FALSE);

                final Throwable throwable = event.getThrowable();

                if(null != throwable)
                {
                    properties.put(EventConstants.EXCEPTION, throwable);

                    properties.put(EventConstants.EXCEPTION_CLASS, throwable
                        .getClass().getName());

                    final String message = throwable.getMessage();

                    if(null != message)
                    {
                        properties.put(EventConstants.EXCEPTION_MESSAGE, message);
                    }
                }

                final ServiceReference eventRef = event.getServiceReference();

                if(null == eventRef)
                {
                    throw new IllegalArgumentException(
                        "WireAdminEvent.getServiceReference() 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(WireAdmin.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

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.