Search in sources :

Example 1 with Volume

use of dev.hawala.xns.level4.filing.fs.Volume in project dodo by devhawala.

the class FilingImpl method copy.

/*
	 * Copy: PROCEDURE [ file, destinationDirectory: Handle ,
	 *                   attributes: AttributeSequence, controls: ControlSequence,
	 *                   session: Session ]
	 *   RETURNS [ newFile: Handle ]
	 *   REPORTS [ AccessError, AttributeTypeError, AttributeValueError,
	 *             AuthenticationError, ControlTypeError, ControlValueError,
	 *             HandleError, InsertionError, SessionError, SpaceError,
	 *             UndefinedError ]
	 *   = 10;
	 */
private static void copy(CopyParams params, CopyResults results) {
    logParams("copy", params);
    // check session
    Session session = resolveSession(params.session);
    Volume vol = session.getService().getVolume();
    // check specified file handle
    Handle fileHandle = Handle.get(params.handle);
    if (fileHandle.isVolumeRoot()) {
        // the file system root cannot be copied
        new AccessErrorRecord(AccessProblem.accessRightsInsufficient).raise();
    }
    if (fileHandle.isNullHandle()) {
        new HandleErrorRecord(HandleProblem.nullDisallowed).raise();
    }
    FileEntry fe = fileHandle.getFe();
    if (fe.getParentID() == FsConstants.rootFileID) {
        // file system root folders cannot be copied
        new AccessErrorRecord(AccessProblem.accessRightsInsufficient).raise();
    }
    // check the destination
    Handle destinationDirHandle = Handle.get(params.destinationDirectory);
    if (destinationDirHandle.isVolumeRoot()) {
        // the file system root cannot be target
        new AccessErrorRecord(AccessProblem.accessRightsInsufficient).raise();
    }
    if (destinationDirHandle.isNullHandle()) {
        new HandleErrorRecord(HandleProblem.nullDisallowed).raise();
    }
    FileEntry destinationDirectory = destinationDirHandle.getFe();
    // copy the file and return new file
    List<iValueSetter> attrSetters = getCourier2FileAttributeSetters(params.attributes);
    try (Volume.Session modSession = vol.startModificationSession()) {
        // do the copy
        FileEntry newFe = modSession.copy(fe, destinationDirectory, attrSetters, session.getUsername());
        // prepare results
        Handle newFeHandle = new Handle(session, newFe);
        newFeHandle.setIdTo(results.newHandle);
        logResult("copy", results);
    } catch (InterruptedException e) {
        new UndefinedErrorRecord(FilingCommon.UNDEFINEDERROR_CANNOT_MODIFY_VOLUME).raise();
    } catch (Exception e) {
        new SpaceErrorRecord(SpaceProblem.mediumFull).raise();
    }
    // prolongate the sessions life if this took longer
    session.continueUse();
}
Also used : AccessErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.AccessErrorRecord) HandleErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.HandleErrorRecord) SpaceErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.SpaceErrorRecord) dev.hawala.xns.level4.filing.fs.iValueSetter(dev.hawala.xns.level4.filing.fs.iValueSetter) NoMoreWriteSpaceException(dev.hawala.xns.level3.courier.iWireStream.NoMoreWriteSpaceException) EndOfMessageException(dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException) IOException(java.io.IOException) CourierException(dev.hawala.xns.level3.courier.exception.CourierException) UndefinedErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.UndefinedErrorRecord) Volume(dev.hawala.xns.level4.filing.fs.Volume) FileEntry(dev.hawala.xns.level4.filing.fs.FileEntry)

Example 2 with Volume

use of dev.hawala.xns.level4.filing.fs.Volume in project dodo by devhawala.

the class FilingImpl method changeAttributes.

/*
	 * ChangeAttributes: PROCEDURE [ file: Handle, attributes: AttributeSequence,
	 *                               session: Session ]
	 *   REPORTS [ AccessError, AttributeTypeError, AttributeValueError,
	 *             AuthenticationError, HandleError, InsertionError,
	 *             SessionError, SpaceError, UndefinedError ]
	 *   = 9;
	 */
private static void changeAttributes(ChangeAttributesParams params, RECORD results) {
    logParams("changeAttributes", params);
    // check session
    Session session = resolveSession(params.session);
    Volume vol = session.getService().getVolume();
    // check specified file handle
    Handle fileHandle = Handle.get(params.handle);
    if (fileHandle == null || fileHandle.isNullHandle()) {
        new HandleErrorRecord(HandleProblem.nullDisallowed).raise();
    }
    if (fileHandle.isVolumeRoot()) {
        // the file system root cannot be modified
        new AccessErrorRecord(AccessProblem.accessRightsInsufficient).raise();
    }
    FileEntry fe = fileHandle.getFe();
    if (fe == null) {
        new HandleErrorRecord(HandleProblem.nullDisallowed).raise();
    }
    // change attributes
    List<iValueSetter> attrSetters = getCourier2FileAttributeSetters(params.attributes);
    try (Volume.Session modSession = vol.startModificationSession()) {
        modSession.updateFileAttributes(fe, attrSetters, session.getUsername());
    } catch (InterruptedException e) {
        new UndefinedErrorRecord(FilingCommon.UNDEFINEDERROR_CANNOT_MODIFY_VOLUME).raise();
    } catch (EndOfMessageException e) {
        new ConnectionErrorRecord(ConnectionProblem.otherCallProblem).raise();
    } catch (CourierException ce) {
        // this is a RuntimeException, why is it catch-ed by Exception ???????
        throw ce;
    } catch (Exception e1) {
        new SpaceErrorRecord(SpaceProblem.mediumFull).raise();
    }
}
Also used : AccessErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.AccessErrorRecord) HandleErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.HandleErrorRecord) SpaceErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.SpaceErrorRecord) dev.hawala.xns.level4.filing.fs.iValueSetter(dev.hawala.xns.level4.filing.fs.iValueSetter) ConnectionErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.ConnectionErrorRecord) NoMoreWriteSpaceException(dev.hawala.xns.level3.courier.iWireStream.NoMoreWriteSpaceException) EndOfMessageException(dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException) IOException(java.io.IOException) CourierException(dev.hawala.xns.level3.courier.exception.CourierException) UndefinedErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.UndefinedErrorRecord) CourierException(dev.hawala.xns.level3.courier.exception.CourierException) Volume(dev.hawala.xns.level4.filing.fs.Volume) EndOfMessageException(dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException) FileEntry(dev.hawala.xns.level4.filing.fs.FileEntry)

Example 3 with Volume

use of dev.hawala.xns.level4.filing.fs.Volume in project dodo by devhawala.

the class FilingImpl method retrieve.

/*
	 * Retrieve: PROCEDURE [ file: Handle, content: BulkData.Sink, session: Session ]
	 *   REPORTS [ AccessError, AuthenticationError, ConnectionError,
	 *             HandleError, SessionError, TransferError, UndefinedError ]
	 *   = 13;
	 */
private static void retrieve(RetrieveParams params, RECORD results) {
    logParams("retrieve", params);
    // check session
    Session session = resolveSession(params.session);
    Volume vol = session.getService().getVolume();
    // check specified file handle
    Handle fileHandle = Handle.get(params.file);
    if (fileHandle == null || fileHandle.isNullHandle()) {
        new HandleErrorRecord(HandleProblem.nullDisallowed).raise();
    }
    FileEntry fe = fileHandle.getFe();
    if (fe == null) {
        new HandleErrorRecord(HandleProblem.nullDisallowed).raise();
    }
    // transfer file content
    try {
        ByteContentSink sink = new ByteContentSink(params.content);
        vol.retrieveContent(fe.getFileID(), sink, session.getUsername());
    } catch (NoMoreWriteSpaceException | IOException e) {
        log("##  Filing.Retrieve() => %s : %s\n", e.getClass().getName(), e.getMessage());
        new TransferErrorRecord(TransferProblem.aborted).raise();
    }
    // prolongate the sessions life if this took longer
    session.continueUse();
}
Also used : Volume(dev.hawala.xns.level4.filing.fs.Volume) TransferErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.TransferErrorRecord) HandleErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.HandleErrorRecord) FileEntry(dev.hawala.xns.level4.filing.fs.FileEntry) IOException(java.io.IOException) NoMoreWriteSpaceException(dev.hawala.xns.level3.courier.iWireStream.NoMoreWriteSpaceException)

Example 4 with Volume

use of dev.hawala.xns.level4.filing.fs.Volume in project dodo by devhawala.

the class FilingImpl method createFile.

private static FileEntry createFile(Volume.Session modificationSession, Session session, long directoryFileID, AttributeSequence pAttributes, iContentSource source, ExceptionHandler exceptionHandler) {
    // get the volume
    Volume vol = session.getService().getVolume();
    // extract the minimal attributes => required: name ; optional: isDirectory(false), version(1/next), type(unknown)
    String name = null;
    boolean isDirectory = false;
    Integer version = null;
    Long type = null;
    for (int i = 0; i < pAttributes.value.size(); i++) {
        Attribute attr = pAttributes.value.get(i);
        switch((int) (attr.type.get() & 0xFFFF)) {
            case FilingCommon.atName:
                name = attr.getAsString();
                break;
            case FilingCommon.atIsDirectory:
                isDirectory = attr.getAsBoolean();
                break;
            case FilingCommon.atVersion:
                version = attr.getAsCardinal();
                break;
            case FilingCommon.atType:
                type = attr.getAsLongCardinal();
                break;
        }
    }
    if (name == null) {
        new AttributeValueErrorRecord(ArgumentProblem.missing, FilingCommon.atName).raise();
    }
    // create the new file
    List<iValueSetter> attrSetters = getCourier2FileAttributeSetters(pAttributes);
    System.out.printf("volStartModificationsession()\n");
    try {
        System.out.printf("createFile( dirId = %d , isdirectory = %s , name = '%s' )\n", directoryFileID, "" + isDirectory, name);
        Volume.Session modSession = (modificationSession == null) ? vol.startModificationSession() : modificationSession;
        final FileEntry fe;
        try {
            fe = modSession.createFile(directoryFileID, isDirectory, name, version, type, session.getUsername(), attrSetters, source);
        } finally {
            if (modificationSession == null) {
                modSession.close();
            }
        }
        System.out.printf("-> done createFile(): fileID = %d\n", (fe != null) ? fe.getFileID() : -2);
        return fe;
    } catch (InterruptedException e) {
        System.out.printf("!!! InterruptedException !!!\n");
        new UndefinedErrorRecord(FilingCommon.UNDEFINEDERROR_CANNOT_MODIFY_VOLUME).raise();
    } catch (EndOfMessageException e) {
        System.out.printf("!!! EndOfMessageException !!!\n");
        new ConnectionErrorRecord(ConnectionProblem.otherCallProblem).raise();
    } catch (CourierException ce) {
        // this is a RuntimeException, why is it catch-ed by Exception ???????
        System.out.printf("!!! CourierException !!!\n");
        throw ce;
    } catch (Exception e) {
        System.out.printf("!!! Exception: %s -- %s !!!\n", e.getClass().getName(), e.getMessage());
        if (exceptionHandler != null) {
            exceptionHandler.accept(e);
        } else {
            new SpaceErrorRecord(SpaceProblem.mediumFull).raise();
        }
    }
    // keep the compiler happy
    return null;
}
Also used : AttributeValueErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.AttributeValueErrorRecord) Attribute(dev.hawala.xns.level4.filing.FilingCommon.Attribute) UninterpretedAttribute(dev.hawala.xns.level4.filing.fs.UninterpretedAttribute) SpaceErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.SpaceErrorRecord) dev.hawala.xns.level4.filing.fs.iValueSetter(dev.hawala.xns.level4.filing.fs.iValueSetter) ConnectionErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.ConnectionErrorRecord) NoMoreWriteSpaceException(dev.hawala.xns.level3.courier.iWireStream.NoMoreWriteSpaceException) EndOfMessageException(dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException) IOException(java.io.IOException) CourierException(dev.hawala.xns.level3.courier.exception.CourierException) UndefinedErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.UndefinedErrorRecord) CourierException(dev.hawala.xns.level3.courier.exception.CourierException) Volume(dev.hawala.xns.level4.filing.fs.Volume) EndOfMessageException(dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException) FileEntry(dev.hawala.xns.level4.filing.fs.FileEntry)

Example 5 with Volume

use of dev.hawala.xns.level4.filing.fs.Volume in project dodo by devhawala.

the class VolumeTests method main.

public static void main(String[] args) throws InterruptedException, Exception {
    String volumeDirectory = prepareVolumeDir();
    log("## Opening volume %s (located in: %s)\n", volumename, volumeDirectory);
    Volume vol = Volume.openVolume(volumeDirectory, new TestErrorRaiser());
    vol.dumpHierarchy(System.out);
    log("## done opening volume\n");
    sep();
    log("## listing from root\n");
    dumpFileList(vol.listDirectory(0, fe -> true, -1, "peter:dev:hawala"));
    sep();
    long folderHansFileID;
    log("## get fileID of folder 'hans'\n");
    {
        FileEntry fe = vol.openByName("HANS", 0L, null, null, "paule:dev:hawala");
        folderHansFileID = fe.getFileID();
    }
    sep();
    log("## changing folder 'hans' to children uniqely named = false\n");
    try (Session session = vol.startModificationSession()) {
        FileEntry fe = vol.openByFileID(folderHansFileID, null, null, "mary:dev:hawala");
        List<iValueSetter> valueSetters = new ArrayList<>();
        valueSetters.add(f -> f.setChildrenUniquelyNamed(false));
        session.updateFileAttributes(fe, valueSetters, "mary:dev:hawala");
    }
    sep();
    log("## listing from root\n");
    dumpFileList(vol.listDirectory(0, fe -> true, -1, null));
    sep();
    log("## creating first file in folder 'hans'\n");
    try (Session session = vol.startModificationSession()) {
        long fileId = createVolumeFile(session, "Filing4.cr.txt", folderHansFileID, "Filing4.courier", null, 2L, "mats:dev:hawala");
        log("  -> 'Filing4.cr.txt' -> 'Filing4.courier' => fileID = %d\n", fileId);
    }
    sep();
    // log("## volume.dumpHierarchy()\n");
    // vol.dumpHierarchy(System.out);
    // sep();
    log("## listing from root\n");
    dumpFileList(vol.findFiles(0, fe -> true, 0, 0, null));
    sep();
    log("########## closing and re-opening volume ######## \n");
    vol.close();
    vol = Volume.openVolume(volumeDirectory, new TestErrorRaiser());
    sep();
    // log("## volume.dumpHierarchy()\n");
    // vol.dumpHierarchy(System.out);
    // sep();
    log("## listing from root\n");
    dumpFileList(vol.findFiles(0, fe -> true, 0, 0, null));
    sep();
    log("## creating same file in additional versions in folder 'hans'\n");
    try (Session session = vol.startModificationSession()) {
        long fileIdA = createVolumeFile(session, "Filing4.cr.txt", folderHansFileID, "Filing4.courier", 5, 2L, "carl:dev:hawala");
        log("  -> 'Filing4.cr.txt' -> 'Filing4.courier;?5?' => fileID = %d\n", fileIdA);
        long fileIdB = createVolumeFile(session, "Filing4.cr.txt", folderHansFileID, "Filing4.courier", null, 2L, "carl:dev:hawala");
        log("  -> 'Filing4.cr.txt' -> 'Filing4.courier;?6?' => fileID = %d\n", fileIdB);
    }
    sep();
    log("## listing from root\n");
    dumpFileList(vol.findFiles(0, fe -> true, 0, 0, null));
    sep();
    log("## trying to open the volume while still open\n");
    try {
        Volume.openVolume(volumeDirectory, new TestErrorRaiser());
        log("ERROR ERROR ERROR :: did not get expected VolumeLockedException\n");
    } catch (VolumeLockedException vle) {
        log("  (OK) -> got expected VolumeLockedException\n");
    }
}
Also used : PrintStream(java.io.PrintStream) dev.hawala.xns.level4.filing.fs.iContentSource(dev.hawala.xns.level4.filing.fs.iContentSource) dev.hawala.xns.level4.filing.fs.iValueSetter(dev.hawala.xns.level4.filing.fs.iValueSetter) FileEntry(dev.hawala.xns.level4.filing.fs.FileEntry) IOException(java.io.IOException) Session(dev.hawala.xns.level4.filing.fs.Volume.Session) FileInputStream(java.io.FileInputStream) File(java.io.File) ArrayList(java.util.ArrayList) Volume(dev.hawala.xns.level4.filing.fs.Volume) List(java.util.List) VolumeLockedException(dev.hawala.xns.level4.filing.fs.Volume.VolumeLockedException) Collections(java.util.Collections) Volume(dev.hawala.xns.level4.filing.fs.Volume) ArrayList(java.util.ArrayList) VolumeLockedException(dev.hawala.xns.level4.filing.fs.Volume.VolumeLockedException) FileEntry(dev.hawala.xns.level4.filing.fs.FileEntry) dev.hawala.xns.level4.filing.fs.iValueSetter(dev.hawala.xns.level4.filing.fs.iValueSetter) Session(dev.hawala.xns.level4.filing.fs.Volume.Session)

Aggregations

Volume (dev.hawala.xns.level4.filing.fs.Volume)13 IOException (java.io.IOException)10 FileEntry (dev.hawala.xns.level4.filing.fs.FileEntry)9 NoMoreWriteSpaceException (dev.hawala.xns.level3.courier.iWireStream.NoMoreWriteSpaceException)7 dev.hawala.xns.level4.filing.fs.iValueSetter (dev.hawala.xns.level4.filing.fs.iValueSetter)7 EndOfMessageException (dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException)6 CourierException (dev.hawala.xns.level3.courier.exception.CourierException)5 File (java.io.File)5 AccessErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.AccessErrorRecord)4 HandleErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.HandleErrorRecord)4 SpaceErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.SpaceErrorRecord)4 UndefinedErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.UndefinedErrorRecord)4 Session (dev.hawala.xns.level4.filing.fs.Volume.Session)4 ArrayList (java.util.ArrayList)4 PathElement (dev.hawala.xns.level4.filing.fs.PathElement)3 dev.hawala.xns.level4.filing.fs.iErrorRaiser (dev.hawala.xns.level4.filing.fs.iErrorRaiser)3 List (java.util.List)3 Attribute (dev.hawala.xns.level4.filing.FilingCommon.Attribute)2 AttributeValueErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.AttributeValueErrorRecord)2 ConnectionErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.ConnectionErrorRecord)2