Search in sources :

Example 1 with LockToken

use of io.milton.http.LockToken in project lobcder by skoulouzis.

the class WebDataResource method getCurrentLock.

@Override
public LockToken getCurrentLock() {
    if (getLogicalData().getLockTokenID() == null) {
        return null;
    } else {
        LockInfo lockInfo = new LockInfo(LockInfo.LockScope.valueOf(getLogicalData().getLockScope()), LockInfo.LockType.valueOf(getLogicalData().getLockType()), getLogicalData().getLockedByUser(), LockInfo.LockDepth.valueOf(getLogicalData().getLockDepth()));
        LockTimeout lockTimeOut = new LockTimeout(getLogicalData().getLockTimeout());
        return new LockToken(getLogicalData().getLockTokenID(), lockInfo, lockTimeOut);
    }
}
Also used : LockToken(io.milton.http.LockToken) LockInfo(io.milton.http.LockInfo) LockTimeout(io.milton.http.LockTimeout)

Example 2 with LockToken

use of io.milton.http.LockToken in project lobcder by skoulouzis.

the class MemoryLockManagerTest method testLockUnLock.

public void testLockUnLock() throws NotAuthorizedException {
    LockTimeout timeout = new LockTimeout(100l);
    LockInfo lockInfo = new LockInfo(LockInfo.LockScope.NONE, LockInfo.LockType.READ, "me", LockInfo.LockDepth.ZERO);
    SimpleFileContentService contentService = new SimpleFileContentService();
    FsResource resource = new FsFileResource(null, null, new File(File.pathSeparator), contentService);
    // lock it
    LockResult res = lockManager.lock(timeout, lockInfo, resource);
    assertNotNull(res);
    assertTrue(res.isSuccessful());
    // check is locked
    LockToken token = lockManager.getCurrentToken(resource);
    assertNotNull(token);
    assertEquals(token.tokenId, res.getLockToken().tokenId);
    // unlock
    lockManager.unlock(token.tokenId, resource);
    // check removed
    token = lockManager.getCurrentToken(resource);
    assertNull(token);
}
Also used : FsResource(io.milton.http.fs.FsResource) LockResult(io.milton.http.LockResult) FsFileResource(io.milton.http.fs.FsFileResource) LockToken(io.milton.http.LockToken) LockInfo(io.milton.http.LockInfo) SimpleFileContentService(io.milton.http.fs.SimpleFileContentService) File(java.io.File) LockTimeout(io.milton.http.LockTimeout)

Example 3 with LockToken

use of io.milton.http.LockToken in project lobcder by skoulouzis.

the class SimpleLockManager method lock.

private LockResult lock(LockTimeout timeout, LockInfo lockInfo, LockableResource r, String token) {
    LockToken currentLock = currentLock(r);
    if (currentLock != null) {
        return LockResult.failed(LockResult.FailureReason.ALREADY_LOCKED);
    }
    LockToken newToken = new LockToken(token, lockInfo, timeout);
    CurrentLock newLock = new CurrentLock(r.getUniqueId(), newToken, lockInfo.lockedByUser);
    locksByUniqueId.put(r.getUniqueId(), newLock);
    locksByToken.put(newToken.tokenId, newLock);
    return LockResult.success(newToken);
}
Also used : LockToken(io.milton.http.LockToken)

Example 4 with LockToken

use of io.milton.http.LockToken in project lobcder by skoulouzis.

the class SimpleLockManager method getCurrentToken.

public LockToken getCurrentToken(LockableResource r) {
    CurrentLock lock = locksByUniqueId.get(r.getUniqueId());
    if (lock == null)
        return null;
    LockToken token = new LockToken();
    token.info = new LockInfo(LockInfo.LockScope.EXCLUSIVE, LockInfo.LockType.WRITE, lock.lockedByUser, LockInfo.LockDepth.ZERO);
    token.info.lockedByUser = lock.lockedByUser;
    token.timeout = lock.token.timeout;
    token.tokenId = lock.token.tokenId;
    return token;
}
Also used : LockToken(io.milton.http.LockToken) LockInfo(io.milton.http.LockInfo)

Example 5 with LockToken

use of io.milton.http.LockToken in project lobcder by skoulouzis.

the class LockHandler method processNewLock.

private void processNewLock(HttpManager manager, Request request, Response response, LockableResource r, LockTimeout timeout) throws IOException, SAXException, NotAuthorizedException, PreConditionFailedException, LockedException {
    LockInfo lockInfo = parseLockInfo(request);
    if (handlerHelper.isLockedOut(request, r)) {
        this.responseHandler.respondLocked(request, response, r);
        return;
    }
    LockResult result = r.lock(timeout, lockInfo);
    if (result.isSuccessful()) {
        LockToken tok = result.getLockToken();
        // spec says to set response header. See 8.10.1
        response.setLockTokenHeader("<opaquelocktoken:" + tok.tokenId + ">");
        respondWithToken(tok, request, response);
    } else {
        response.setStatus(result.getFailureReason().status);
    }
}
Also used : LockResult(io.milton.http.LockResult) LockToken(io.milton.http.LockToken) LockInfo(io.milton.http.LockInfo)

Aggregations

LockToken (io.milton.http.LockToken)7 LockInfo (io.milton.http.LockInfo)5 LockTimeout (io.milton.http.LockTimeout)3 LockResult (io.milton.http.LockResult)2 FsFileResource (io.milton.http.fs.FsFileResource)1 FsResource (io.milton.http.fs.FsResource)1 SimpleFileContentService (io.milton.http.fs.SimpleFileContentService)1 LockingCollectionResource (io.milton.resource.LockingCollectionResource)1 File (java.io.File)1 IOException (java.io.IOException)1 SAXException (org.xml.sax.SAXException)1