本文整理汇总了Java中org.jdeferred.multiple.MultipleResults类的典型用法代码示例。如果您正苦于以下问题:Java MultipleResults类的具体用法?Java MultipleResults怎么用?Java MultipleResults使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MultipleResults类属于org.jdeferred.multiple包,在下文中一共展示了MultipleResults类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: send
import org.jdeferred.multiple.MultipleResults; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Promise<MultipleResults, OneReject, MasterProgress> send(final List<SendingTask<M>> tasks) {
logger.debug("Sending {} messages.", tasks.size());
Object[] messageAndDeferred = SendingTask.unzipGeneric(tasks);
final List<M> messages = (List<M>) messageAndDeferred[0];
final List<Deferred> deferreds = (List<Deferred>) messageAndDeferred[1];
executor.execute(new Runnable() {
@Override
public void run() {
try {
List<R> result = delegate.send(messages);
Deferreds.resolveAll(result, deferreds);
} catch (Throwable t) {
Deferreds.rejectAll(t, deferreds, messages);
}
}
});
return new MasterDeferredObject(deferreds.toArray(new Deferred[0])).promise();
}
开发者ID:tramchamploo,项目名称:buffer-slayer,代码行数:21,代码来源:AsyncSenderAdaptor.java
示例2: sendingFailed
import org.jdeferred.multiple.MultipleResults; //导入依赖的package包/类
@Test
public void sendingFailed() throws InterruptedException {
FakeSender sender = new FakeSender();
RuntimeException ex = new RuntimeException("expected");
sender.onMessages(messages -> {
throw ex;
});
CountDownLatch countDown = new CountDownLatch(1);
adaptor = new AsyncSenderAdaptor<>(sender, 1);
Promise<MultipleResults, OneReject, MasterProgress> promise = adaptor.send(
Arrays.asList(newSendingTask(0), newSendingTask(1), newSendingTask(2)));
promise.fail(t -> {
assertEquals(ex, ((MessageDroppedException) t.getReject()).getCause());
countDown.countDown();
});
assertTrue(countDown.await(500, TimeUnit.MILLISECONDS));
}
开发者ID:tramchamploo,项目名称:buffer-slayer,代码行数:19,代码来源:AsyncSenderAdaptorTest.java
示例3: testFutures
import org.jdeferred.multiple.MultipleResults; //导入依赖的package包/类
@Test
public void testFutures() {
final Callable<Integer> callable1 = successCallable(999, 100);
final Callable<String> callable2 = successCallable("HI", 1000);
ExecutorService es = deferredManager.getExecutorService();
Future<Integer> future1 = es.submit(callable1);
Future<String> future2 = es.submit(callable2);
final AtomicInteger doneCount = new AtomicInteger();
deferredManager.when(future1, future2).done(new DoneCallback<MultipleResults>() {
@Override
public void onDone(MultipleResults result) {
Assert.assertEquals(2, result.size());
Assert.assertEquals(999, result.get(0).getResult());
Assert.assertEquals("HI", result.get(1).getResult());
doneCount.incrementAndGet();
}
});
waitForCompletion();
Assert.assertEquals(1, doneCount.get());
}
开发者ID:jdeferred,项目名称:jdeferred,代码行数:23,代码来源:MultiplePromisesTest.java
示例4: when
import org.jdeferred.multiple.MultipleResults; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public Promise<MultipleResults, OneReject, MasterProgress> when(
DeferredAsyncTask<Void, ?, ?> ... tasks) {
assertNotEmpty(tasks);
Promise[] promises = new Promise[tasks.length];
for (int i = 0; i < tasks.length; i++) {
promises[i] = when(tasks[i]);
}
return when(promises);
}
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:14,代码来源:AndroidDeferredManager.java
示例5: flush
import org.jdeferred.multiple.MultipleResults; //导入依赖的package包/类
@Override
public void flush() {
try {
for (SizeBoundedQueue pending : queueManager.elements()) {
Promise<MultipleResults, OneReject, MasterProgress> promise = flush(pending);
promise.waitSafely();
}
} catch (InterruptedException e) {
logger.warn("Interrupted flushing messages.");
}
}
开发者ID:tramchamploo,项目名称:buffer-slayer,代码行数:12,代码来源:AsyncReporter.java
示例6: collectResults
import org.jdeferred.multiple.MultipleResults; //导入依赖的package包/类
private Object[] collectResults(MultipleResults mr) {
int size = mr.size();
Object[] results = new Object[size];
for (int i = 0 ; i < size; i++) {
results[i] = mr.get(i).getResult();
}
return results;
}
开发者ID:tramchamploo,项目名称:buffer-slayer,代码行数:9,代码来源:AsyncSenderAdaptorTest.java
示例7: sendingSuccess
import org.jdeferred.multiple.MultipleResults; //导入依赖的package包/类
@Test
public void sendingSuccess() throws InterruptedException {
FakeSender sender = new FakeSender();
CountDownLatch countDown = new CountDownLatch(1);
adaptor = new AsyncSenderAdaptor<>(sender, 1);
Promise<MultipleResults, OneReject, MasterProgress> promise = adaptor.send(
Arrays.asList(newSendingTask(0), newSendingTask(1), newSendingTask(2)));
promise.done(mr -> {
assertArrayEquals(new Integer[]{0, 1, 2}, collectResults(mr));
countDown.countDown();
});
assertTrue(countDown.await(500, TimeUnit.MILLISECONDS));
}
开发者ID:tramchamploo,项目名称:buffer-slayer,代码行数:15,代码来源:AsyncSenderAdaptorTest.java
示例8: when
import org.jdeferred.multiple.MultipleResults; //导入依赖的package包/类
@Override
public Promise<MultipleResults, OneReject, MasterProgress> when(Runnable... runnables) {
assertNotEmpty(runnables);
Promise[] promises = new Promise[runnables.length];
for (int i = 0; i < runnables.length; i++) {
if (runnables[i] instanceof DeferredRunnable)
promises[i] = when((DeferredRunnable) runnables[i]);
else
promises[i] = when(runnables[i]);
}
return when(promises);
}
开发者ID:jdeferred,项目名称:jdeferred,代码行数:16,代码来源:AbstractDeferredManager.java
示例9: getEntriesAsync
import org.jdeferred.multiple.MultipleResults; //导入依赖的package包/类
@Override
Promise<Object, Throwable, Void> getEntriesAsync(Context context) {
MyPackageManager myPackageManager = MyPackageManagerImpl.getInstance(context);
Promise<Collection<MyPackageInfo>, Void, Void> packagesPromise = myPackageManager.getPackages(false);
Promise<Map<String, MyPermissionInfo>, Void, Void> permissionsPromise = myPackageManager.getPermissions();
DefaultDeferredManager dm = new DefaultDeferredManager();
final PackageManager pm = context.getPackageManager();
return dm
.when(packagesPromise, permissionsPromise)
.then(new DoneFilter<MultipleResults, Object>() {
@Override
public Object filterDone(MultipleResults result) {
@SuppressWarnings("unchecked")
Collection<MyPackageInfo> packages = (Collection<MyPackageInfo>) result.get(0).getResult();
@SuppressWarnings("unchecked")
Map<String, MyPermissionInfo> permissions = (Map<String, MyPermissionInfo>) result.get(1).getResult();
ArrayList<Category> selectedApps = new ArrayList<Category>();
//
for (MyPackageInfo pack : packages) {
// System app filter
if (((
pack.isSystemApplication() ?
APP_TYPE_SYSTEM :
APP_TYPE_USER)
& appType) == 0) {
continue;
}
// Scan components
ArrayList<Component> selectedComponents = new ArrayList<Component>();
if ((type & PackageManager.GET_ACTIVITIES) != 0) {
scanComponents(permissions, pack.getActivities(), selectedComponents, false);
}
if ((type & PackageManager.GET_RECEIVERS) != 0) {
scanComponents(permissions, pack.getReceivers(), selectedComponents, false);
}
if ((type & PackageManager.GET_SERVICES) != 0) {
scanComponents(permissions, pack.getServices(), selectedComponents, false);
}
if ((type & PackageManager.GET_PROVIDERS) != 0) {
scanComponents(permissions, pack.getProviders(), selectedComponents, testWritePermissionForProviders);
}
// Check if we filtered out all components and skip whole app if so
if (selectedComponents.isEmpty()) {
continue;
}
// Build and add app descriptor
Category app = new Category();
app.title = String.valueOf(pack.loadLabel(pm));
app.subtitle = pack.getPackageName();
app.components = selectedComponents.toArray(new Component[selectedComponents.size()]);
selectedApps.add(app);
}
Category[] selectedAppsArray = selectedApps.toArray(new Category[selectedApps.size()]);
Arrays.sort(selectedAppsArray, new Comparator<Category>() {
@Override
public int compare(Category lhs, Category rhs) {
return lhs.subtitle.compareTo(rhs.subtitle);
}
});
return selectedAppsArray;
}
});
}
开发者ID:michalbednarski,项目名称:IntentsLab,代码行数:72,代码来源:ComponentFetcher.java
示例10: when
import org.jdeferred.multiple.MultipleResults; //导入依赖的package包/类
public abstract Promise<MultipleResults, OneReject, MasterProgress> when(
Future<?> ... futures);
开发者ID:jdeferred,项目名称:jdeferred,代码行数:3,代码来源:DeferredManager.java
示例11: send
import org.jdeferred.multiple.MultipleResults; //导入依赖的package包/类
/**
* asynchronously send messages
*
* @param messages messages to send
*/
Promise<MultipleResults, OneReject, MasterProgress> send(List<SendingTask<M>> messages);
开发者ID:tramchamploo,项目名称:buffer-slayer,代码行数:7,代码来源:AsyncSender.java
注:本文中的org.jdeferred.multiple.MultipleResults类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论