You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2013/04/22 13:42:55 UTC
svn commit: r1470462 [6/7] - in /sling/trunk/bundles/extensions/event: ./
src/main/java/org/apache/sling/event/
src/main/java/org/apache/sling/event/impl/
src/main/java/org/apache/sling/event/impl/dea/
src/main/java/org/apache/sling/event/impl/jobs/ sr...
Propchange: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/ResourceHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/ResourceHelper.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/ResourceHelper.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/SubPackagesTopicMatcher.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/SubPackagesTopicMatcher.java?rev=1470462&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/SubPackagesTopicMatcher.java (added)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/SubPackagesTopicMatcher.java Mon Apr 22 11:42:53 2013
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.event.impl.support;
+
+
+/**
+ * Sub package matcher - the topic must be in the same package or a sub package.
+ */
+public class SubPackagesTopicMatcher implements TopicMatcher {
+
+ private final String packageName;
+
+ public SubPackagesTopicMatcher(final String name) {
+ // remove last char and maybe a trailing slash
+ int lastPos = name.length() - 1;
+ if ( lastPos > 0 && name.charAt(lastPos - 1) == '/' ) {
+ this.packageName = name.substring(0, lastPos);
+ } else {
+ this.packageName = name.substring(0, lastPos) + '/';
+ }
+ }
+
+ /**
+ * @see org.apache.sling.event.impl.support.TopicMatcher#match(java.lang.String)
+ */
+ @Override
+ public String match(final String topic) {
+ final int pos = topic.lastIndexOf('/');
+ return pos > -1 && topic.substring(0, pos + 1).startsWith(this.packageName) ? topic.substring(this.packageName.length()) : null;
+ }
+
+ @Override
+ public String toString() {
+ return "SubPackageMatcher [packageName=" + packageName + "]";
+ }
+}
\ No newline at end of file
Propchange: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/SubPackagesTopicMatcher.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/SubPackagesTopicMatcher.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/SubPackagesTopicMatcher.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/TopicMatcher.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/TopicMatcher.java?rev=1470462&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/TopicMatcher.java (added)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/TopicMatcher.java Mon Apr 22 11:42:53 2013
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.event.impl.support;
+
+/**
+ * Interface for topic matchers
+ */
+public interface TopicMatcher {
+
+ /** Check if the topic matches and return the variable part - null if not matching. */
+ String match(String topic);
+}
Propchange: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/TopicMatcher.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/TopicMatcher.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/TopicMatcher.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/TopicMatcherHelper.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/TopicMatcherHelper.java?rev=1470462&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/TopicMatcherHelper.java (added)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/TopicMatcherHelper.java Mon Apr 22 11:42:53 2013
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.event.impl.support;
+
+public abstract class TopicMatcherHelper {
+
+ public static final TopicMatcher[] MATCH_ALL = new TopicMatcher[] {
+ new TopicMatcher() {
+
+ @Override
+ public String match(String topic) {
+ return topic;
+ }
+ }
+ };
+
+ /**
+ * Create matchers based on the topic parameters.
+ * If the topic parameters do not contain any definition
+ * <code>null</code> is returned.
+ */
+ public static TopicMatcher[] buildMatchers(final String[] topicsParam) {
+ final TopicMatcher[] matchers;
+ if ( topicsParam == null
+ || topicsParam.length == 0
+ || (topicsParam.length == 1 && (topicsParam[0] == null || topicsParam[0].length() == 0))) {
+ matchers = null;
+ } else {
+ final TopicMatcher[] newMatchers = new TopicMatcher[topicsParam.length];
+ for(int i=0; i < topicsParam.length; i++) {
+ String value = topicsParam[i];
+ if ( value != null ) {
+ value = value.trim();
+ }
+ if ( value != null && value.length() > 0 ) {
+ if ( value.equals("*") ) {
+ return MATCH_ALL;
+ }
+ if ( value.endsWith(".") ) {
+ newMatchers[i] = new PackageTopicMatcher(value);
+ } else if ( value.endsWith("*") ) {
+ newMatchers[i] = new SubPackagesTopicMatcher(value);
+ } else {
+ newMatchers[i] = new ExactTopicMatcher(value);
+ }
+ }
+ }
+ matchers = newMatchers;
+ }
+ return matchers;
+ }
+
+}
Propchange: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/TopicMatcherHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/TopicMatcherHelper.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/TopicMatcherHelper.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/Job.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/Job.java?rev=1470462&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/Job.java (added)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/Job.java Mon Apr 22 11:42:53 2013
@@ -0,0 +1,219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.event.jobs;
+
+import java.util.Calendar;
+import java.util.Set;
+
+/**
+ * A job
+ *
+ *
+ * Property Types
+ *
+ * In general all scalar types and all serializable classes are supported as
+ * property types. However, in order for deseralizing classes these must be
+ * exported. Serializable classes are not searchable in the query either.
+ * Due to the above to potential problems, it is advisable to not use
+ * custom classes as job properties, but rather use out of the box supported
+ * types in combination with collections.
+ *
+ * A resource provider might convert numbers to a different type, JCR is well-known
+ * for this behavior as it only supports long but neither integer nor short.
+ * Therefore if you are dealing with numbers, use the {@link #getProperty(String, Class)}
+ * method to get the correct type instead of directly casting it.
+ *
+ * @since 1.2
+ */
+public interface Job {
+
+ /**
+ * The name of the job queue processing this job.
+ * This property is set by the job handling when the job is processed.
+ * If this property is set by the client creating the job it's value is ignored
+ */
+ String PROPERTY_JOB_QUEUE_NAME = "event.job.queuename";
+
+ /**
+ * This property is set by the job handling to define the priority of this job
+ * execution.
+ * The property is evaluated by the job handling before starting the
+ * {@link JobConsumer} and sets the priority of the thread accordingly.
+ * For possible values see {@link JobUtil.JobPriority}.
+ * If this property is set by the client creating the job it's value is ignored
+ */
+ String PROPERTY_JOB_PRIORITY = "event.job.priority";
+
+ /**
+ * The property to track the retry count for jobs. Value is of type Integer.
+ * On first execution the value of this property is zero.
+ * This property is managed by the job handling.
+ * If this property is set by the client creating the job it's value is ignored
+ */
+ String PROPERTY_JOB_RETRY_COUNT = "event.job.retrycount";
+
+ /**
+ * The property to track the retry maximum retry count for jobs. Value is of type Integer.
+ * This property is managed by the job handling.
+ * If this property is set by the client creating the job it's value is ignored
+ */
+ String PROPERTY_JOB_RETRIES = "event.job.retries";
+
+ /**
+ * This property is set by the job handling and contains a calendar object
+ * specifying the date and time when this job has been created.
+ * If this property is set by the client creating the job it's value is ignored
+ */
+ String PROPERTY_JOB_CREATED = "slingevent:created";
+
+ /**
+ * This property is set by the job handling and contains the Sling instance ID
+ * of the instance where this job has been created.
+ */
+ String PROPERTY_JOB_CREATED_INSTANCE = "slingevent:application";
+
+ /**
+ * This property is set by the job handling and contains the Sling instance ID
+ * of the instance where this job should be processed.
+ */
+ String PROPERTY_JOB_TARGET_INSTANCE = "event.job.application";
+
+ /**
+ * This property is set by the job handling and contains a calendar object
+ * specifying the date and time when this job has been started.
+ * This property is only set if the job is currently in processing
+ * If this property is set by the client creating the job it's value is ignored
+ */
+ String PROPERTY_JOB_STARTED_TIME = "event.job.started.time";
+
+ /**
+ * The job topic.
+ * @return The job topic
+ */
+ String getTopic();
+
+ /**
+ * Optional job name
+ * @return The job name or <code>null</code>
+ */
+ String getName();
+
+ /**
+ * Unique job ID.
+ * @return The unique job ID.
+ */
+ String getId();
+
+ /**
+ * Get the value of a property.
+ * @param name The property name
+ * @return The value of the property or <code>null</code>
+ */
+ Object getProperty(String name);
+
+ /**
+ * Get all property names.
+ * @return A set of property names.
+ */
+ Set<String> getPropertyNames();
+
+ /**
+ * Get a named property and convert it into the given type.
+ * This method does not support conversion into a primitive type or an
+ * array of a primitive type. It should return <code>null</code> in this
+ * case.
+ *
+ * @param name The name of the property
+ * @param type The class of the type
+ * @return Return named value converted to type T or <code>null</code> if
+ * non existing or can't be converted.
+ */
+ <T> T getProperty(String name, Class<T> type);
+
+ /**
+ * Get a named property and convert it into the given type.
+ * This method does not support conversion into a primitive type or an
+ * array of a primitive type. It should return the default value in this
+ * case.
+ *
+ * @param name The name of the property
+ * @param defaultValue The default value to use if the named property does
+ * not exist or cannot be converted to the requested type. The
+ * default value is also used to define the type to convert the
+ * value to. If this is <code>null</code> any existing property is
+ * not converted.
+ * @return Return named value converted to type T or the default value if
+ * non existing or can't be converted.
+ */
+ <T> T getProperty(String name, T defaultValue);
+
+ /**
+ * This property is set by the job handling to define the priority of this job
+ * execution.
+ * The property is evaluated by the job handling before starting the
+ * {@link JobConsumer} and sets the priority of the thread accordingly.
+ * For possible values see {@link JobUtil.JobPriority}.
+ */
+ JobUtil.JobPriority getJobPriority();
+
+ /**
+ * On first execution the value of this property is zero.
+ * This property is managed by the job handling.
+ */
+ int getRetryCount();
+
+ /**
+ * The property to track the retry maximum retry count for jobs.
+ * This property is managed by the job handling.
+ */
+ int getNumberOfRetries();
+
+ /**
+ * The name of the job queue processing this job.
+ * This property is set by the job handling when the job is processed.
+ * @return The queue name or <code>null</code>
+ */
+ String getQueueName();
+
+ /**
+ * This property is set by the job handling and contains the Sling instance ID
+ * of the instance where this job should be processed.
+ * @return The sling ID or <code>null</code>
+ */
+ String getTargetInstance();
+
+ /**
+ * This property is set by the job handling and contains a calendar object
+ * specifying the date and time when this job has been started.
+ * This property is only set if the job is currently in processing
+ */
+ Calendar getProcessingStarted();
+
+ /**
+ * This property is set by the job handling and contains a calendar object
+ * specifying the date and time when this job has been created.
+ */
+ Calendar getCreated();
+
+ /**
+ * This property is set by the job handling and contains the Sling instance ID
+ * of the instance where this job has been created.
+ */
+ String getCreatedInstance();
+}
Propchange: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/Job.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/Job.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/Job.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobConsumer.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobConsumer.java?rev=1470462&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobConsumer.java (added)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobConsumer.java Mon Apr 22 11:42:53 2013
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.event.jobs;
+
+
+/**
+ * A job consumer consumes a job.
+ *
+ * A job consumer registers itself with the {@link #PROPERTY_TOPICS} service registration
+ * property. The value of this property defines which topics a consumer is able to process.
+ * Each string value of this property is either a job topic or a topic category ending
+ * with "/*" which means all topics in this category.
+ * For example, the value "org/apache/sling/jobs/*" matches the topics
+ * "org/apache/sling/jobs/a" and "org/apache/sling/jobs/b" but neither
+ * "org/apache/sling/jobs" nor "org/apache/sling/jobs/subcategory/a"
+ *
+ * If there is more than one job consumer registered for a job topic, the selection is as
+ * follows:
+ * - If there is a single consumer registering for the exact topic, this one is used
+ * - If there is more than a single consumer registering for the exact topic, the one
+ * with the highest service ranking is used. If the ranking is equal, the one with
+ * the lowest service ID is used.
+ * - If there is a single consumer registered for the category, it is used
+ * - If there is more than a single consumer registered for the category, the service
+ * with the highest service ranking is used. If the ranking is equal, the one with
+ * the lowest service ID is used.
+ *
+ * @since 1.2
+ */
+public interface JobConsumer {
+
+ /**
+ * Service registration property defining the jobs this consumer is able to process.
+ * The value is either a string or an array of strings.
+ */
+ String PROPERTY_TOPICS = "job.topics";
+
+ /**
+ * Execute the job.
+ * If the job fails with throwing an exception/throwable, the process will not be rescheduled.
+ * However in this case the job will be treated as run successfully.
+ *
+ * @param job The job
+ * @return True if the job could be finished (either successful or by an error).
+ * Return false if the job should be rescheduled.
+ */
+ boolean process(Job job);
+}
Propchange: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobConsumer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobConsumer.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobConsumer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobManager.java?rev=1470462&r1=1470461&r2=1470462&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobManager.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobManager.java Mon Apr 22 11:42:53 2013
@@ -18,6 +18,7 @@
*/
package org.apache.sling.event.jobs;
+import java.util.Collection;
import java.util.Map;
import org.osgi.service.event.Event;
@@ -71,7 +72,9 @@ public interface JobManager {
* must match the template (AND query). By providing several maps, different filters
* are possible (OR query).
* @return A non null collection.
+ * @deprecated
*/
+ @Deprecated
JobsIterator queryJobs(QueryType type, String topic, Map<String, Object>... templates);
/**
@@ -85,7 +88,9 @@ public interface JobManager {
* are possible (OR query).
* @return A non null collection.
* @since 1.1
+ * @deprecated
*/
+ @Deprecated
JobsIterator queryJobs(QueryType type, String topic, long limit, Map<String, Object>... templates);
/**
@@ -97,7 +102,9 @@ public interface JobManager {
* @param template The map acts like a template. The searched job
* must match the template (AND query).
* @return An event or <code>null</code>
+ * @deprecated
*/
+ @Deprecated
Event findJob(String topic, Map<String, Object> template);
/**
@@ -106,7 +113,9 @@ public interface JobManager {
* @param jobId The unique identifier as found in the property {@link JobUtil#JOB_ID}.
* @return <code>true</code> if the job could be cancelled or does not exist anymore.
* <code>false</code> otherwise.
+ * @deprecated
*/
+ @Deprecated
boolean removeJob(String jobId);
/**
@@ -115,7 +124,9 @@ public interface JobManager {
* for a job to finish. The job will be removed when this method returns - however
* this method blocks until the job is finished!
* @param jobId The unique identifier as found in the property {@link JobUtil#JOB_ID}.
+ * @deprecated
*/
+ @Deprecated
void forceRemoveJob(String jobId);
/**
@@ -128,6 +139,71 @@ public interface JobManager {
/**
* Is job processing enabled?
* It is possible to completely turn off job processing.
+ * @deprecated This method always returns true
*/
+ @Deprecated
boolean isJobProcessingEnabled();
+
+ /**
+ * Add a new job
+ * @param topic The job topic,
+ * @param name Optional unique job name
+ * @param properties Optional job properties
+ * @return The new job
+ * @since 1.2
+ */
+ Job addJob(String topic, String name, Map<String, Object> properties);
+
+ /**
+ * @return A job or <code>null</code>
+ * @since 1.2
+ */
+ Job getJobByName(String name);
+
+ /**
+ * @param jobId The unique identifier from {@link Job#getId()}
+ * @return A job or <code>null</code>
+ * @since 1.2
+ */
+ Job getJobById(String jobId);
+
+ /**
+ * Removes the job even if it is currently in processing.
+ * If the job exists and is not in processing, it gets removed from the processing queue.
+ * If the job exists and is in processing, it is removed from the persistence layer,
+ * however processing is not stopped.
+ * @param jobId The unique identifier from {@link Job#getId()}
+ * @return <code>true</code> if the job could be removed or does not exist anymore.
+ * <code>false</code> otherwise.
+ * @since 1.2
+ */
+ boolean removeJobById(String jobId);
+
+ /**
+ * Find a job - either scheduled or active.
+ * This method searches for an event with the given topic and filter properties. If more than one
+ * job matches, the first one found is returned which could be any of the matching jobs.
+ *
+ * @param topic Topic is required.
+ * @param template The map acts like a template. The searched job
+ * must match the template (AND query).
+ * @return A job or <code>null</code>
+ * @since 1.2
+ */
+ Job getJob(String topic, Map<String, Object> template);
+
+ /**
+ * Return all jobs either running or scheduled.
+ *
+ * @param type Required parameter for the type: either all jobs, only queued or only started can be returned.
+ * @param topic Topic can be used as a filter, if it is non-null, only jobs with this topic will be returned.
+ * @param limit A positive number indicating the maximum number of jobs returned by the iterator. A value
+ * of zero or less indicates that all jobs should be returned.
+ * @param templates A list of filter property maps. Each map acts like a template. The searched job
+ * must match the template (AND query). By providing several maps, different filters
+ * are possible (OR query).
+ * @return A collection of jobs - the collection might be empty.
+ * @since 1.2
+ */
+ Collection<Job> findJobs(QueryType type, String topic, long limit, Map<String, Object>... templates);
}
Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobProcessor.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobProcessor.java?rev=1470462&r1=1470461&r2=1470462&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobProcessor.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobProcessor.java Mon Apr 22 11:42:53 2013
@@ -24,7 +24,9 @@ import org.osgi.service.event.Event;
* A job processor processes a job in the background.
* It is used by {@link JobUtil#processJob(Event, JobProcessor)}.
* @since 3.0
+ * @deprecated - Use the new {@link JobConsumer} interface instead.
*/
+@Deprecated
public interface JobProcessor {
/**
Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobUtil.java?rev=1470462&r1=1470461&r2=1470462&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobUtil.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobUtil.java Mon Apr 22 11:42:53 2013
@@ -21,7 +21,7 @@ package org.apache.sling.event.jobs;
import java.util.Calendar;
import org.apache.sling.commons.threads.ThreadPool;
-import org.apache.sling.event.impl.jobs.JobStatusNotifier;
+import org.apache.sling.event.impl.jobs.deprecated.JobStatusNotifier;
import org.apache.sling.event.impl.support.Environment;
import org.osgi.service.event.Event;
import org.slf4j.LoggerFactory;
@@ -33,71 +33,121 @@ import org.slf4j.LoggerFactory;
*/
public abstract class JobUtil {
- /** The job topic property. */
+ /**
+ * The job topic property.
+ * @deprecated - Jobs should be started via {@link JobManager#addJob(String, String, java.util.Map)}
+ */
+ @Deprecated
public static final String PROPERTY_JOB_TOPIC = "event.job.topic";
- /** The property for the unique event name. Value is of type String (This is optional). */
+ /**
+ * The property for the unique event name. Value is of type String.
+ * This property should only be used if it can happen that the exact same
+ * job is started on different cluster nodes.
+ * By specifying the same id for this job on all cluster nodes,
+ * the job handling can detect the duplicates and process the job
+ * only once.
+ * This is optional - and should only be used for the case mentioned.
+ * @deprecated - Jobs should be started via {@link JobManager#addJob(String, String, java.util.Map)}
+ */
+ @Deprecated
public static final String PROPERTY_JOB_NAME = "event.job.id";
- /** The property to set if a job can be run parallel to any other job.
- * The following values are supported:
- * - boolean value <code>true</code> and <code>false</code>
- * - string value <code>true</code> and <code>false</code>
- * - integer value higher than 1 - if this is specified jobs are run in
- * parallel but never more than the specified number.
- *
- * We might want to use different values in the future for enhanced
- * parallel job handling.
- *
- * This value is only used, if {@link JobUtil#PROPERTY_JOB_QUEUE_NAME} is
- * specified and the referenced queue is not started yet.
+ /**
+ * This property is not supported anymore
+ * @deprecated
*/
+ @Deprecated
public static final String PROPERTY_JOB_PARALLEL = "event.job.parallel";
- /** The property to set if a job should only be run on the same app it has been created. */
+ /**
+ * This property is not supported anymore
+ * @deprecated
+ */
+ @Deprecated
public static final String PROPERTY_JOB_RUN_LOCAL = "event.job.run.local";
- /** The property to track the retry count for jobs. Value is of type Integer. */
+ /**
+ * The property to track the retry count for jobs. Value is of type Integer.
+ * On first execution the value of this property is zero.
+ * This property is managed by the job handling.
+ * If this property is set by the client creating the job it's value is ignored
+ * @deprecated - Use the new {@link Job} interface instead.
+ */
+ @Deprecated
public static final String PROPERTY_JOB_RETRY_COUNT = "event.job.retrycount";
- /** The property for setting the maximum number of retries. Value is of type Integer. */
+ /**
+ * The property to track the retry maximum retry count for jobs. Value is of type Integer.
+ * This property is managed by the job handling.
+ * If this property is set by the client creating the job it's value is ignored
+ * @deprecated - Use the new {@link Job} interface instead.
+ */
+ @Deprecated
public static final String PROPERTY_JOB_RETRIES = "event.job.retries";
- /** The property to set a retry delay. Value is of type Long and specifies milliseconds. */
+ /**
+ * This property is not supported anymore
+ * @deprecated
+ */
+ @Deprecated
public static final String PROPERTY_JOB_RETRY_DELAY = "event.job.retrydelay";
- /** The property to set to put the jobs into a separate job queue. This property
- * specifies the name of the job queue. If the job queue does not exists yet
- * a new queue is created.
- * If a ordered job queue is used, the jobs are never executed in parallel
- * from this queue! For non ordered queues the {@link #PROPERTY_JOB_PARALLEL}
- * with an integer value higher than 1 can be used to specify the maximum number
- * of parallel jobs for this queue.
+ /**
+ * The name of the job queue processing this job.
+ * This property is set by the job handling when the job is processed.
+ * If this property is set by the client creating the job it's value is ignored
+ * @deprecated - Use the new {@link Job} interface instead.
*/
+ @Deprecated
public static final String PROPERTY_JOB_QUEUE_NAME = "event.job.queuename";
- /** If this property is set with any value, the queue processes the jobs in the same
- * order as they have arrived.
- * This property has only an effect if {@link #PROPERTY_JOB_QUEUE_NAME} is specified
- * and the job queue has not been started yet.
+ /**
+ * This property is not supported anymore
+ * @deprecated
*/
+ @Deprecated
public static final String PROPERTY_JOB_QUEUE_ORDERED = "event.job.queueordered";
- /** This property allows to override the priority for the thread used to start this job.
+ /**
+ * This property is set by the job handling to define the priority of this job
+ * execution.
* The property is evaluated by the {@link #processJob(Event, JobProcessor)} method.
- * If another way of executing the job is used, it is up to the client to ensure
- * the job priority.
+ * If another way of executing the job is used, it is up to the processor to ensure
+ * the job priority is taken into account.
* For possible values see {@link JobPriority}.
+ * If this property is set by the client creating the job it's value is ignored
+ * @deprecated - Use the new {@link Job} interface instead.
*/
+ @Deprecated
public static final String PROPERTY_JOB_PRIORITY = "event.job.priority";
/**
- * This property is set by the eventing and contains a calendar object
+ * This property is set by the job handling and contains a calendar object
* specifying the date and time when this job has been created.
+ * If this property is set by the client creating the job it's value is ignored
+ * @deprecated - Use the new {@link Job} interface instead.
*/
+ @Deprecated
public static final String PROPERTY_JOB_CREATED = "slingevent:created";
/**
+ * This property is set by the job handling and contains the Sling instance ID
+ * of the instance where this job has been created.
+ * @deprecated - Use the new {@link Job} interface instead.
+ */
+ @Deprecated
+ public static final String PROPERTY_JOB_CREATED_APPLICATION = "slingevent:application";
+
+ /**
+ * This property is set by the job handling and contains the Sling instance ID
+ * of the instance where this job should be processed.
+ * @deprecated - Use the new {@link Job} interface instead.
+ */
+ @Deprecated
+ public static final String PROPERTY_JOB_APPLICATION = "event.job.application";
+
+ /**
* The priority for jobs.
*/
public enum JobPriority {
@@ -106,58 +156,104 @@ public abstract class JobUtil {
MAX
}
- /** The topic for jobs. */
+ /**
+ * The topic for jobs.
+ * @deprecated - Use the new {@link JobManager#addJob(String, String, java.util.Map)} method instead.
+ */
+ @Deprecated
public static final String TOPIC_JOB = "org/apache/sling/event/job";
/**
* This is a unique identifier which can be used to cancel the job.
+ * @deprecated - Use the new {@link Job} interface instead.
*/
+ @Deprecated
public static final String JOB_ID = "slingevent:eventId";
/**
* Notification events for jobs.
*/
- /** Asynchronous notification event when a job is started.
- * The property {@link #PROPERTY_NOTIFICATION_JOB} contains the job event and the
- * property {@link org.osgi.service.event.EventConstants#TIMESTAMP} contains the
- * time stamp of the event (as a Long).
+ /**
+ * Asynchronous notification event when a job is started.
+ * The property {@link #NOTIFICATION_PROPERTY_JOB_TOPIC} contains the job topic,
+ * the property {@link #NOTIFICATION_PROPERTY_JOB_NAME} might contain the job name,
+ * and the property {@link #NOTIFICATION_PROPERTY_JOB_ID} contains the unique job id.
+ * The time stamp of the event (as a Long) is available from the property
+ * {@link org.osgi.service.event.EventConstants#TIMESTAMP}.
+ * The payload of the job is available as additional job specific properties.
*/
public static final String TOPIC_JOB_STARTED = "org/apache/sling/event/notification/job/START";
- /** Asynchronous notification event when a job is finished.
- * The property {@link #PROPERTY_NOTIFICATION_JOB} contains the job event and the
- * property {@link org.osgi.service.event.EventConstants#TIMESTAMP} contains the
- * time stamp of the event (as a Long).
+ /**
+ * Asynchronous notification event when a job is finished.
+ * The property {@link #NOTIFICATION_PROPERTY_JOB_TOPIC} contains the job topic,
+ * the property {@link #NOTIFICATION_PROPERTY_JOB_NAME} might contain the job name,
+ * and the property {@link #NOTIFICATION_PROPERTY_JOB_ID} contains the unique job id.
+ * The time stamp of the event (as a Long) is available from the property
+ * {@link org.osgi.service.event.EventConstants#TIMESTAMP}.
+ * The payload of the job is available as additional job specific properties.
*/
public static final String TOPIC_JOB_FINISHED = "org/apache/sling/event/notification/job/FINISHED";
- /** Asynchronous notification event when a job failed.
+ /**
+ * Asynchronous notification event when a job failed.
* If a job execution fails, it is rescheduled for another try.
- * The property {@link #PROPERTY_NOTIFICATION_JOB} contains the job event and the
- * property {@link org.osgi.service.event.EventConstants#TIMESTAMP} contains the
- * time stamp of the event (as a Long).
+ * The property {@link #NOTIFICATION_PROPERTY_JOB_TOPIC} contains the job topic,
+ * the property {@link #NOTIFICATION_PROPERTY_JOB_NAME} might contain the job name,
+ * and the property {@link #NOTIFICATION_PROPERTY_JOB_ID} contains the unique job id.
+ * The time stamp of the event (as a Long) is available from the property
+ * {@link org.osgi.service.event.EventConstants#TIMESTAMP}.
+ * The payload of the job is available as additional job specific properties.
*/
public static final String TOPIC_JOB_FAILED = "org/apache/sling/event/notification/job/FAILED";
- /** Asynchronous notification event when a job is cancelled.
+ /** A
+ * synchronous notification event when a job is cancelled.
* If a job execution is cancelled it is not rescheduled.
- * The property {@link #PROPERTY_NOTIFICATION_JOB} contains the job event and the
- * property {@link org.osgi.service.event.EventConstants#TIMESTAMP} contains the
- * time stamp of the event (as a Long).
+ * The property {@link #NOTIFICATION_PROPERTY_JOB_TOPIC} contains the job topic,
+ * the property {@link #NOTIFICATION_PROPERTY_JOB_NAME} might contain the job name,
+ * and the property {@link #NOTIFICATION_PROPERTY_JOB_ID} contains the unique job id.
+ * The time stamp of the event (as a Long) is available from the property
+ * {@link org.osgi.service.event.EventConstants#TIMESTAMP}.
+ * The payload of the job is available as additional job specific properties.
*/
public static final String TOPIC_JOB_CANCELLED = "org/apache/sling/event/notification/job/CANCELLED";
- /** Property containing the job event. The value is of type org.osgi.service.event.Event. */
+ /**
+ * Property containing the job event. The value is of type org.osgi.service.event.Event.
+ * @deprecated
+ */
+ @Deprecated
public static final String PROPERTY_NOTIFICATION_JOB = "event.notification.job";
/**
+ * Property containing the job topic. Value is of type String.
+ * @see Job#getTopic()
+ */
+ public static final String NOTIFICATION_PROPERTY_JOB_TOPIC = "event.job.topic";
+
+ /**
+ * Property containing the optional job name. Value is of type String.
+ * @see Job#getName()
+ */
+ public static final String NOTIFICATION_PROPERTY_JOB_NAME = "event.job.id";
+
+ /**
+ * Property containing the unique job ID. Value is of type String.
+ * @see Job#getId()
+ */
+ public static final String NOTIFICATION_PROPERTY_JOB_ID = "slingevent:eventId";
+
+ /**
* Is this a job event?
* This method checks if the event contains the {@link #PROPERTY_JOB_TOPIC}
* property.
* @param event The event to check.
* @return <code>true></code> if this is a job event.
+ * @deprecated - Use the new {@link Job} interface instead.
*/
+ @Deprecated
public static boolean isJobEvent(final Event event) {
return event.getProperty(PROPERTY_JOB_TOPIC) != null;
}
@@ -165,7 +261,9 @@ public abstract class JobUtil {
/**
* Check if this a job event and return the notifier context.
* @throws IllegalArgumentException If the event is a job event but does not have a notifier context.
+ * @deprecated - Use the new {@link JobConsumer} interface instead.
*/
+ @Deprecated
private static JobStatusNotifier.NotifierContext getNotifierContext(final Event job) {
// check if this is a job event
if ( !isJobEvent(job) ) {
@@ -186,7 +284,9 @@ public abstract class JobUtil {
* processing this job, and the caller should not process the event anymore.
* @return Returns <code>true</code> if the acknowledge could be sent
* @throws IllegalArgumentException If the event is a job event but does not have a notifier context.
+ * @deprecated - Use the new {@link JobConsumer} interface instead.
*/
+ @Deprecated
public static boolean acknowledgeJob(final Event job) {
final JobStatusNotifier.NotifierContext ctx = getNotifierContext(job);
if ( ctx != null ) {
@@ -204,7 +304,9 @@ public abstract class JobUtil {
/**
* Notify a finished job.
* @throws IllegalArgumentException If the event is a job event but does not have a notifier context.
+ * @deprecated - Use the new {@link JobConsumer} interface instead.
*/
+ @Deprecated
public static void finishedJob(final Event job) {
final JobStatusNotifier.NotifierContext ctx = getNotifierContext(job);
if ( ctx != null ) {
@@ -216,7 +318,9 @@ public abstract class JobUtil {
* Notify a failed job.
* @return <code>true</code> if the job has been rescheduled, <code>false</code> otherwise.
* @throws IllegalArgumentException If the event is a job event but does not have a notifier context.
+ * @deprecated - Use the new {@link JobConsumer} interface instead.
*/
+ @Deprecated
public static boolean rescheduleJob(final Event job) {
final JobStatusNotifier.NotifierContext ctx = getNotifierContext(job);
if ( ctx != null ) {
@@ -229,18 +333,18 @@ public abstract class JobUtil {
* Process a job in the background and notify its success.
* This method also sends an acknowledge message to the job event handler.
* @throws IllegalArgumentException If the event is a job event but does not have a notifier context.
+ * @deprecated - Use the new {@link JobConsumer} interface instead.
*/
+ @Deprecated
public static void processJob(final Event job, final JobProcessor processor) {
// first check for a notifier context to send an acknowledge
- boolean notify = true;
final JobStatusNotifier.NotifierContext ctx = getNotifierContext(job);
- if ( ctx != null ) {
- if ( !ctx.getJobStatusNotifier().sendAcknowledge(job) ) {
- // if we don't get an ack, someone else is already processing this job.
- // we process but do not notify the job event handler.
- LoggerFactory.getLogger(JobUtil.class).info("Someone else is already processing job {}.", job);
- notify = false;
- }
+ boolean notify = ctx != null;
+ if ( ctx != null && !ctx.getJobStatusNotifier().sendAcknowledge(job) ) {
+ // if we don't get an ack, someone else is already processing this job.
+ // we process but do not notify the job event handler.
+ LoggerFactory.getLogger(JobUtil.class).info("Someone else is already processing job {}.", job);
+ notify = false;
}
final JobPriority priority = (JobPriority) job.getProperty(PROPERTY_JOB_PRIORITY);
final boolean notifyResult = notify;
@@ -305,7 +409,9 @@ public abstract class JobUtil {
* Get the created calendar object.
* @param job The job event
* @return The created info or <code>null</code> if this is not a job event.
+ * @deprecated - Use the new {@link Job} interface instead.
*/
+ @Deprecated
public static Calendar getJobCreated(final Event job) {
return (Calendar) job.getProperty(PROPERTY_JOB_CREATED);
}
Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobsIterator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobsIterator.java?rev=1470462&r1=1470461&r2=1470462&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobsIterator.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/JobsIterator.java Mon Apr 22 11:42:53 2013
@@ -27,7 +27,9 @@ import org.osgi.service.event.Event;
* In addition to an iterator it might return the number of elements
* in the collection and allows to skip several elements.
* @since 3.0
+ * @deprecated - Use the new {@link JobManager#findJobs} methods instead.
*/
+@Deprecated
public interface JobsIterator extends Iterator<Event>, Iterable<Event> {
/**
Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/QueueConfiguration.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/QueueConfiguration.java?rev=1470462&r1=1470461&r2=1470462&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/QueueConfiguration.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/jobs/QueueConfiguration.java Mon Apr 22 11:42:53 2013
@@ -27,9 +27,9 @@ public interface QueueConfiguration {
/** The queue type. */
static enum Type {
- UNORDERED, // unordered, parallel prpcessing
- ORDERED, // ordered, fifo
- TOPIC_ROUND_ROBIN, // unordered, parallel processing, executed based on topic
+ UNORDERED, // unordered, parallel processing (push)
+ ORDERED, // ordered, FIFO (push)
+ TOPIC_ROUND_ROBIN, // unordered, parallel processing, executed based on topic (push)
IGNORE, // ignore job, but do not remove
DROP // drop job without processing!
}
@@ -60,15 +60,15 @@ public interface QueueConfiguration {
int getMaxParallel();
/**
- * Is this a local running queue (= processing only
- * jobs started on the same instance.)
+ * @deprecated This information is not used anymore
*/
+ @Deprecated
boolean isLocalQueue();
/**
- * Application ids - returns an array of application
- * ids if this queue is bound to some cluster nodes.
+ * @deprecated This information is not used anymore
*/
+ @Deprecated
String[] getApplicationIds();
/**
Modified: sling/trunk/bundles/extensions/event/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1470462&r1=1470461&r2=1470462&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/resources/OSGI-INF/metatype/metatype.properties (original)
+++ sling/trunk/bundles/extensions/event/src/main/resources/OSGI-INF/metatype/metatype.properties Mon Apr 22 11:42:53 2013
@@ -23,27 +23,6 @@
# the SCR plugin
#
-# Distributing Event Handler
-dist.events.name = Apache Sling Distributing Event Handler
-dist.events.description = Distributes local OSGi Event Admin events to \
- other nodes of the same cluster. The events are written to the JCR \
- repository for distribution to other nodes while events written to the \
- repository are picked up and distributed locally through the OSGi Event Admin \
- Service.
-
-scheduler.period.name = Cleanup Internal
-scheduler.period.description = Interval in seconds in which events older than \
- a specific age (see Event Cleanup Age) are purged from the repository. \
- The default value is 30 minutes (1800 seconds).
-
-cleanup.period.name = Event Cleanup Age
-cleanup.period.description = The maximum age in minutes of persisted events to \
- be purged from the repository during the cleanup run. The default is 15 \
- minutes. Note that this setting defines the minimum time an event remains \
- in the repository.
-
-
-#
# Queue Configuration and Job Event Handler
queue.name = Apache Sling Job Queue Configuration
queue.description = The configuration of a job processing queue.
@@ -82,79 +61,16 @@ queue.maxparallel.name = Maximum Paralle
queue.maxparallel.description = The maximum number of parallel jobs started for this queue. \
A value of -1 is substituted with the number of available processors.
-queue.runlocal.name = Run Local
-queue.runlocal.description = Jobs for this queue are only processed on the cluster node \
- where the job has been started.
-
-queue.applicationids.name = Application Ids
-queue.applicationids.description = An optional list of application ids. If configured, \
- jobs for this queue are only processed on those cluster nodes.
-
#
# Job Event Handler
-job.events.name = Apache Sling Job Event Handler
-job.events.description = Manages job scheduling on a single system as well \
- as on a cluster. A Job runs only on a single cluster node. \
- The respective scheduling is persisted in the repository and distributed \
- amongst the cluster nodes through repository events. The jobs are started \
- locally on a single cluster node through the OSGi Event Admin.
-
-jobscheduler.period.name = Cleanup Internal
-jobscheduler.period.description = Interval in seconds in which unused \
- queues are stopped. The default value is 5 minutes (300 seconds).
-
-jobmanager.enabled.name = Job Processing Enabled
-jobmanager.enabled.description = This flag controls wheter the job processing \
- is running or is completly turned off. Turning off job processing will stop \
- all job processing and the jobs are queued up.
-
-jobmanager.applicationids.name = Application Ids
-jobmanager.applicationids.description = An optional list of application ids. If configured, \
- the job manager is only enabled on these instances.
-
-#
-# Persistence Handler
-job.persistence.name = Apache Sling Job Persistence Manager
-job.persistence.description = This service persists and loads jobs from the repository.
-
-persscheduler.period.name = Event Cleanup Internal
-persscheduler.period.description = Interval in seconds in which jobs older than \
- a specific age (see Event Cleanup Age) are purged from the repository. \
- The default value is 5 minutes (300 seconds).
+job.events.name = Apache Sling Job Default Queue
+job.events.description = The configuration of the default job queue.
-sleep.time.name = Retry Interval
-sleep.time.description = The number of milliseconds to sleep between two \
- consecutive retries of a job which failed and was set to be retried. The \
- default value is 30 seconds. This value is only relevant if there is a single \
- failed job in the queue. If there are multiple failed jobs, each job is \
- retried in turn without an intervening delay.
-
-jobcleanup.period.name = Event Cleanup Age
-jobcleanup.period.description = The maximum age in minutes of persisted job to \
- be purged from the repository during the cleanup run. The default is 5 \
- minutes. Note that this setting defines the minimum time an event remains \
- in the repository.
-
-max.load.jobs.name = Max Load Jobs
-max.load.jobs.description = The maximum amount of jobs being loaded from the repository on startup. \
- Default is 1000 jobs.
-
-load.threshold.name = Load Threshold
-load.threshold.description = If the queue is lower than this threshold the repository is checked \
- for events. The default value is 400. This works together with the maximum load jobs.
-
-load.delay.name = Background Load Delay
-load.delay.description = The background loader waits this time of seconds after startup before \
- loading events from the repository. Default value is 30 seconds.
-
-load.checkdelay.name = Background Check Delay
-load.checkdelay.description = The background loader sleeps this time of seconds before \
- checking the repository for jobs. Default value is 240 seconds.
#
# Event Pool
-event.pool.name = Apache Sling Event Thread Pool
+event.pool.name = Apache Sling Eventing Thread Pool
event.pool.description = This is the thread pool used by the Apache Sling eventing support. The \
threads from this pool are merely used for the job handling. By limiting this pool, it is \
possible to limit the maximum number of parallel processed jobs - regardless of the queue \
@@ -168,16 +84,21 @@ priority.name = Priority
priority.description = The priority for the threads from this pool. Default is norm.
#
-# Lock Manager
-lm.name = Apache Sling Event Lock Manager
-lm.description = This service is responsible for locking and unlock the event nodes. Dependening \
- on the environment, special configuration can improve the performance.
-
-lm.mode.name = Lock Mode
-lm.mode.description = The lock mode defines how the events are locked in the repository. The default \
- is to use session scoped locks. With session scoped locks it's the task of the repository to propagate \
- unlocks in a cluster if a session/cluster node dies. When open scoped locks are used, the lock manager \
- takes care to propagate this information. Please note, that Apache Jackrabbit currently does not support \
- session scoped locks in a cluster and the security is too strong when it comes to open scoped locks. \
- The setting none should only be used, if no cluster is used or if by other means it is guaranteed that \
- only a single node in the cluster is processing jobs.
+# Consumer Manager
+job.consumermanager.name = Apache Sling Job Consumer Manager
+job.consumermanager.description = The consumer manager controls the job consumer (= processors). \
+ It can be used to temporarily disable job processing on the current instance. Other instances \
+ in a cluster are not affected.
+
+job.consumermanager.whitelist.name = Topic Whitelist
+job.consumermanager.whitelist.desscription = This is a list of topics which currently should be \
+ processed by this instance. Leaving it empty, all job consumers are disabled. Putting a '*' as \
+ one entry, enables all job consumers. Adding separate topics enables job consumers for exactly \
+ this topic.
+
+job.consumermanager.blacklist.name = Topic Blacklist
+job.consumermanager.blacklist.desscription = This is a list of topics which currently shouldn't be \
+ processed by this instance. Leaving it empty, all job consumers are enabled. Putting a '*' as \
+ one entry, disables all job consumers. Adding separate topics disables job consumers for exactly \
+ this topic.
+
Modified: sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/EventUtilTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/EventUtilTest.java?rev=1470462&r1=1470461&r2=1470462&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/EventUtilTest.java (original)
+++ sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/EventUtilTest.java Mon Apr 22 11:42:53 2013
@@ -22,17 +22,9 @@ import static org.junit.Assert.assertEqu
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import java.util.Calendar;
import java.util.Dictionary;
import java.util.Hashtable;
-import java.util.Properties;
-import javax.jcr.PropertyType;
-import javax.jcr.Value;
-import javax.jcr.ValueFactory;
-
-import org.apache.sling.event.impl.jobs.jcr.JCRHelper;
-import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
import org.jmock.integration.junit4.JUnit4Mockery;
@@ -71,46 +63,9 @@ public class EventUtilTest {
@Test public void testLocalFlag() {
final Event localEvent = new Event("local/event", (Dictionary<String, Object>)null);
assertTrue(EventUtil.isLocal(localEvent));
- final Properties props = new Properties();
+ final Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(EventUtil.PROPERTY_APPLICATION, "application1");
- final Event remoteEvent = new Event("remote/event", (Dictionary<Object, Object>)props);
+ final Event remoteEvent = new Event("remote/event", props);
assertFalse(EventUtil.isLocal(remoteEvent));
}
-
- protected Value getValueOfType(final int type, String name) {
- final Value v = this.context.mock(Value.class, name);
- this.context.checking(new Expectations() {{
- allowing(v).getType();will(returnValue(type));
- }});
- return v;
- }
-
- @Test public void testGetNodePropertyValue() {
- final ValueFactory factory = this.context.mock(ValueFactory.class);
- this.context.checking(new Expectations() {{
- allowing(factory).createValue(true);
- will(returnValue(getValueOfType(PropertyType.BOOLEAN, "booleanValue1")));
- allowing(factory).createValue(false);
- will(returnValue(getValueOfType(PropertyType.BOOLEAN, "booleanValue2")));
- allowing(factory).createValue(with(any(Long.class)));
- will(returnValue(getValueOfType(PropertyType.LONG, "longValue")));
- allowing(factory).createValue(with(any(String.class)));
- will(returnValue(getValueOfType(PropertyType.STRING, "stringValue")));
- allowing(factory).createValue(with(any(Calendar.class)));
- will(returnValue(getValueOfType(PropertyType.DATE, "dateValue")));
- }});
- // boolean
- assertEquals(PropertyType.BOOLEAN, JCRHelper.getNodePropertyValue(factory, true).getType());
- assertEquals(PropertyType.BOOLEAN, JCRHelper.getNodePropertyValue(factory, false).getType());
- assertEquals(PropertyType.BOOLEAN, JCRHelper.getNodePropertyValue(factory, Boolean.TRUE).getType());
- assertEquals(PropertyType.BOOLEAN, JCRHelper.getNodePropertyValue(factory, Boolean.FALSE).getType());
- // long
- assertEquals(PropertyType.LONG, JCRHelper.getNodePropertyValue(factory, (long)5).getType());
- // int = not possible
- assertEquals(null, JCRHelper.getNodePropertyValue(factory, 5));
- // string
- assertEquals(PropertyType.STRING, JCRHelper.getNodePropertyValue(factory, "something").getType());
- // calendar
- assertEquals(PropertyType.DATE, JCRHelper.getNodePropertyValue(factory, Calendar.getInstance()).getType());
- }
}
Added: sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/dea/DistributingEventHandlerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/dea/DistributingEventHandlerTest.java?rev=1470462&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/dea/DistributingEventHandlerTest.java (added)
+++ sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/dea/DistributingEventHandlerTest.java Mon Apr 22 11:42:53 2013
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.event.impl.dea;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Hashtable;
+
+import junitx.util.PrivateAccessor;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ResourceResolverFactory;
+import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.event.EventUtil;
+import org.apache.sling.event.impl.support.Environment;
+import org.apache.sling.testing.resourceresolver.MockResourceResolverFactory;
+import org.junit.After;
+import org.junit.Before;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventConstants;
+
+public class DistributingEventHandlerTest {
+
+ private DistributedEventAdminConfiguration config;
+
+ private DistributedEventReceiver receiver;
+
+ private ResourceResolverFactory factory;
+ @Before
+ public void setup() throws Exception {
+ Environment.APPLICATION_ID = "1234";
+
+ this.factory = new MockResourceResolverFactory();
+
+ this.config = new DistributedEventAdminConfiguration();
+ this.config.activate(new HashMap<String, Object>());
+
+ this.receiver = new DistributedEventReceiver();
+
+ PrivateAccessor.setField(this.receiver, "config", this.config);
+ PrivateAccessor.setField(this.receiver, "resourceResolverFactory", factory);
+ this.receiver.activate();
+ }
+
+ @After
+ public void cleanup() {
+ this.receiver.deactivate();
+ Environment.APPLICATION_ID = null;
+ }
+
+ @org.junit.Test public void testWriteEvent() throws Exception {
+ final String topic = "write/event/test";
+ final Dictionary<String, Object> props = new Hashtable<String, Object>();
+ props.put("a property", "some value");
+ final Event e = new Event(topic, props);
+ this.receiver.handleEvent(e);
+
+ Thread.sleep(400);
+
+ final ResourceResolver resolver = this.factory.getAdministrativeResourceResolver(null);
+ final Resource rootResource = resolver.getResource(this.config.getOwnRootPath());
+ assertNotNull(rootResource);
+ final Resource yearResource = rootResource.getChildren().iterator().next();
+ assertNotNull(yearResource);
+ final Resource monthResource = yearResource.getChildren().iterator().next();
+ assertNotNull(monthResource);
+ final Resource dayResource = monthResource.getChildren().iterator().next();
+ assertNotNull(dayResource);
+ final Resource hourResource = dayResource.getChildren().iterator().next();
+ assertNotNull(hourResource);
+ final Resource minResource = hourResource.getChildren().iterator().next();
+ assertNotNull(minResource);
+
+ final Resource eventResource = minResource.getChildren().iterator().next();
+ assertNotNull(eventResource);
+
+ final ValueMap vm = ResourceUtil.getValueMap(eventResource);
+ assertEquals(topic, vm.get(EventConstants.EVENT_TOPIC));
+ assertEquals(Environment.APPLICATION_ID, vm.get(EventUtil.PROPERTY_APPLICATION));
+ assertNotNull(vm.get("a property"));
+
+ resolver.delete(eventResource);
+ resolver.delete(minResource);
+ resolver.delete(hourResource);
+ resolver.delete(dayResource);
+ resolver.delete(monthResource);
+ resolver.delete(yearResource);
+
+ resolver.commit();
+ }
+
+ @org.junit.Test public void testWriteEventPlusAppId() throws Exception {
+ final String topic = "write/event/test";
+ final Dictionary<String, Object> props = new Hashtable<String, Object>();
+ props.put("a property", "some value");
+ // now we check if the application id is handled correctly
+ props.put(EventUtil.PROPERTY_APPLICATION, "foo");
+
+ final Event e = new Event(topic, props);
+ this.receiver.handleEvent(e);
+
+ Thread.sleep(400);
+
+ final ResourceResolver resolver = this.factory.getAdministrativeResourceResolver(null);
+ final Resource rootResource = resolver.getResource(this.config.getOwnRootPath());
+ assertNotNull(rootResource);
+ final Resource yearResource = rootResource.getChildren().iterator().next();
+ assertNotNull(yearResource);
+ final Resource monthResource = yearResource.getChildren().iterator().next();
+ assertNotNull(monthResource);
+ final Resource dayResource = monthResource.getChildren().iterator().next();
+ assertNotNull(dayResource);
+ final Resource hourResource = dayResource.getChildren().iterator().next();
+ assertNotNull(hourResource);
+ final Resource minResource = hourResource.getChildren().iterator().next();
+ assertNotNull(minResource);
+
+ final Resource eventResource = minResource.getChildren().iterator().next();
+ assertNotNull(eventResource);
+
+ final ValueMap vm = ResourceUtil.getValueMap(eventResource);
+ assertEquals(topic, vm.get(EventConstants.EVENT_TOPIC));
+ assertEquals(Environment.APPLICATION_ID, vm.get(EventUtil.PROPERTY_APPLICATION));
+ assertNotNull(vm.get("a property"));
+
+ resolver.delete(eventResource);
+ resolver.delete(minResource);
+ resolver.delete(hourResource);
+ resolver.delete(dayResource);
+ resolver.delete(monthResource);
+ resolver.delete(yearResource);
+
+ resolver.commit();
+ }
+}
Propchange: sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/dea/DistributingEventHandlerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/dea/DistributingEventHandlerTest.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/dea/DistributingEventHandlerTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/StatisticsImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/StatisticsImplTest.java?rev=1470462&r1=1470461&r2=1470462&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/StatisticsImplTest.java (original)
+++ sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/StatisticsImplTest.java Mon Apr 22 11:42:53 2013
@@ -21,6 +21,8 @@ package org.apache.sling.event.impl.jobs
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import org.apache.sling.event.impl.jobs.stats.StatisticsImpl;
+
public class StatisticsImplTest {
protected StatisticsImpl stat;
Modified: sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/UtilityTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/UtilityTest.java?rev=1470462&r1=1470461&r2=1470462&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/UtilityTest.java (original)
+++ sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/UtilityTest.java Mon Apr 22 11:42:53 2013
@@ -20,49 +20,51 @@ package org.apache.sling.event.impl.jobs
import junit.framework.TestCase;
+import org.apache.sling.event.impl.support.ResourceHelper;
+
public class UtilityTest extends TestCase {
public void test_filter_allowed() {
final String allowed = "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz0123456789_,.-+#!?$%&()=";
assertEquals("Allowed Characters must not be filtered", allowed,
- Utility.filter(allowed));
+ ResourceHelper.filterName(allowed));
}
public void test_filter_illegal_jcr() {
- assertEquals("_", Utility.filter("["));
- assertEquals("_", Utility.filter("]"));
- assertEquals("_", Utility.filter("*"));
- assertEquals("_", Utility.filter("/"));
- assertEquals("_", Utility.filter(":"));
- assertEquals("_", Utility.filter("'"));
- assertEquals("_", Utility.filter("\""));
-
- assertEquals("a_b", Utility.filter("a[b"));
- assertEquals("a_b", Utility.filter("a]b"));
- assertEquals("a_b", Utility.filter("a*b"));
- assertEquals("a_b", Utility.filter("a/b"));
- assertEquals("a_b", Utility.filter("a:b"));
- assertEquals("a_b", Utility.filter("a'b"));
- assertEquals("a_b", Utility.filter("a\"b"));
-
- assertEquals("_b", Utility.filter("[b"));
- assertEquals("_b", Utility.filter("]b"));
- assertEquals("_b", Utility.filter("*b"));
- assertEquals("_b", Utility.filter("/b"));
- assertEquals("_b", Utility.filter(":b"));
- assertEquals("_b", Utility.filter("'b"));
- assertEquals("_b", Utility.filter("\"b"));
-
- assertEquals("a_", Utility.filter("a["));
- assertEquals("a_", Utility.filter("a]"));
- assertEquals("a_", Utility.filter("a*"));
- assertEquals("a_", Utility.filter("a/"));
- assertEquals("a_", Utility.filter("a:"));
- assertEquals("a_", Utility.filter("a'"));
- assertEquals("a_", Utility.filter("a\""));
+ assertEquals("_", ResourceHelper.filterName("["));
+ assertEquals("_", ResourceHelper.filterName("]"));
+ assertEquals("_", ResourceHelper.filterName("*"));
+ assertEquals("_", ResourceHelper.filterName("/"));
+ assertEquals("_", ResourceHelper.filterName(":"));
+ assertEquals("_", ResourceHelper.filterName("'"));
+ assertEquals("_", ResourceHelper.filterName("\""));
+
+ assertEquals("a_b", ResourceHelper.filterName("a[b"));
+ assertEquals("a_b", ResourceHelper.filterName("a]b"));
+ assertEquals("a_b", ResourceHelper.filterName("a*b"));
+ assertEquals("a_b", ResourceHelper.filterName("a/b"));
+ assertEquals("a_b", ResourceHelper.filterName("a:b"));
+ assertEquals("a_b", ResourceHelper.filterName("a'b"));
+ assertEquals("a_b", ResourceHelper.filterName("a\"b"));
+
+ assertEquals("_b", ResourceHelper.filterName("[b"));
+ assertEquals("_b", ResourceHelper.filterName("]b"));
+ assertEquals("_b", ResourceHelper.filterName("*b"));
+ assertEquals("_b", ResourceHelper.filterName("/b"));
+ assertEquals("_b", ResourceHelper.filterName(":b"));
+ assertEquals("_b", ResourceHelper.filterName("'b"));
+ assertEquals("_b", ResourceHelper.filterName("\"b"));
+
+ assertEquals("a_", ResourceHelper.filterName("a["));
+ assertEquals("a_", ResourceHelper.filterName("a]"));
+ assertEquals("a_", ResourceHelper.filterName("a*"));
+ assertEquals("a_", ResourceHelper.filterName("a/"));
+ assertEquals("a_", ResourceHelper.filterName("a:"));
+ assertEquals("a_", ResourceHelper.filterName("a'"));
+ assertEquals("a_", ResourceHelper.filterName("a\""));
}
public void test_filter_consecutive_replace() {
- assertEquals("a_b_", Utility.filter("a/[b]"));
+ assertEquals("a_b_", ResourceHelper.filterName("a/[b]"));
}
}
Modified: sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/config/InternalQueueConfigurationTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/config/InternalQueueConfigurationTest.java?rev=1470462&r1=1470461&r2=1470462&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/config/InternalQueueConfigurationTest.java (original)
+++ sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/config/InternalQueueConfigurationTest.java Mon Apr 22 11:42:53 2013
@@ -20,6 +20,8 @@ package org.apache.sling.event.impl.jobs
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.Dictionary;
@@ -27,36 +29,15 @@ import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
-import org.apache.sling.event.impl.jobs.JobEvent;
import org.apache.sling.event.jobs.JobUtil;
import org.osgi.service.event.Event;
public class InternalQueueConfigurationTest {
- private JobEvent getJobEvent(final String topic) {
+ private Event getJobEvent(final String topic) {
final Dictionary<String, Object> dict = new Hashtable<String, Object>();
dict.put(JobUtil.PROPERTY_JOB_TOPIC, topic);
- return new JobEvent(new Event(topic, dict), topic) {
- public void unlock() {
- // dummy
- }
- public boolean reschedule() {
- return false;
- }
- public boolean remove() {
- return false;
- }
- public boolean lock() {
- return false;
- }
- public void finished() {
- // dummy
- }
- public void restart() {
- // dummy
- }
- public boolean isAlive() { return false; }
- };
+ return new Event(topic, dict);
}
@org.junit.Test public void testMaxParallel() {
final Map<String, Object> p = new HashMap<String, Object>();
@@ -73,12 +54,12 @@ public class InternalQueueConfigurationT
InternalQueueConfiguration c = InternalQueueConfiguration.fromConfiguration(p);
assertTrue(c.isValid());
- assertTrue(c.match(getJobEvent("a/b")));
- assertTrue(c.match(getJobEvent("a/c")));
- assertFalse(c.match(getJobEvent("a")));
- assertFalse(c.match(getJobEvent("a/b/c")));
- assertFalse(c.match(getJobEvent("t")));
- assertFalse(c.match(getJobEvent("t/x")));
+ assertNotNull(c.match(getJobEvent("a/b").getTopic()));
+ assertNotNull(c.match(getJobEvent("a/c").getTopic()));
+ assertNull(c.match(getJobEvent("a").getTopic()));
+ assertNull(c.match(getJobEvent("a/b/c").getTopic()));
+ assertNull(c.match(getJobEvent("t").getTopic()));
+ assertNull(c.match(getJobEvent("t/x").getTopic()));
}
@org.junit.Test public void testTopicMatchersStar() {
@@ -88,12 +69,12 @@ public class InternalQueueConfigurationT
InternalQueueConfiguration c = InternalQueueConfiguration.fromConfiguration(p);
assertTrue(c.isValid());
- assertTrue(c.match(getJobEvent("a/b")));
- assertTrue(c.match(getJobEvent("a/c")));
- assertFalse(c.match(getJobEvent("a")));
- assertTrue(c.match(getJobEvent("a/b/c")));
- assertFalse(c.match(getJobEvent("t")));
- assertFalse(c.match(getJobEvent("t/x")));
+ assertNotNull(c.match(getJobEvent("a/b").getTopic()));
+ assertNotNull(c.match(getJobEvent("a/c").getTopic()));
+ assertNull(c.match(getJobEvent("a").getTopic()));
+ assertNotNull(c.match(getJobEvent("a/b/c").getTopic()));
+ assertNull(c.match(getJobEvent("t").getTopic()));
+ assertNull(c.match(getJobEvent("t/x").getTopic()));
}
@org.junit.Test public void testTopicMatchers() {
@@ -103,12 +84,12 @@ public class InternalQueueConfigurationT
InternalQueueConfiguration c = InternalQueueConfiguration.fromConfiguration(p);
assertTrue(c.isValid());
- assertFalse(c.match(getJobEvent("a/b")));
- assertFalse(c.match(getJobEvent("a/c")));
- assertTrue(c.match(getJobEvent("a")));
- assertFalse(c.match(getJobEvent("a/b/c")));
- assertFalse(c.match(getJobEvent("t")));
- assertFalse(c.match(getJobEvent("t/x")));
+ assertNull(c.match(getJobEvent("a/b").getTopic()));
+ assertNull(c.match(getJobEvent("a/c").getTopic()));
+ assertNotNull(c.match(getJobEvent("a").getTopic()));
+ assertNull(c.match(getJobEvent("a/b/c").getTopic()));
+ assertNull(c.match(getJobEvent("t").getTopic()));
+ assertNull(c.match(getJobEvent("t/x").getTopic()));
}
@org.junit.Test public void testTopicMatcherAndReplacement() {
@@ -118,12 +99,12 @@ public class InternalQueueConfigurationT
InternalQueueConfiguration c = InternalQueueConfiguration.fromConfiguration(p);
assertTrue(c.isValid());
- final JobEvent b = getJobEvent("a/b");
- assertTrue(c.match(b));
- assertEquals("test-queue-b", b.queueName);
- final JobEvent d = getJobEvent("a/d");
- assertTrue(c.match(d));
- assertEquals("test-queue-d", d.queueName);
+ final Event b = getJobEvent("a/b");
+ assertNotNull(c.match(b.getTopic()));
+ assertEquals("test-queue-b", c.match(b.getTopic()));
+ final Event d = getJobEvent("a/d");
+ assertNotNull(c.match(d.getTopic()));
+ assertEquals("test-queue-d", c.match(d.getTopic()));
}
@org.junit.Test public void testTopicMatchersDotAndSlash() {
@@ -133,12 +114,12 @@ public class InternalQueueConfigurationT
InternalQueueConfiguration c = InternalQueueConfiguration.fromConfiguration(p);
assertTrue(c.isValid());
- assertTrue(c.match(getJobEvent("a/b")));
- assertTrue(c.match(getJobEvent("a/c")));
- assertFalse(c.match(getJobEvent("a")));
- assertFalse(c.match(getJobEvent("a/b/c")));
- assertFalse(c.match(getJobEvent("t")));
- assertFalse(c.match(getJobEvent("t/x")));
+ assertNotNull(c.match(getJobEvent("a/b").getTopic()));
+ assertNotNull(c.match(getJobEvent("a/c").getTopic()));
+ assertNull(c.match(getJobEvent("a").getTopic()));
+ assertNull(c.match(getJobEvent("a/b/c").getTopic()));
+ assertNull(c.match(getJobEvent("t").getTopic()));
+ assertNull(c.match(getJobEvent("t/x").getTopic()));
}
@org.junit.Test public void testTopicMatchersStarAndSlash() {
@@ -148,12 +129,12 @@ public class InternalQueueConfigurationT
InternalQueueConfiguration c = InternalQueueConfiguration.fromConfiguration(p);
assertTrue(c.isValid());
- assertTrue(c.match(getJobEvent("a/b")));
- assertTrue(c.match(getJobEvent("a/c")));
- assertFalse(c.match(getJobEvent("a")));
- assertTrue(c.match(getJobEvent("a/b/c")));
- assertFalse(c.match(getJobEvent("t")));
- assertFalse(c.match(getJobEvent("t/x")));
+ assertNotNull(c.match(getJobEvent("a/b").getTopic()));
+ assertNotNull(c.match(getJobEvent("a/c").getTopic()));
+ assertNull(c.match(getJobEvent("a").getTopic()));
+ assertNotNull(c.match(getJobEvent("a/b/c").getTopic()));
+ assertNull(c.match(getJobEvent("t").getTopic()));
+ assertNull(c.match(getJobEvent("t/x").getTopic()));
}
@org.junit.Test public void testTopicMatcherAndReplacementAndSlash() {
@@ -163,12 +144,12 @@ public class InternalQueueConfigurationT
InternalQueueConfiguration c = InternalQueueConfiguration.fromConfiguration(p);
assertTrue(c.isValid());
- final JobEvent b = getJobEvent("a/b");
- assertTrue(c.match(b));
- assertEquals("test-queue-b", b.queueName);
- final JobEvent d = getJobEvent("a/d");
- assertTrue(c.match(d));
- assertEquals("test-queue-d", d.queueName);
+ final Event b = getJobEvent("a/b");
+ assertNotNull(c.match(b.getTopic()));
+ assertEquals("test-queue-b", c.match(b.getTopic()));
+ final Event d = getJobEvent("a/d");
+ assertNotNull(c.match(d.getTopic()));
+ assertEquals("test-queue-d", c.match(d.getTopic()));
}
@org.junit.Test public void testNoTopicMatchers() {
Modified: sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/jmx/QueuesMBeanImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/jmx/QueuesMBeanImplTest.java?rev=1470462&r1=1470461&r2=1470462&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/jmx/QueuesMBeanImplTest.java (original)
+++ sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/jmx/QueuesMBeanImplTest.java Mon Apr 22 11:42:53 2013
@@ -22,7 +22,6 @@ import java.util.Dictionary;
import junit.framework.Assert;
-import org.apache.sling.event.impl.jobs.QueueStatusEvent;
import org.apache.sling.event.jobs.Queue;
import org.apache.sling.event.jobs.Statistics;
import org.apache.sling.event.jobs.jmx.StatisticsMBean;
@@ -38,7 +37,7 @@ import org.osgi.framework.ServiceRegistr
import org.osgi.service.component.ComponentContext;
public class QueuesMBeanImplTest {
-
+
private QueuesMBeanImpl mbean;
@Mock
private BundleContext bundleContext;
@@ -53,7 +52,7 @@ public class QueuesMBeanImplTest {
private ArgumentCaptor<Dictionary> serviceProperties;
@Mock
private ServiceRegistration serviceRegistration;
-
+
public QueuesMBeanImplTest() {
MockitoAnnotations.initMocks(this);
}
@@ -64,13 +63,13 @@ public class QueuesMBeanImplTest {
Mockito.when(componentContext.getBundleContext()).thenReturn(bundleContext);
mbean.activate(componentContext);
}
-
-
+
+
@Test
public void testAddQueue() {
addQueue();
}
-
+
public Queue addQueue() {
Queue queue = Mockito.mock(Queue.class, Mockito.withSettings().extraInterfaces(Statistics.class));
mockStatistics((Statistics) queue);
@@ -84,7 +83,7 @@ public class QueuesMBeanImplTest {
testStatistics((StatisticsMBean) serviceObject.getValue());
return queue;
}
-
+
@Test
public void updateQueue() {
@@ -95,13 +94,13 @@ public class QueuesMBeanImplTest {
mbean.handleEvent(new QueueStatusEvent(queue,firstQueue));
Mockito.verify(bundleContext, Mockito.never()).registerService(serviceClass.capture(), serviceObject.capture(), serviceProperties.capture());
}
-
+
@Test
public void removeQueue() {
Queue firstQueue = addQueue();
mbean.handleEvent(new QueueStatusEvent(null,firstQueue));
Mockito.verify(serviceRegistration, Mockito.only()).unregister();
-
+
}
private void mockStatistics(Statistics queue) {
@@ -129,7 +128,7 @@ public class QueuesMBeanImplTest {
Assert.assertEquals(7, statisticsMbean.getNumberOfQueuedJobs());
Assert.assertEquals(8, statisticsMbean.getNumberOfJobs());
Assert.assertEquals(9, statisticsMbean.getLastActivatedJobTime());
- Assert.assertEquals(new Date(9), statisticsMbean.getLastActivatedJobDate());
+ Assert.assertEquals(new Date(9), statisticsMbean.getLastActivatedJobDate());
Assert.assertEquals(10, statisticsMbean.getLastFinishedJobTime());
Assert.assertEquals(new Date(10), statisticsMbean.getLastFinishedJobDate());
Assert.assertEquals(11, statisticsMbean.getAverageWaitingTime());