本文整理汇总了Java中java.util.concurrent.Callable.call方法的典型用法代码示例。如果您正苦于以下问题:Java Callable.call方法的具体用法?Java Callable.call怎么用?Java Callable.call使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.Callable
的用法示例。
在下文中一共展示了Callable.call方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSetWhereFrom
import java.util.concurrent.Callable; //导入方法依赖的package包/类
@Test
public void testSetWhereFrom() throws Exception {
final QuarantineService q = new LaunchServicesQuarantineService();
Callable<Local> c = new Callable<Local>() {
@Override
public Local call() throws Exception {
final NullLocal l = new NullLocal(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
LocalTouchFactory.get().touch(l);
q.setWhereFrom(l,
"http://cyberduck.ch");
l.delete();
return l;
}
};
c.call();
}
示例2: convertParamsToLua
import java.util.concurrent.Callable; //导入方法依赖的package包/类
public static LuaValue[] convertParamsToLua(Object instance, Object[] objects, final Callable supercall) {
LuaValue[] parameters = new LuaValue[objects.length + 2];
parameters[0] = LuaConversion.convertToLua(instance);
for (int i = 0; i < objects.length; i++) {
parameters[i + 1] = LuaConversion.convertToLua(objects[i]);
}
parameters[parameters.length - 1] = new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
try {
Object o = supercall.call();
return LuaConversion.convertToLua(o);
} catch (Exception e) {
throw new DynamicDelegationError("Supercall threw exception - called from supplied delegation", e);
}
}
};
return parameters;
}
示例3: performRegistration
import java.util.concurrent.Callable; //导入方法依赖的package包/类
public <T> T performRegistration(PetRegistrationEntry registrationEntry, Callable<T> callable){
Class<?> existingEntityClass = ID_TO_CLASS_MODIFIER.getMap().get(registrationEntry.getRegistrationId());
// Just to be sure, remove any existing mappings and replace them afterwards
// Make this entity the 'default' while the pet is being spawned
ID_TO_CLASS_MODIFIER.clear(existingEntityClass);
ID_TO_CLASS_MODIFIER.modify(registrationEntry.getRegistrationId(), registrationEntry.getEntityClass());
try{
ID_TO_CLASS_MODIFIER.applyModifications();
return callable.call();
}catch(Exception e){
throw new PetRegistrationException(e);
}finally{
// Ensure everything is back to normal
// Client will now receive the correct entity ID and we're all set!
ID_TO_CLASS_MODIFIER.removeModifications();
ID_TO_CLASS_MODIFIER.add(existingEntityClass);
}
}
示例4: uncheckedCall
import java.util.concurrent.Callable; //导入方法依赖的package包/类
/**
* Calls the given callable converting any thrown exception to an unchecked exception via {@link UncheckedException#throwAsUncheckedException(Throwable)}
*
* @param callable The callable to call
* @param <T> Callable's return type
* @return The value returned by {@link Callable#call()}
*/
public static <T> T uncheckedCall(Callable<T> callable) {
try {
return callable.call();
} catch (Exception e) {
throw UncheckedException.throwAsUncheckedException(e);
}
}
示例5: callWithRetry
import java.util.concurrent.Callable; //导入方法依赖的package包/类
public RespT callWithRetry(Callable<RespT> proc, String methodName) {
for(;true;) {
try {
RespT result = proc.call();
if (handler != null) {
handler.handle(result);
}
return result;
} catch (Exception e) {
handleFailure(e, methodName, backOff.nextBackOffMillis());
}
}
}
示例6: doTestUnloadableInStaticFieldIfClosed
import java.util.concurrent.Callable; //导入方法依赖的package包/类
private WeakReference<ClassLoader> doTestUnloadableInStaticFieldIfClosed() throws Exception {
final URLClassLoader myLoader = (URLClassLoader) getClass().getClassLoader();
final URL[] urls = myLoader.getURLs();
URLClassLoader sepLoader = new URLClassLoader(urls, myLoader.getParent());
Class<?> frqC = FinalizableReferenceQueue.class;
Class<?> sepFrqC = sepLoader.loadClass(frqC.getName());
assertNotSame(frqC, sepFrqC);
Class<?> sepFrqSystemLoaderC =
sepLoader.loadClass(FinalizableReferenceQueue.SystemLoader.class.getName());
Field disabled = sepFrqSystemLoaderC.getDeclaredField("disabled");
disabled.setAccessible(true);
disabled.set(null, true);
Class<?> frqUserC = FrqUser.class;
Class<?> sepFrqUserC = sepLoader.loadClass(frqUserC.getName());
assertNotSame(frqUserC, sepFrqUserC);
assertSame(sepLoader, sepFrqUserC.getClassLoader());
Callable<?> sepFrqUser = (Callable<?>) sepFrqUserC.newInstance();
WeakReference<?> finalizableWeakReference = (WeakReference<?>) sepFrqUser.call();
GcFinalization.awaitClear(finalizableWeakReference);
Field sepFrqUserFinalizedF = sepFrqUserC.getField("finalized");
Semaphore finalizeCount = (Semaphore) sepFrqUserFinalizedF.get(null);
boolean finalized = finalizeCount.tryAcquire(5, TimeUnit.SECONDS);
assertTrue(finalized);
Field sepFrqUserFrqF = sepFrqUserC.getField("frq");
Closeable frq = (Closeable) sepFrqUserFrqF.get(null);
frq.close();
return new WeakReference<ClassLoader>(sepLoader);
}
示例7: runInTransaction
import java.util.concurrent.Callable; //导入方法依赖的package包/类
@Override
public <T> T runInTransaction(Callable<T> callable) {
// We still track insideTransaction, so we can catch bugs.
hardAssert(
!insideTransaction,
"runInTransaction called when an existing transaction is already in progress.");
insideTransaction = true;
try {
return callable.call();
} catch (Throwable e) {
throw new RuntimeException(e);
} finally {
insideTransaction = false;
}
}
示例8: assertEventuallyTrue
import java.util.concurrent.Callable; //导入方法依赖的package包/类
protected static void assertEventuallyTrue(final String message, final Callable<Boolean> callable,
final int timeout, final int interval) throws Exception {
boolean done = false;
for (StopWatch time = new StopWatch(true); !done && time.elapsedTimeMillis() < timeout; done =
(callable.call())) {
Thread.sleep(interval);
}
assertTrue(message, done);
}
示例9: exec
import java.util.concurrent.Callable; //导入方法依赖的package包/类
@SuppressWarnings("unchecked") public static <X> X exec(final Callable<X> callable) {
final Object[] result = new Object[] { null };
final Exception[] exc = new Exception[] { null };
Runnable r = new Runnable() {
@Override public void run() {
try {
result[0] = callable.call();
} catch (Exception e) {
exc[0] = e;
}
}
};
invokeAndWait(r);
if (exc[0] != null) {
if (exc[0] instanceof InvocationTargetException) {
Throwable cause = exc[0].getCause();
if (cause instanceof Exception) {
exc[0] = (Exception) cause;
} else {
exc[0] = new RuntimeException(cause);
}
}
if (exc[0] instanceof RuntimeException) {
throw (RuntimeException) exc[0];
}
throw new JavaAgentException("Call to invokeAndWait failed: " + exc[0].getMessage(), exc[0]);
}
return (X) result[0];
}
示例10: tryRunWithAllPerm
import java.util.concurrent.Callable; //导入方法依赖的package包/类
/**
* Run the supplier with all permissions. This won't impact global policy.
*
* @param s
* Supplier to run
*/
public static <T> T tryRunWithAllPerm(Callable<T> c) throws Exception {
Optional<JAXPPolicyManager> policyManager = Optional.ofNullable(JAXPPolicyManager
.getJAXPPolicyManager(false));
policyManager.ifPresent(manager -> manager.setAllowAll(true));
try {
return c.call();
} finally {
policyManager.ifPresent(manager -> manager.setAllowAll(false));
}
}
示例11: callMethod
import java.util.concurrent.Callable; //导入方法依赖的package包/类
public static int callMethod(Callable<Integer> callable, int expected) {
int result = 0;
for (int i = 0; i < THRESHOLD; ++i) {
try {
result = callable.call();
} catch (Exception e) {
throw new AssertionError(
"Exception occurred during test method execution", e);
}
Asserts.assertEQ(result, expected, "Method returns unexpected value");
}
return result;
}
示例12: intercept
import java.util.concurrent.Callable; //导入方法依赖的package包/类
@RuntimeType
public Object intercept(@SuperCall Callable<?> superMethod, @Origin Method method, @AllArguments Object[] args, @This Object me) {
beginTrace((Jedis) me, method);
Throwable error = null;
try {
return superMethod.call();
} catch (Throwable t) {
error = t;
throw new JaRedisCallException("Call superMethod error.", t);
} finally {
endTrace(error);
}
}
示例13: execute
import java.util.concurrent.Callable; //导入方法依赖的package包/类
@Override
public <V> V execute(UserState state, Callable<V> runnable)
{
final UserState originalUser = CurrentUser.getUserState();
final Institution originalInstitution = CurrentInstitution.get();
final DataSourceHolder originalDataSource = CurrentDataSource.get();
try
{
Institution institution = state.getInstitution();
CurrentInstitution.set(institution);
if( institution == null )
{
CurrentDataSource.set(null);
}
else
{
CurrentDataSource.set(databaseSchemaService
.getDataSourceForId(institutionService.getSchemaIdForInstitution(institution)));
}
CurrentUser.setUserState(state);
return runnable.call();
}
catch( Exception e )
{
throw new RuntimeException(e);
}
finally
{
CurrentUser.setUserState(originalUser);
CurrentDataSource.set(originalDataSource);
CurrentInstitution.set(originalInstitution);
}
}
示例14: profileExecution
import java.util.concurrent.Callable; //导入方法依赖的package包/类
public static <T> T profileExecution(Callable<T> callable) throws Exception {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
try {
return callable.call();
}
finally {
stopWatch.stop();
log.debug(stopWatch.prettyPrint());
}
}
示例15: call
import java.util.concurrent.Callable; //导入方法依赖的package包/类
/**
* Execute specified callable in lock of specified name.
*
* @param name
* name of the lock to be acquired
* @param callable
* callable to be execute within the named lock
* @return
* return value of the callable
*/
public static <T> T call(String name, Callable<T> callable) {
Lock lock = getLock(name);
try {
lock.lockInterruptibly();
return callable.call();
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
lock.unlock();
}
}