diff options
Diffstat (limited to 'catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/workers/CacheWorker.java')
-rw-r--r-- | catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/workers/CacheWorker.java | 109 |
1 files changed, 54 insertions, 55 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/workers/CacheWorker.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/workers/CacheWorker.java index d29ade9c95..e70916f170 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/workers/CacheWorker.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/cache/workers/CacheWorker.java @@ -20,13 +20,12 @@ package org.openecomp.sdc.be.model.cache.workers; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.TimeUnit; - import org.openecomp.sdc.be.model.cache.jobs.Job; import org.openecomp.sdc.be.workers.Worker; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.openecomp.sdc.common.log.wrappers.Logger; + +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; /** * Created by mlando on 9/6/2016. the class represents a worker the pull job @@ -34,59 +33,59 @@ import org.slf4j.LoggerFactory; * */ public class CacheWorker implements Runnable, IWorker { - private String workerName; - private static Logger log = LoggerFactory.getLogger(Worker.class.getName()); - private LinkedBlockingQueue<Job> jobQueue; - private volatile boolean shutdown = false; + private String workerName; + private static final Logger log = Logger.getLogger(Worker.class.getName()); + private LinkedBlockingQueue<Job> jobQueue; + private volatile boolean shutdown = false; - /** - * constructor - * - * @param workerName - * the name of the given worker - * @param jobQueue - * the queue the worker will block on. - */ - public CacheWorker(String workerName, LinkedBlockingQueue<Job> jobQueue) { - this.workerName = workerName; - this.jobQueue = jobQueue; - } + /** + * constructor + * + * @param workerName + * the name of the given worker + * @param jobQueue + * the queue the worker will block on. + */ + public CacheWorker(String workerName, LinkedBlockingQueue<Job> jobQueue) { + this.workerName = workerName; + this.jobQueue = jobQueue; + } - /** - * the method will try to get a job if one is avilable it will be retrived - * and handled. if no jobs are available the worker will block for 500 - * milliseconds and then it wil check if it needs to shutdown. if not it - * will block again and so on until sutdown or a new job is available - */ - @Override - public void run() { - while (true) { - log.trace("CacheWorker:{} doing work", workerName); - try { - Job job = jobQueue.poll(500, TimeUnit.MILLISECONDS); - if (job != null) { - job.doWork(); - log.trace("worker:{} done with work", workerName); - } - } catch (Throwable e) { - log.debug("worker {} failed during job execution.", workerName); - log.debug("exception", e); - } - if (shutdown) { - log.debug("worker:{} nothing to do stoping", workerName); - break; - } - } + /** + * the method will try to get a job if one is avilable it will be retrived + * and handled. if no jobs are available the worker will block for 500 + * milliseconds and then it wil check if it needs to shutdown. if not it + * will block again and so on until sutdown or a new job is available + */ + @Override + public void run() { + while (true) { + log.trace("CacheWorker:{} doing work", workerName); + try { + Job job = jobQueue.poll(500, TimeUnit.MILLISECONDS); + if (job != null) { + job.doWork(); + log.trace("worker:{} done with work", workerName); + } + } catch (Exception e) { + log.debug("worker {} failed during job execution.", workerName); + log.debug("exception", e); + } + if (shutdown) { + log.debug("worker:{} nothing to do stoping", workerName); + break; + } + } - } + } - /** - * the method sets the shutdown flag, when set the worker will stop it's - * execution as soon as possible with out completing its work - */ - @Override - public void shutDown() { - this.shutdown = true; - } + /** + * the method sets the shutdown flag, when set the worker will stop it's + * execution as soon as possible with out completing its work + */ + @Override + public void shutDown() { + this.shutdown = true; + } } |