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:de.matzefratze123.heavyspleef.core.uuid.UUIDManager.java

@SuppressWarnings("deprecation")
public List<GameProfile> getProfiles(String[] names) throws ExecutionException {
    List<GameProfile> profiles = Lists.newArrayList();

    if (onlineMode) {
        for (String name : names) {
            OfflinePlayer player = Bukkit.getOfflinePlayer(name);
            GameProfile profile = new GameProfile(player.getUniqueId(), player.getName());
            profiles.add(profile);/* ww w.jav  a2  s.co  m*/
        }
    } else {
        List<String> profilesToLoad = Lists.newArrayList();

        for (String name : names) {
            if (profileNameCache.getIfPresent(name) == null) {
                profilesToLoad.add(name);
            } else {
                profiles.add(profileNameCache.get(name));
            }
        }

        if (!profilesToLoad.isEmpty()) {
            try {
                profiles.addAll(fetchGameProfiles(profilesToLoad.toArray(new String[profilesToLoad.size()])));
            } catch (Exception e) {
                throw new ExecutionException(e);
            }

            for (String loadingName : profilesToLoad) {
                GameProfile found = null;

                for (GameProfile profile : profiles) {
                    if (profile.getName().equalsIgnoreCase(loadingName)) {
                        found = profile;
                        break;
                    }
                }

                if (found == null) {
                    OfflinePlayer player = Bukkit.getOfflinePlayer(loadingName);
                    UUID uuid = player.getUniqueId();

                    profiles.add(new GameProfile(uuid, player.getName()));
                }

                profileNameCache.put(loadingName, found);
                profileUUIDCache.put(found.getUniqueIdentifier(), found);
            }
        }
    }

    return profiles;
}

From source file:de.xaniox.heavyspleef.core.uuid.UUIDManager.java

@SuppressWarnings("deprecation")
public List<GameProfile> getProfiles(String[] names, boolean forceMojangAPI, boolean checkOriginal)
        throws ExecutionException {
    List<GameProfile> profiles = Lists.newArrayList();

    if (onlineMode && !forceMojangAPI) {
        for (String name : names) {
            OfflinePlayer player = Bukkit.getOfflinePlayer(name);
            GameProfile profile = new GameProfile(player.getUniqueId(), player.getName());
            profiles.add(profile);/*from  w  w w. j  av a2  s .c o m*/
        }
    } else {
        List<String> profilesToLoad = Lists.newArrayList();

        for (String name : names) {
            if (profileNameCache.getIfPresent(name) == null) {
                profilesToLoad.add(name);
            } else {
                profiles.add(profileNameCache.get(name));
            }
        }

        if (!profilesToLoad.isEmpty()) {
            try {
                profiles.addAll(fetchGameProfiles(profilesToLoad.toArray(new String[profilesToLoad.size()])));
            } catch (Exception e) {
                throw new ExecutionException(e);
            }

            for (String loadingName : profilesToLoad) {
                GameProfile found = null;

                for (GameProfile profile : profiles) {
                    if (profile.getName().equalsIgnoreCase(loadingName)) {
                        found = profile;
                        break;
                    }
                }

                String cachingName = loadingName;

                if (found == null) {
                    if (checkOriginal) {
                        long difSinceLastLookup = System.currentTimeMillis() - recentOriginalLookup;
                        int seconds = (int) TimeUnit.MILLISECONDS.toSeconds(difSinceLastLookup);

                        originalLookupsLeft += seconds;
                        if (originalLookupsLeft > MAX_ORIGINAL_LOOKUPS_LEFT) {
                            //Cannot lookup more than 600 profiles per 10 minutes
                            originalLookupsLeft = MAX_ORIGINAL_LOOKUPS_LEFT;
                        }

                        if (originalLookupsLeft == 0) {
                            try {
                                Thread.sleep(1250L);
                            } catch (InterruptedException e) {
                                throw new ExecutionException(e);
                            }
                        } else {
                            originalLookupsLeft--;
                        }

                        GameProfile current;

                        try {
                            current = fetchOriginalGameProfile(loadingName);
                        } catch (Exception e) {
                            throw new ExecutionException(e);
                        }

                        recentOriginalLookup = System.currentTimeMillis();

                        if (current == null) {
                            //Skip this profile, we can't find a matching uuid
                            continue;
                        }

                        found = current;
                        cachingName = current.getName();
                    } else {
                        OfflinePlayer player = Bukkit.getOfflinePlayer(loadingName);
                        UUID uuid = player.getUniqueId();

                        found = new GameProfile(uuid, loadingName);
                    }
                }

                profiles.add(found);
                profileNameCache.put(cachingName, found);
                profileUUIDCache.put(found.getUniqueIdentifier(), found);
            }
        }
    }

    return profiles;
}

From source file:com.autentia.common.util.systemexecuter.SystemExecuter.java

/**
 * Method that executes a system command
 * //  www .  j  a  va  2 s  . c om
 * @param command command with parameters to execute
 * @throws ExecutionException if an error ocurred during execution
 */
public void execute(String[] command) throws ExecutionException {

    ExecuterThread executerThread = new ExecuterThread(command);

    try {
        executerThread.start();

        if (!executeInBackground) {
            executerThread.join();
        }

        if (exception != null) {
            throw new ExecutionException(exception);
        }
    } catch (InterruptedException e) {
        log.error(e);
        throw new ExecutionException(e);
    }
}

From source file:org.apache.gobblin.elasticsearch.writer.FutureCallbackHolder.java

private WriteResponse getWriteResponseorThrow(Pair<WriteResponse, Throwable> writeResponseThrowablePair)
        throws ExecutionException {
    try {/*from  ww  w .  jav a2s.c  om*/
        if (writeResponseThrowablePair.getFirst() != null) {
            return writeResponseThrowablePair.getFirst();
        } else if (writeResponseThrowablePair.getSecond() != null) {
            throw new ExecutionException(writeResponseThrowablePair.getSecond());
        } else {
            throw new ExecutionException(new RuntimeException("Could not find non-null WriteResponse pair"));
        }
    } finally {
        done.set(true);
    }

}

From source file:org.limewire.mojito.manager.StoreProcess.java

private void handleSecurityToken(GetSecurityTokenResult result) {
    SecurityToken securityToken = result.getSecurityToken();
    if (securityToken == null) {
        exchanger.setException(//from  w  ww. j av  a  2s .  c om
                new ExecutionException(new DHTException("Could not get SecurityToken from " + node)));
    } else {
        Entry<Contact, SecurityToken> entry = new EntryImpl<Contact, SecurityToken>(node.getKey(),
                securityToken);

        doStoreOnPath(Collections.singleton(entry));
    }
}

From source file:de.matzefratze123.heavyspleef.core.uuid.UUIDManager.java

public List<GameProfile> getProfiles(UUID[] uuids) throws ExecutionException {
    List<GameProfile> profiles = Lists.newArrayList();

    if (onlineMode) {
        for (UUID uuid : uuids) {
            OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
            GameProfile profile = new GameProfile(uuid, player.getName());
            profiles.add(profile);//from w ww.  j av a 2 s  .  co  m
        }
    } else {
        List<UUID> profilesToLoad = Lists.newArrayList();

        for (UUID uuid : uuids) {
            if (profileUUIDCache.getIfPresent(uuid) == null) {
                profilesToLoad.add(uuid);
            } else {
                GameProfile profile;

                try {
                    profile = fetchGameProfile(uuid);
                } catch (Exception e) {
                    throw new ExecutionException(e);
                }

                if (profile == null) {
                    OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
                    profile = new GameProfile(uuid, player.getName());
                }

                profileUUIDCache.put(uuid, profile);
                profileNameCache.put(profile.getName(), profile);

                profiles.add(profile);
            }
        }
    }

    return profiles;
}

From source file:gobblin.couchbase.writer.CouchbaseWriter.java

private WriteResponse getWriteResponseorThrow(Pair<WriteResponse, Throwable> writeResponseThrowablePair)
        throws ExecutionException {
    if (writeResponseThrowablePair.getFirst() != null) {
        return writeResponseThrowablePair.getFirst();
    } else if (writeResponseThrowablePair.getSecond() != null) {
        throw new ExecutionException(writeResponseThrowablePair.getSecond());
    } else {/*ww  w . j a  va  2 s . c o  m*/
        throw new ExecutionException(new RuntimeException("Could not find non-null WriteResponse pair"));
    }
}

From source file:org.limewire.mojito.handler.response.AbstractResponseHandler.java

/**
 * Sets the Exception which will be thrown by the
 * call() method./* w  w w.j av a2  s. c  om*/
 */
protected void setException(DHTException ex) {
    ExecutionException e = new ExecutionException(ex);
    e.setStackTrace(ex.getStackTrace());
    exchanger.setException(e);
}

From source file:org.apache.axis2.jaxws.client.async.AsyncResponse.java

private Object processResponse() throws ExecutionException {

    // If we don't have a fault, then we have to have a MessageContext for the response.
    if (response == null) {
        latch.countDown();//from w  w w.j av a2  s.c o  m
        throw new ExecutionException(
                ExceptionFactory.makeWebServiceException(Messages.getMessage("processRespErr")));
    }

    // Avoid a reparse of the message. If we already retrived the object, return
    // it now.
    if (cacheValid) {
        if (log.isDebugEnabled()) {
            log.debug("Return object cached from last get()");
        }
        return cachedObject;
    }

    Object obj = null;
    try {
        // Install the adapters and invoke inbound handlers.
        TransportHeadersAdapter.install(response);
        AttachmentsAdapter.install(response);
        SOAPHeadersAdapter.install(response);
        HandlerInvokerUtils.invokeInboundHandlers(response.getMEPContext(),
                response.getInvocationContext().getHandlers(), HandlerChainProcessor.MEP.RESPONSE, false);

        // TODO: IMPORTANT: this is the right call here, but beware that the 
        // messagecontext may be turned into a fault context with a fault message.  
        // We need to check for this and, if necessary, make an exception and throw it.
        if (log.isDebugEnabled()) {
            log.debug("Unmarshalling the async response message.");
        }

        // Do the real work to unmarshall the response.
        obj = getResponseValueObject(response);

        if (log.isDebugEnabled() && obj != null) {
            log.debug("Unmarshalled response object of type: " + obj.getClass());
        }

        // Cache the object in case it is required again
        cacheValid = true;
        cachedObject = obj;

        responseContext = new HashMap<String, Object>();

        // Migrate the properties from the response MessageContext back
        // to the client response context bag.
        ApplicationContextMigratorUtil.performMigrationFromMessageContext(
                Constants.APPLICATION_CONTEXT_MIGRATOR_LIST_ID, responseContext, response);
    } catch (Throwable t) {
        throw new ExecutionException(ExceptionFactory.makeWebServiceException(t));
    }

    return obj;
}

From source file:com.cloudant.sync.replication.PullStrategy.java

private int processOneChangesBatch(ChangesResultWrapper changeFeeds)
        throws ExecutionException, InterruptedException, DocumentException {
    String feed = String.format("Change feed: { last_seq: %s, change size: %s}", changeFeeds.getLastSeq(),
            changeFeeds.getResults().size());
    logger.info(feed);/*from  ww  w.j av  a  2  s. com*/

    Multimap<String, String> openRevs = changeFeeds.openRevisions(0, changeFeeds.size());
    Map<String, Collection<String>> missingRevisions = this.targetDb.getDbCore().revsDiff(openRevs);

    int changesProcessed = 0;

    // Process the changes in batches
    List<String> ids = Lists.newArrayList(missingRevisions.keySet());
    List<List<String>> batches = Lists.partition(ids, this.insertBatchSize);

    for (List<String> batch : batches) {

        List<BatchItem> batchesToInsert = new ArrayList<BatchItem>();

        if (this.state.cancel) {
            break;
        }

        try {
            Iterable<DocumentRevsList> result = createTask(batch, missingRevisions);

            for (DocumentRevsList revsList : result) {
                // We promise not to insert documents after cancel is set
                if (this.state.cancel) {
                    break;
                }

                // attachments, keyed by docId and revId, so that
                // we can add the attachments to the correct leaf
                // nodes
                HashMap<String[], List<PreparedAttachment>> atts = new HashMap<String[], List<PreparedAttachment>>();

                // now put together a list of attachments we need to download
                if (!this.pullAttachmentsInline) {
                    try {
                        for (DocumentRevs documentRevs : revsList) {
                            Map<String, Object> attachments = documentRevs.getAttachments();
                            // keep track of attachments we are going to prepare
                            ArrayList<PreparedAttachment> preparedAtts = new ArrayList<PreparedAttachment>();
                            atts.put(new String[] { documentRevs.getId(), documentRevs.getRev() },
                                    preparedAtts);

                            for (Map.Entry<String, Object> entry : attachments.entrySet()) {
                                Map attachmentMetadata = (Map) entry.getValue();
                                int revpos = (Integer) attachmentMetadata.get("revpos");
                                String contentType = (String) attachmentMetadata.get("content_type");
                                String encoding = (String) attachmentMetadata.get("encoding");
                                long length = (Integer) attachmentMetadata.get("length");
                                long encodedLength = 0; // encodedLength can default to 0 if
                                // it's not encoded
                                if (Attachment.getEncodingFromString(encoding) != Attachment.Encoding.Plain) {
                                    encodedLength = (Integer) attachmentMetadata.get("encoded_length");
                                }

                                // do we already have the attachment @ this revpos?
                                // look back up the tree for this document and see:
                                // if we already have it, then we don't need to fetch it
                                DocumentRevs.Revisions revs = documentRevs.getRevisions();
                                int offset = revs.getStart() - revpos;
                                if (offset >= 0 && offset < revs.getIds().size()) {
                                    String revId = String.valueOf(revpos) + "-" + revs.getIds().get(offset);

                                    Attachment a = this.targetDb.getDbCore().getAttachment(documentRevs.getId(),
                                            revId, entry.getKey());
                                    if (a != null) {
                                        // skip attachment, already got it
                                        continue;
                                    }

                                }
                                UnsavedStreamAttachment usa = this.sourceDb.getAttachmentStream(
                                        documentRevs.getId(), documentRevs.getRev(), entry.getKey(),
                                        contentType, encoding);

                                // by preparing the attachment here, it is downloaded outside
                                // of the database transaction
                                preparedAtts.add(this.targetDb.prepareAttachment(usa, length, encodedLength));
                            }
                        }
                    } catch (Exception e) {
                        logger.log(Level.SEVERE, "There was a problem downloading an attachment to the"
                                + " datastore, terminating replication", e);
                        this.state.cancel = true;
                    }
                }

                if (this.state.cancel) {
                    break;
                }

                batchesToInsert.add(new BatchItem(revsList, atts));
                changesProcessed++;
            }
            this.targetDb.bulkInsert(batchesToInsert, this.pullAttachmentsInline);
        } catch (Exception e) {
            throw new ExecutionException(e);
        }
    }

    if (!this.state.cancel) {
        try {
            this.targetDb.putCheckpoint(this.getReplicationId(), changeFeeds.getLastSeq());
        } catch (DatastoreException e) {
            logger.log(Level.WARNING,
                    "Failed to put checkpoint doc, next replication will " + "start from previous checkpoint",
                    e);
        }
    }

    return changesProcessed;
}