Package org.osgi.service.event

Examples of org.osgi.service.event.Event


                } else {
                    // let's add the event to our started jobs list
                    synchronized ( this.startedJobsLists ) {
                        this.startedJobsLists.put(job.getId(), handler);
                    }
                    final Event jobEvent = this.getJobEvent(handler);
                    // we need async delivery, otherwise we might create a deadlock
                    // as this method runs inside a synchronized block and the finishedJob
                    // method as well!
                    this.services.eventAdmin.postEvent(jobEvent);
                }
View Full Code Here


        // remove app id and distributable flag
        properties.remove(EventUtil.PROPERTY_DISTRIBUTE);
        properties.remove(EventUtil.PROPERTY_APPLICATION);

        return new Event(eventTopic, properties);
    }
View Full Code Here

        this.startedSchedulerJobs.clear();

        // stop background threads by putting empty objects into the queue
        this.queue.clear();
        try {
            this.queue.put(new Event(NotificationConstants.TOPIC_JOB_FINISHED, (Dictionary<String, Object>)null));
        } catch (final InterruptedException e) {
            this.ignoreException(e);
            Thread.currentThread().interrupt();
        }
    }
View Full Code Here

    /**
     * @see org.apache.sling.event.impl.AbstractRepositoryEventHandler#runInBackground()
     */
    protected void runInBackground() {
        Event event = null;
        while ( this.running ) {
            // so let's wait/get the next event from the queue
            if ( event == null ) {
                try {
                    event = this.queue.take();
                } catch (final InterruptedException e) {
                    this.ignoreException(e);
                    Thread.currentThread().interrupt();
                    this.running = false;
                }
            }
            if ( event != null && this.running ) {
                // check event type
                if ( event.getTopic().equals(SlingConstants.TOPIC_RESOURCE_ADDED)
                     || event.getTopic().equals(SlingConstants.TOPIC_RESOURCE_CHANGED)) {
                    final String path = (String)event.getProperty(SlingConstants.PROPERTY_PATH);
                    event = null;
                    ResourceResolver resolver = null;
                    try {
                        resolver = this.resourceResolverFactory.getAdministrativeResourceResolver(null);
                        final Resource eventResource = resolver.getResource(path);
                        if ( TimedEventReceiver.TIMED_EVENT_RESOURCE_TYPE.equals(eventResource.getResourceType()) ) {
                            final ReadResult result = this.readEvent(eventResource);
                            if ( result != null ) {
                                if ( result.hasReadErrors ) {
                                    synchronized ( this.unloadedEvents ) {
                                        this.unloadedEvents.add(eventResource.getPath());
                                    }
                                } else {
                                    event = result.event;
                                }
                            }
                        }
                    } catch (final LoginException le) {
                        this.ignoreException(le);
                    } finally {
                        if ( resolver != null ) {
                            resolver.close();
                        }
                    }
                } else if ( event.getTopic().equals(SlingConstants.TOPIC_RESOURCE_REMOVED) ) {
                    final String path = (String)event.getProperty(SlingConstants.PROPERTY_PATH);
                    final String jobId = ResourceUtil.getName(path);
                    this.startedSchedulerJobs.remove(jobId);
                    logger.debug("Stopping job with id : {}", jobId);
                    this.scheduler.unschedule(jobId);
                    event = null;

                } else if ( !NotificationConstants.TOPIC_JOB_FINISHED.equals(event.getTopic()) ) {
                    ScheduleInfo scheduleInfo = null;
                    try {
                        scheduleInfo = new ScheduleInfo(event);
                    } catch (final IllegalArgumentException iae) {
                        this.logger.error(iae.getMessage());
                    }
                    if ( scheduleInfo != null ) {
                        // if something went wrong, we reschedule
                        if ( !this.processEvent(event, scheduleInfo) ) {
                            try {
                                this.queue.put(event);
                            } catch (final InterruptedException e) {
                                this.ignoreException(e);
                                Thread.currentThread().interrupt();
                                this.running = false;
                            }
                        }
                    }

                    event = null;
                } else if (NotificationConstants.TOPIC_JOB_FINISHED.equals(event.getTopic())){
                    // stopScheduling() puts this event on the queue, but the intention is unclear to me.
                    // as the threadStarted flag ensures the background thread is only started once, we must not stop
                    // the thread, otherwise its never started again upon topology changes.
                    event = null;
                } else {
View Full Code Here

        @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

                        logger.error("Unable to read event: date property is neither date nor calendar!");
                        return null;
                    }
                }
                try {
                    result.event = new Event(topic, properties);
                    return result;
                } catch (final IllegalArgumentException iae) {
                    // this exception occurs if the topic is not correct (it should never happen,
                    // but you never know)
                    logger.error("Unable to read event: " + iae.getMessage(), iae);
View Full Code Here

    @Deactivate
    protected void deactivate() {
        // stop background threads by putting empty objects into the queue
        this.running = false;
        try {
            this.writeQueue.put(new Event(NotificationConstants.TOPIC_JOB_FINISHED, (Dictionary<String, Object>)null));
        } catch (final InterruptedException e) {
            this.ignoreException(e);
            Thread.currentThread().interrupt();
        }
    }
View Full Code Here

    /**
     * Background thread processing the write queue
     */
    private void processWriteQueue() {
        while ( this.running ) {
            Event event = null;
            try {
                event = this.writeQueue.take();
            } catch (final InterruptedException e) {
                this.ignoreException(e);
                Thread.currentThread().interrupt();
View Full Code Here

        final String message;
        if ( jobTopic != null ) {
            if ( jobTopic instanceof String ) {
                boolean topicIsCorrect = false;
                try {
                    new Event((String)jobTopic, (Dictionary<String, Object>)null);
                    topicIsCorrect = true;
                } catch (final IllegalArgumentException iae) {
                    // we just have to catch it
                }
                if ( !topicIsCorrect ) {
View Full Code Here

        if ( job.getName() != null ) {
            eventProps.put(JobUtil.PROPERTY_JOB_NAME, job.getName());
        }
        eventProps.put(ResourceHelper.PROPERTY_JOB_ID, job.getId());
        eventProps.remove(JobConsumer.PROPERTY_JOB_ASYNC_HANDLER);
        return new Event(job.getTopic(), eventProps);
    }
View Full Code Here

TOP

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

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.