gpJobID = gp.submitJob(params).getJobID();
// If no response in 60 seconds, cancel out
gpTimeout = new Timer();
gpTimeout.schedule(new TimerTask() {
@Override
public void run() {
uiHandler.sendEmptyMessage(CANCEL_LOADING_WINDOW);
}
}, 60000);
// Check periodically for results
checkGPResults = new Timer();
checkGPResults.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
try {
GPJobResource gpJR = gp.checkJobStatus(gpJobID);
if ( gpJR.getJobStatus() == JobStatus.succeeded ) {
uiHandler.sendEmptyMessage(CLOSE_LOADING_WINDOW);
checkGPResults.cancel();
lyrOutputResults.removeAll();
GPParameter result =
gp.getResultData( gpJobID, "SewerMainsTraced" );
GPFeatureRecordSetLayer resultFeats = (GPFeatureRecordSetLayer) result;
for (Graphic feature : resultFeats.getGraphics()) {
Geometry geom = feature.getGeometry();
final Graphic g = new Graphic(geom, new SimpleLineSymbol(Color.CYAN, 2));
lyrOutputResults.addGraphic(g);
}
}
else if ( gpJR.getJobStatus() == JobStatus.failed ) {
uiHandler.sendEmptyMessage(CLOSE_LOADING_WINDOW);
checkGPResults.cancel();
showToast( "Error in tracing: " + gpJR.getMessages()[ gpJR.getMessages().length-1 ].toString(), Toast.LENGTH_LONG );
}
}
catch (final Exception exc) {
Log.e(TAG, exc.getMessage());
showToast("Error in tracing: " + exc.getMessage(), Toast.LENGTH_LONG);
}
}
}, 2000, 2000);
strmv.setParamName("Layers_to_Clip");
strmv.setValues(arrayList);
final ArrayList<GPParameter> paramlist = new ArrayList<GPParameter>();
paramlist.add(strmv);
paramlist.add(areaofinterest);
paramlist.add(featureformat);
handler = new Handler();
submitJobandPolling(gp, paramlist); /**
* Method submitJobandPolling.
* @param gp Geoprocessor
* @param params List<GPParameter>
*/
void submitJobandPolling(final Geoprocessor gp,
List<GPParameter> params) {
try {
GPJobResource gpjr1 = gp.submitJob(params);
JobStatus jobstatus = gpjr1.getJobStatus();
final String jobid = gpjr1.getJobID();
Log.d("Test", "jobid " + jobid);
Log.d("Test", "jobstatus " + jobstatus);
// if (!jobstatus.equals("esriJobSucceeded")) {
if (jobstatus != JobStatus.succeeded) {
handler.postDelayed(new Runnable() {
@Override
public void run() {
try {
GPJobResource gpjr2 = gp.checkJobStatus(jobid);
GPMessage[] messages = gpjr2.getMessages();
if ( messages!= null && messages.length > 0) {
for (int i = 0; i < messages.length; i++) {
Log.d("Test", "Message: " + messages.getDescription());
}
}
Log.d("Test", "Polling thread is: "
+ Thread.currentThread().getName());
JobStatus status = gpjr2.getJobStatus();
boolean jobcomplete = false;
if (status == JobStatus.canceled
|| status == JobStatus.deleted
|| status == JobStatus.failed || status == JobStatus.succeeded
|| status == JobStatus.timedOut) {
jobcomplete = true;
}
if (jobcomplete) {
if (status == JobStatus.succeeded) {
GPDataFile outputZipfile = (GPDataFile) gp
.getResultData(jobid, "Output_Zip_File");
Log.d("Test", "zip file is "
+ outputZipfile.getUrl().toURI()
.toString());
}else {
Log.d("Test", "GP failed");
}
} else {
handler.postDelayed(this, 5000);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}, 4000);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Are you specifically wanting to use the Viewshed service? If so, it does not support asynchronous execution. Before you can use the Geoprocessing task you have to know whether the task is asynchronous or synchronous. This is described in the ArcGIS Services Directory.
I found it very difficult to troubleshoot GP parameter issues until I pointed my device to a Fiddler proxy running on my PC. Once I was able to spy on the JSON requests going over the wire, I was able to copy/paste those parameters into a web browser at the GP service REST endpoint. The problems quickly became apparent...