当前位置: 首页>>代码示例>>Java>>正文


Java Callable.call方法代码示例

本文整理汇总了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();
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:17,代码来源:LaunchServicesQuarantineServiceTest.java

示例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;
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:20,代码来源:LuaGeneration.java

示例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);
	}
}
 
开发者ID:Borlea,项目名称:EchoPet,代码行数:19,代码来源:PetRegistry.java

示例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);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:15,代码来源:GUtil.java

示例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());
    }
  }
}
 
开发者ID:pingcap,项目名称:tikv-client-lib-java,代码行数:14,代码来源:RetryPolicy.java

示例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);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:37,代码来源:FinalizableReferenceQueueClassLoaderUnloadingTest.java

示例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;
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:16,代码来源:NoopPersistenceManager.java

示例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);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:10,代码来源:HostedLocatorsDUnitTest.java

示例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];
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:30,代码来源:EventQueueWait.java

示例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));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:JAXPTestUtilities.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:Helper.java

示例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);
    }
}
 
开发者ID:YanXs,项目名称:nighthawk,代码行数:14,代码来源:JaRedisInterceptor.java

示例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);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:35,代码来源:RunAsInstitutionImpl.java

示例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());
	}
}
 
开发者ID:venilnoronha,项目名称:movie-rating-prediction,代码行数:12,代码来源:ProfileUtils.java

示例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();
  	}
  }
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:22,代码来源:LockUtils.java


注:本文中的java.util.concurrent.Callable.call方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。