Search in sources :

Example 1 with SdbItem

use of com.spaceprogram.simplejpa.SdbItem in project simplejpa by appoxy.

the class ConcurrentRetriever method getParallel.

private static List<ItemAndAttributes> getParallel(List<SdbItem> items, Executor executor, EntityManagerSimpleJPA em) throws InterruptedException, ExecutionException {
    CompletionService<ItemAndAttributes> ecs = new ExecutorCompletionService<ItemAndAttributes>(executor);
    for (SdbItem item : items) {
        Callable callable = new GetAttributes(item, em);
        ecs.submit(callable);
    }
    List<ItemAndAttributes> ret = new ArrayList<ItemAndAttributes>();
    int n = items.size();
    for (int i = 0; i < n; ++i) {
        ItemAndAttributes r = ecs.take().get();
        if (r != null) {
            ret.add(r);
        }
    }
    return ret;
}
Also used : GetAttributes(com.spaceprogram.simplejpa.operations.GetAttributes) SdbItem(com.spaceprogram.simplejpa.SdbItem) ArrayList(java.util.ArrayList) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) ItemAndAttributes(com.spaceprogram.simplejpa.ItemAndAttributes) Callable(java.util.concurrent.Callable)

Example 2 with SdbItem

use of com.spaceprogram.simplejpa.SdbItem in project simplejpa by appoxy.

the class ConcurrentRetriever method test.

public static List<ItemAndAttributes> test(EntityManagerSimpleJPA em, String domainName) throws AmazonClientException, ExecutionException, InterruptedException {
    AmazonSimpleDB db = em.getSimpleDb();
    SelectResult result = DomainHelper.selectItems(db, "select * from `" + domainName + "`", null);
    List<SdbItem> list = new ArrayList<SdbItem>();
    for (Item item : result.getItems()) {
        list.add(new SdbItemImpl2(item));
    }
    return getAttributesFromSdb(list, em.getExecutor(), em);
}
Also used : SelectResult(com.amazonaws.services.simpledb.model.SelectResult) SdbItem(com.spaceprogram.simplejpa.SdbItem) Item(com.amazonaws.services.simpledb.model.Item) SdbItem(com.spaceprogram.simplejpa.SdbItem) AmazonSimpleDB(com.amazonaws.services.simpledb.AmazonSimpleDB) ArrayList(java.util.ArrayList) SdbItemImpl2(com.spaceprogram.simplejpa.SdbItemImpl2)

Example 3 with SdbItem

use of com.spaceprogram.simplejpa.SdbItem in project simplejpa by appoxy.

the class ConcurrentRetriever method getSerially.

private static List<ItemAndAttributes> getSerially(List<SdbItem> items) throws AmazonClientException {
    List<ItemAndAttributes> ret = new ArrayList<ItemAndAttributes>();
    for (SdbItem item : items) {
        // logger.fine("item=" + item.getIdentifier());
        List<Attribute> atts = item.getAttributes();
        ret.add(new ItemAndAttributes(item, atts));
    }
    return ret;
}
Also used : SdbItem(com.spaceprogram.simplejpa.SdbItem) Attribute(com.amazonaws.services.simpledb.model.Attribute) ArrayList(java.util.ArrayList) ItemAndAttributes(com.spaceprogram.simplejpa.ItemAndAttributes)

Aggregations

SdbItem (com.spaceprogram.simplejpa.SdbItem)3 ArrayList (java.util.ArrayList)3 ItemAndAttributes (com.spaceprogram.simplejpa.ItemAndAttributes)2 AmazonSimpleDB (com.amazonaws.services.simpledb.AmazonSimpleDB)1 Attribute (com.amazonaws.services.simpledb.model.Attribute)1 Item (com.amazonaws.services.simpledb.model.Item)1 SelectResult (com.amazonaws.services.simpledb.model.SelectResult)1 SdbItemImpl2 (com.spaceprogram.simplejpa.SdbItemImpl2)1 GetAttributes (com.spaceprogram.simplejpa.operations.GetAttributes)1 Callable (java.util.concurrent.Callable)1 ExecutorCompletionService (java.util.concurrent.ExecutorCompletionService)1