本文整理汇总了Java中java.util.concurrent.Callable类的典型用法代码示例。如果您正苦于以下问题:Java Callable类的具体用法?Java Callable怎么用?Java Callable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Callable类属于java.util.concurrent包,在下文中一共展示了Callable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: returnArticleByUrl
import java.util.concurrent.Callable; //导入依赖的package包/类
@Override
public Observable<Article> returnArticleByUrl(final String url) {
return Observable.fromCallable(new Callable<Article>() {
@Override
public Article call() throws Exception {
List<Article> articles = mDaoSession.getArticleDao().queryBuilder()
.where(ArticleDao.Properties.Url.eq(url))
.list();
if (articles.isEmpty()) {
return null;
} else {
return articles.get(0);
}
}
});
}
示例2: loadNextActiveSubscriptionHistoryForPriceModel_FpEndsAtUpgradeTime
import java.util.concurrent.Callable; //导入依赖的package包/类
@Test
public void loadNextActiveSubscriptionHistoryForPriceModel_FpEndsAtUpgradeTime()
throws Exception {
// given
setupSubAndPmHistoriesForAsyncUpgrade();
// when
SubscriptionHistory subHistory = runTX(
new Callable<SubscriptionHistory>() {
@Override
public SubscriptionHistory call() throws Exception {
return bdr
.loadNextActiveSubscriptionHistoryForPriceModel(
PRICEMODEL1_KEY,
dateToMillis("2012-10-03 10:20:00"));
}
});
// then
assertNull(subHistory);
}
示例3: disposedOnCallThrows
import java.util.concurrent.Callable; //导入依赖的package包/类
@Test
public void disposedOnCallThrows() {
List<Throwable> errors = TestCommonHelper.trackPluginErrors();
try {
final TestObserver<Integer> to = new TestObserver<Integer>();
Observable.fromCallable(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
to.cancel();
throw new TestException();
}
})
.subscribe(to);
to.assertEmpty();
TestCommonHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaCommonPlugins.reset();
}
}
示例4: grantGlobal
import java.util.concurrent.Callable; //导入依赖的package包/类
/**
* Grant permissions globally to the given user. Will wait until all active
* AccessController instances have updated their permissions caches or will
* throw an exception upon timeout (10 seconds).
*/
public static void grantGlobal(final HBaseTestingUtility util, final String user,
final Permission.Action... actions) throws Exception {
SecureTestUtil.updateACLs(util, new Callable<Void>() {
@Override
public Void call() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(util.getConfiguration())) {
try (Table acl = connection.getTable(AccessControlLists.ACL_TABLE_NAME)) {
BlockingRpcChannel service = acl.coprocessorService(HConstants.EMPTY_START_ROW);
AccessControlService.BlockingInterface protocol =
AccessControlService.newBlockingStub(service);
ProtobufUtil.grant(null, protocol, user, actions);
}
}
return null;
}
});
}
示例5: testAdd
import java.util.concurrent.Callable; //导入依赖的package包/类
/**
* <b>Test case:</b> Add a new tag entry<br>
* <b>ExpectedResult:</b>
* <ul>
* <li>The tag entry can be retrieved from DB and is identical to the
* provided object</li>
* <li>A history object is created for the tag entry</li>
* </ul>
*
* @throws Exception
*/
@Test
public void testAdd() throws Exception {
runTX(new Callable<Void>() {
public Void call() throws Exception {
doTestAdd();
return null;
}
});
runTX(new Callable<Void>() {
public Void call() throws Exception {
doTestAddCheck();
return null;
}
});
}
示例6: getDecodeOptions
import java.util.concurrent.Callable; //导入依赖的package包/类
Callable<C> $(I i, CompressSpec spec) throws Exception {
BitmapFactory.Options decodeBoundsOptions = BitmapOptionsCompat.getDefaultDecodeBoundsOptions();
getDecodeOptions(i, decodeBoundsOptions);
spec.options.inSampleSize =
spec.calculation.calculateInSampleSize(
decodeBoundsOptions.outWidth,
decodeBoundsOptions.outHeight);
Logger.i("inSampleSize-->" + spec.options.inSampleSize);
spec.options.quality =
spec.calculation.calculateQuality(
decodeBoundsOptions.outWidth,
decodeBoundsOptions.outHeight,
decodeBoundsOptions.outWidth / spec.options.inSampleSize,
decodeBoundsOptions.outHeight / spec.options.inSampleSize);
Logger.i("quality-->" + spec.options.quality);
while (!MemoryUtil.memoryEnough(
decodeBoundsOptions.outWidth / spec.options.inSampleSize,
decodeBoundsOptions.outHeight / spec.options.inSampleSize,
decodeBoundsOptions.inPreferredConfig,
spec.safeMemory));
Callable<C> callable = getCallable(i, spec);
return callable;
}
示例7: createUser_LDAPUsed
import java.util.concurrent.Callable; //导入依赖的package包/类
@Test(expected = UnsupportedOperationException.class)
public void createUser_LDAPUsed() throws Exception {
try {
final VOUserDetails userToCreate = new VOUserDetails();
userToCreate.setUserId("newUser");
runTX(new Callable<Void>() {
@Override
public Void call() throws Exception {
idMgmt.createUser(userToCreate, Collections.singletonList(
UserRoleType.ORGANIZATION_ADMIN), null);
return null;
}
});
} catch (EJBException e) {
throw e.getCausedByException();
}
}
示例8: isInstance
import java.util.concurrent.Callable; //导入依赖的package包/类
@Override
public boolean isInstance(final Object instance) {
if (! (instance instanceof ScriptObjectMirror)) {
return false;
}
final ScriptObjectMirror mirror = (ScriptObjectMirror)instance;
// if not belongs to my global scope, return false
if (global != mirror.global) {
return false;
}
return inGlobal(new Callable<Boolean>() {
@Override public Boolean call() {
return sobj.isInstance(mirror.sobj);
}
});
}
示例9: testViolateUniqueConstraint
import java.util.concurrent.Callable; //导入依赖的package包/类
/**
* <b>Testcase:</b> Try to insert two products with the same productId<br>
* <b>ExpectedResult:</b> SaasNonUniqueBusinessKeyException
*
* @throws Throwable
*/
@Test(expected = NonUniqueBusinessKeyException.class)
public void testViolateUniqueConstraint() throws Throwable {
try {
runTX(new Callable<Void>() {
@Override
public Void call() throws Exception {
doTestViolateUniqueConstraintPrepare();
return null;
}
});
runTX(new Callable<Void>() {
@Override
public Void call() throws Exception {
doTestViolateUniqueConstraint();
return null;
}
});
} catch (EJBException e) {
throw e.getCause();
}
}
示例10: testPerformBillingRunForOrganizationNoCosts
import java.util.concurrent.Callable; //导入依赖的package包/类
@Test
public void testPerformBillingRunForOrganizationNoCosts() throws Exception {
runTX(new Callable<Void>() {
@Override
public Void call() throws Exception {
Scenario.setup(container, false, true);
PriceModel priceModel = Scenario.getPriceModel();
priceModel = mgr.getReference(PriceModel.class,
priceModel.getKey());
priceModel.setType(PriceModelType.FREE_OF_CHARGE);
return null;
}
});
BillingResult res = serviceBill.generateBillingForAnyPeriod(
System.currentTimeMillis(), System.currentTimeMillis() + 20,
Scenario.getCustomer().getKey()).get(0);
Assert.assertNotNull("Result must not be null", res);
checkEquals("Wrong costs contained", new BigDecimal("0.68"),
res.getGrossAmount(), PriceConverter.NORMALIZED_PRICE_SCALING);
}
示例11: setup
import java.util.concurrent.Callable; //导入依赖的package包/类
@Before
public void setup() {
sessionContext = new TestSessionContext(null, null);
callable = new Callable<Object>() {
@Override
public Void call() {
return null;
}
};
ctx = new IInvocationCtx() {
@Override
public TransactionManager getTransactionManager() {
return null;
}
@Override
public boolean isApplicationException(Exception e) {
return false;
}
};
}
示例12: addPartner
import java.util.concurrent.Callable; //导入依赖的package包/类
public void addPartner(String key, Partner partner) {
String partnerPath = ZKPaths.makePath(partnerStorePath, key);
RetryRunner.create().onFinalError(e -> {
LOGGER.error("addPartner.error", e);
ReporterHolder.incException(e);
throw new ServiceErrorException(ErrorCode.SYSTEM_ERROR);
}).run((Callable<Void>) () -> {
if (client.checkExists().creatingParentsIfNeeded().forPath(partnerPath) != null) {
client.setData()
.forPath(partnerPath, JSONObject.toJSONBytes(partner));
} else {
client.create()
.creatingParentsIfNeeded()
.withMode(CreateMode.PERSISTENT)
.forPath(partnerPath, JSONObject.toJSONBytes(partner));
}
return null;
});
}
示例13: createMarketingPermission
import java.util.concurrent.Callable; //导入依赖的package包/类
private void createMarketingPermission(final long tpKey,
final long orgRefKey) throws Exception {
runTX(new Callable<Void>() {
@Override
public Void call() throws Exception {
TechnicalProduct technicalProduct = dm.find(
TechnicalProduct.class, tpKey);
OrganizationReference reference = dm.find(
OrganizationReference.class, orgRefKey);
MarketingPermission permission = new MarketingPermission();
permission.setOrganizationReference(reference);
permission.setTechnicalProduct(technicalProduct);
dm.persist(permission);
return null;
}
});
}
示例14: getMarketplacesForOrganization_InitialSupplier
import java.util.concurrent.Callable; //导入依赖的package包/类
@Test
public void getMarketplacesForOrganization_InitialSupplier()
throws Exception {
Long suppInitialUserKey = runTX(new Callable<Long>() {
@Override
public Long call() throws Exception {
Organization org = Organizations.createOrganization(mgr,
OrganizationRoleType.SUPPLIER);
PlatformUser user = Organizations.createUserForOrg(mgr, org,
true, "testGetMarketplaces_InitialSupplier");
mgr.flush();
return Long.valueOf(user.getKey());
}
});
container.login(suppInitialUserKey.longValue(), ROLE_SERVICE_MANAGER);
List<VOMarketplace> list = marketplaceService
.getMarketplacesForOrganization();
assertNotNull(list);
assertEquals("Created user may at least publish to open mp", 1,
list.size());
assertEquals("Created user may at least publish to open mp",
OPEN_MP_ID, list.get(0).getMarketplaceId());
}
开发者ID:servicecatalog,项目名称:oscm,代码行数:25,代码来源:MarketplaceServiceBeanGetMarketplaceAndOrganizationIT.java
示例15: doModify
import java.util.concurrent.Callable; //导入依赖的package包/类
private TechnicalProductOperation doModify(
final TechnicalProductOperation op) throws Exception {
final TechnicalProductOperation read = runTX(new Callable<TechnicalProductOperation>() {
@Override
public TechnicalProductOperation call() throws Exception {
TechnicalProductOperation tpo = mgr.getReference(
TechnicalProductOperation.class, op.getKey());
tpo.setActionUrl("someOtherUlr");
return mgr.getReference(TechnicalProductOperation.class,
tpo.getKey());
}
});
Assert.assertEquals("ID", read.getOperationId());
Assert.assertEquals("someOtherUlr", read.getActionUrl());
return read;
}