Merge "Omaha #3668 Switch grid requests to job pool." into omaha_14.4.1
Former-commit-id:c721f2f06c
[formerly7bff603b2c
] [formerly 138b73a020743f216f4062817e06da2c478f3507 [formerlyb9ffe1b4ce
]] [formerlyc721f2f06c
[formerly7bff603b2c
] [formerly 138b73a020743f216f4062817e06da2c478f3507 [formerlyb9ffe1b4ce
]] [formerlyd50a3bab27
[formerlyb9ffe1b4ce
[formerly 6360d4efca94ed47661c239a7a84088661027d64]]]] Former-commit-id:d50a3bab27
Former-commit-id:9fc03a6229
[formerlyd693703c63
] [formerly 723989b954efe79664a0eff6420cabf0f658947f [formerly04ba3e6583
]] Former-commit-id: a6e05534caf6d5e06195fd3b039d2cf5ee077b0d [formerly9435df398f
] Former-commit-id:d56f2baea8
This commit is contained in:
commit
ad5f8d760a
1 changed files with 26 additions and 29 deletions
|
@ -22,8 +22,6 @@ package com.raytheon.viz.grid.rsc.general;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import com.raytheon.uf.common.dataplugin.PluginDataObject;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
|
@ -31,6 +29,7 @@ import com.raytheon.uf.common.status.UFStatus;
|
|||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
import com.raytheon.uf.common.time.DataTime;
|
||||
import com.raytheon.uf.viz.core.exception.VizException;
|
||||
import com.raytheon.uf.viz.core.jobs.JobPool;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -48,6 +47,8 @@ import com.raytheon.uf.viz.core.exception.VizException;
|
|||
* Jun 24, 2013 2140 randerso Moved safe name code into AbstractVizResource
|
||||
* Oct 07, 2014 3668 bclement uses executor instead of eclipse job
|
||||
* renamed to GridDataRequestRunner
|
||||
* Oct 23, 2014 3668 bsteffen replace executor with job pool so user
|
||||
* sees progress.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -59,8 +60,8 @@ class GridDataRequestRunner implements Runnable {
|
|||
private static final int POOL_SIZE = Integer.getInteger(
|
||||
"grid.request.pool.size", 10);
|
||||
|
||||
private static final Executor executor = Executors
|
||||
.newFixedThreadPool(POOL_SIZE);
|
||||
private static final JobPool jobPool = new JobPool("Requesting Grid Data",
|
||||
POOL_SIZE);
|
||||
|
||||
private static final transient IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(GridDataRequestRunner.class);
|
||||
|
@ -95,7 +96,15 @@ class GridDataRequestRunner implements Runnable {
|
|||
|
||||
}
|
||||
|
||||
private volatile boolean cancelled = false;
|
||||
/**
|
||||
* This class is not designed to handle multiple requests concurrently. To
|
||||
* ensure this doesn't happen we track when it is scheduled and do not
|
||||
* schedule again. It would have been simpler to synchronize the run method
|
||||
* but that ties up threads from the pool that other resources should use.
|
||||
* So we don't leave dangling requests this should only be modified while
|
||||
* synchronized on requests.
|
||||
*/
|
||||
private volatile boolean scheduled = false;
|
||||
|
||||
private AbstractGridResource<?> resource;
|
||||
|
||||
|
@ -111,8 +120,10 @@ class GridDataRequestRunner implements Runnable {
|
|||
try {
|
||||
request.gridData = resource.getData(request.time, request.pdos);
|
||||
if (request.gridData == null) {
|
||||
// need to remove unfulfillable requests to avoid infinite
|
||||
// loop.
|
||||
/*
|
||||
* need to remove unfulfillable requests to avoid infinite
|
||||
* loop.
|
||||
*/
|
||||
synchronized (requests) {
|
||||
requests.remove(request);
|
||||
}
|
||||
|
@ -123,9 +134,6 @@ class GridDataRequestRunner implements Runnable {
|
|||
request.exception = e;
|
||||
resource.issueRefresh();
|
||||
}
|
||||
if (cancelled) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,6 +149,7 @@ class GridDataRequestRunner implements Runnable {
|
|||
return request;
|
||||
}
|
||||
}
|
||||
scheduled = false;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -172,21 +181,14 @@ class GridDataRequestRunner implements Runnable {
|
|||
if ((request.exception != null) && !request.exceptionHandled) {
|
||||
handleExceptions();
|
||||
}
|
||||
}
|
||||
if (request.shouldRequest()) {
|
||||
this.schedule();
|
||||
if (!scheduled && request.shouldRequest()) {
|
||||
scheduled = true;
|
||||
jobPool.schedule(this);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* send current requests
|
||||
*/
|
||||
private void schedule() {
|
||||
cancelled = false;
|
||||
executor.execute(this);
|
||||
}
|
||||
|
||||
private void handleExceptions() {
|
||||
|
||||
List<GridDataRequest> failedRequests = new ArrayList<GridDataRequest>(
|
||||
|
@ -266,15 +268,10 @@ class GridDataRequestRunner implements Runnable {
|
|||
public void stopAndClear() {
|
||||
synchronized (requests) {
|
||||
requests.clear();
|
||||
if (jobPool.cancel(this)) {
|
||||
scheduled = false;
|
||||
}
|
||||
}
|
||||
this.cancel();
|
||||
}
|
||||
|
||||
/**
|
||||
* cancel current request
|
||||
*/
|
||||
private void cancel() {
|
||||
cancelled = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue