use of io.milton.http.exceptions.LockedException in project lobcder by skoulouzis.
the class WebDataResource method lock.
@Override
public LockResult lock(LockTimeout timeout, LockInfo lockInfo) throws NotAuthorizedException, PreConditionFailedException, LockedException {
if (getCurrentLock() != null) {
throw new LockedException(this);
}
LockToken lockToken = new LockToken(UUID.randomUUID().toString(), lockInfo, timeout);
Long lockTimeout;
try (Connection connection = getCatalogue().getConnection()) {
try {
getLogicalData().setLockTokenID(lockToken.tokenId);
getCatalogue().setLockTokenID(getLogicalData().getUid(), getLogicalData().getLockTokenID(), connection);
getLogicalData().setLockScope(lockToken.info.scope.toString());
getCatalogue().setLockScope(getLogicalData().getUid(), getLogicalData().getLockScope(), connection);
getLogicalData().setLockType(lockToken.info.type.toString());
getCatalogue().setLockType(getLogicalData().getUid(), getLogicalData().getLockType(), connection);
getLogicalData().setLockedByUser(lockToken.info.lockedByUser);
getCatalogue().setLockByUser(getLogicalData().getUid(), getLogicalData().getLockedByUser(), connection);
getLogicalData().setLockDepth(lockToken.info.depth.toString());
getCatalogue().setLockDepth(getLogicalData().getUid(), getLogicalData().getLockDepth(), connection);
lockTimeout = lockToken.timeout.getSeconds();
if (lockTimeout == null) {
lockTimeout = Long.valueOf(System.currentTimeMillis() + Constants.LOCK_TIME);
}
getLogicalData().setLockTimeout(lockTimeout);
getCatalogue().setLockTimeout(getLogicalData().getUid(), lockTimeout, connection);
connection.commit();
return LockResult.success(lockToken);
} catch (Exception ex) {
Logger.getLogger(WebDataResource.class.getName()).log(Level.SEVERE, null, ex);
connection.rollback();
throw new PreConditionFailedException(this);
}
} catch (SQLException e) {
Logger.getLogger(WebDataResource.class.getName()).log(Level.SEVERE, null, e);
throw new PreConditionFailedException(this);
}
}
use of io.milton.http.exceptions.LockedException in project lobcder by skoulouzis.
the class LockHandler method process.
@Override
public void process(HttpManager httpManager, Request request, Response response) throws ConflictException, NotAuthorizedException, BadRequestException, NotFoundException {
if (!handlerHelper.checkExpects(responseHandler, request, response)) {
return;
}
String host = request.getHostHeader();
String url = HttpManager.decodeUrl(request.getAbsolutePath());
Resource r = httpManager.getResourceFactory().getResource(host, url);
try {
// Find a resource if it exists
if (r != null) {
processExistingResource(httpManager, request, response, r);
} else {
processNonExistingResource(httpManager, request, response, host, url);
}
} catch (IOException ex) {
throw new BadRequestException(r);
} catch (SAXException ex) {
throw new BadRequestException(r);
} catch (LockedException ex) {
responseHandler.respondLocked(request, response, r);
} catch (PreConditionFailedException ex) {
responseHandler.respondPreconditionFailed(request, response, r);
}
}
Aggregations