List of usage examples for com.google.common.util.concurrent SimpleTimeLimiter SimpleTimeLimiter
public SimpleTimeLimiter(ExecutorService executor)
From source file:google.registry.util.AppEngineTimeLimiter.java
public static TimeLimiter create() { return new SimpleTimeLimiter(new NewRequestThreadExecutorService()); }
From source file:com.facebook.presto.raptor.backup.TimeoutBackupStore.java
private static <T> T timeLimited(T target, Class<T> clazz, Duration timeout, ExecutorService executor) { TimeLimiter limiter = new SimpleTimeLimiter(executor); return limiter.newProxy(target, clazz, timeout.toMillis(), MILLISECONDS); }
From source file:com.infinities.skyport.timeout.ServiceProviderTimeLimiter.java
public ServiceProviderTimeLimiter(ExecutorService executor) { this.limiter = new SimpleTimeLimiter(executor); }
From source file:org.openqa.selenium.net.UrlChecker.java
public UrlChecker() { this(new SimpleTimeLimiter(THREAD_POOL)); }
From source file:com.facebook.presto.ml.AbstractSvmModel.java
@Override public void train(Dataset dataset) { params.svm_type = getLibsvmType();/* www .j a v a 2 s . co m*/ svm_problem problem = toSvmProblem(dataset); ExecutorService service = newCachedThreadPool( threadsNamed("libsvm-trainer-" + System.identityHashCode(this) + "-%s")); try { TimeLimiter limiter = new SimpleTimeLimiter(service); //TODO: this time limit should be configurable model = limiter.callWithTimeout(getTrainingFunction(problem, params), 1, TimeUnit.HOURS, true); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw Throwables.propagate(e); } catch (Exception e) { throw Throwables.propagate(e); } finally { service.shutdownNow(); } }
From source file:org.terasology.flexiblepathfinding.JPSImpl.java
public JPSImpl(JPSConfig config) { this.config = config; if (config.executor != null) { this.timeLimiter = new SimpleTimeLimiter(config.executor); }/*from ww w . j ava 2 s . com*/ }
From source file:org.glukit.dexcom.sync.tasks.IsReceiverOnThisPortRunner.java
public boolean isReceiver(String portName) { ExecutorService executor = Executors.newSingleThreadExecutor(); final SerialPort serialPort = new SerialPort(portName); try {/*w w w . jav a 2 s . com*/ SimpleTimeLimiter timeout = new SimpleTimeLimiter(executor); Boolean result = timeout.callWithTimeout(new Callable<Boolean>() { @Override public Boolean call() throws Exception { return isFirmware(serialPort); } }, 5, TimeUnit.SECONDS, true); return result; } catch (Exception e) { LOGGER.info("Receiver not running on this port since we had an exception while checking.", e); return false; } finally { executor.shutdown(); if (serialPort.isOpened()) { try { LOGGER.debug(format("Closing port %s", serialPort.getPortName())); serialPort.closePort(); } catch (SerialPortException e) { LOGGER.warn("Error closing port, ignoring.", e); } } } }
From source file:org.graylog2.streams.StreamRouterEngine.java
@Inject public StreamRouterEngine(@Assisted List<Stream> streams, @Assisted ExecutorService executorService, StreamFaultManager streamFaultManager, StreamMetrics streamMetrics) { this.streams = streams; this.streamFaultManager = streamFaultManager; this.streamMetrics = streamMetrics; this.timeLimiter = new SimpleTimeLimiter(executorService); this.streamProcessingTimeout = streamFaultManager.getStreamProcessingTimeout(); this.fingerprint = new StreamListFingerprint(streams).getFingerprint(); final List<Rule> presenceRules = Lists.newArrayList(); final List<Rule> exactRules = Lists.newArrayList(); final List<Rule> greaterRules = Lists.newArrayList(); final List<Rule> smallerRules = Lists.newArrayList(); final List<Rule> regexRules = Lists.newArrayList(); for (Stream stream : streams) { for (StreamRule streamRule : stream.getStreamRules()) { final Rule rule; try { rule = new Rule(stream, streamRule, stream.getMatchingType()); } catch (InvalidStreamRuleTypeException e) { LOG.warn("Invalid stream rule type. Skipping matching for this rule. " + e.getMessage(), e); continue; }//from w w w . jav a 2 s. c o m switch (streamRule.getType()) { case PRESENCE: presenceRules.add(rule); break; case EXACT: exactRules.add(rule); break; case GREATER: greaterRules.add(rule); break; case SMALLER: smallerRules.add(rule); break; case REGEX: regexRules.add(rule); break; } } } final int size = presenceRules.size() + exactRules.size() + greaterRules.size() + smallerRules.size() + regexRules.size(); this.rulesList = Lists.newArrayListWithCapacity(size); this.rulesList.addAll(presenceRules); this.rulesList.addAll(exactRules); this.rulesList.addAll(greaterRules); this.rulesList.addAll(smallerRules); this.rulesList.addAll(regexRules); }
From source file:org.grycap.gpf4med.DocumentManager.java
private DocumentManager() { executor = Executors.newCachedThreadPool(); limiter = new SimpleTimeLimiter(executor); }
From source file:org.jclouds.concurrent.config.ExecutorServiceModule.java
@Provides
@Singleton
TimeLimiter timeLimiter(@Named(PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
return new SimpleTimeLimiter(userExecutor);
}