Example usage for java.util.logging Level FINEST

List of usage examples for java.util.logging Level FINEST

Introduction

In this page you can find the example usage for java.util.logging Level FINEST.

Prototype

Level FINEST

To view the source code for java.util.logging Level FINEST.

Click Source Link

Document

FINEST indicates a highly detailed tracing message.

Usage

From source file:edu.umass.cs.gigapaxos.PaxosInstanceStateMachine.java

private MessagingTask pokeLocalCoordinator() {
    if (!POKE_COORDINATOR)
        return null;
    AcceptPacket accept = PaxosCoordinator.reissueAcceptIfWaitingTooLong(this.coordinator,
            this.paxosState.getSlot());
    if (accept != null)
        log.log(Level.INFO, "{0} resending timed out ACCEPT {1}", new Object[] { this, accept.getSummary() });
    else/* w w w.ja v a  2 s.c  om*/
        log.log(Level.FINEST, "{0} coordinator {1} is good for now", new Object[] { this, this.coordinator });
    MessagingTask reAccept = (accept != null ? new MessagingTask(this.groupMembers, accept) : null);
    return reAccept;
}

From source file:fr.ortolang.diffusion.core.CoreServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public DataObject createDataObject(String wskey, String key, String path, String hash)
        throws CoreServiceException, KeyAlreadyExistsException, InvalidPathException, AccessDeniedException,
        PathNotFoundException, PathAlreadyExistsException, WorkspaceReadOnlyException {
    LOGGER.log(Level.FINE,//from w  ww.j  a  va2  s  .  c om
            "create data object with key [" + key + "] into workspace [" + wskey + "] at path [" + path + "]");
    try {
        PathBuilder npath = PathBuilder.fromPath(path);
        if (npath.isRoot()) {
            throw new InvalidPathException("forbidden to create an object at root level");
        }
        PathBuilder ppath = npath.clone().parent();

        String caller = membership.getProfileKeyForConnectedIdentifier();
        List<String> subjects = membership.getConnectedIdentifierSubjects();
        authorisation.checkAuthentified(subjects);
        LOGGER.log(Level.FINEST, "user [" + caller + "] is authentified");

        OrtolangObjectIdentifier wsidentifier = registry.lookup(wskey);
        checkObjectType(wsidentifier, Workspace.OBJECT_TYPE);
        LOGGER.log(Level.FINEST, "workspace with key [" + wskey + "] exists");

        Workspace ws = em.find(Workspace.class, wsidentifier.getId());
        if (ws == null) {
            throw new CoreServiceException(
                    "unable to load workspace with id [" + wsidentifier.getId() + "] from storage");
        }
        if (applyReadOnly(caller, subjects, ws)) {
            throw new WorkspaceReadOnlyException("unable to create data object in workspace with key [" + wskey
                    + "] because it is read only");
        }
        ws.setKey(wskey);
        LOGGER.log(Level.FINEST, "workspace loaded");

        authorisation.checkPermission(ws.getHead(), subjects, "create");
        LOGGER.log(Level.FINEST,
                "user [" + caller + "] has 'create' permission on the head collection of this workspace");

        Collection parent = loadCollectionAtPath(ws.getHead(), ppath, ws.getClock());
        LOGGER.log(Level.FINEST, "parent collection loaded for path " + ppath.build());

        if (parent.containsElementName(npath.part())) {
            throw new PathAlreadyExistsException(npath.build());
        }

        DataObject object = new DataObject();
        object.setId(UUID.randomUUID().toString());
        object.setName(npath.part());
        if (hash != null && hash.length() > 0) {
            object.setSize(binarystore.size(hash));
            object.setMimeType(binarystore.type(hash, npath.part()));
            object.setStream(hash);
        } else {
            object.setSize(0);
            object.setMimeType("application/octet-stream");
            object.setStream("");
        }
        object.setClock(ws.getClock());
        object.setKey(key);
        em.persist(object);
        LOGGER.log(Level.FINEST, "object [" + key + "] created");

        Properties properties = new Properties();
        properties.put(WORKSPACE_REGISTRY_PROPERTY_KEY, wskey);
        registry.register(key, object.getObjectIdentifier(), caller, properties);
        indexing.index(key);

        authorisation.clonePolicy(key, ws.getHead());
        LOGGER.log(Level.FINEST, "security policy cloned from head collection to key [" + key + "]");

        parent.addElement(new CollectionElement(DataObject.OBJECT_TYPE, object.getName(),
                System.currentTimeMillis(), object.getSize(), object.getMimeType(), key));
        em.merge(parent);
        registry.update(parent.getKey());

        LOGGER.log(Level.FINEST, "object [" + key + "] added to parent [" + parent.getKey() + "]");

        try {
            extraction.extract(object.getKey());
        } catch (ExtractionServiceException e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
        }

        ws.setChanged(true);
        em.merge(ws);
        registry.update(ws.getKey());
        LOGGER.log(Level.FINEST, "workspace set changed");

        ArgumentsBuilder argsBuilder = new ArgumentsBuilder(5).addArgument("ws-alias", ws.getAlias())
                .addArgument("key", key).addArgument("path", npath.build())
                .addArgument("hash", object.getStream()).addArgument("mimetype", object.getMimeType());
        notification.throwEvent(wskey, caller, Workspace.OBJECT_TYPE,
                OrtolangEvent.buildEventType(CoreService.SERVICE_NAME, DataObject.OBJECT_TYPE, "create"),
                argsBuilder.build());

        return object;
    } catch (KeyLockedException | KeyNotFoundException | RegistryServiceException | NotificationServiceException
            | IdentifierAlreadyRegisteredException | AuthorisationServiceException | MembershipServiceException
            | BinaryStoreServiceException | DataNotFoundException | IndexingServiceException e) {
        LOGGER.log(Level.SEVERE, "unexpected error occurred during object creation", e);
        ctx.setRollbackOnly();
        throw new CoreServiceException(
                "unable to create object into workspace [" + wskey + "] at path [" + path + "]", e);
    }
}

From source file:edu.umass.cs.reconfiguration.SQLReconfiguratorDB.java

@Override
public ReconfigurationRecord<NodeIDType> readNextActiveRecord() {
    ReconfigurationRecord<NodeIDType> record = null;
    try {/*from w w  w.ja  v a  2  s  . c om*/
        while (this.cursorRS.next())
            if ((record = new ReconfigurationRecord<NodeIDType>(
                    new JSONObject(this.cursorRS.getString(Columns.STRINGIFIED_RECORD.toString())),
                    this.consistentNodeConfig)).getActiveReplicas() != null
                    && record.getActiveReplicas().contains(this.cursorActive)
                    && record.isReconfigurationReady())
                return record;
            else
                log.log(Level.FINEST, "{0} read record {1} not replicated at {2}",
                        new Object[] { this, record.getName(), this.cursorActive });
    } catch (SQLException | JSONException sqle) {
        log.severe(this + " encountered exception in readNextActiveRecord: " + sqle.getMessage());
        sqle.printStackTrace();
    }
    return null;
}

From source file:edu.umass.cs.gigapaxos.SQLPaxosLogger.java

public boolean initiateReadMessages() {
    if (isClosed())
        return false;

    log.log(Level.FINE, "{0} invoked initiatedReadMessages()", new Object[] { this, });
    boolean initiated = false;
    if (!isJournalingEnabled())
        try {// ww w .ja va2  s .co m
            synchronized (this) {
                if (this.cursorPstmt != null || this.cursorRset != null || this.cursorConn != null)
                    return false;
                this.cursorPstmt = this.getPreparedStatement(this.getCursorConn(), getMTable(), null,
                        "message");
                this.cursorRset = this.cursorPstmt.executeQuery();
                initiated = true;
            }
        } catch (SQLException sqle) {
            log.severe("SQLException while getting all paxos IDs " + " : " + sqle);
        }
    else if (isJournalingEnabled()) {
        logfiles = ((logfiles = this.getJournalFiles()) != null ?
        // important to sort to replay in order
                toFiles(getLatest(logfiles, logfiles.length).toArray(new Filename[0])) : new File[0]);

        if (logfiles.length > 0)
            try {
                int i = 0;
                for (File minLogfile = this.getMinLogfile(); minLogfile != null && i < logfiles.length; i++)
                    if (logfiles[i].toString().equals(minLogfile.toString()))
                        break;
                if (i == logfiles.length)
                    i = 0; // not found

                log.log(Level.INFO, "{0} rolling forward logged messages from logfile {1} onwards",
                        new Object[] { this, logfiles[i] });

                this.logfileIndex = i;
                curRAF = new RandomAccessFile(logfiles[i], "r");
                log.log(Level.FINEST, "{0} rolling forward logged messages from file {1}",
                        new Object[] { this.journaler, this.logfiles[this.logfileIndex] });
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
    }
    return initiated;
}

From source file:fr.ortolang.diffusion.core.CoreServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public DataObject updateDataObject(String wskey, String path, String hash) throws CoreServiceException,
        InvalidPathException, AccessDeniedException, PathNotFoundException, WorkspaceReadOnlyException {
    LOGGER.log(Level.FINE, "updating object into workspace [" + wskey + "] at path [" + path + "]");
    try {//from  w  w  w .  ja va 2s  .  co m
        PathBuilder npath = PathBuilder.fromPath(path);
        if (npath.isRoot()) {
            throw new InvalidPathException("path is empty");
        }
        PathBuilder ppath = npath.clone().parent();

        String caller = membership.getProfileKeyForConnectedIdentifier();
        List<String> subjects = membership.getConnectedIdentifierSubjects();
        authorisation.checkAuthentified(subjects);
        LOGGER.log(Level.FINEST, "user [" + caller + "] is authentified");

        OrtolangObjectIdentifier wsidentifier = registry.lookup(wskey);
        checkObjectType(wsidentifier, Workspace.OBJECT_TYPE);
        LOGGER.log(Level.FINEST, "workspace with key [" + wskey + "] exists");

        Workspace ws = em.find(Workspace.class, wsidentifier.getId());
        if (ws == null) {
            throw new CoreServiceException(
                    "unable to load workspace with id [" + wsidentifier.getId() + "] from storage");
        }
        if (applyReadOnly(caller, subjects, ws)) {
            throw new WorkspaceReadOnlyException("unable to update data object in workspace with key [" + wskey
                    + "] because it is read only");
        }
        ws.setKey(wskey);
        LOGGER.log(Level.FINEST, "workspace loaded");

        authorisation.checkPermission(ws.getHead(), subjects, "update");
        LOGGER.log(Level.FINEST,
                "user [" + caller + "] has 'update' permission on the head collection of this workspace");

        String current = resolveWorkspacePath(wskey, Workspace.HEAD, npath.build());
        OrtolangObjectIdentifier cidentifier = registry.lookup(current);
        checkObjectType(cidentifier, DataObject.OBJECT_TYPE);
        DataObject cobject = em.find(DataObject.class, cidentifier.getId());
        if (cobject == null) {
            throw new CoreServiceException(
                    "unable to load object with id [" + cidentifier.getId() + "] from storage");
        }
        cobject.setKey(current);
        LOGGER.log(Level.FINEST, "current object loaded");

        if (!hash.equals(cobject.getStream())) {
            Collection parent = loadCollectionAtPath(ws.getHead(), ppath, ws.getClock());
            LOGGER.log(Level.FINEST, "parent collection loaded for path " + npath.build());

            CollectionElement element = parent.findElementByName(npath.part());
            if (element == null) {
                throw new PathNotFoundException(npath.build());
            }
            LOGGER.log(Level.FINEST, "object element found for name " + npath.part());
            if (!element.getType().equals(DataObject.OBJECT_TYPE)) {
                throw new InvalidPathException("path [" + npath.build() + "] is not a data object");
            }

            OrtolangObjectIdentifier identifier = registry.lookup(element.getKey());
            checkObjectType(identifier, DataObject.OBJECT_TYPE);
            DataObject object = em.find(DataObject.class, identifier.getId());
            if (object == null) {
                throw new CoreServiceException(
                        "unable to load object with id [" + identifier.getId() + "] from storage");
            }
            object.setKey(element.getKey());
            if (object.getClock() < ws.getClock()) {
                DataObject clone = cloneDataObject(ws.getHead(), object, ws.getClock());
                object = clone;
            }
            if (hash.length() > 0) {
                object.setSize(binarystore.size(hash));
                object.setMimeType(binarystore.type(hash, object.getName()));
                object.setStream(hash);
            } else {
                object.setSize(0);
                object.setMimeType("application/octet-stream");
                object.setStream("");
            }
            parent.removeElement(element);
            CollectionElement celement = new CollectionElement(DataObject.OBJECT_TYPE, object.getName(),
                    System.currentTimeMillis(), object.getSize(), object.getMimeType(), object.getKey());
            parent.addElement(celement);
            em.merge(parent);
            em.merge(object);
            registry.update(parent.getKey());
            registry.update(object.getKey());
            indexing.index(object.getKey());
            LOGGER.log(Level.FINEST, "object updated");

            try {
                extraction.extract(object.getKey());
            } catch (ExtractionServiceException e) {
                LOGGER.log(Level.SEVERE, e.getMessage(), e);
            }

            ws.setChanged(true);
            em.merge(ws);
            registry.update(ws.getKey());
            LOGGER.log(Level.FINEST, "workspace set changed");

            ArgumentsBuilder argsBuilder = new ArgumentsBuilder(6).addArgument("ws-alias", ws.getAlias())
                    .addArgument("key", object.getKey()).addArgument("okey", element.getKey())
                    .addArgument("path", npath.build()).addArgument("hash", object.getStream())
                    .addArgument("mimetype", object.getMimeType());
            notification.throwEvent(wskey, caller, Workspace.OBJECT_TYPE,
                    OrtolangEvent.buildEventType(CoreService.SERVICE_NAME, DataObject.OBJECT_TYPE, "update"),
                    argsBuilder.build());

            return object;
        } else {
            LOGGER.log(Level.FINEST, "no changes detected with current object, nothing to do");
            return cobject;
        }
    } catch (KeyLockedException | KeyNotFoundException | RegistryServiceException | NotificationServiceException
            | AuthorisationServiceException | MembershipServiceException | BinaryStoreServiceException
            | DataNotFoundException | CloneException | IndexingServiceException e) {
        LOGGER.log(Level.SEVERE, "unexpected error occurred while reading object", e);
        throw new CoreServiceException(
                "unable to read object into workspace [" + wskey + "] at path [" + path + "]", e);
    }
}

From source file:edu.umass.cs.gigapaxos.SQLPaxosLogger.java

@Override
public PaxosPacket readNextMessage() {
    String packetStr = null;/*w ww.j a v a2s.c o  m*/
    byte[] packetBytes = null;
    PaxosPacket pp = null;
    if (!isJournalingEnabled())
        try {
            synchronized (this) {
                try {
                    if (cursorRset != null && cursorRset.next()) {
                        if (!getLogMessageBlobOption()) {
                            packetStr = cursorRset.getString(1);
                            if (packetStr != null)
                                pp = this.getPacketizer() != null
                                        ? this.getPacketizer().stringToPaxosPacket(packetStr)
                                        : PaxosPacket.getPaxosPacket(packetStr);
                        } else {
                            packetBytes = lobToBytes(cursorRset.getBlob(1));
                            if (packetBytes != null)
                                pp = this.getPacketizer() != null
                                        ? this.getPacketizer().stringToPaxosPacket(packetBytes)
                                        : PaxosPacket.getPaxosPacket(new String(packetBytes, CHARSET));
                        }
                    }
                } catch (JSONException je) {
                    je.printStackTrace();
                }
            }
        } catch (SQLException | IOException e) {
            log.severe(this + " got " + e.getClass().getSimpleName() + " in readNextMessage while reading: "
                    + " : " + packetStr);
            e.printStackTrace();
        }
    else if (isJournalingEnabled()) {
        String latest = this.getLatestJournalFile();
        try {
            while (this.curRAF != null && this.curRAF.getFilePointer() == this.curRAF.length()) {
                this.curRAF.close();
                this.curRAF = null;
                // move on to the next file
                if (this.logfileIndex + 1 < this.logfiles.length)
                    this.curRAF = new RandomAccessFile(this.logfiles[++this.logfileIndex], "r");
                if (this.curRAF != null)
                    log.log(Level.INFO, "{0} rolling forward logged messages from file {1}",
                            new Object[] { this.journaler, this.logfiles[this.logfileIndex] });
            }
            if (this.curRAF == null)
                return null;

            log.log(Level.FINEST, "{0} reading from offset {1} from file {2}",
                    new Object[] { this, this.curRAF.getFilePointer(), this.logfiles[this.logfileIndex] });

            long msgOffset = this.curRAF.getFilePointer();
            int msgLength = this.curRAF.readInt();
            byte[] msg = new byte[msgLength];
            this.curRAF.readFully(msg);
            // packetStr = new String(msg, CHARSET);
            packetBytes = msg;

            pp = this.getPacketizer() != null ? this.getPacketizer().stringToPaxosPacket(msg)
                    : PaxosPacket.getPaxosPacket(new String(msg, CHARSET));

            // also index latest log file
            if (DB_INDEX_JOURNAL && latest != null
                    && this.logfiles[this.logfileIndex].toString().equals(latest))
                this.indexJournalEntryInDB(pp, this.logfiles[this.logfileIndex].toString(), msgOffset,
                        msgLength);

            if (this.messageLog.getLogIndex(pp.getPaxosID()) == null)
                this.unpauseLogIndex(pp.getPaxosID());

            // feed into in-memory log
            this.messageLog.add(pp, this.logfiles[this.logfileIndex].toString(), msgOffset, msgLength);

        } catch (IOException | JSONException e) {
            e.printStackTrace();
        }
    }
    return pp;
}

From source file:fr.ortolang.diffusion.core.CoreServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public DataObject moveDataObject(String wskey, String source, String destination)
        throws CoreServiceException, KeyNotFoundException, InvalidPathException, AccessDeniedException,
        PathNotFoundException, PathAlreadyExistsException, WorkspaceReadOnlyException {
    LOGGER.log(Level.FINE, "moving object into workspace [" + wskey + "] from path [" + source + "] to path ["
            + destination + "]");
    try {/* ww  w.j a va 2s  . co m*/
        PathBuilder spath = PathBuilder.fromPath(source);
        if (spath.isRoot()) {
            throw new InvalidPathException("path is empty");
        }
        PathBuilder sppath = spath.clone().parent();

        PathBuilder dpath = PathBuilder.fromPath(destination);
        if (dpath.isRoot()) {
            throw new InvalidPathException("path is empty");
        }
        PathBuilder dppath = dpath.clone().parent();

        if (dpath.equals(spath)) {
            throw new InvalidPathException("unable to move into the same path");
        }
        if (spath.isParent(dpath)) {
            throw new InvalidPathException("unable to move into a children of this path");
        }

        String caller = membership.getProfileKeyForConnectedIdentifier();
        List<String> subjects = membership.getConnectedIdentifierSubjects();
        authorisation.checkAuthentified(subjects);
        LOGGER.log(Level.FINEST, "user [" + caller + "] is authentified");

        OrtolangObjectIdentifier wsidentifier = registry.lookup(wskey);
        checkObjectType(wsidentifier, Workspace.OBJECT_TYPE);
        LOGGER.log(Level.FINEST, "workspace with key [" + wskey + "] exists");

        Workspace ws = em.find(Workspace.class, wsidentifier.getId());
        if (ws == null) {
            throw new CoreServiceException(
                    "unable to load workspace with id [" + wsidentifier.getId() + "] from storage");
        }
        if (applyReadOnly(caller, subjects, ws)) {
            throw new WorkspaceReadOnlyException(
                    "unable to move data object in workspace with key [" + wskey + "] because it is read only");
        }
        ws.setKey(wskey);
        LOGGER.log(Level.FINEST, "workspace loaded");

        authorisation.checkPermission(ws.getHead(), subjects, "update");
        LOGGER.log(Level.FINEST,
                "user [" + caller + "] has 'update' permission on the head collection of this workspace");

        Collection sparent = loadCollectionAtPath(ws.getHead(), sppath, ws.getClock());
        CollectionElement selement = sparent.findElementByName(spath.part());
        if (selement == null) {
            throw new PathNotFoundException(spath.build());
        }
        LOGGER.log(Level.FINEST, "source object element found for name " + spath.part());

        OrtolangObjectIdentifier soidentifier = registry.lookup(selement.getKey());
        checkObjectType(soidentifier, DataObject.OBJECT_TYPE);
        DataObject sobject = em.find(DataObject.class, soidentifier.getId());
        if (sobject == null) {
            throw new CoreServiceException(
                    "unable to load source object with id [" + soidentifier.getId() + "] from storage");
        }
        sobject.setKey(selement.getKey());
        LOGGER.log(Level.FINEST, "source object exists and loaded from storage");

        Collection dparent = loadCollectionAtPath(ws.getHead(), dppath, ws.getClock());
        if (dparent.containsElementName(dpath.part())) {
            throw new PathAlreadyExistsException(dpath.build());
        }

        sparent.removeElement(selement);
        em.merge(sparent);
        registry.update(sparent.getKey());
        LOGGER.log(Level.FINEST, "parent [" + sparent.getKey() + "] has been updated");

        LOGGER.log(Level.FINEST, "destination element does not exists, creating it");
        if (!dpath.part().equals(spath.part())) {
            if (sobject.getClock() < ws.getClock()) {
                sobject = cloneDataObject(ws.getHead(), sobject, ws.getClock());
            }
            sobject.setName(dpath.part());
            em.merge(sobject);
            registry.update(sobject.getKey());
        }
        dparent.addElement(new CollectionElement(DataObject.OBJECT_TYPE, sobject.getName(),
                System.currentTimeMillis(), sobject.getSize(), sobject.getMimeType(), sobject.getKey()));
        em.merge(dparent);
        registry.update(dparent.getKey());

        LOGGER.log(Level.FINEST,
                "object [" + sobject.getKey() + "] added to destination parent [" + dparent.getKey() + "]");

        ws.setChanged(true);
        em.merge(ws);
        registry.update(ws.getKey());
        LOGGER.log(Level.FINEST, "workspace set changed");

        ArgumentsBuilder argsBuilder = new ArgumentsBuilder(5).addArgument("ws-alias", ws.getAlias())
                .addArgument("key", sobject.getKey()).addArgument("okey", selement.getKey())
                .addArgument("src-path", spath.build()).addArgument("dest-path", dpath.build());
        notification.throwEvent(wskey, caller, Workspace.OBJECT_TYPE,
                OrtolangEvent.buildEventType(CoreService.SERVICE_NAME, DataObject.OBJECT_TYPE, "move"),
                argsBuilder.build());

        return sobject;
    } catch (KeyLockedException | NotificationServiceException | RegistryServiceException
            | MembershipServiceException | AuthorisationServiceException | CloneException e) {
        ctx.setRollbackOnly();
        LOGGER.log(Level.SEVERE, "unexpected error while moving object", e);
        throw new CoreServiceException("unable to move object into workspace [" + wskey + "] from path ["
                + source + "] to path [" + destination + "]", e);
    }
}

From source file:fr.ortolang.diffusion.core.CoreServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void deleteDataObject(String wskey, String path) throws CoreServiceException, KeyNotFoundException,
        InvalidPathException, AccessDeniedException, PathNotFoundException, WorkspaceReadOnlyException {
    LOGGER.log(Level.FINE, "deleting object into workspace [" + wskey + "] at path [" + path + "]");
    try {/*from www. java 2s .c o  m*/
        PathBuilder npath = PathBuilder.fromPath(path);
        if (npath.isRoot()) {
            throw new InvalidPathException("path is empty");
        }
        PathBuilder ppath = npath.clone().parent();

        String caller = membership.getProfileKeyForConnectedIdentifier();
        List<String> subjects = membership.getConnectedIdentifierSubjects();
        authorisation.checkAuthentified(subjects);
        LOGGER.log(Level.FINEST, "user [" + caller + "] is authentified");

        OrtolangObjectIdentifier wsidentifier = registry.lookup(wskey);
        checkObjectType(wsidentifier, Workspace.OBJECT_TYPE);
        LOGGER.log(Level.FINEST, "workspace with key [" + wskey + "] exists");

        Workspace ws = em.find(Workspace.class, wsidentifier.getId());
        if (ws == null) {
            throw new CoreServiceException(
                    "unable to load workspace with id [" + wsidentifier.getId() + "] from storage");
        }
        if (applyReadOnly(caller, subjects, ws)) {
            throw new WorkspaceReadOnlyException("unable to delete data object in workspace with key [" + wskey
                    + "] because it is read only");
        }
        ws.setKey(wskey);
        LOGGER.log(Level.FINEST, "workspace loaded");

        authorisation.checkPermission(ws.getHead(), subjects, "delete");
        LOGGER.log(Level.FINEST,
                "user [" + caller + "] has 'delete' permission on the head collection of this workspace");

        Collection parent = loadCollectionAtPath(ws.getHead(), ppath, ws.getClock());
        CollectionElement element = parent.findElementByName(npath.part());
        if (element == null) {
            throw new PathNotFoundException(npath.build());
        }
        LOGGER.log(Level.FINEST,
                "object element found for path " + npath.build() + ", key: " + element.getKey());

        OrtolangObjectIdentifier oidentifier = registry.lookup(element.getKey());
        checkObjectType(oidentifier, DataObject.OBJECT_TYPE);
        DataObject leaf = em.find(DataObject.class, oidentifier.getId());
        if (leaf == null) {
            throw new CoreServiceException(
                    "unable to load object with id [" + oidentifier.getId() + "] from storage");
        }
        leaf.setKey(element.getKey());
        LOGGER.log(Level.FINEST, "object exists and loaded from storage");

        parent.removeElement(element);
        em.merge(parent);
        registry.update(parent.getKey());

        LOGGER.log(Level.FINEST, "parent [" + parent.getKey() + "] has been updated");

        ws.setChanged(true);
        em.merge(ws);
        registry.update(ws.getKey());
        LOGGER.log(Level.FINEST, "workspace set changed");

        if (leaf.getClock() == ws.getClock()) {
            LOGGER.log(Level.FINEST, "leaf clock [" + leaf.getClock()
                    + "] is the same than workspace, key can be deleted and unindexed");
            for (MetadataElement mde : leaf.getMetadatas()) {
                registry.delete(mde.getKey());
            }
            registry.delete(leaf.getKey());
            indexing.remove(leaf.getKey());
        }

        ArgumentsBuilder argsBuilder = new ArgumentsBuilder(3).addArgument("ws-alias", ws.getAlias())
                .addArgument("key", leaf.getKey()).addArgument("path", npath.build());
        notification.throwEvent(wskey, caller, Workspace.OBJECT_TYPE,
                OrtolangEvent.buildEventType(CoreService.SERVICE_NAME, DataObject.OBJECT_TYPE, "delete"),
                argsBuilder.build());
    } catch (KeyLockedException | NotificationServiceException | RegistryServiceException
            | MembershipServiceException | AuthorisationServiceException | IndexingServiceException e) {
        ctx.setRollbackOnly();
        LOGGER.log(Level.SEVERE, "unexpected error while deleting object", e);
        throw new CoreServiceException(
                "unable to delete object into workspace [" + wskey + "] at path [" + path + "]", e);
    }
}

From source file:edu.umass.cs.gigapaxos.SQLPaxosLogger.java

private byte[] getJournaledMessage(String logfile, long offset, int length, RandomAccessFile raf)
        throws IOException {
    assert (logfile != null);
    if (!new File(logfile).exists())
        return null;
    boolean locallyOpened = false;
    if (raf == null) {
        locallyOpened = true;/*  w  w w . j a  va  2 s .c om*/
        raf = new RandomAccessFile(logfile, "r");
    }
    boolean error = false;
    String msg = null;
    byte[] buf = null;
    try {
        raf.seek(offset);
        assert (raf.length() > offset) : this + " " + raf.length() + " <= " + offset + " while reading logfile "
                + logfile;
        int readLength = raf.readInt();
        try {
            assert (readLength == length) : this + " : " + readLength + " != " + length;
        } catch (Error e) {
            error = true;
            log.severe(this + ": " + e);
            e.printStackTrace();
        }
        int bufLength = length;
        buf = new byte[bufLength];
        raf.readFully(buf);
        if (JOURNAL_COMPRESSION)
            buf = inflate(buf);
        msg = new String(buf, CHARSET);
    } catch (IOException | Error e) {
        log.log(Level.INFO, "{0} incurred IOException while retrieving journaled message {1}:{2}",
                new Object[] { this, logfile, offset + ":" + length });
        e.printStackTrace();
        if (locallyOpened)
            raf.close();
        throw e;
    }
    log.log(error ? Level.INFO : Level.FINEST, "{0} returning journaled message from {1}:{2} = [{3}]",
            new Object[] { this, logfile, offset + ":" + length, msg });
    return buf;// msg;
}

From source file:fr.ortolang.diffusion.core.CoreServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public Link createLink(String wskey, String key, String path, String target)
        throws CoreServiceException, KeyAlreadyExistsException, InvalidPathException, AccessDeniedException,
        PathNotFoundException, PathAlreadyExistsException, WorkspaceReadOnlyException {
    LOGGER.log(Level.FINE,//from   w  ww.  j  av  a2 s  .com
            "create link with key [" + key + "] into workspace [" + wskey + "] at path [" + path + "]");
    try {
        PathBuilder npath = PathBuilder.fromPath(path);
        if (npath.isRoot()) {
            throw new InvalidPathException("path is empty");
        }
        PathBuilder ppath = npath.clone().parent();

        String caller = membership.getProfileKeyForConnectedIdentifier();
        List<String> subjects = membership.getConnectedIdentifierSubjects();
        authorisation.checkAuthentified(subjects);
        LOGGER.log(Level.FINEST, "user [" + caller + "] is authentified");

        authorisation.checkPermission(target, subjects, "read");
        LOGGER.log(Level.FINEST, "user [" + caller + "] has 'read' permissions on the target");

        OrtolangObjectIdentifier wsidentifier = registry.lookup(wskey);
        checkObjectType(wsidentifier, Workspace.OBJECT_TYPE);
        LOGGER.log(Level.FINEST, "workspace with key [" + wskey + "] exists");

        Workspace ws = em.find(Workspace.class, wsidentifier.getId());
        if (ws == null) {
            throw new CoreServiceException(
                    "unable to load workspace with id [" + wsidentifier.getId() + "] from storage");
        }
        if (applyReadOnly(caller, subjects, ws)) {
            throw new WorkspaceReadOnlyException(
                    "unable to create link in workspace with key [" + wskey + "] because it is read only");
        }
        ws.setKey(wskey);
        LOGGER.log(Level.FINEST, "workspace loaded");

        authorisation.checkPermission(ws.getHead(), subjects, "create");
        LOGGER.log(Level.FINEST,
                "user [" + caller + "] has 'create' permission on the head collection of this workspace");

        Collection parent = loadCollectionAtPath(ws.getHead(), ppath, ws.getClock());
        LOGGER.log(Level.FINEST, "parent collection loaded for path " + ppath.build());

        if (parent.containsElementName(npath.part())) {
            throw new PathAlreadyExistsException(npath.build());
        }

        String ntarget = PathBuilder.fromPath(target).build();

        Link link = new Link();
        link.setId(UUID.randomUUID().toString());
        link.setKey(key);
        link.setName(npath.part());
        link.setClock(ws.getClock());
        link.setTarget(ntarget);
        em.persist(link);

        Properties properties = new Properties();
        properties.put(WORKSPACE_REGISTRY_PROPERTY_KEY, wskey);
        registry.register(key, link.getObjectIdentifier(), caller, properties);
        indexing.index(key);

        authorisation.clonePolicy(key, ws.getHead());
        LOGGER.log(Level.FINEST, "security policy cloned from head collection to key [" + key + "]");

        parent.addElement(new CollectionElement(Link.OBJECT_TYPE, link.getName(), System.currentTimeMillis(), 0,
                Link.MIME_TYPE, key));
        em.merge(parent);
        registry.update(parent.getKey());
        LOGGER.log(Level.FINEST, "link [" + key + "] added to parent [" + parent.getKey() + "]");

        ws.setChanged(true);
        em.merge(ws);
        registry.update(ws.getKey());
        LOGGER.log(Level.FINEST, "workspace set changed");

        ArgumentsBuilder argsBuilder = new ArgumentsBuilder(3).addArgument("ws-alias", ws.getAlias())
                .addArgument("key", key).addArgument("path", npath.build());
        notification.throwEvent(wskey, caller, Workspace.OBJECT_TYPE,
                OrtolangEvent.buildEventType(CoreService.SERVICE_NAME, Link.OBJECT_TYPE, "create"),
                argsBuilder.build());

        return link;
    } catch (KeyLockedException | KeyNotFoundException | RegistryServiceException | NotificationServiceException
            | IdentifierAlreadyRegisteredException | AuthorisationServiceException | MembershipServiceException
            | IndexingServiceException e) {
        LOGGER.log(Level.SEVERE, "unexpected error occurred during link creation", e);
        ctx.setRollbackOnly();
        throw new CoreServiceException(
                "unable to create link into workspace [" + wskey + "] at path [" + path + "]", e);
    }
}