package to.etc.webapp.pendingoperations;

import to.etc.util.*;

public class PendingJobExecutor {
	private final PendingOperation m_pendingOperation;

	private final ILogSink m_logSink;

	public PendingJobExecutor(final PendingOperation pendingOperation, final ILogSink sink) {
		m_pendingOperation = pendingOperation;
		m_logSink = sink;
	}

	public ILogSink getLogSink() {
		return m_logSink;
	}

	static public void register() {
		PendingOperationTaskProvider.getInstance().registerPendingOperationType("PJEX", new IPendingOperationExecutor() {
			@Override
			public void executePendingOperation(final PendingOperation po, final ILogSink ls) throws Exception {
				IPendingJob j = (IPendingJob) po.getSerializedObject();
				Progress p = new Progress("Job");
				j.execute(ls, po, p);
			}
		});
	}

	public String getRequestID() {
		return "pjix" + m_pendingOperation.getId();
	}

	public PendingOperation getPendingOperation() {
		return m_pendingOperation;
	}
}

@@ -58,16 +58,17 @@
 til.*;%0A%0A
+%0A
 public c
@@ -91,17 +91,38 @@
 xecutor 
-%7B
+implements Runnable %7B%0A
 %0A%09privat
@@ -203,16 +203,17 @@
 gSink;%0A%0A
+%0A
 %09public 
@@ -686,17 +686,20 @@
 n %7B%0A%09%09%09%09
-I
+new 
 PendingJ
@@ -704,75 +704,319 @@
 gJob
- j = (IPendingJob) po.getSerializedObject();%0A%09%09%09%09Progress
+Executor(po, ls).run();%0A%09%09%09%7D%0A%09%09%7D);%0A%09%7D%0A%0A%09/**%0A%09 * Registers a delayed pending job. It will be executed as soon as possible.%0A%09 *%0A%09 */%0A%0A%09static public void registerOperation(final String userid, final String submitter, final String desc, final IPendingJob operation) throws Exception %7B%0A%09%09PendingOperation
  p
+o
  = new P
 rogr
@@ -1015,63 +1015,257 @@
 ew P
-rogress(%22Job%22
+endingOperation();%0A%09%09po.setCreationTime(new java.util.Date());%0A%09%09po.setUserID(userid);%0A%09%09po.setDescription(desc);%0A%09%09po.setSubmitsource(submitter
 );%0A
+%0A
 %09%09
-%09%09j.execute(ls, po, p);%0A%09%09%09%7D%0A%09%09%7D);%0A%09%7D
+po.setType(%22PJEX%22);%0A%09%09PendingOperationTaskProvider.getInstance().saveOperation(po, operation);%0A%09%7D%0A%0A
 %0A%0A%09p
@@ -1306,17 +1306,17 @@
 turn %22pj
-i
+e
 x%22 + m_p
@@ -1424,11 +1424,397 @@
 tion;%0A%09%7D
+%0A%0A%09@Override%0A%09public void run() %7B%0A%09%09try %7B%0A%09%09%09IPendingJob j = (IPendingJob) m_pendingOperation.getSerializedObject();%0A%09%09%09Progress p = new Progress(%22Job%22);%0A%09%09%09j.execute(m_logSink, m_pendingOperation, p);%0A%0A%09%09%7D catch(Exception x) %7B%0A%09%09%09m_logSink.exception(x, %22in executing pending scenario claculation job%22);%0A%09%09%09m_pendingOperation.setError(PendingOperationState.FATL, %22Error: %22 + x);%0A%09%09%7D%0A%0A%09%7D
 %0A%7D%0A

Add save job to db and run a job logic to PendingJobExecutor