Example usage for com.google.common.util.concurrent FutureCallback onFailure

List of usage examples for com.google.common.util.concurrent FutureCallback onFailure

Introduction

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

Prototype

void onFailure(Throwable t);

Source Link

Document

Invoked when a Future computation fails or is canceled.

Usage

From source file:com.vmware.photon.controller.api.client.resource.VmRestApi.java

/**
 * Get tasks associated with the specified vm.
 * @param vmId//from ww w.ja v a 2  s.c  om
 * @param responseCallback
 * @throws IOException
 */
@Override
public void getTasksForVmAsync(final String vmId, final FutureCallback<ResourceList<Task>> responseCallback)
        throws IOException {
    String path = String.format("%s/%s/tasks", getBasePath(), vmId);

    ResourceList<Task> taskResourceList = new ResourceList<>();
    FutureCallback<ResourceList<Task>> callback = new FutureCallback<ResourceList<Task>>() {
        @Override
        public void onSuccess(@Nullable ResourceList<Task> result) {
            if (taskResourceList.getItems() == null) {
                taskResourceList.setItems(result.getItems());
            } else {
                taskResourceList.getItems().addAll(result.getItems());
            }
            if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) {
                try {
                    getObjectByPathAsync(result.getNextPageLink(), this,
                            new TypeReference<ResourceList<Task>>() {
                            });
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else {
                responseCallback.onSuccess(taskResourceList);
            }
        }

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

    getObjectByPathAsync(path, callback, new TypeReference<ResourceList<Task>>() {
    });
}

From source file:com.vmware.photon.controller.api.client.resource.TenantsApi.java

/**
 * Returns a list of all resource tickets for the specified tenant.
 *
 * @param tenantId//from  w w  w .  j av  a2  s.  c o m
 * @param responseCallback
 * @throws IOException
 */
public void getResourceTicketsAsync(final String tenantId,
        final FutureCallback<ResourceList<ResourceTicket>> responseCallback) throws IOException {
    String path = String.format("%s/%s/resource-tickets", getBasePath(), tenantId);

    ResourceList<ResourceTicket> resourceTicketResourceList = new ResourceList<>();
    FutureCallback<ResourceList<ResourceTicket>> callback = new FutureCallback<ResourceList<ResourceTicket>>() {
        @Override
        public void onSuccess(@Nullable ResourceList<ResourceTicket> result) {
            if (resourceTicketResourceList.getItems() == null) {
                resourceTicketResourceList.setItems(result.getItems());
            } else {
                resourceTicketResourceList.getItems().addAll(result.getItems());
            }
            if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) {
                try {
                    getObjectByPathAsync(result.getNextPageLink(), this,
                            new TypeReference<ResourceList<ResourceTicket>>() {
                            });
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else {
                responseCallback.onSuccess(resourceTicketResourceList);
            }
        }

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

    getObjectByPathAsync(path, callback, new TypeReference<ResourceList<ResourceTicket>>() {
    });
}

From source file:com.vmware.photon.controller.api.client.resource.ProjectRestApi.java

/**
 * Get tasks associated with the specified project.
 *
 * @param projectId//  w ww  .jav a2s. co  m
 * @param responseCallback
 * @throws IOException
 */
@Override
public void getTasksForProjectAsync(final String projectId,
        final FutureCallback<ResourceList<Task>> responseCallback) throws IOException {
    final String path = String.format("%s/%s/tasks", getBasePath(), projectId);

    ResourceList<Task> taskResourceList = new ResourceList<>();
    FutureCallback<ResourceList<Task>> callback = new FutureCallback<ResourceList<Task>>() {
        @Override
        public void onSuccess(@Nullable ResourceList<Task> result) {
            if (taskResourceList.getItems() == null) {
                taskResourceList.setItems(result.getItems());
            } else {
                taskResourceList.getItems().addAll(result.getItems());
            }
            if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) {
                try {
                    getObjectByPathAsync(result.getNextPageLink(), this,
                            new TypeReference<ResourceList<Task>>() {
                            });
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else {
                responseCallback.onSuccess(taskResourceList);
            }
        }

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

    getObjectByPathAsync(path, callback, new TypeReference<ResourceList<Task>>() {
    });
}

From source file:com.vmware.photon.controller.api.client.resource.TenantsRestApi.java

/**
 * Returns a list of all resource tickets for the specified tenant.
 *
 * @param tenantId//from  www  .ja  v  a  2  s.  c  om
 * @param responseCallback
 * @throws IOException
 */
@Override
public void getResourceTicketsAsync(final String tenantId,
        final FutureCallback<ResourceList<ResourceTicket>> responseCallback) throws IOException {
    String path = String.format("%s/%s/resource-tickets", getBasePath(), tenantId);

    ResourceList<ResourceTicket> resourceTicketResourceList = new ResourceList<>();
    FutureCallback<ResourceList<ResourceTicket>> callback = new FutureCallback<ResourceList<ResourceTicket>>() {
        @Override
        public void onSuccess(@Nullable ResourceList<ResourceTicket> result) {
            if (resourceTicketResourceList.getItems() == null) {
                resourceTicketResourceList.setItems(result.getItems());
            } else {
                resourceTicketResourceList.getItems().addAll(result.getItems());
            }
            if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) {
                try {
                    getObjectByPathAsync(result.getNextPageLink(), this,
                            new TypeReference<ResourceList<ResourceTicket>>() {
                            });
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else {
                responseCallback.onSuccess(resourceTicketResourceList);
            }
        }

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

    getObjectByPathAsync(path, callback, new TypeReference<ResourceList<ResourceTicket>>() {
    });
}

From source file:com.vmware.photon.controller.api.client.resource.ProjectApi.java

/**
 * Get a list of clusters in the specified project.
 *
 * @param projectId//from  w w w  .j  ava2s .  com
 * @param responseCallback
 * @throws IOException
 */
public void getClustersInProjectAsync(final String projectId,
        final FutureCallback<ResourceList<Cluster>> responseCallback) throws IOException {
    String path = String.format("%s/%s/clusters", getBasePath(), projectId);

    ResourceList<Cluster> clusterResourceList = new ResourceList<>();
    FutureCallback<ResourceList<Cluster>> callback = new FutureCallback<ResourceList<Cluster>>() {
        @Override
        public void onSuccess(@Nullable ResourceList<Cluster> result) {
            if (clusterResourceList.getItems() == null) {
                clusterResourceList.setItems(result.getItems());
            } else {
                clusterResourceList.getItems().addAll(result.getItems());
            }
            if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) {
                try {
                    getObjectByPathAsync(result.getNextPageLink(), this,
                            new TypeReference<ResourceList<Cluster>>() {
                            });
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else {
                responseCallback.onSuccess(clusterResourceList);
            }
        }

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

    getObjectByPathAsync(path, callback, new TypeReference<ResourceList<Cluster>>() {
    });
}

From source file:com.vmware.photon.controller.api.client.resource.ProjectRestApi.java

/**
 * Get a list of clusters in the specified project.
 *
 * @param projectId//from  w ww .ja  v a2s.c  o  m
 * @param responseCallback
 * @throws IOException
 */
@Override
public void getClustersInProjectAsync(final String projectId,
        final FutureCallback<ResourceList<Cluster>> responseCallback) throws IOException {
    String path = String.format("%s/%s/clusters", getBasePath(), projectId);

    ResourceList<Cluster> clusterResourceList = new ResourceList<>();
    FutureCallback<ResourceList<Cluster>> callback = new FutureCallback<ResourceList<Cluster>>() {
        @Override
        public void onSuccess(@Nullable ResourceList<Cluster> result) {
            if (clusterResourceList.getItems() == null) {
                clusterResourceList.setItems(result.getItems());
            } else {
                clusterResourceList.getItems().addAll(result.getItems());
            }
            if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) {
                try {
                    getObjectByPathAsync(result.getNextPageLink(), this,
                            new TypeReference<ResourceList<Cluster>>() {
                            });
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else {
                responseCallback.onSuccess(clusterResourceList);
            }
        }

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

    getObjectByPathAsync(path, callback, new TypeReference<ResourceList<Cluster>>() {
    });
}

From source file:org.d4rxh4wx.thread.executor.CustomUserThreadPoolExecutor.java

public <T> void submit(final Callable<T> task, final FutureCallback<T> future) {
    // Increment submitted tasks
    nbSubmittedTasks.incrementAndGet();/* w w w.j  a  v a  2  s  .  com*/

    // Verifing quota is reached (blocking waiting, non-consumptive for CPU, thanks to use of BlockingQueue.put())
    try {

        logBeforePuttingToken();

        long start = System.currentTimeMillis();

        bq.put(TOKEN);

        logAfterPuttingToken(start);
    } catch (InterruptedException e) {
        throw new RuntimeException("Error while trying to put in blockingqueue", e);
    }

    logBeforeSubmitToSharedThreadPool();

    // Submit task to shared ThreadPoolExecutor
    // This is a ListeningThreadPoolTaskExecutor: it returns a ListenableFuture
    ListenableFuture<T> futureTask = (ListenableFuture<T>) service.submit(task);

    // Adding a callback to this future
    Futures.addCallback(futureTask, new FutureCallback<T>() {

        public void onSuccess(T task) {

            logSuccessBeforePolling();

            // releasing token and add to completed tasks
            bq.poll();
            doneTasks.add(TOKEN);

            logSuccessAfterPolling();

            if (future != null) {
                future.onSuccess(task);
            }
        }

        public void onFailure(Throwable thrown) {

            logFailureBeforePolling();

            // releasing token and add to completed tasks
            bq.poll();
            doneTasks.add(TOKEN);

            logFailureAfterPolling();

            if (future != null) {
                future.onFailure(thrown);
            }
        }
    });
}

From source file:com.vmware.photon.controller.api.client.resource.ProjectApi.java

/**
 * Get the list of persistent disks in the specified project.
 *
 * @param projectId//  w  w w .j  a  va 2  s. c  o  m
 * @param responseCallback
 * @throws IOException
 */
public void getDisksInProjectAsync(final String projectId,
        final FutureCallback<ResourceList<PersistentDisk>> responseCallback) throws IOException {
    final String path = String.format("%s/%s/disks", getBasePath(), projectId);

    ResourceList<PersistentDisk> persistentDiskResourceList = new ResourceList<>();
    FutureCallback<ResourceList<PersistentDisk>> callback = new FutureCallback<ResourceList<PersistentDisk>>() {
        @Override
        public void onSuccess(@Nullable ResourceList<PersistentDisk> result) {
            if (persistentDiskResourceList.getItems() == null) {
                persistentDiskResourceList.setItems(result.getItems());
            } else {
                persistentDiskResourceList.getItems().addAll(result.getItems());
            }
            if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) {
                try {
                    getObjectByPathAsync(result.getNextPageLink(), this,
                            new TypeReference<ResourceList<PersistentDisk>>() {
                            });
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else {
                responseCallback.onSuccess(persistentDiskResourceList);
            }
        }

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

    getObjectByPathAsync(path, callback, new TypeReference<ResourceList<PersistentDisk>>() {
    });
}

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

private void applyMustacheParameters(String mustacheDirectory, ContainerService.State containerService,
        String containerType, FutureCallback<ContainerService.State> callback) {
    ServiceConfigurator serviceConfigurator = HostUtils.getServiceConfiguratorFactory(this).create();

    try {/*from  ww w.  j  av a 2  s .  c  o m*/
        Map<String, Object> dynamicParameters = new HashMap<>();
        if (containerService.dynamicParameters != null) {
            dynamicParameters.putAll(containerService.dynamicParameters);
        }

        // Deserialize the string to get load balancer servers and zookeeper quorum
        Type lbType = new TypeToken<ArrayList<LoadBalancerServer>>() {
        }.getType();
        dynamicParameters.computeIfPresent(BuildRuntimeConfigurationTaskService.ENV_LOADBALANCER_SERVERS,
                (k, v) -> new Gson().fromJson(v.toString(), lbType));
        Type zkType = new TypeToken<ArrayList<ZookeeperServer>>() {
        }.getType();
        dynamicParameters.computeIfPresent(BuildRuntimeConfigurationTaskService.ENV_ZOOKEEPER_QUORUM,
                (k, v) -> new Gson().fromJson(v.toString(), zkType));

        serviceConfigurator.applyDynamicParameters(mustacheDirectory,
                ContainersConfig.ContainerType.valueOf(containerType), dynamicParameters);
        callback.onSuccess(containerService);
    } catch (Throwable t) {
        callback.onFailure(t);
    }
}

From source file:com.vmware.photon.controller.api.client.resource.ProjectApi.java

/**
 * Get a list of vms in the specified project.
 *
 * @param projectId// w  w w. j  a  v a 2 s .  co  m
 * @param responseCallback
 * @throws IOException
 */
public void getVmsInProjectAsync(final String projectId,
        final FutureCallback<ResourceList<FlavoredCompact>> responseCallback) throws IOException {
    final String path = String.format("%s/%s/vms", getBasePath(), projectId);

    ResourceList<FlavoredCompact> flavoredCompactResourceList = new ResourceList<>();
    FutureCallback<ResourceList<FlavoredCompact>> callback = new FutureCallback<ResourceList<FlavoredCompact>>() {
        @Override
        public void onSuccess(@Nullable ResourceList<FlavoredCompact> result) {
            if (flavoredCompactResourceList.getItems() == null) {
                flavoredCompactResourceList.setItems(result.getItems());
            } else {
                flavoredCompactResourceList.getItems().addAll(result.getItems());
            }
            if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) {
                try {
                    getObjectByPathAsync(result.getNextPageLink(), this,
                            new TypeReference<ResourceList<FlavoredCompact>>() {
                            });
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else {
                responseCallback.onSuccess(flavoredCompactResourceList);
            }
        }

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

    getObjectByPathAsync(path, callback, new TypeReference<ResourceList<FlavoredCompact>>() {
    });
}