DeviceControlApi deviceControlApi;
class Executor implements Runnable {
@Override
public void run() {
OperationRepresentation op = null;
running.set(true);
while (isActive()) {
try {
op = queue.poll(queuePollTimeOut, TimeUnit.MILLISECONDS);
if (op != null) {
// TODO - refactor. This isn't pretty
GId gid = op.getId();
Boolean internalOperation = false;
if (gid.getValue().startsWith(OperationsQueueHandler.INTERNAL)) {
internalOperation = true;
}
OperationRepresentation executingOperation = null;
if (!internalOperation) {
// change status of operation in REST to "executing"
op.setStatus(OperationStatus.EXECUTING.toString());
executingOperation = deviceControlApi.update(op);
}
boolean result = operationProcessor.process(op);
if (!internalOperation) {
// change status of operation in REST according to
// result
if (result) {
executingOperation.setStatus(OperationStatus.SUCCESSFUL.toString());
} else {
executingOperation.setStatus(OperationStatus.FAILED.toString());
}
deviceControlApi.update(executingOperation);
}
}