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() 

Source Link

Document

Constructs a TimeoutException with no specified detail message.

Usage

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

private void waitForServicesStartup(DeployerDcpServiceHost host)
        throws TimeoutException, InterruptedException, NoSuchFieldException, IllegalAccessException {

    serviceSelfLinks = ServiceHostUtils.getServiceSelfLinks(
            DeployerDcpServiceHost.FACTORY_SERVICE_FIELD_NAME_SELF_LINK,
            DeployerDcpServiceHost.FACTORY_SERVICES);

    final CountDownLatch latch = new CountDownLatch(serviceSelfLinks.size());
    Operation.CompletionHandler handler = new Operation.CompletionHandler() {
        @Override//from  w  w w.j a  v  a2 s .c  o  m
        public void handle(Operation completedOp, Throwable failure) {
            latch.countDown();
        }
    };

    String[] links = new String[serviceSelfLinks.size()];
    host.registerForServiceAvailability(handler, serviceSelfLinks.toArray(links));
    if (!latch.await(10, TimeUnit.SECONDS)) {
        throw new TimeoutException();
    }
}

From source file:org.fusesource.meshkeeper.util.DefaultProcessListener.java

public int waitForExit(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException {
    if (exitLatch.await(timeout, unit))
        return exitCode.get();
    throw new TimeoutException();
}

From source file:com.brienwheeler.lib.test.stepper.SteppableThread.java

public void releaseAndJoin() {
    try {//from w w  w .  j  a  v  a 2s .c  o  m
        release();
        verbose("joining " + getName());
        join(joinDelay);
        if (isAlive())
            throw new RuntimeException(new TimeoutException());
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new RuntimeException(e);
    }
}

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

private void waitForServicesStartup(DeployerXenonServiceHost host)
        throws TimeoutException, InterruptedException, NoSuchFieldException, IllegalAccessException {

    serviceSelfLinks = ServiceHostUtils.getServiceSelfLinks(
            DeployerXenonServiceHost.FACTORY_SERVICE_FIELD_NAME_SELF_LINK,
            DeployerXenonServiceHost.FACTORY_SERVICES);
    serviceSelfLinks.add(DeployerXenonServiceHost.UPLOAD_VIB_SCHEDULER_SERVICE);

    final CountDownLatch latch = new CountDownLatch(serviceSelfLinks.size());
    Operation.CompletionHandler handler = new Operation.CompletionHandler() {
        @Override/*from  w w w .  ja va 2 s.c  o m*/
        public void handle(Operation completedOp, Throwable failure) {
            latch.countDown();
        }
    };

    String[] links = new String[serviceSelfLinks.size()];
    host.registerForServiceAvailability(handler, serviceSelfLinks.toArray(links));
    if (!latch.await(10, TimeUnit.SECONDS)) {
        throw new TimeoutException();
    }
}

From source file:org.eclipse.flux.client.SingleResponseHandler.java

private void ensureTimeout() {
    if (!future.isDone() && TIME_OUT > 0 && timeoutStarted.compareAndSet(false, true)) {
        timer().schedule(new TimerTask() {
            @Override/*from  w  w  w. j  a v a 2  s.  c om*/
            public void run() {
                try {
                    future.reject(new TimeoutException());
                } catch (Throwable e) {
                    //don't let Exception fly.. or the timer thread will die!
                    e.printStackTrace();
                }
            }
        }, TIME_OUT);
    }
}

From source file:com.eventsourcing.hlc.NTPServerTimeProvider.java

TimeStamp getTimestamp() throws TimeoutException {
    if (timestamp == null) {
        throw new TimeoutException();
    }/* ww  w .  j a  v a2  s .  c  o  m*/
    TimeStamp ts = new TimeStamp(timestamp.ntpValue());
    long fraction = ts.getFraction();
    long seconds = ts.getSeconds();
    long nanoTime = System.nanoTime();
    long l = (nanoTime - nano) / 1_000_000_000;
    double v = (nanoTime - nano) / 1_000_000_000.0 - l;
    long i = (long) (v * 1_000_000_000);
    long fraction_ = fraction + i;
    if (fraction_ >= 1_000_000_000) {
        fraction_ -= 1_000_000_000;
        l++;
    }
    return new TimeStamp((seconds + l) << 32 | fraction_);
}

From source file:org.apache.servicemix.nmr.core.ChannelImpl.java

/**
 * Synchronously send the exchange/*  w w w .ja va  2  s. c  o  m*/
 *
 * @param exchange the exchange to send
 * @param timeout  time to wait in milliseconds
 * @return <code>true</code> if the exchange has been processed succesfully
 */
public boolean sendSync(Exchange exchange, long timeout) {
    InternalExchange e = (InternalExchange) exchange;
    Semaphore lock = e.getRole() == Role.Consumer ? e.getConsumerLock(true) : e.getProviderLock(true);
    dispatch(e);
    Thread thread = Thread.currentThread();
    String original = thread.getName();
    try {
        if (timeout > 0) {
            if (!lock.tryAcquire(timeout, TimeUnit.MILLISECONDS)) {
                throw new TimeoutException();
            }
        } else {
            thread.setName(original + " (waiting for exchange " + exchange.getId() + ")");
            lock.acquire();
        }
        e.setRole(e.getRole() == Role.Consumer ? Role.Provider : Role.Consumer);
    } catch (InterruptedException ex) {
        exchange.setError(ex);
        for (ExchangeListener l : nmr.getListenerRegistry().getListeners(ExchangeListener.class)) {
            l.exchangeFailed(exchange);
        }
        return false;
    } catch (TimeoutException ex) {
        exchange.setError(new AbortedException(ex));
        for (ExchangeListener l : nmr.getListenerRegistry().getListeners(ExchangeListener.class)) {
            l.exchangeFailed(exchange);
        }
        return false;
    } finally {
        thread.setName(original);
    }
    return true;
}

From source file:no.group09.connection.Protocol.java

/**
 * /*from   w  w  w .  j  a v a  2s.c o m*/
 * @throws TimeoutException
 */
protected void handshakeConnection() throws TimeoutException {
    ProtocolInstruction newInstruction = new ProtocolInstruction(OpCode.DEVICE_INFO, (byte) 0, new byte[1]);

    // Blocking method lock();
    lock();
    try {
        waitingForAck = OpCode.DEVICE_INFO;
        tempAckProcessor = OpCode.DEVICE_INFO;
        sendBytes(newInstruction.getInstructionBytes());
        Log.d(TAG, "Metadatarequest sucessfully SENT: " + newInstruction.getInstructionBytes());

    } catch (IOException ex) {
        Log.d(TAG, "Failed to send metadata request: " + ex);
    }
    release();

    //Wait until we get a response or a timeout
    long timeout = System.currentTimeMillis() + TIMEOUT;

    Log.d(TAG, "trying handshakeConnection()");

    while (waitingForAck != null) {

        //Waits 'timeout' seconds before it gives up
        if (System.currentTimeMillis() > timeout) {
            Log.d(TAG, "handshakeConnection() has timed out (did not recieve all data)");
            throw new TimeoutException();
        }

        //Wait 10 ms for a resonse
        try {
            Thread.sleep(10);
        } catch (InterruptedException ex) {
        }
    }

    if (currentCommand.getContent() != null) {

        //Build a string from the byte array
        String response = new String(currentCommand.getContent());

        //Finished processing this instruction
        tempAckProcessor = null;
        ackProcessingComplete();

        //Build a MetaData package out from the raw String object using JSON parsing
        try {
            connectionMetadata = new ConnectionMetadata(new JSONObject(response));
        } catch (JSONException e) {
            Log.d(TAG, "JSONException when constructing metadata: " + e);
        }
    } else {
        Log.d(TAG, "Got a nullpointer in protocol where it should not be null\n"
                + "(no bytes received from arduino)");
    }
}

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

private void waitForServicesStartup(PhotonControllerXenonHost host)
        throws TimeoutException, InterruptedException, NoSuchFieldException, IllegalAccessException {

    serviceSelfLinks = ServiceHostUtils.getServiceSelfLinks(
            DeployerServiceGroup.FACTORY_SERVICE_FIELD_NAME_SELF_LINK, DeployerServiceGroup.FACTORY_SERVICES);
    serviceSelfLinks.add(DeployerServiceGroup.UPLOAD_VIB_WORK_QUEUE_SELF_LINK);

    final CountDownLatch latch = new CountDownLatch(serviceSelfLinks.size());
    Operation.CompletionHandler handler = new Operation.CompletionHandler() {
        @Override//from   w  w w .  ja va2 s  . co  m
        public void handle(Operation completedOp, Throwable failure) {
            latch.countDown();
        }
    };

    String[] links = new String[serviceSelfLinks.size()];
    host.registerForServiceAvailability(handler, serviceSelfLinks.toArray(links));
    if (!latch.await(10, TimeUnit.SECONDS)) {
        throw new TimeoutException();
    }
}

From source file:org.openo.nfvo.jujuvnfmadapter.common.EntityUtils.java

/**
 * <br/>//from  w  ww .  ja  v a 2  s.  c  om
 * 
 * @param er
 * @param p
 * @throws TimeoutException
 * @throws InterruptedException
 * @since NFVO 0.5
 */
private static void buildProcessResult(ExeRes er, Process p) throws TimeoutException, InterruptedException {
    Worker worker = new Worker(p);
    worker.start();
    try {
        worker.join(Constant.PROCESS_WAIT_MILLIS);
        if (worker.exitValue != null) {
            int exit = worker.exitValue;
            if (exit != 0) {
                er.setCode(ExeRes.FAILURE);
                LOG.warn("the process exit non-normal");
            } else {
                er.setCode(ExeRes.SUCCESS);
            }
        } else {
            er.setCode(ExeRes.FAILURE);
            LOG.warn("the process execute timeout.");
            throw new TimeoutException();
        }
    } catch (InterruptedException e) {
        worker.interrupt();
        Thread.currentThread().interrupt();
        throw e;
    }
}