本文整理汇总了Java中com.google.common.util.concurrent.UncheckedTimeoutException类的典型用法代码示例。如果您正苦于以下问题:Java UncheckedTimeoutException类的具体用法?Java UncheckedTimeoutException怎么用?Java UncheckedTimeoutException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UncheckedTimeoutException类属于com.google.common.util.concurrent包,在下文中一共展示了UncheckedTimeoutException类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import com.google.common.util.concurrent.UncheckedTimeoutException; //导入依赖的package包/类
@Override
public void run() {
try {
if (jobControl.isActive(name())) {
try (Lock lock = jobControl.curator().lockMaintenanceJob(name())) {
maintain();
}
}
}
catch (UncheckedTimeoutException e) {
// another controller instance is running this job at the moment; ok
}
catch (Throwable t) {
log.log(Level.WARNING, this + " failed. Will retry in " + maintenanceInterval.toMinutes() + " minutes", t);
}
}
示例2: acquire
import com.google.common.util.concurrent.UncheckedTimeoutException; //导入依赖的package包/类
@Override
public boolean acquire(long timeout, TimeUnit unit) {
if (throwExceptionOnLock)
throw new CuratorLockException("Thrown by mock");
if (timeoutOnLock) return false;
try {
lock = locks.lock(path, timeout, unit);
return true;
}
catch (UncheckedTimeoutException e) {
return false;
}
}
示例3: acquire
import com.google.common.util.concurrent.UncheckedTimeoutException; //导入依赖的package包/类
/** Take the lock with the given timeout. This may be called multiple times from the same thread - each matched by a close */
public void acquire(Duration timeout) {
boolean acquired;
try {
acquired = mutex.acquire(timeout.toMillis(), TimeUnit.MILLISECONDS);
}
catch (Exception e) {
throw new RuntimeException("Exception acquiring lock '" + lockPath + "'", e);
}
if (! acquired) throw new UncheckedTimeoutException("Timed out after waiting " + timeout.toString() +
" to acquire lock '" + lockPath + "'");
}
示例4: test_application_lock_failure
import com.google.common.util.concurrent.UncheckedTimeoutException; //导入依赖的package包/类
@Test
public void test_application_lock_failure() throws InterruptedException, IOException {
String message = "Timed out after waiting PT1M to acquire lock '/provision/v1/locks/foo/bar/default'";
SessionThrowingException session =
new SessionThrowingException(new ApplicationLockException(new UncheckedTimeoutException(message)));
localRepo.addSession(session);
HttpResponse response = createHandler()
.handle(SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.PUT, Cmd.PREPARED, 1L));
assertEquals(500, response.getStatus());
Slime data = getData(response);
assertThat(data.get().field("error-code").asString(), is(HttpErrorResponse.errorCodes.APPLICATION_LOCK_FAILURE.name()));
assertThat(data.get().field("message").asString(), is(message));
}
示例5: lock
import com.google.common.util.concurrent.UncheckedTimeoutException; //导入依赖的package包/类
/** Acquires the single cluster-global, reentrant lock with the specified timeout for active nodes of this application */
public Lock lock(ApplicationId application, Duration timeout) {
try {
return lock(lockPath(application), timeout);
}
catch (UncheckedTimeoutException e) {
throw new ApplicationLockException(e);
}
}
示例6: backupShard
import com.google.common.util.concurrent.UncheckedTimeoutException; //导入依赖的package包/类
@Override
public void backupShard(UUID uuid, File source)
{
try {
store.backupShard(uuid, source);
}
catch (UncheckedTimeoutException e) {
throw new PrestoException(RAPTOR_BACKUP_TIMEOUT, "Shard backup timed out");
}
}
示例7: restoreShard
import com.google.common.util.concurrent.UncheckedTimeoutException; //导入依赖的package包/类
@Override
public void restoreShard(UUID uuid, File target)
{
try {
store.restoreShard(uuid, target);
}
catch (UncheckedTimeoutException e) {
throw new PrestoException(RAPTOR_BACKUP_TIMEOUT, "Shard restore timed out");
}
}
示例8: deleteShard
import com.google.common.util.concurrent.UncheckedTimeoutException; //导入依赖的package包/类
@Override
public void deleteShard(UUID uuid)
{
try {
store.deleteShard(uuid);
}
catch (UncheckedTimeoutException e) {
throw new PrestoException(RAPTOR_BACKUP_TIMEOUT, "Shard delete timed out");
}
}
示例9: shardExists
import com.google.common.util.concurrent.UncheckedTimeoutException; //导入依赖的package包/类
@Override
public boolean shardExists(UUID uuid)
{
try {
return store.shardExists(uuid);
}
catch (UncheckedTimeoutException e) {
throw new PrestoException(RAPTOR_BACKUP_TIMEOUT, "Shard existence check timed out");
}
}
示例10: query
import com.google.common.util.concurrent.UncheckedTimeoutException; //导入依赖的package包/类
private JoinQueryResultDto query(QueryType type, JoinQuery joinQuery,
CountStatsData.Builder countBuilder, QueryScope scope, QueryMode mode) {
boolean havePermit = false;
try {
havePermit = acquireSemaphorePermit();
if (havePermit)
return unsafeQuery(type, joinQuery, countBuilder, scope, mode);
else
throw new UncheckedTimeoutException("Too many queries in a short time. Please retry later.");
} finally {
if (havePermit)
releaseSemaphorePermit();
}
}
示例11: getErrorDto
import com.google.common.util.concurrent.UncheckedTimeoutException; //导入依赖的package包/类
@Override
protected GeneratedMessage.ExtendableMessage<?> getErrorDto(UncheckedTimeoutException e) {
return ErrorDtos.ClientErrorDto.newBuilder()
.setCode(getStatus().getStatusCode())
.setMessageTemplate("server.error.search.timeout")
.setMessage(e.getMessage())
.build();
}
示例12: createRealConnection
import com.google.common.util.concurrent.UncheckedTimeoutException; //导入依赖的package包/类
/**
* Creates a real database connection, failing if one is not obtained in the specified time.
* @param timeoutMillis The timeout in milliseconds.
* @return The connection.
* @throws SQLException on connection problem or timeout waiting for connection.
*/
private Connection createRealConnection(final long timeoutMillis) throws SQLException {
if(timeoutMillis < 1L) {
String usePassword = getPassword();
Connection conn = dbConnection.datasource == null ?
DriverManager.getConnection(dbConnection.connectionString, dbConnection.user, usePassword) :
dbConnection.datasource.getConnection(dbConnection.user, usePassword);
if(conn != null) {
return conn;
} else {
throw new SQLException("Unable to create connection: driver/datasource returned [null]");
}
} else {
try {
return connectionTimeLimiter.callWithTimeout(new Callable<Connection>() {
public Connection call() throws Exception {
return createRealConnection(0L);
}
}, timeoutMillis, TimeUnit.MILLISECONDS, true);
} catch(UncheckedTimeoutException ute) {
throw new SQLException("Unable to create connection after waiting " + timeoutMillis + " ms");
} catch(Exception e) {
if(e instanceof SQLException) {
throw (SQLException)e;
} else {
throw new SQLException("Unable to create connection: driver/datasource", e);
}
}
}
}
示例13: shouldTriggerTimeout
import com.google.common.util.concurrent.UncheckedTimeoutException; //导入依赖的package包/类
@Test(expected = UncheckedTimeoutException.class)
public void shouldTriggerTimeout() throws Exception {
new SimpleTimeLimiter().callWithTimeout(
() -> doSomeHeavyWeightOperation(), NOT_ENOUGH_MS, MILLISECONDS, true);
}
示例14: checkTimeout
import com.google.common.util.concurrent.UncheckedTimeoutException; //导入依赖的package包/类
/**
* Throws UncheckedTimeoutException if current time is past the provided timeout timestamp.
* @param timeoutTS timestamp of when the query times out in milliseconds
*/
public void checkTimeout(long timeoutTS) {
if(System.currentTimeMillis() > timeoutTS) {
throw new UncheckedTimeoutException("The query took longer than the allowed timeout of " + executionTimeout.toString(PeriodFormat.getDefault()));
}
}