Example usage for java.lang InterruptedException getCause

List of usage examples for java.lang InterruptedException getCause

Introduction

In this page you can find the example usage for java.lang InterruptedException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.apache.pulsar.broker.admin.impl.NamespacesBase.java

protected void internalGrantPermissionOnNamespace(String role, Set<AuthAction> actions) {
    validateAdminAccessForTenant(namespaceName.getTenant());

    try {/* w  ww  .j  a v  a 2s. c om*/
        AuthorizationService authService = pulsar().getBrokerService().getAuthorizationService();
        if (null != authService) {
            authService.grantPermissionAsync(namespaceName, actions, role, null/*additional auth-data json*/)
                    .get();
        } else {
            throw new RestException(Status.NOT_IMPLEMENTED, "Authorization is not enabled");
        }
    } catch (InterruptedException e) {
        log.error("[{}] Failed to get permissions for namespace {}", clientAppId(), namespaceName, e);
        throw new RestException(e);
    } catch (ExecutionException e) {
        if (e.getCause() instanceof IllegalArgumentException) {
            log.warn("[{}] Failed to set permissions for namespace {}: does not exist", clientAppId(),
                    namespaceName);
            throw new RestException(Status.NOT_FOUND, "Namespace does not exist");
        } else if (e.getCause() instanceof IllegalStateException) {
            log.warn("[{}] Failed to set permissions for namespace {}: concurrent modification", clientAppId(),
                    namespaceName);
            throw new RestException(Status.CONFLICT, "Concurrent modification");
        } else {
            log.error("[{}] Failed to get permissions for namespace {}", clientAppId(), namespaceName, e);
            throw new RestException(e);
        }
    }
}

From source file:org.apache.pulsar.broker.admin.impl.NamespacesBase.java

protected void internalGrantPermissionOnSubscription(String subscription, Set<String> roles) {
    /** controlled by system-admin(super-user) to prevent metadata footprint size */
    validateSuperUserAccess();//  w  w  w. j av a  2  s  . c om

    try {
        AuthorizationService authService = pulsar().getBrokerService().getAuthorizationService();
        if (null != authService) {
            authService.grantSubscriptionPermissionAsync(namespaceName, subscription, roles,
                    null/* additional auth-data json */).get();
        } else {
            throw new RestException(Status.NOT_IMPLEMENTED, "Authorization is not enabled");
        }
    } catch (InterruptedException e) {
        log.error("[{}] Failed to get permissions for namespace {}", clientAppId(), namespaceName, e);
        throw new RestException(e);
    } catch (ExecutionException e) {
        if (e.getCause() instanceof IllegalArgumentException) {
            log.warn("[{}] Failed to set permissions for namespace {}: does not exist", clientAppId(),
                    namespaceName);
            throw new RestException(Status.NOT_FOUND, "Namespace does not exist");
        } else if (e.getCause() instanceof IllegalStateException) {
            log.warn("[{}] Failed to set permissions for namespace {}: concurrent modification", clientAppId(),
                    namespaceName);
            throw new RestException(Status.CONFLICT, "Concurrent modification");
        } else {
            log.error("[{}] Failed to get permissions for namespace {}", clientAppId(), namespaceName, e);
            throw new RestException(e);
        }
    }
}

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

/**
 * Gets access to a view contained in a design document from the cluster.
 *
 * The purpose of a view is take the structured data stored within the
 * Couchbase Server database as JSON documents, extract the fields and
 * information, and to produce an index of the selected information.
 *
 * The result is a view on the stored data. The view that is created
 * during this process allows you to iterate, select and query the
 * information in your database from the raw data objects that have
 * been stored./*from   w  w  w .j a  v a 2 s.  com*/
 *
 * @param designDocumentName the name of the design document.
 * @param viewName the name of the view to get.
 * @return a View object from the cluster.
 * @throws InvalidViewException if no design document or view was found.
 * @throws CancellationException if operation was canceled.
 */
public View getView(final String designDocumentName, final String viewName) {
    try {
        View view = asyncGetView(designDocumentName, viewName).get();
        if (view == null) {
            throw new InvalidViewException(
                    "Could not load view \"" + viewName + "\" for design doc \"" + designDocumentName + "\"");
        }
        return view;
    } catch (InterruptedException e) {
        throw new RuntimeException("Interrupted getting views", e);
    } catch (ExecutionException e) {
        if (e.getCause() instanceof CancellationException) {
            throw (CancellationException) e.getCause();
        } else {
            throw new RuntimeException("Failed getting views", e);
        }
    }
}

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

/**
 * Getl with a single key. By default the maximum allowed timeout is 30
 * seconds. Timeouts greater than this will be set to 30 seconds.
 *
 * @param key the key to get and lock//from  ww w  .j  ava 2 s  .co  m
 * @param exp the amount of time the lock should be valid for in seconds.
 * @param tc the transcoder to serialize and unserialize value
 * @return the result from the cache (null if there is none)
 * @throws OperationTimeoutException if the global operation timeout is
 *           exceeded
 * @throws IllegalStateException in the rare circumstance where queue is too
 *           full to accept any more requests
 * @throws CancellationException if operation was canceled
 */
public <T> CASValue<T> getAndLock(String key, int exp, Transcoder<T> tc) {
    try {
        return asyncGetAndLock(key, exp, tc).get(operationTimeout, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
        throw new RuntimeException("Interrupted waiting for value", e);
    } catch (ExecutionException e) {
        if (e.getCause() instanceof CancellationException) {
            throw (CancellationException) e.getCause();
        } else {
            throw new RuntimeException("Exception waiting for value", e);
        }
    } catch (TimeoutException e) {
        throw new OperationTimeoutException("Timeout waiting for value", e);
    }
}

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

/**
 * Unlock the given key synchronously from the cache.
 *
 * @param key the key to unlock/*from   w w  w  .  j  av  a  2 s  . c  om*/
 * @param casId the CAS identifier
 * @param tc the transcoder to serialize and unserialize value
 * @return whether or not the operation was performed
 * @throws IllegalStateException in the rare circumstance where queue is too
 *           full to accept any more requests
 * @throws CancellationException if operation was canceled
 */
public <T> Boolean unlock(final String key, long casId, final Transcoder<T> tc) {
    try {
        return asyncUnlock(key, casId, tc).get(operationTimeout, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
        throw new RuntimeException("Interrupted waiting for value", e);
    } catch (ExecutionException e) {
        if (e.getCause() instanceof CancellationException) {
            throw (CancellationException) e.getCause();
        } else {
            throw new RuntimeException("Exception waiting for value", e);
        }
    } catch (TimeoutException e) {
        throw new OperationTimeoutException("Timeout waiting for value", e);
    }

}

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

/**
 * Queries a Couchbase view and returns the result.
 * The result can be accessed row-wise via an iterator.
 * This type of query will return the view result along
 * with all of the documents for each row in
 * the query.//from   ww w  .  ja v  a  2  s  .c om
 *
 * @param view the view to run the query against.
 * @param query the type of query to run against the view.
 * @return a ViewResponseWithDocs containing the results of the query.
 * @throws CancellationException if operation was canceled.
 */
public ViewResponse query(AbstractView view, Query query) {
    try {
        return asyncQuery(view, query).get();
    } catch (InterruptedException e) {
        throw new RuntimeException("Interrupted while accessing the view", e);
    } catch (ExecutionException e) {
        if (e.getCause() instanceof CancellationException) {
            throw (CancellationException) e.getCause();
        } else {
            throw new RuntimeException("Failed to access the view", e);
        }
    }
}

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

/**
 * Gets access to a spatial view contained in a design document from the
 * cluster./*from w  w w  .  j a v  a  2  s  .c  o  m*/
 *
 * Spatial views enable you to return recorded geometry data in the bucket
 * and perform queries which return information based on whether the recorded
 * geometries existing within a given two-dimensional range such as a
 * bounding box.
 *
 * @param designDocumentName the name of the design document.
 * @param viewName the name of the view to get.
 * @return a SpatialView object from the cluster.
 * @throws InvalidViewException if no design document or view was found.
 * @throws CancellationException if operation was canceled.
 */
public SpatialView getSpatialView(final String designDocumentName, final String viewName) {
    try {
        SpatialView view = asyncGetSpatialView(designDocumentName, viewName).get();
        if (view == null) {
            throw new InvalidViewException("Could not load spatial view \"" + viewName + "\" for design doc \""
                    + designDocumentName + "\"");
        }
        return view;
    } catch (InterruptedException e) {
        throw new RuntimeException("Interrupted getting spatial view", e);
    } catch (ExecutionException e) {
        if (e.getCause() instanceof CancellationException) {
            throw (CancellationException) e.getCause();
        } else {
            throw new RuntimeException("Failed getting views", e);
        }
    }
}

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

/**
 * Store a design document in the cluster.
 *
 * @param doc the design document to store.
 * @return the result of the creation operation.
 * @throws CancellationException if operation was canceled.
 *//*from w  w w. j  a  va  2  s .c  o m*/
public Boolean createDesignDoc(final DesignDocument doc) {
    try {
        return asyncCreateDesignDoc(doc).get();
    } catch (InterruptedException e) {
        throw new RuntimeException("Interrupted creating design document", e);
    } catch (ExecutionException e) {
        if (e.getCause() instanceof CancellationException) {
            throw (CancellationException) e.getCause();
        } else {
            throw new RuntimeException("Failed creating design document", e);
        }
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException("Failed creating design document", e);
    }
}

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

/**
 * Delete a design document in the cluster.
 *
 * @param name the design document to delete.
 * @return the result of the deletion operation.
 * @throws CancellationException if operation was canceled.
 */// w  ww  . j  av  a2s  . c o m
public Boolean deleteDesignDoc(final String name) {
    try {
        return asyncDeleteDesignDoc(name).get();
    } catch (InterruptedException e) {
        throw new RuntimeException("Interrupted deleting design document", e);
    } catch (ExecutionException e) {
        if (e.getCause() instanceof CancellationException) {
            throw (CancellationException) e.getCause();
        } else {
            throw new RuntimeException("Failed deleting design document", e);
        }
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException("Failed deleting design document", e);
    }
}

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

/**
 * Returns a representation of a design document stored in the cluster.
 *
 * @param designDocumentName the name of the design document.
 * @return a DesignDocument object from the cluster.
 * @throws InvalidViewException if no design document or view was found.
 * @throws CancellationException if operation was canceled.
 *//*from   ww w .  j av  a 2s . c  o  m*/
public DesignDocument getDesignDocument(final String designDocumentName) {
    try {
        DesignDocument design = asyncGetDesignDocument(designDocumentName).get();
        if (design == null) {
            throw new InvalidViewException("Could not load design document \"" + designDocumentName + "\"");
        }
        return design;
    } catch (InterruptedException e) {
        throw new RuntimeException("Interrupted getting design document", e);
    } catch (ExecutionException e) {
        if (e.getCause() instanceof CancellationException) {
            throw (CancellationException) e.getCause();
        } else {
            throw new RuntimeException("Failed getting design document", e);
        }
    }
}