Implement LockingCollectionResource

OK, this is the tricky one, despite its simple looking interface

Implement LockingCollectionResource.java
public interface  LockingCollectionResource extends CollectionResource, LockableResource {
    
    /**
     * Create an empty non-collection resource of the given name and immediately
     * lock it.
     * <P/>
     * It is suggested that the implementor have a specific Resource class to act
     * as the lock null resource. You should consider using the {@see LockNullResource}
     * interface.
     *
     * @see  LockNullResource
     *
     * @param name - the name of the resource to create
     * @param timeout - in seconds
     * @param lockInfo
     * @return
     */
    public LockToken createAndLock(String name, LockTimeout timeout, LockInfo lockInfo) throws NotAuthorizedException;
    
}

When createAndLock is called you somehow need to record a placeholder resource which is neither a file nor a collection, but which will become a file or collection when the next PUT or MKCOL is called on the same resource.

Note that you shouldnt ignore this, because it implements a vitally important mechanism for operating system clients. It provides an atomic action which:

  • checks for the existence of a resource with the given path
  • creates it (sort of)
  • locks it

Its necessary that these steps can all be done atomically to ensure files dont get overwritten by different processes. In reality this will happen rarely, but because some operating systems are predicated on this capability being available, you really need it.

Next Article:

Lock enforcement