SLING-6574 : Remove unnecessary dependency to Guava
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1784738 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index 72e02c4..3037738 100644
--- a/pom.xml
+++ b/pom.xml
@@ -92,20 +92,12 @@
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.core</artifactId>
- <version>6.0.0</version>
- <scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>2.0.1</version>
</dependency>
- <dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- <!-- Use the version being used in Sling -->
- <version>15.0</version>
- </dependency>
<!-- Testing -->
<dependency>
<groupId>junit</groupId>
diff --git a/src/main/java/org/apache/sling/jobs/Job.java b/src/main/java/org/apache/sling/jobs/Job.java
index 284f346..5c55a71 100644
--- a/src/main/java/org/apache/sling/jobs/Job.java
+++ b/src/main/java/org/apache/sling/jobs/Job.java
@@ -19,17 +19,12 @@
package org.apache.sling.jobs;
-import com.google.common.collect.ImmutableSet;
-import org.apache.sling.mom.TopicManager;
-import org.osgi.annotation.versioning.ProviderType;
-import org.slf4j.LoggerFactory;
+import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
+
+import org.osgi.annotation.versioning.ProviderType;
/**
* Largely based on org.apache.sling.event.Job.
diff --git a/src/main/java/org/apache/sling/jobs/JobController.java b/src/main/java/org/apache/sling/jobs/JobController.java
index 153ad62..b1e86cd 100644
--- a/src/main/java/org/apache/sling/jobs/JobController.java
+++ b/src/main/java/org/apache/sling/jobs/JobController.java
@@ -16,10 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.jobs;
-
import org.osgi.annotation.versioning.ProviderType;
/**
@@ -42,6 +40,4 @@
* Abort the job immediately.
*/
void abort();
-
-
}
diff --git a/src/main/java/org/apache/sling/jobs/JobManager.java b/src/main/java/org/apache/sling/jobs/JobManager.java
index 1354342..c0eaa60 100644
--- a/src/main/java/org/apache/sling/jobs/JobManager.java
+++ b/src/main/java/org/apache/sling/jobs/JobManager.java
@@ -18,12 +18,10 @@
*/
package org.apache.sling.jobs;
-import org.osgi.annotation.versioning.ProviderType;
-
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import java.util.Collection;
-import java.util.Map;
+
+import org.osgi.annotation.versioning.ProviderType;
/**
* Based on org.apache.sling.event.job.JobManager but trimmed down and adjusted to deal with distributed job queues.
diff --git a/src/main/java/org/apache/sling/jobs/JobUpdate.java b/src/main/java/org/apache/sling/jobs/JobUpdate.java
index 301cf47..4e5bd8e 100644
--- a/src/main/java/org/apache/sling/jobs/JobUpdate.java
+++ b/src/main/java/org/apache/sling/jobs/JobUpdate.java
@@ -18,12 +18,12 @@
*/
package org.apache.sling.jobs;
-import org.apache.sling.mom.TopicManager;
-import org.osgi.annotation.versioning.ProviderType;
+import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import java.util.Map;
+
+import org.osgi.annotation.versioning.ProviderType;
/**
* Job updates are messages that update the state of the job at all subscribers.
diff --git a/src/main/java/org/apache/sling/jobs/impl/JobBuilderImpl.java b/src/main/java/org/apache/sling/jobs/impl/JobBuilderImpl.java
index a9da26a..8450718 100644
--- a/src/main/java/org/apache/sling/jobs/impl/JobBuilderImpl.java
+++ b/src/main/java/org/apache/sling/jobs/impl/JobBuilderImpl.java
@@ -18,22 +18,21 @@
*/
package org.apache.sling.jobs.impl;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.annotation.Nonnull;
+
import org.apache.sling.jobs.Job;
import org.apache.sling.jobs.JobBuilder;
import org.apache.sling.jobs.Types;
import org.apache.sling.jobs.impl.spi.JobStarter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.annotation.Nonnull;
-import java.util.HashMap;
-import java.util.Map;
/**
* Provides an implementation of a JobBuilder.
*/
public class JobBuilderImpl implements JobBuilder {
- private static final Logger LOGGER = LoggerFactory.getLogger(JobBuilderImpl.class);
+
private final String id;
private final Map<String, Object> properties;
private final JobStarter jobStarter;
diff --git a/src/main/java/org/apache/sling/jobs/impl/JobImpl.java b/src/main/java/org/apache/sling/jobs/impl/JobImpl.java
index 6ece8f1..be965d2 100644
--- a/src/main/java/org/apache/sling/jobs/impl/JobImpl.java
+++ b/src/main/java/org/apache/sling/jobs/impl/JobImpl.java
@@ -18,13 +18,18 @@
*/
package org.apache.sling.jobs.impl;
-import com.google.common.base.Preconditions;
-import org.apache.sling.jobs.*;
+import java.util.HashMap;
+import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import java.util.HashMap;
-import java.util.Map;
+
+import org.apache.sling.jobs.Job;
+import org.apache.sling.jobs.JobController;
+import org.apache.sling.jobs.JobUpdate;
+import org.apache.sling.jobs.JobUpdateBuilder;
+import org.apache.sling.jobs.JobUpdateListener;
+import org.apache.sling.jobs.Types;
/**
* JobImpl is a data object to hold the current state of the job in the current JVM as loaded into memory.
@@ -202,7 +207,9 @@
* @param properties the update properties.
*/
private void updateProperties(@Nonnull Map<String, Object> properties) {
- Preconditions.checkNotNull(properties, "Properties cant be null.");
+ if ( properties == null ) {
+ throw new IllegalArgumentException("Properties cant be null.");
+ }
for (Map.Entry<String, Object> e : properties.entrySet()) {
if (e.getValue() instanceof JobUpdate.JobPropertyAction ) {
switch(((JobUpdate.JobPropertyAction)e.getValue())) {
diff --git a/src/main/java/org/apache/sling/jobs/impl/JobManagerImpl.java b/src/main/java/org/apache/sling/jobs/impl/JobManagerImpl.java
index 58bb464..0850bd7 100644
--- a/src/main/java/org/apache/sling/jobs/impl/JobManagerImpl.java
+++ b/src/main/java/org/apache/sling/jobs/impl/JobManagerImpl.java
@@ -18,14 +18,17 @@
*/
package org.apache.sling.jobs.impl;
-import org.apache.sling.jobs.*;
-import org.apache.sling.jobs.impl.spi.JobStarter;
-import org.apache.sling.jobs.impl.spi.JobStorage;
-
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import java.util.Collection;
-import java.util.Map;
+
+import org.apache.sling.jobs.Job;
+import org.apache.sling.jobs.JobBuilder;
+import org.apache.sling.jobs.JobManager;
+import org.apache.sling.jobs.JobUpdate;
+import org.apache.sling.jobs.JobUpdateListener;
+import org.apache.sling.jobs.Types;
+import org.apache.sling.jobs.impl.spi.JobStarter;
+import org.apache.sling.jobs.impl.spi.JobStorage;
/**
* Implements a JobManager, storing Jobs in a JobStorage implementation.
diff --git a/src/main/java/org/apache/sling/jobs/impl/JobQueueConsumerFactory.java b/src/main/java/org/apache/sling/jobs/impl/JobQueueConsumerFactory.java
index a1091ec..62c5214 100644
--- a/src/main/java/org/apache/sling/jobs/impl/JobQueueConsumerFactory.java
+++ b/src/main/java/org/apache/sling/jobs/impl/JobQueueConsumerFactory.java
@@ -19,19 +19,34 @@
package org.apache.sling.jobs.impl;
-import com.google.common.collect.ImmutableSet;
-import org.apache.felix.scr.annotations.*;
-import org.apache.sling.jobs.*;
-import org.apache.sling.mom.*;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+import javax.annotation.Nonnull;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.ConfigurationPolicy;
+import org.apache.felix.scr.annotations.Properties;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.jobs.Job;
+import org.apache.sling.jobs.JobCallback;
+import org.apache.sling.jobs.JobConsumer;
+import org.apache.sling.jobs.JobManager;
+import org.apache.sling.jobs.JobUpdate;
+import org.apache.sling.jobs.JobUpdateListener;
+import org.apache.sling.mom.MessageFilter;
+import org.apache.sling.mom.QueueManager;
+import org.apache.sling.mom.QueueReader;
+import org.apache.sling.mom.RequeueMessageException;
+import org.apache.sling.mom.TopicManager;
import org.apache.sling.mom.Types;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.annotation.Nonnull;
-import java.util.Map;
-import java.util.Queue;
-import java.util.Set;
-
/**
* This is a configuration factory that creates QueueReader instances on configuration. These connect to the JobManager
* service and are registered using the OSGi Whiteboard pattern with the QueueManager. The JobManager service must implement JobConsumer.
@@ -48,7 +63,7 @@
public class JobQueueConsumerFactory implements QueueReader, MessageFilter {
private static final Logger LOGGER = LoggerFactory.getLogger(JobQueueConsumerFactory.class);
- private static final Set<JobUpdate.JobUpdateCommand> ALLOWED_COMMANDS = ImmutableSet.of(JobUpdate.JobUpdateCommand.UPDATE_JOB) ;
+ private static final Set<JobUpdate.JobUpdateCommand> ALLOWED_COMMANDS = Collections.unmodifiableSet(Collections.singleton(JobUpdate.JobUpdateCommand.UPDATE_JOB));
@Reference
private JobManager jobManager;
@@ -59,20 +74,13 @@
private QueueManager queueManager;
@Activate
- public void activate(Map<String, Object> properties) {
+ public void activate() {
if ( !(jobManager instanceof JobConsumer) ) {
LOGGER.error("JobManager must implement JobConsumer interface. {} does not. ", jobManager.getClass());
throw new IllegalStateException("JobManager does not implement JobConsumer");
}
}
- @Deactivate
- public void deactivate(@SuppressWarnings("UnusedParameters") Map<String, Object> properties) {
- }
-
-
-
-
@Override
public void onMessage(Types.QueueName queueName, Map<String, Object> message) throws RequeueMessageException {
diff --git a/src/main/java/org/apache/sling/jobs/impl/JobSubsystem.java b/src/main/java/org/apache/sling/jobs/impl/JobSubsystem.java
index 1be6a00..e8f5750 100644
--- a/src/main/java/org/apache/sling/jobs/impl/JobSubsystem.java
+++ b/src/main/java/org/apache/sling/jobs/impl/JobSubsystem.java
@@ -19,8 +19,17 @@
package org.apache.sling.jobs.impl;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
+import java.io.Closeable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
@@ -44,15 +53,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import java.io.Closeable;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
/**
* NB, this does *not* register as a JobConsumer service. it implements a JobConsumer so that it can consume Jobs from JobQueueConsumers.
*/
@@ -83,14 +83,14 @@
private QueueManager queueManager;
@Activate
- public synchronized void activate(@SuppressWarnings("UnusedParameters") Map<String, Object> properties) {
+ public synchronized void activate() {
jobStorage = new InMemoryJobStorage();
messageSender = new OutboundJobUpdateListener(topicManager, queueManager);
manager = new JobManagerImpl(jobStorage, messageSender);
}
@Deactivate
- public synchronized void deactivate(@SuppressWarnings("UnusedParameters") Map<String, Object> properties) {
+ public synchronized void deactivate() {
for (Map.Entry<ServiceReference<JobConsumer>, JobConsumerHolder> e : registrations.entrySet()) {
e.getValue().close();
}
@@ -137,18 +137,10 @@
LOGGER.error("Registration for service reference is already present {}",serviceRef);
return;
}
- JobConsumerHolder jobConsumerHolder = new JobConsumerHolder(serviceRef.getBundle().getBundleContext().getService(serviceRef), getServiceProperties(serviceRef));
+ JobConsumerHolder jobConsumerHolder = new JobConsumerHolder(serviceRef.getBundle().getBundleContext().getService(serviceRef), serviceRef);
registrations.put(serviceRef, jobConsumerHolder);
}
- private Map<Object, Object> getServiceProperties(ServiceReference<JobConsumer> serviceRef) {
- ImmutableMap.Builder<Object, Object> builder = ImmutableMap.builder();
- for ( String k : serviceRef.getPropertyKeys()) {
- builder.put(k, serviceRef.getProperty(k));
- }
- return builder.build();
- }
-
public synchronized void removeConsumer(ServiceReference<JobConsumer> serviceRef) {
JobConsumerHolder jobConsumerHolder = registrations.remove(serviceRef);
if ( jobConsumerHolder != null) {
@@ -182,17 +174,17 @@
private final JobConsumer consumer;
private final Set<Types.JobType> jobTypes;
- public JobConsumerHolder(JobConsumer consumer, Map<Object, Object> properties) {
+ public JobConsumerHolder(JobConsumer consumer, ServiceReference<JobConsumer> ref) {
this.consumer = consumer;
if ( consumer instanceof JobTypeValve) {
- jobTypes = ImmutableSet.of();
+ jobTypes = Collections.emptySet();
} else {
- jobTypes = getJobTypes(properties);
+ jobTypes = getJobTypes(ref);
}
}
- public Set<Types.JobType> getJobTypes(Map<Object, Object> properties) {
- Object types = properties.get(JobConsumer.JOB_TYPES);
+ public Set<Types.JobType> getJobTypes(ServiceReference<JobConsumer> ref) {
+ Object types = ref.getProperty(JobConsumer.JOB_TYPES);
if (types instanceof String) {
return Types.jobType(new String[]{(String) types});
@@ -204,7 +196,7 @@
for (Object o : (Iterable<?>) types) {
l.add(String.valueOf(o));
}
- return Types.jobType((String[]) l.toArray(new String[l.size()]));
+ return Types.jobType(l.toArray(new String[l.size()]));
}
throw new IllegalArgumentException("For the JobConsumer to work, the job consumer must either " +
"implement a JobTypeValve or define a list of JobTypes, neither were specified. " +
@@ -223,6 +215,7 @@
return jobTypes.contains(jobType);
}
+ @Override
public void close() {
// nothing to do at the moment.
}
diff --git a/src/main/java/org/apache/sling/jobs/impl/JobUpdateBuilderImpl.java b/src/main/java/org/apache/sling/jobs/impl/JobUpdateBuilderImpl.java
index f708c25..5347b5c 100644
--- a/src/main/java/org/apache/sling/jobs/impl/JobUpdateBuilderImpl.java
+++ b/src/main/java/org/apache/sling/jobs/impl/JobUpdateBuilderImpl.java
@@ -18,14 +18,16 @@
*/
package org.apache.sling.jobs.impl;
-import com.google.common.collect.ImmutableMap;
-import org.apache.sling.jobs.Job;
-import org.apache.sling.jobs.JobUpdate;
-import org.apache.sling.jobs.JobUpdateBuilder;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import java.util.Map;
+
+import org.apache.sling.jobs.Job;
+import org.apache.sling.jobs.JobUpdate;
+import org.apache.sling.jobs.JobUpdateBuilder;
/**
*/
@@ -34,7 +36,7 @@
private final String jobId;
private final Job job;
private JobUpdate.JobUpdateCommand command;
- private final ImmutableMap.Builder<String, Object> updateProperties = ImmutableMap.builder();
+ private final Map<String, Object> updateProperties = new HashMap<>();
/**
* Create a JobUpdateBuilder from a job.
@@ -96,7 +98,7 @@
@Override
public JobUpdate build() {
if ( job != null) {
- return new JobUpdateImpl(job, command, updateProperties.build());
+ return new JobUpdateImpl(job, command, Collections.unmodifiableMap(this.updateProperties));
} else if ( command == JobUpdate.JobUpdateCommand.ABORT_JOB || command == JobUpdate.JobUpdateCommand.STOP_JOB) {
return new JobUpdateImpl(jobId, command);
} else {
diff --git a/src/main/java/org/apache/sling/jobs/impl/JobUpdateImpl.java b/src/main/java/org/apache/sling/jobs/impl/JobUpdateImpl.java
index 03f20cf..5fb8394 100644
--- a/src/main/java/org/apache/sling/jobs/impl/JobUpdateImpl.java
+++ b/src/main/java/org/apache/sling/jobs/impl/JobUpdateImpl.java
@@ -18,18 +18,18 @@
*/
package org.apache.sling.jobs.impl;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableMap;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
import org.apache.sling.jobs.Job;
import org.apache.sling.jobs.JobUpdate;
import org.apache.sling.jobs.Types;
import org.apache.sling.jobs.impl.spi.MapValueAdapter;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import java.util.HashMap;
-import java.util.Map;
-
/**
* Represents messages sent to the Job via a message queue.
* Abort, stop and update messages should be sent via a priority queue.
@@ -61,9 +61,15 @@
* @param properties properties in the update message.
*/
public JobUpdateImpl(@Nonnull Job job, @Nonnull JobUpdateCommand command, @Nonnull Map<String, Object> properties) {
- Preconditions.checkNotNull(job, "Job argument cant be null");
- Preconditions.checkNotNull(command, "JobCommand argument cant be null");
- Preconditions.checkNotNull(properties, "Map of properties cant be null");
+ if ( job == null ) {
+ throw new IllegalArgumentException("Job argument cant be null");
+ }
+ if ( command == null ) {
+ throw new IllegalArgumentException("JobCommand argument cant be null");
+ }
+ if ( properties == null ) {
+ throw new IllegalArgumentException("Map of properties cant be null");
+ }
jobQueue = job.getQueue();
jobType = job.getJobType();
@@ -86,20 +92,26 @@
* @param message a inbound message in map form.
*/
public JobUpdateImpl(@Nonnull Map<String, Object> message) {
- Preconditions.checkNotNull(message, "Message cant be null");
+ if ( message == null ) {
+ throw new IllegalArgumentException("Message cant be null");
+ }
fromMapValue(message);
}
public JobUpdateImpl(@Nonnull String jobId, @Nonnull JobUpdateCommand command) {
- Preconditions.checkNotNull(jobId, "JobId argument cant be null");
- Preconditions.checkNotNull(command, "JobUpdateCommand argument cant be null");
+ if ( jobId == null ) {
+ throw new IllegalArgumentException("JobId argument cant be null");
+ }
+ if ( command == null ) {
+ throw new IllegalArgumentException("JobUpdateCommand argument cant be null");
+ }
jobQueue = Types.ANY_JOB_QUEUE;
id = jobId;
updateTimestamp = System.currentTimeMillis();
expires = updateTimestamp + TTL;
jobState = Job.JobState.ANY_STATE;
this.command = command;
- this.properties = ImmutableMap.of();
+ this.properties = Collections.emptyMap();
}
@@ -211,7 +223,7 @@
@Override
@Nonnull
public Object toMapValue() {
- ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
+ final Map<String, Object> builder = new HashMap<>();
builder.put("tp", jobQueue.toString());
builder.put("jt",jobType.toString());
builder.put("id",id);
@@ -226,9 +238,9 @@
builder.put("finishedAt", finishedAt);
builder.put("jobState", jobState.toString());
builder.put("resultMessage", resultMessage);
- builder.put("properties", ImmutableMap.builder().putAll(properties).build());
+ builder.put("properties", Collections.unmodifiableMap(properties));
}
- return builder.build();
+ return Collections.unmodifiableMap(builder);
}
}
diff --git a/src/main/java/org/apache/sling/jobs/impl/OutboundJobUpdateListener.java b/src/main/java/org/apache/sling/jobs/impl/OutboundJobUpdateListener.java
index d6bebad..734bb2a 100644
--- a/src/main/java/org/apache/sling/jobs/impl/OutboundJobUpdateListener.java
+++ b/src/main/java/org/apache/sling/jobs/impl/OutboundJobUpdateListener.java
@@ -16,17 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.jobs.impl;
+import javax.annotation.Nonnull;
+
import org.apache.sling.jobs.JobUpdate;
import org.apache.sling.jobs.JobUpdateListener;
-import org.apache.sling.jobs.Types;
import org.apache.sling.mom.QueueManager;
import org.apache.sling.mom.TopicManager;
-import javax.annotation.Nonnull;
-
/**
* Sends messages out to JMS Queues or topics. Normally called by the local JobManager Implementation.
* Uses a TopicManager or QueueManager to perform the send operation.
@@ -43,7 +41,7 @@
this.queueManager = queueManager;
active = true;
}
-
+
public void dispose() {
active = false;
}
diff --git a/src/main/java/org/apache/sling/jobs/impl/Utils.java b/src/main/java/org/apache/sling/jobs/impl/Utils.java
index 662d002..6882303 100644
--- a/src/main/java/org/apache/sling/jobs/impl/Utils.java
+++ b/src/main/java/org/apache/sling/jobs/impl/Utils.java
@@ -18,21 +18,23 @@
*/
package org.apache.sling.jobs.impl;
-import org.apache.sling.jobs.impl.spi.MapValueAdapter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
import java.io.File;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
-import java.util.*;
+import java.util.Enumeration;
+import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.apache.sling.jobs.impl.spi.MapValueAdapter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
*/
public class Utils {