Example usage for java.util.concurrent TimeoutException TimeoutException

List of usage examples for java.util.concurrent TimeoutException TimeoutException

Introduction

In this page you can find the example usage for java.util.concurrent TimeoutException TimeoutException.

Prototype

public TimeoutException(String message) 

Source Link

Document

Constructs a TimeoutException with the specified detail message.

Usage

From source file:com.couchbase.client.CouchbaseClient.java

/**
* Flush all caches from all servers with a delay of application.
*
* @param delay the period of time to delay, in seconds
* @return whether or not the operation was accepted
*//*from www.  j a  v a2  s.  com*/
@Override
public OperationFuture<Boolean> flush(final int delay) {

    final CountDownLatch latch = new CountDownLatch(1);
    final FlushRunner flushRunner = new FlushRunner(latch);

    final OperationFuture<Boolean> rv = new OperationFuture<Boolean>("", latch, operationTimeout) {
        private CouchbaseConnectionFactory factory = (CouchbaseConnectionFactory) connFactory;

        @Override
        public boolean cancel() {
            throw new UnsupportedOperationException("Flush cannot be" + " canceled");
        }

        @Override
        public boolean isDone() {
            return flushRunner.status();
        }

        @Override
        public Boolean get(long duration, TimeUnit units)
                throws InterruptedException, TimeoutException, ExecutionException {
            if (!latch.await(duration, units)) {
                throw new TimeoutException("Flush not completed within" + " timeout.");
            }

            return flushRunner.status();
        }

        @Override
        public Boolean get() throws InterruptedException, ExecutionException {
            try {
                return get(factory.getViewTimeout(), TimeUnit.MILLISECONDS);
            } catch (TimeoutException e) {
                throw new RuntimeException("Timed out waiting for operation", e);
            }
        }

        @Override
        public Long getCas() {
            throw new UnsupportedOperationException("Flush has no CAS" + " value.");
        }

        @Override
        public String getKey() {
            throw new UnsupportedOperationException("Flush has no" + " associated key.");
        }

        @Override
        public OperationStatus getStatus() {
            throw new UnsupportedOperationException("Flush has no" + " OperationStatus.");
        }

        @Override
        public boolean isCancelled() {
            throw new UnsupportedOperationException("Flush cannot be" + " canceled.");
        }
    };

    Thread flusher = new Thread(flushRunner, "Temporary Flusher");
    flusher.setDaemon(true);
    flusher.start();

    return rv;
}

From source file:org.cloudifysource.rest.controllers.ServiceController.java

private void deployAndWait(final String serviceName, final ElasticStatefulProcessingUnitDeployment deployment)
        throws TimeoutException, AdminException {
    final ProcessingUnit pu = getGridServiceManager().deploy(deployment, 60, TimeUnit.SECONDS);
    if (pu == null) {
        throw new TimeoutException("Timed out waiting for Service " + serviceName + " deployment.");
    }//from  ww w . j a v  a 2s  .  c  o  m
}

From source file:com.cloud.hypervisor.xenserver.resource.CitrixResourceBase.java

public void waitForTask(final Connection c, final Task task, final long pollInterval, final long timeout)
        throws XenAPIException, XmlRpcException, TimeoutException {
    final long beginTime = System.currentTimeMillis();
    if (s_logger.isTraceEnabled()) {
        s_logger.trace("Task " + task.getNameLabel(c) + " (" + task.getUuid(c) + ") sent to "
                + c.getSessionReference() + " is pending completion with a " + timeout + "ms timeout");
    }// w  w w .jav a  2  s.co m
    while (task.getStatus(c) == Types.TaskStatusType.PENDING) {
        try {
            if (s_logger.isTraceEnabled()) {
                s_logger.trace("Task " + task.getNameLabel(c) + " (" + task.getUuid(c)
                        + ") is pending, sleeping for " + pollInterval + "ms");
            }
            Thread.sleep(pollInterval);
        } catch (final InterruptedException e) {
        }
        if (System.currentTimeMillis() - beginTime > timeout) {
            final String msg = "Async " + timeout / 1000 + " seconds timeout for task " + task.toString();
            s_logger.warn(msg);
            task.cancel(c);
            task.destroy(c);
            throw new TimeoutException(msg);
        }
    }
}