Example usage for com.google.common.util.concurrent ListenableFutureTask create

List of usage examples for com.google.common.util.concurrent ListenableFutureTask create

Introduction

In this page you can find the example usage for com.google.common.util.concurrent ListenableFutureTask create.

Prototype

public static <V> ListenableFutureTask<V> create(Callable<V> callable) 

Source Link

Document

Creates a ListenableFutureTask that will upon running, execute the given Callable .

Usage

From source file:com.vmware.photon.controller.deployer.dcp.task.CreateIsoTaskService.java

/**
 * This method performs document state updates in response to an operation which
 * sets the state to STARTED.//from   w w  w  .j  a va  2s .c om
 *
 * @param currentState Supplies the current state object.
 */
private void attachAndUploadIso(final State currentState, final String isoFile) throws IOException {
    final ApiClient client = HostUtils.getApiClient(this);
    ListenableFutureTask<Task> futureTask = ListenableFutureTask.create(new Callable<Task>() {
        @Override
        public Task call() {
            try {
                return client.getVmApi().uploadAndAttachIso(currentState.vmId, isoFile);
            } catch (RuntimeException e) {
                throw e;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    });

    HostUtils.getListeningExecutorService(this).submit(futureTask);

    FutureCallback<Task> futureCallback = new FutureCallback<Task>() {
        @Override
        public void onSuccess(@Nullable Task result) {
            try {
                if (null == result) {
                    failTask(new IllegalStateException("IsoUploadAndAttach returned null"));
                    return;
                }
                Files.deleteIfExists(Paths.get(isoFile));
                processTask(currentState, result);
            } catch (Throwable e) {
                failTask(e);
            }
        }

        @Override
        public void onFailure(Throwable t) {
            failTask(t);
        }
    };

    Futures.addCallback(futureTask, futureCallback);
}

From source file:org.apache.jackrabbit.oak.plugins.blob.MarkSweepGarbageCollector.java

/**
 * Checks for the DataStore consistency and reports the number of missing blobs still referenced.
 * // www.ja v a2s  .  c  o m
 * @return the missing blobs
 * @throws Exception
 */
@Override
public long checkConsistency() throws Exception {
    boolean threw = true;
    GarbageCollectorFileState fs = new GarbageCollectorFileState(root);
    long candidates = 0;

    try {
        LOG.info("Starting blob consistency check");

        // Find all blobs available in the blob store
        ListenableFutureTask<Integer> blobIdRetriever = ListenableFutureTask.create(new BlobIdRetriever(fs));
        executor.execute(blobIdRetriever);

        // Mark all used blob references
        iterateNodeTree(fs);

        try {
            blobIdRetriever.get();
        } catch (ExecutionException e) {
            LOG.warn("Error occurred while fetching all the blobIds from the BlobStore");
            threw = false;
            throw e;
        }

        LOG.trace("Starting difference phase of the consistency check");
        FileLineDifferenceIterator iter = new FileLineDifferenceIterator(fs.getAvailableRefs(),
                fs.getMarkedRefs(), transformer);
        candidates = calculateDifference(fs, iter);
        LOG.trace("Ending difference phase of the consistency check");

        LOG.info("Consistency check found [{}] missing blobs", candidates);
        if (candidates > 0) {
            LOG.warn(
                    "Consistency check failure in the the blob store : {}, check missing candidates in file {}",
                    blobStore, fs.getGcCandidates().getAbsolutePath());
        }
    } finally {
        if (!LOG.isTraceEnabled() && candidates == 0) {
            Closeables.close(fs, threw);
        }
    }
    return candidates;
}

From source file:com.vmware.photon.controller.deployer.xenon.task.ProvisionHostTaskService.java

private void processConfigureSyslogSubStage(DeploymentService.State deploymentState,
        HostService.State hostState) {

    List<String> command = Arrays.asList("./" + CONFIGURE_SYSLOG_SCRIPT_NAME, hostState.hostAddress,
            hostState.userName, hostState.password, deploymentState.syslogEndpoint);

    DeployerContext deployerContext = HostUtils.getDeployerContext(this);

    File scriptLogFile = new File(deployerContext.getScriptLogDirectory(),
            CONFIGURE_SYSLOG_SCRIPT_NAME + "-" + hostState.hostAddress + "-"
                    + ServiceUtils.getIDFromDocumentSelfLink(hostState.documentSelfLink) + ".log");

    ScriptRunner scriptRunner = new ScriptRunner.Builder(command, deployerContext.getScriptTimeoutSec())
            .directory(deployerContext.getScriptDirectory())
            .redirectOutput(ProcessBuilder.Redirect.to(scriptLogFile)).redirectErrorStream(true).build();

    ListenableFutureTask<Integer> futureTask = ListenableFutureTask.create(scriptRunner);
    HostUtils.getListeningExecutorService(this).submit(futureTask);

    Futures.addCallback(futureTask, new FutureCallback<Integer>() {
        @Override//w  w  w  . ja  v a2 s .  c om
        public void onSuccess(@javax.validation.constraints.NotNull Integer result) {
            try {
                if (result != 0) {
                    logSyslogConfigurationErrorAndFail(hostState, result, scriptLogFile);
                } else {
                    sendStageProgressPatch(TaskState.TaskStage.STARTED, TaskState.SubStage.REMOVE_VIBS);
                }
            } catch (Throwable t) {
                failTask(t);
            }
        }

        @Override
        public void onFailure(Throwable throwable) {
            failTask(throwable);
        }
    });
}

From source file:com.vmware.photon.controller.deployer.xenon.task.CreateDhcpVmTaskService.java

private void processConfigIso(State currentState, VmService.State vmState, HostService.State hostState)
        throws Throwable {

    checkState(hostState.metadata.containsKey(HostService.State.METADATA_KEY_NAME_MANAGEMENT_NETWORK_GATEWAY));
    checkState(hostState.metadata.containsKey(HostService.State.METADATA_KEY_NAME_MANAGEMENT_NETWORK_IP));
    checkState(hostState.metadata.containsKey(HostService.State.METADATA_KEY_NAME_MANAGEMENT_NETWORK_NETMASK));
    checkState(//  w w w  . ja  va 2  s. com
            hostState.metadata.containsKey(HostService.State.METADATA_KEY_NAME_MANAGEMENT_NETWORK_DNS_SERVER));

    String gateway = hostState.metadata.get(HostService.State.METADATA_KEY_NAME_MANAGEMENT_NETWORK_GATEWAY);
    String ipAddress = hostState.metadata.get(HostService.State.METADATA_KEY_NAME_MANAGEMENT_NETWORK_IP);
    String netmask = hostState.metadata.get(HostService.State.METADATA_KEY_NAME_MANAGEMENT_NETWORK_NETMASK);
    String dnsEndpointList = hostState.metadata
            .get(HostService.State.METADATA_KEY_NAME_MANAGEMENT_NETWORK_DNS_SERVER);
    if (!Strings.isNullOrEmpty(dnsEndpointList)) {
        dnsEndpointList = Stream.of(dnsEndpointList.split(",")).map((dnsServer) -> "DNS=" + dnsServer + "\n")
                .collect(StringBuilder::new, StringBuilder::append, StringBuilder::append).toString();
    }

    DeployerContext deployerContext = HostUtils.getDeployerContext(this);
    String scriptDirectory = deployerContext.getScriptDirectory();

    String userDataConfigFileContent = new String(
            Files.readAllBytes(Paths.get(scriptDirectory, "user-data.template")), StandardCharsets.UTF_8)
                    .replace("$GATEWAY", gateway)
                    .replace("$ADDRESS", new SubnetUtils(ipAddress, netmask).getInfo().getCidrSignature())
                    .replace("$DNS", dnsEndpointList);

    if (currentState.ntpEndpoint != null) {
        userDataConfigFileContent = userDataConfigFileContent.replace("$NTP", currentState.ntpEndpoint);
    }

    String metadataConfigFileContent = new String(
            Files.readAllBytes(Paths.get(scriptDirectory, "meta-data.template")), StandardCharsets.UTF_8)
                    .replace("$INSTANCE_ID", vmState.name).replace("$LOCAL_HOSTNAME", vmState.name);

    Path vmConfigDirectoryPath = Files.createTempDirectory("iso-" + currentState.vmId).toAbsolutePath();
    Path userDataConfigFilePath = vmConfigDirectoryPath.resolve("user-data.yml");
    Files.write(userDataConfigFilePath, userDataConfigFileContent.getBytes(StandardCharsets.UTF_8));
    Path metadataConfigFilePath = vmConfigDirectoryPath.resolve("meta-data.yml");
    Files.write(metadataConfigFilePath, metadataConfigFileContent.getBytes(StandardCharsets.UTF_8));
    Path isoFilePath = vmConfigDirectoryPath.resolve("config.iso");

    List<String> command = new ArrayList<>();
    command.add("./" + SCRIPT_NAME);
    command.add(isoFilePath.toAbsolutePath().toString());
    command.add(userDataConfigFilePath.toAbsolutePath().toString());
    command.add(metadataConfigFilePath.toAbsolutePath().toString());
    command.add(currentState.serviceConfigDirectory);

    File scriptLogFile = new File(deployerContext.getScriptLogDirectory(), SCRIPT_NAME + "-" + vmState.vmId
            + "-" + ServiceUtils.getIDFromDocumentSelfLink(currentState.documentSelfLink) + ".log");

    ScriptRunner scriptRunner = new ScriptRunner.Builder(command, deployerContext.getScriptTimeoutSec())
            .directory(deployerContext.getScriptDirectory())
            .redirectOutput(ProcessBuilder.Redirect.to(scriptLogFile)).build();

    ListenableFutureTask<Integer> futureTask = ListenableFutureTask.create(scriptRunner);
    HostUtils.getListeningExecutorService(this).submit(futureTask);
    Futures.addCallback(futureTask, new FutureCallback<Integer>() {
        @Override
        public void onSuccess(@javax.validation.constraints.NotNull Integer result) {
            try {
                if (result != 0) {
                    logScriptErrorAndFail(currentState, result, scriptLogFile);
                } else {
                    State patchState = buildPatch(TaskState.TaskStage.STARTED, TaskState.SubStage.ATTACH_ISO,
                            null);
                    patchState.vmConfigDirectory = vmConfigDirectoryPath.toAbsolutePath().toString();
                    TaskUtils.sendSelfPatch(CreateDhcpVmTaskService.this, patchState);
                }
            } catch (Throwable t) {
                failTask(t);
            }
        }

        @Override
        public void onFailure(Throwable throwable) {
            failTask(throwable);
        }
    });
}

From source file:com.vmware.photon.controller.deployer.xenon.task.ProvisionHostTaskService.java

private void processInstallVibsSubStage(VibService.State vibState, DeploymentService.State deploymentState,
        HostService.State hostState, Boolean createCert) {

    String oAuthDomain = "";
    String oAuthAddress = "";
    String oAuthPassword = "";
    if (deploymentState.oAuthTenantName != null) {
        oAuthDomain = deploymentState.oAuthTenantName;
    }/*from  ww  w .  j ava 2 s . co  m*/
    if (deploymentState.oAuthServerAddress != null) {
        oAuthAddress = deploymentState.oAuthServerAddress;
    }
    if (deploymentState.oAuthPassword != null) {
        oAuthPassword = deploymentState.oAuthPassword;
    }
    List<String> command = Arrays.asList("./" + INSTALL_VIB_SCRIPT_NAME, hostState.hostAddress,
            hostState.userName, hostState.password, vibState.uploadPath, createCert.toString(), oAuthDomain,
            oAuthAddress, oAuthPassword);

    DeployerContext deployerContext = HostUtils.getDeployerContext(this);

    File scriptLogFile = new File(deployerContext.getScriptLogDirectory(),
            INSTALL_VIB_SCRIPT_NAME + "-" + hostState.hostAddress + "-"
                    + ServiceUtils.getIDFromDocumentSelfLink(vibState.documentSelfLink) + ".log");

    ScriptRunner scriptRunner = new ScriptRunner.Builder(command, deployerContext.getScriptTimeoutSec())
            .directory(deployerContext.getScriptDirectory())
            .redirectOutput(ProcessBuilder.Redirect.to(scriptLogFile)).redirectErrorStream(true).build();

    ListenableFutureTask<Integer> futureTask = ListenableFutureTask.create(scriptRunner);
    HostUtils.getListeningExecutorService(this).submit(futureTask);

    Futures.addCallback(futureTask, new FutureCallback<Integer>() {
        @Override
        public void onSuccess(@javax.validation.constraints.NotNull Integer result) {
            try {
                if (result != 0) {
                    logVibInstallationFailureAndFail(vibState, hostState, result, scriptLogFile);
                } else {
                    deleteVibService(vibState);
                }
            } catch (Throwable t) {
                failTask(t);
            }
        }

        @Override
        public void onFailure(Throwable throwable) {
            failTask(throwable);
        }
    });
}

From source file:com.vmware.photon.controller.deployer.xenon.task.CreateManagementVmTaskService.java

private void processConfigIso(State currentState, VmService.State vmState, HostService.State hostState)
        throws Throwable {

    checkState(hostState.metadata.containsKey(HostService.State.METADATA_KEY_NAME_MANAGEMENT_NETWORK_GATEWAY));
    checkState(hostState.metadata.containsKey(HostService.State.METADATA_KEY_NAME_MANAGEMENT_NETWORK_IP));
    checkState(hostState.metadata.containsKey(HostService.State.METADATA_KEY_NAME_MANAGEMENT_NETWORK_NETMASK));
    checkState(//  www . ja  v  a 2s . c om
            hostState.metadata.containsKey(HostService.State.METADATA_KEY_NAME_MANAGEMENT_NETWORK_DNS_SERVER));

    String gateway = hostState.metadata.get(HostService.State.METADATA_KEY_NAME_MANAGEMENT_NETWORK_GATEWAY);
    String ipAddress = hostState.metadata.get(HostService.State.METADATA_KEY_NAME_MANAGEMENT_NETWORK_IP);
    String netmask = hostState.metadata.get(HostService.State.METADATA_KEY_NAME_MANAGEMENT_NETWORK_NETMASK);
    String dnsEndpointList = hostState.metadata
            .get(HostService.State.METADATA_KEY_NAME_MANAGEMENT_NETWORK_DNS_SERVER);
    String allowedServices = hostState.metadata.get(HostService.State.METADATA_KEY_NAME_ALLOWED_SERVICES);

    if (!Strings.isNullOrEmpty(dnsEndpointList)) {
        dnsEndpointList = Stream.of(dnsEndpointList.split(",")).map((dnsServer) -> "DNS=" + dnsServer + "\n")
                .collect(StringBuilder::new, StringBuilder::append, StringBuilder::append).toString();
    }

    DeployerContext deployerContext = HostUtils.getDeployerContext(this);
    String scriptDirectory = deployerContext.getScriptDirectory();

    String domainName = DOMAIN_NAME;
    if (currentState.oAuthTenantName != null) {
        domainName = currentState.oAuthTenantName;
    }

    String userDataConfigFileContent = new String(
            Files.readAllBytes(Paths.get(scriptDirectory, "user-data.template")), StandardCharsets.UTF_8)
                    .replace("$GATEWAY", gateway)
                    .replace("$ADDRESS", new SubnetUtils(ipAddress, netmask).getInfo().getCidrSignature())
                    .replace("$DOMAIN_NAME", domainName);

    if (currentState.ntpEndpoint != null) {
        userDataConfigFileContent = userDataConfigFileContent.replace("$NTP", currentState.ntpEndpoint);
    }

    // If auth is enabled and this VM is the lightwave server, then set dns to its own address and add domain name.
    // If auth is enabled and this VM is not the lightwave server, then set dns to lightwave VM address and add
    // domain name.
    // If auth is not enabled, then use the default dns server, don't set domain.
    if (currentState.isAuthEnabled && vmState.ipAddress.equals(currentState.oAuthServerAddress)) {
        userDataConfigFileContent = userDataConfigFileContent.replace("$DNS", "DNS=" + vmState.ipAddress)
                .replace("$DOMAINS", "Domains=" + domainName);
    } else if (currentState.isAuthEnabled) {
        userDataConfigFileContent = userDataConfigFileContent
                .replace("$DNS", "DNS=" + currentState.oAuthServerAddress)
                .replace("$DOMAINS", "Domains=" + domainName);
    } else {
        userDataConfigFileContent = userDataConfigFileContent.replace("$DNS", dnsEndpointList)
                .replace("\n        $DOMAINS", "");
    }

    String metadataConfigFileContent = new String(
            Files.readAllBytes(Paths.get(scriptDirectory, "meta-data.template")), StandardCharsets.UTF_8)
                    .replace("$INSTANCE_ID", vmState.name).replace("$LOCAL_HOSTNAME", vmState.name);

    Path vmConfigDirectoryPath = Files.createTempDirectory("iso-" + currentState.vmId).toAbsolutePath();
    Path userDataConfigFilePath = vmConfigDirectoryPath.resolve("user-data.yml");
    Files.write(userDataConfigFilePath, userDataConfigFileContent.getBytes(StandardCharsets.UTF_8));
    Path metadataConfigFilePath = vmConfigDirectoryPath.resolve("meta-data.yml");
    Files.write(metadataConfigFilePath, metadataConfigFileContent.getBytes(StandardCharsets.UTF_8));
    Path isoFilePath = vmConfigDirectoryPath.resolve("config.iso");

    List<String> command = new ArrayList<>();
    command.add("./" + SCRIPT_NAME);
    command.add(isoFilePath.toAbsolutePath().toString());
    command.add(userDataConfigFilePath.toAbsolutePath().toString());
    command.add(metadataConfigFilePath.toAbsolutePath().toString());
    command.add(currentState.serviceConfigDirectory);

    File scriptLogFile = new File(deployerContext.getScriptLogDirectory(), SCRIPT_NAME + "-" + vmState.vmId
            + "-" + ServiceUtils.getIDFromDocumentSelfLink(currentState.documentSelfLink) + ".log");

    ScriptRunner scriptRunner = new ScriptRunner.Builder(command, deployerContext.getScriptTimeoutSec())
            .directory(deployerContext.getScriptDirectory())
            .redirectOutput(ProcessBuilder.Redirect.to(scriptLogFile)).build();

    ListenableFutureTask<Integer> futureTask = ListenableFutureTask.create(scriptRunner);
    HostUtils.getListeningExecutorService(this).submit(futureTask);
    Futures.addCallback(futureTask, new FutureCallback<Integer>() {
        @Override
        public void onSuccess(@javax.validation.constraints.NotNull Integer result) {
            try {
                if (result != 0) {
                    logScriptErrorAndFail(currentState, result, scriptLogFile);
                } else {
                    State patchState = buildPatch(TaskState.TaskStage.STARTED, TaskState.SubStage.ATTACH_ISO,
                            null);
                    patchState.vmConfigDirectory = vmConfigDirectoryPath.toAbsolutePath().toString();
                    TaskUtils.sendSelfPatch(CreateManagementVmTaskService.this, patchState);
                }
            } catch (Throwable t) {
                failTask(t);
            }
        }

        @Override
        public void onFailure(Throwable throwable) {
            failTask(throwable);
        }
    });
}

From source file:com.vmware.photon.controller.deployer.dcp.task.CreateManagementVmTaskService.java

private void processConfigIso(State currentState, VmService.State vmState, HostService.State hostState)
        throws Throwable {

    checkState(hostState.metadata.containsKey(HostService.State.METADATA_KEY_NAME_MANAGEMENT_NETWORK_GATEWAY));
    checkState(hostState.metadata.containsKey(HostService.State.METADATA_KEY_NAME_MANAGEMENT_NETWORK_IP));
    checkState(hostState.metadata.containsKey(HostService.State.METADATA_KEY_NAME_MANAGEMENT_NETWORK_NETMASK));
    checkState(/* w ww . j a  v a 2 s.c o  m*/
            hostState.metadata.containsKey(HostService.State.METADATA_KEY_NAME_MANAGEMENT_NETWORK_DNS_SERVER));

    String gateway = hostState.metadata.get(HostService.State.METADATA_KEY_NAME_MANAGEMENT_NETWORK_GATEWAY);
    String ipAddress = hostState.metadata.get(HostService.State.METADATA_KEY_NAME_MANAGEMENT_NETWORK_IP);
    String netmask = hostState.metadata.get(HostService.State.METADATA_KEY_NAME_MANAGEMENT_NETWORK_NETMASK);
    String dnsEndpointList = hostState.metadata
            .get(HostService.State.METADATA_KEY_NAME_MANAGEMENT_NETWORK_DNS_SERVER);
    if (!Strings.isNullOrEmpty(dnsEndpointList)) {
        dnsEndpointList = Stream.of(dnsEndpointList.split(",")).map((dnsServer) -> "DNS=" + dnsServer + "\n")
                .collect(StringBuilder::new, StringBuilder::append, StringBuilder::append).toString();
    }

    DeployerContext deployerContext = HostUtils.getDeployerContext(this);
    String scriptDirectory = deployerContext.getScriptDirectory();

    String userDataConfigFileContent = new String(
            Files.readAllBytes(Paths.get(scriptDirectory, "user-data.template")), StandardCharsets.UTF_8)
                    .replace("$GATEWAY", gateway)
                    .replace("$ADDRESS", new SubnetUtils(ipAddress, netmask).getInfo().getCidrSignature())
                    .replace("$DNS", dnsEndpointList);

    if (currentState.ntpEndpoint != null) {
        userDataConfigFileContent = userDataConfigFileContent.replace("$NTP", currentState.ntpEndpoint);
    }

    String metadataConfigFileContent = new String(
            Files.readAllBytes(Paths.get(scriptDirectory, "meta-data.template")), StandardCharsets.UTF_8)
                    .replace("$INSTANCE_ID", vmState.name).replace("$LOCAL_HOSTNAME", vmState.name);

    Path vmConfigDirectoryPath = Files.createTempDirectory("iso-" + currentState.vmId).toAbsolutePath();
    Path userDataConfigFilePath = vmConfigDirectoryPath.resolve("user-data.yml");
    Files.write(userDataConfigFilePath, userDataConfigFileContent.getBytes(StandardCharsets.UTF_8));
    Path metadataConfigFilePath = vmConfigDirectoryPath.resolve("meta-data.yml");
    Files.write(metadataConfigFilePath, metadataConfigFileContent.getBytes(StandardCharsets.UTF_8));
    Path isoFilePath = vmConfigDirectoryPath.resolve("config.iso");

    List<String> command = new ArrayList<>();
    command.add("./" + SCRIPT_NAME);
    command.add(isoFilePath.toAbsolutePath().toString());
    command.add(userDataConfigFilePath.toAbsolutePath().toString());
    command.add(metadataConfigFilePath.toAbsolutePath().toString());
    command.add(currentState.serviceConfigDirectory);

    File scriptLogFile = new File(deployerContext.getScriptLogDirectory(), SCRIPT_NAME + "-" + vmState.vmId
            + "-" + ServiceUtils.getIDFromDocumentSelfLink(currentState.documentSelfLink) + ".log");

    ScriptRunner scriptRunner = new ScriptRunner.Builder(command, deployerContext.getScriptTimeoutSec())
            .directory(deployerContext.getScriptDirectory())
            .redirectOutput(ProcessBuilder.Redirect.to(scriptLogFile)).build();

    ListenableFutureTask<Integer> futureTask = ListenableFutureTask.create(scriptRunner);
    HostUtils.getListeningExecutorService(this).submit(futureTask);
    Futures.addCallback(futureTask, new FutureCallback<Integer>() {
        @Override
        public void onSuccess(@javax.validation.constraints.NotNull Integer result) {
            try {
                if (result != 0) {
                    logScriptErrorAndFail(currentState, result, scriptLogFile);
                } else {
                    State patchState = buildPatch(TaskState.TaskStage.STARTED, TaskState.SubStage.ATTACH_ISO,
                            null);
                    patchState.vmConfigDirectory = vmConfigDirectoryPath.toAbsolutePath().toString();
                    TaskUtils.sendSelfPatch(CreateManagementVmTaskService.this, patchState);
                }
            } catch (Throwable t) {
                failTask(t);
            }
        }

        @Override
        public void onFailure(Throwable throwable) {
            failTask(throwable);
        }
    });
}

From source file:com.vmware.photon.controller.deployer.dcp.task.CreateManagementVmTaskService.java

private void callAttachIso(State currentState) {

    ////  w w w  . ja v  a 2  s .c o  m
    // N.B. The uploadAndAttachIso call is performed on a separate thread because it is blocking.
    // This behavior can be removed if and when an asynchronous version of this call is added to
    // the Java API client library.
    //

    ListenableFutureTask<Task> futureTask = ListenableFutureTask
            .create(() -> HostUtils.getApiClient(this).getVmApi().uploadAndAttachIso(currentState.vmId,
                    Paths.get(currentState.vmConfigDirectory, "config.iso").toAbsolutePath().toString()));

    HostUtils.getListeningExecutorService(this).submit(futureTask);
    Futures.addCallback(futureTask, new FutureCallback<Task>() {
        @Override
        public void onSuccess(@javax.validation.constraints.NotNull Task task) {
            try {
                processAttachIsoTaskResult(currentState, task);
            } catch (Throwable t) {
                failTask(t);
            }
        }

        @Override
        public void onFailure(Throwable throwable) {
            failTask(throwable);
        }
    });
}