com.bazaarvoice.emodb.job.dao.InMemoryJobStatusDAO Maven / Gradle / Ivy
The newest version!
package com.bazaarvoice.emodb.job.dao;
import com.bazaarvoice.emodb.common.json.JsonHelper;
import com.bazaarvoice.emodb.job.api.JobIdentifier;
import com.bazaarvoice.emodb.job.api.JobStatus;
import com.google.common.collect.Maps;
import javax.annotation.Nullable;
import java.util.Map;
import static com.bazaarvoice.emodb.job.util.JobStatusUtil.narrow;
public class InMemoryJobStatusDAO implements JobStatusDAO {
private final Map, Object> _statusMap = Maps.newConcurrentMap();
@Override
public void updateJobStatus(JobIdentifier jobId, JobStatus jobStatus) {
_statusMap.put(jobId, JsonHelper.convert(jobStatus, Map.class));
}
@Nullable
@Override
public JobStatus getJobStatus(final JobIdentifier jobId) {
Object jobStatusJson = _statusMap.get(jobId);
if (jobStatusJson == null) {
return null;
}
return narrow(jobStatusJson, jobId.getJobType());
}
@Override
public void deleteJobStatus(JobIdentifier, ?> jobId) {
_statusMap.remove(jobId);
}
}