Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  import java.util.Map;
  import  javax.enterprise.context.ApplicationScoped;
 import  org.slf4j.Logger;
 import  org.slf4j.LoggerFactory;

This class caches the job result information in order to provide it upon request (so that users can check the status of a deployment or undeployment job).
 public class JobResultManager {
     private static final Logger logger = LoggerFactory.getLogger(JobResultManager.class);
     private static AtomicInteger created = new AtomicInteger(0);
     private static class Cache<T> extends LinkedHashMap<String, T> {

generated serial version UID
         private static final long serialVersionUID = -5369827812060944667L;
         private int maxSize = 1000;
         public Cache(int maxSize) {
             this. = maxSize;
         protected boolean removeEldestEntry(Map.Entry<String, T> stringFutureEntry) {
             return size() > ;
     private Map<String, JaxbDeploymentJobResult> jobs = null;
     private Map<StringStringdeploymentIdMostRecentJobIdMap = null;
     private int maxCacheSize = 10000;

Initialization method to initialize the 2 caches that hold the job result information.
     public void start() {
         if (!.compareAndSet(0, 1)) {
             throw new IllegalStateException("Only 1 JobResultManager instance is allowed per container!");
         Cache<JaxbDeploymentJobResult> cache = new Cache<JaxbDeploymentJobResult>();
          = Collections.synchronizedMap(cache);
         Cache<StringidCache = new Cache<String>();
          = Collections.synchronizedMap(idCache);

Add a job to the cache

jobId The unique id of the job (unique to the kie-services-remote code)
job The job to cache
jobType The job type, for logging purposes
     public void putJob(String jobId, JaxbDeploymentJobResult jobJobType jobType) {
         .debug( "Adding job [{}] to cache");
         String deploymentId = job.getDeploymentUnit().getIdentifier();
         .debug( "Adding job id [{}] to \"most recent job\" cache");
         String oldJobId = .put(deploymentIdjobId);
         ifoldJobId != null ) { 
             JaxbDeploymentJobResult oldJobResult = .get(oldJobId);
             if( ! JaxbDeploymentStatus.DEPLOYED.equals(oldJobResult.getDeploymentUnit().getStatus()) 
                     && ! JaxbDeploymentStatus.UNDEPLOYED.equals(oldJobResult.getDeploymentUnit().getStatus()) )
             .info( "New {} job [{}] for '{}' requested while old job [{}] has status {}",

Get a job using the job's unique id

jobId The job id
The JaxbDeploymentJobResult instance
     public JaxbDeploymentJobResult getJob(String jobId) {
         .debug( "Getting job [{}]");
        return .get(jobId); 
Get the most recent job requested for a given deployment

deploymentId The id of the deployment
The JaxbDeploymentJobResult with the job information
    public JaxbDeploymentJobResult getMostRecentJob(String deploymentId) {
        .debug( "Getting most recent job for '{}'"deploymentId);
        String jobId = .get(deploymentId);
        ifjobId != null ) { 
            return .get(jobId);
        return null;
New to GrepCode? Check out our FAQ X