Search in sources :

Example 56 with NodeState

use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit-oak by apache.

the class BundleLoader method loadBundle.

NodePropBundle loadBundle(NodeId id) throws ItemStateException {
    if (loadBundle != null) {
        try {
            return checkNotNull((NodePropBundle) loadBundle.invoke(pm, id), "Could not load NodePropBundle for id [%s]", id);
        } catch (InvocationTargetException e) {
            if (e.getCause() instanceof ItemStateException) {
                throw (ItemStateException) e.getCause();
            }
        // fall through
        } catch (IllegalArgumentException e) {
        // fall through
        } catch (IllegalAccessException e) {
        // fall through
        }
    }
    NodeState state = pm.load(id);
    checkNotNull(state, "Could not load NodeState for id [%s]", id);
    NodePropBundle bundle = new NodePropBundle(state);
    for (Name name : state.getPropertyNames()) {
        if (NameConstants.JCR_UUID.equals(name)) {
            bundle.setReferenceable(true);
        } else if (!NameConstants.JCR_PRIMARYTYPE.equals(name) && !NameConstants.JCR_MIXINTYPES.equals(name)) {
            bundle.addProperty(new PropertyEntry(pm.load(new PropertyId(id, name))));
        }
    }
    return bundle;
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) PropertyEntry(org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry) NodePropBundle(org.apache.jackrabbit.core.persistence.util.NodePropBundle) InvocationTargetException(java.lang.reflect.InvocationTargetException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId)

Example 57 with NodeState

use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.

the class GarbageCollector method scanPersistenceManagersByNodeInfos.

private void scanPersistenceManagersByNodeInfos() throws RepositoryException, ItemStateException {
    int pmCount = 0;
    for (IterablePersistenceManager pm : pmList) {
        pmCount++;
        int count = 0;
        Map<NodeId, NodeInfo> batch = pm.getAllNodeInfos(null, NODESATONCE);
        while (!batch.isEmpty()) {
            NodeId lastId = null;
            for (NodeInfo info : batch.values()) {
                count++;
                if (count % 1000 == 0) {
                    LOG.debug(pm.toString() + " (" + pmCount + "/" + pmList.length + "): analyzed " + count + " nodes...");
                }
                lastId = info.getId();
                if (callback != null) {
                    callback.beforeScanning(null);
                }
                if (info.hasBlobsInDataStore()) {
                    try {
                        NodeState state = pm.load(info.getId());
                        Set<Name> propertyNames = state.getPropertyNames();
                        for (Name name : propertyNames) {
                            PropertyId pid = new PropertyId(info.getId(), name);
                            PropertyState ps = pm.load(pid);
                            if (ps.getType() == PropertyType.BINARY) {
                                for (InternalValue v : ps.getValues()) {
                                    // getLength will update the last modified date
                                    // if the persistence manager scan is running
                                    v.getLength();
                                }
                            }
                        }
                    } catch (NoSuchItemStateException ignored) {
                    // the node may have been deleted in the meantime
                    }
                }
            }
            batch = pm.getAllNodeInfos(lastId, NODESATONCE);
        }
    }
    NodeInfo.clearPool();
}
Also used : IterablePersistenceManager(org.apache.jackrabbit.core.persistence.IterablePersistenceManager) NodeState(org.apache.jackrabbit.core.state.NodeState) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) NodeInfo(org.apache.jackrabbit.core.persistence.util.NodeInfo) NodeId(org.apache.jackrabbit.core.id.NodeId) InternalValue(org.apache.jackrabbit.core.value.InternalValue) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId) PropertyState(org.apache.jackrabbit.core.state.PropertyState)

Example 58 with NodeState

use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.

the class GarbageCollector method scanNodeIdList.

private void scanNodeIdList(int split, List<NodeId> nodeList, PersistenceManager pm, int pmCount) throws RepositoryException, ItemStateException {
    int count = 0;
    for (NodeId id : nodeList) {
        count++;
        if (count % 1000 == 0) {
            if (split > 0) {
                LOG.debug("[Split " + split + "] " + pm.toString() + " (" + pmCount + "/" + pmList.length + "): analyzed " + count + " nodes [" + nodeList.size() + "]...");
            } else {
                LOG.debug(pm.toString() + " (" + pmCount + "/" + pmList.length + "): analyzed " + count + " nodes [" + nodeList.size() + "]...");
            }
        }
        if (callback != null) {
            callback.beforeScanning(null);
        }
        try {
            NodeState state = pm.load(id);
            Set<Name> propertyNames = state.getPropertyNames();
            for (Name name : propertyNames) {
                PropertyId pid = new PropertyId(id, name);
                PropertyState ps = pm.load(pid);
                if (ps.getType() == PropertyType.BINARY) {
                    for (InternalValue v : ps.getValues()) {
                        // getLength will update the last modified date
                        // if the persistence manager scan is running
                        v.getLength();
                    }
                }
            }
        } catch (NoSuchItemStateException e) {
        // the node may have been deleted or moved in the meantime
        // ignore it
        }
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) NodeId(org.apache.jackrabbit.core.id.NodeId) InternalValue(org.apache.jackrabbit.core.value.InternalValue) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId) PropertyState(org.apache.jackrabbit.core.state.PropertyState)

Example 59 with NodeState

use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.

the class ObjectPersistenceManager method load.

/**
     * {@inheritDoc}
     */
public synchronized NodeState load(NodeId id) throws NoSuchItemStateException, ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    String nodeFilePath = buildNodeFilePath(id);
    try {
        if (!itemStateFS.isFile(nodeFilePath)) {
            throw new NoSuchItemStateException(nodeFilePath);
        }
    } catch (FileSystemException fse) {
        String msg = "failed to read node state: " + nodeFilePath;
        log.debug(msg);
        throw new ItemStateException(msg, fse);
    }
    try {
        BufferedInputStream in = new BufferedInputStream(itemStateFS.getInputStream(nodeFilePath));
        try {
            NodeState state = createNew(id);
            Serializer.deserialize(state, in);
            return state;
        } catch (Exception e) {
            String msg = "failed to read node state: " + id;
            log.debug(msg);
            throw new ItemStateException(msg, e);
        } finally {
            in.close();
        }
    } catch (Exception e) {
        String msg = "failed to read node state: " + nodeFilePath;
        log.debug(msg);
        throw new ItemStateException(msg, e);
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) NodeState(org.apache.jackrabbit.core.state.NodeState) BufferedInputStream(java.io.BufferedInputStream) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 60 with NodeState

use of org.apache.jackrabbit.core.state.NodeState in project jackrabbit by apache.

the class InMemPersistenceManager method load.

/**
     * {@inheritDoc}
     */
public synchronized NodeState load(NodeId id) throws NoSuchItemStateException, ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    byte[] data = stateStore.get(id);
    if (data == null) {
        throw new NoSuchItemStateException(id.toString());
    }
    ByteArrayInputStream in = new ByteArrayInputStream(data);
    try {
        NodeState state = createNew(id);
        Serializer.deserialize(state, in);
        return state;
    } catch (Exception e) {
        String msg = "failed to read node state: " + id;
        log.debug(msg);
        throw new ItemStateException(msg, e);
    }
}
Also used : NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) NodeState(org.apache.jackrabbit.core.state.NodeState) ByteArrayInputStream(java.io.ByteArrayInputStream) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Aggregations

NodeState (org.apache.jackrabbit.core.state.NodeState)114 RepositoryException (javax.jcr.RepositoryException)53 NodeId (org.apache.jackrabbit.core.id.NodeId)52 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)44 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)34 Name (org.apache.jackrabbit.spi.Name)28 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)26 PropertyState (org.apache.jackrabbit.core.state.PropertyState)25 Path (org.apache.jackrabbit.spi.Path)24 PropertyId (org.apache.jackrabbit.core.id.PropertyId)23 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)16 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)16 ItemNotFoundException (javax.jcr.ItemNotFoundException)15 ArrayList (java.util.ArrayList)14 InvalidItemStateException (javax.jcr.InvalidItemStateException)12 InternalValue (org.apache.jackrabbit.core.value.InternalValue)12 HashSet (java.util.HashSet)10 ItemExistsException (javax.jcr.ItemExistsException)10 IOException (java.io.IOException)8 NodeTypeImpl (org.apache.jackrabbit.core.nodetype.NodeTypeImpl)7