Example usage for java.util.concurrent ExecutionException ExecutionException

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

Introduction

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

Prototype

public ExecutionException(Throwable cause) 

Source Link

Document

Constructs an ExecutionException with the specified cause.

Usage

From source file:org.jclouds.blobstore.integration.internal.StubAsyncBlobStore.java

public void throwResponseException(int code) throws ExecutionException {
    HttpResponse response = null;// w ww. ja v a 2  s  .  c  o m
    response = new HttpResponse(); // TODO: Get real object URL?
    response.setStatusCode(code);
    throw new ExecutionException(new HttpResponseException(new HttpCommand() {

        public int getRedirectCount() {
            return 0;
        }

        public int incrementRedirectCount() {
            return 0;
        }

        public boolean isReplayable() {
            return false;
        }

        public HttpRequest setHostAndPort(String host, int port) {
            return null;
        }

        public HttpRequest setMethod(String method) {
            return null;
        }

        public Exception getException() {
            return null;
        }

        public int getFailureCount() {
            return 0;
        }

        public HttpRequest getRequest() {
            return new HttpRequest("GET", URI.create("http://stub"));
        }

        public int incrementFailureCount() {
            return 0;
        }

        public void setException(Exception exception) {

        }
    }, response));
}

From source file:org.jclouds.blobstore.integration.internal.StubAsyncBlobStore.java

public Future<? extends Blob> getBlob(final String bucketName, final String key, GetOptions... optionsList) {
    final GetOptions options = (optionsList.length == 0) ? new GetOptions() : optionsList[0];
    return new FutureBase<Blob>() {
        public Blob get() throws InterruptedException, ExecutionException {
            if (!getContainerToBlobs().containsKey(bucketName))
                throw new ContainerNotFoundException(bucketName);
            Map<String, Blob> realContents = getContainerToBlobs().get(bucketName);
            if (!realContents.containsKey(key))
                throw new KeyNotFoundException(bucketName, key);

            Blob object = realContents.get(key);

            if (options.getIfMatch() != null) {
                if (!object.getMetadata().getETag().equals(options.getIfMatch()))
                    throwResponseException(412);
            }/*from ww  w.ja v  a 2 s . co m*/
            if (options.getIfNoneMatch() != null) {
                if (object.getMetadata().getETag().equals(options.getIfNoneMatch()))
                    throwResponseException(304);
            }
            if (options.getIfModifiedSince() != null) {
                DateTime modifiedSince = options.getIfModifiedSince();
                if (object.getMetadata().getLastModified().isBefore(modifiedSince)) {
                    HttpResponse response = new HttpResponse();
                    response.setStatusCode(304);
                    throw new ExecutionException(new HttpResponseException(String.format("%1$s is before %2$s",
                            object.getMetadata().getLastModified(), modifiedSince), null, response));
                }

            }
            if (options.getIfUnmodifiedSince() != null) {
                DateTime unmodifiedSince = options.getIfUnmodifiedSince();
                if (object.getMetadata().getLastModified().isAfter(unmodifiedSince)) {
                    HttpResponse response = new HttpResponse();
                    response.setStatusCode(412);
                    throw new ExecutionException(new HttpResponseException(String.format("%1$s is after %2$s",
                            object.getMetadata().getLastModified(), unmodifiedSince), null, response));
                }
            }
            Blob returnVal = copyBlob(object);

            if (options.getRanges() != null && options.getRanges().size() > 0) {
                byte[] data = (byte[]) returnVal.getData();
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                for (String s : options.getRanges()) {
                    if (s.startsWith("-")) {
                        int length = Integer.parseInt(s);
                        out.write(data, data.length - length, length);
                    } else if (s.endsWith("-")) {
                        int offset = Integer.parseInt(s);
                        out.write(data, offset, data.length - offset);
                    } else if (s.contains("-")) {
                        String[] firstLast = s.split("\\-");
                        int offset = Integer.parseInt(firstLast[0]);
                        int last = Integer.parseInt(firstLast[1]);
                        int length = (last < data.length) ? last + 1 : data.length - offset;
                        out.write(data, offset, length);
                    } else {
                        throw new IllegalArgumentException("first and last were null!");
                    }

                }
                returnVal.setData(out.toByteArray());
                returnVal.setContentLength(out.size());
                returnVal.getMetadata().setSize(new Long(data.length));
            }
            returnVal.setData(new ByteArrayInputStream((byte[]) returnVal.getData()));
            return returnVal;
        }
    };
}

From source file:org.cleverbus.component.externalcall.ExternalCallComponentTest.java

private Future<String> getStringBodyFuture(final Future<Exchange> reply) {
    return new Future<String>() {
        @Override/*from   w  ww . j av  a  2 s .c  o m*/
        public boolean cancel(boolean mayInterruptIfRunning) {
            return reply.cancel(mayInterruptIfRunning);
        }

        @Override
        public boolean isCancelled() {
            return reply.isCancelled();
        }

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

        @Override
        public String get() throws InterruptedException, ExecutionException {
            return getReplyString(reply.get());
        }

        @Override
        public String get(long timeout, TimeUnit unit)
                throws InterruptedException, ExecutionException, TimeoutException {
            return getReplyString(reply.get(timeout, unit));
        }

        private String getReplyString(Exchange exchange) throws InterruptedException, ExecutionException {
            throwExceptionOptionally(exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class));
            throwExceptionOptionally(exchange.getException());
            return exchange.getOut().getBody(String.class);
        }

        private void throwExceptionOptionally(Exception exc) throws InterruptedException, ExecutionException {
            if (exc != null) {
                if (exc instanceof InterruptedException) {
                    throw (InterruptedException) exc;
                } else if (exc instanceof ExecutionException) {
                    throw (ExecutionException) exc;
                } else {
                    throw new ExecutionException(exc);
                }
            }
        }
    };
}

From source file:org.limewire.mojito.routing.impl.RouteTableImpl.java

/**
 * Pings the given Contact and adds the given DHTEventListener to
 * the DHTFuture if it's not null./*from ww w.jav  a2 s .  c o m*/
 */
private void ping(Contact node, DHTFutureListener<PingResult> listener) {
    ContactPinger pinger = this.pinger;
    if (pinger != null) {
        pinger.ping(node, listener);
    } else {
        handleFailure(node.getNodeID(), node.getContactAddress());

        if (listener != null) {
            ExecutionException exception = new ExecutionException(
                    new DHTTimeoutException(node.getNodeID(), node.getContactAddress(), null, 0L));
            listener.handleExecutionException(exception);
        }
    }
}

From source file:de.fiz.ddb.aas.utils.LDAPEngineUtilityOrganisation.java

private boolean convertOrganizationToLdapOrgAttrs(Organisation pOrganisation,
        final Organisation pOldOrganisation, Attributes pOrgAttributes, Attributes pOrgRemoveAttributes,
        boolean isUpdate, final AasPrincipal performer) throws ExecutionException {
    boolean hasChanged = false;
    if ((pOrganisation != null) && (pOrgAttributes != null)) {
        // -- Organisation Krzel:
        pOrgAttributes.put(new BasicAttribute("o", pOrganisation.getId()));

        // hierarchical sort
        // reverse orgrdn
        if (pOrganisation.getOrgRDN() != null) {
            String[] parts = pOrganisation.getOrgRDN().split(",");
            if (parts != null && parts.length > 0) {
                StringBuilder builder = new StringBuilder();
                for (int i = parts.length - 1; i >= 0; i--) {
                    builder.append(parts[i]);
                    if (i > 0) {
                        builder.append("|");
                    }//from  w  ww.j a  v  a 2  s. c  om
                }
                pOrgAttributes
                        .put(new BasicAttribute(Constants.ldap_ddbOrg_HierarchicalSort, builder.toString()));
            }
        }

        //properties
        //add create/update properties
        boolean isCreate = true;
        if (isUpdate) {
            isCreate = false;
        }

        pOrganisation.setProperties(PropertiesHelper.setModificationProperties(pOldOrganisation.getProperties(),
                isCreate, performer));

        // -- PID:
        if (checkAttribute(pOrganisation.getOrgPID(), pOldOrganisation.getOrgPID(), Constants.ldap_ddbOrg_PID,
                pOrgAttributes, pOrgRemoveAttributes, isUpdate)) {
            hasChanged = true;
        }

        // -- Rechtsform:
        if (checkAttribute(pOrganisation.getBusinessCategory(), pOldOrganisation.getBusinessCategory(),
                Constants.ldap_ddbOrg_BusinessCategory, pOrgAttributes, pOrgRemoveAttributes, isUpdate)) {
            hasChanged = true;
        }
        // -- Sub-Sectors:
        if (checkAttributeEnum(pOrganisation.getSubSector(), pOldOrganisation.getSubSector(),
                Constants.ldap_ddbOrg_SubBusinessCategory, pOrgAttributes, pOrgRemoveAttributes, isUpdate)) {
            hasChanged = true;
        }

        // -- Funding Agency
        if (checkAttribute(pOrganisation.getFundingAgency(), pOldOrganisation.getFundingAgency(),
                Constants.ldap_ddbOrg_FundingAgency, pOrgAttributes, pOrgRemoveAttributes, isUpdate)) {
            hasChanged = true;
        }

        // -- Kurzbeschreibung der Einrichtung
        if (checkAttribute(pOrganisation.getDescription(), pOldOrganisation.getDescription(),
                Constants.ldap_ddbOrg_Description, pOrgAttributes, pOrgRemoveAttributes, isUpdate)) {
            hasChanged = true;
        }
        // -- Name der Einrichtung
        if (checkAttribute(pOrganisation.getDisplayName(), pOldOrganisation.getDisplayName(),
                Constants.ldap_ddbOrg_DisplayName, pOrgAttributes, pOrgRemoveAttributes, isUpdate)) {
            hasChanged = true;
        }
        // -- E-Mail
        if (checkAttribute(pOrganisation.getEmail(), pOldOrganisation.getEmail(), Constants.ldap_ddbOrg_Email,
                pOrgAttributes, pOrgRemoveAttributes, isUpdate)) {
            hasChanged = true;
        }
        // -- Telefonnummer
        if (checkAttribute(pOrganisation.getTel(), pOldOrganisation.getTel(),
                Constants.ldap_ddbOrg_TelephoneNumber, pOrgAttributes, pOrgRemoveAttributes, isUpdate)) {
            hasChanged = true;
        }
        // -- FAX
        if (checkAttribute(pOrganisation.getFax(), pOldOrganisation.getFax(), Constants.ldap_ddbOrg_FaxNumber,
                pOrgAttributes, pOrgRemoveAttributes, isUpdate)) {
            hasChanged = true;
        }

        // -- HouseIdentifier
        if (checkAttribute(pOrganisation.getAddress().getHouseIdentifier(),
                pOldOrganisation.getAddress().getHouseIdentifier(), Constants.ldap_ddbOrg_HouseIdentifier,
                pOrgAttributes, pOrgRemoveAttributes, isUpdate)) {
            hasChanged = true;
        }
        // -- Strasse
        if (checkAttribute(pOrganisation.getAddress().getStreet(), pOldOrganisation.getAddress().getStreet(),
                Constants.ldap_ddbOrg_Street, pOrgAttributes, pOrgRemoveAttributes, isUpdate)) {
            hasChanged = true;
        }

        // -- Zusatz-Info:
        if (checkAttribute(pOrganisation.getAddress().getAddressSuplement(),
                pOldOrganisation.getAddress().getAddressSuplement(), Constants.ldap_ddbOrg_AddressSuplement,
                pOrgAttributes, pOrgRemoveAttributes, isUpdate)) {
            hasChanged = true;
        }
        // -- PLZ
        if (checkAttribute(pOrganisation.getAddress().getPostalCode(),
                pOldOrganisation.getAddress().getPostalCode(), Constants.ldap_ddbOrg_PostalCode, pOrgAttributes,
                pOrgRemoveAttributes, isUpdate)) {
            hasChanged = true;
        }
        // -- I; Ortsname
        if (checkAttribute(pOrganisation.getAddress().getLocalityName(),
                pOldOrganisation.getAddress().getLocalityName(), Constants.ldap_ddbOrg_LocalityName,
                pOrgAttributes, pOrgRemoveAttributes, isUpdate)) {
            hasChanged = true;
        }
        // -- Bundesland
        if (checkAttribute(pOrganisation.getAddress().getStateOrProvinceName(),
                pOldOrganisation.getAddress().getStateOrProvinceName(),
                Constants.ldap_ddbOrg_StateOrProvinceName, pOrgAttributes, pOrgRemoveAttributes, isUpdate)) {
            hasChanged = true;
        }
        // -- Land
        if (checkAttribute(pOrganisation.getAddress().getCountryName(),
                pOldOrganisation.getAddress().getCountryName(), Constants.ldap_ddbOrg_CountryName,
                pOrgAttributes, pOrgRemoveAttributes, isUpdate)) {
            hasChanged = true;
        }
        // -- Geokoordinaten:
        if (checkAttribute(pOrganisation.getAddress().getLatitude(),
                pOldOrganisation.getAddress().getLatitude(), Constants.ldap_ddbOrg_GeoLatitude, pOrgAttributes,
                pOrgRemoveAttributes, isUpdate)) {
            hasChanged = true;
        }
        if (checkAttribute(pOrganisation.getAddress().getLongitude(),
                pOldOrganisation.getAddress().getLongitude(), Constants.ldap_ddbOrg_GeoLongitude,
                pOrgAttributes, pOrgRemoveAttributes, isUpdate)) {
            hasChanged = true;
        }
        if (checkAttribute(pOrganisation.getAddress().getLocationDisplayName(),
                pOldOrganisation.getAddress().getLocationDisplayName(),
                Constants.ldap_ddbOrg_LocationDisplayName, pOrgAttributes, pOrgRemoveAttributes, isUpdate)) {
            hasChanged = true;
        }

        if (checkAttribute(pOrganisation.getAbbreviation(), pOldOrganisation.getAbbreviation(),
                Constants.ldap_ddbOrg_Abbreviation, pOrgAttributes, pOrgRemoveAttributes, isUpdate)) {
            hasChanged = true;
        }
        if (checkAttribute(pOrganisation.getLegalStatus(), pOldOrganisation.getLegalStatus(),
                Constants.ldap_ddbOrg_LegalStatus, pOrgAttributes, pOrgRemoveAttributes, isUpdate)) {
            hasChanged = true;
        }

        if (checkAttribute(pOrganisation.getUrl(), pOldOrganisation.getUrl(), Constants.ldap_ddbOrg_URL,
                pOrgAttributes, pOrgRemoveAttributes, isUpdate)) {
            hasChanged = true;
        }

        if (checkAttribute(pOrganisation.getLogo(), pOldOrganisation.getLogo(), Constants.ldap_ddbOrg_Logo,
                pOrgAttributes, pOrgRemoveAttributes, isUpdate)) {
            hasChanged = true;
        }
        // -- Status
        if (checkAttribute(pOrganisation.getStatus(), pOldOrganisation.getStatus(),
                Constants.ldap_ddbOrg_Status, pOrgAttributes, pOrgRemoveAttributes, isUpdate)) {
            hasChanged = true;
        }

        // -- Properties:
        if (pOrganisation.getProperties() != null && !pOrganisation.getProperties().isEmpty()) {
            try {
                pOrgAttributes.put(new BasicAttribute(Constants.ldap_ddbOrg_Properties,
                        serializer.serialize(pOrganisation.getProperties())));
            } catch (IllegalAccessException e) {
                throw new ExecutionException(e);
            }
        }

    }
    return hasChanged;
}

From source file:de.fiz.ddb.aas.utils.LDAPEngineUtilityOrganisation.java

protected String getOrgRdnForOrgId(final OIDs pOIDs, AasPrincipal pPerformer) throws ExecutionException {
    ThreadOrganisationRead threadOrganisationRead = new ThreadOrganisationRead(pOIDs, pPerformer);
    Organisation vOrganisation = null;/*from   ww w . j a  v a 2  s .co  m*/
    try {
        vOrganisation = threadOrganisationRead.call();
    } catch (NameNotFoundException e) {
        throw new ExecutionException(e);
    } catch (AASUnauthorizedException e) {
        throw new ExecutionException(e);
    }
    if (vOrganisation != null && vOrganisation.getOIDs() != null) {
        return vOrganisation.getOIDs().getOrgRDN();
    } else {
        throw new ExecutionException("Organization with ID: '" + pOIDs + "' could not be found.", null);
    }

}

From source file:co.cask.cdap.gateway.handlers.AppFabricHttpHandler.java

private void deleteHandler(Id.Program programId, ProgramType type) throws ExecutionException {
    try {/*w ww .j av a2s . c  o m*/
        switch (type) {
        case FLOW:
            //Stop the flow if it not running
            ProgramRuntimeService.RuntimeInfo flowRunInfo = findRuntimeInfo(programId.getAccountId(),
                    programId.getApplicationId(), programId.getId(), type);
            if (flowRunInfo != null) {
                doStop(flowRunInfo);
            }
            break;
        case PROCEDURE:
            //Stop the procedure if it not running
            ProgramRuntimeService.RuntimeInfo procedureRunInfo = findRuntimeInfo(programId.getAccountId(),
                    programId.getApplicationId(), programId.getId(), type);
            if (procedureRunInfo != null) {
                doStop(procedureRunInfo);
            }
            break;
        case WORKFLOW:
            List<String> scheduleIds = scheduler.getScheduleIds(programId, type);
            scheduler.deleteSchedules(programId, ProgramType.WORKFLOW, scheduleIds);
            break;
        case MAPREDUCE:
            //no-op
            break;
        }
    } catch (InterruptedException e) {
        throw new ExecutionException(e);
    }
}