Package org.jboss.dna.graph.request

Examples of org.jboss.dna.graph.request.ReadBranchRequest


    protected void indexSubgraph( String workspaceName,
                                  Location startingLocation,
                                  int depth ) {
        int depthPerRead = Math.min(maxDepthPerRead, depth);
        // Read the first subgraph ...
        ReadBranchRequest readSubgraph = new ReadBranchRequest(startingLocation, workspaceName, depthPerRead);
        try {
            channel.addAndAwait(readSubgraph);
            checkRequestForErrors(readSubgraph);
        } catch (InterruptedException e) {
            // Clear the interrupted status of the thread and continue ...
            Thread.interrupted();
            return;
        } catch (InvalidPathException e) {
            // The node must no longer exist, so delete it from the indexes ...
            process(new DeleteBranchRequest(startingLocation, workspaceName));
            return;
        }
        Iterator<Location> locationIter = readSubgraph.iterator();
        assert locationIter.hasNext();

        // Destroy the nodes at the supplied location ...
        if (startingLocation.getPath().isRoot()) {
            // Just delete the whole content ...
            process(new DeleteBranchRequest(startingLocation, workspaceName));
        } else {
            // We can't delete the node, since later same-name-siblings might be changed. So delete the children ...
            process(new DeleteChildrenRequest(startingLocation, workspaceName));
        }

        // Now update all of the properties, removing any that are no longer needed ...
        Location topNode = locationIter.next();
        assert topNode.equals(startingLocation);
        Map<Name, Property> properties = readSubgraph.getPropertiesFor(topNode);
        if (properties == null) return;
        if (startingLocation.getPath().isRoot()) {
            // The properties of the root node generally don't include the primary type, but we need to add it here ...
            Property rootPrimaryType = context.getPropertyFactory().create(JcrLexicon.PRIMARY_TYPE, DnaLexicon.ROOT);
            properties.put(JcrLexicon.PRIMARY_TYPE, rootPrimaryType);
        }
        UpdatePropertiesRequest request = new UpdatePropertiesRequest(topNode, workspaceName, properties, true);
        request.setActualLocationOfNode(topNode);
        process(request);
        checkRequestForErrors(request);

        // Create a queue that we'll use to walk the content ...
        LinkedList<Location> locationsToRead = new LinkedList<Location>();

        // Now walk the remaining nodes in the subgraph ...
        while (true) {
            while (locationIter.hasNext()) {

                // Index the node ...
                Location location = locationIter.next();
                Path path = location.getPath();
                Location parent = readSubgraph.getLocationFor(path.getParent());
                Name childName = path.getLastSegment().getName();
                Collection<Property> nodePoperties = readSubgraph.getPropertiesFor(location).values();
                CreateNodeRequest create = new CreateNodeRequest(parent, workspaceName, childName, nodePoperties);
                create.setActualLocationOfNode(location); // set this so we don't have to figure it out
                process(create);
                if (create.isCancelled() || create.hasError()) return;

                // Process the children ...
                for (Location child : readSubgraph.getChildren(location)) {
                    if (!readSubgraph.includes(child)) {
                        // Record this location as needing to be read ...
                        locationsToRead.add(child);
                    }
                }
            }

            if (locationsToRead.isEmpty()) break;
            Location location = locationsToRead.poll();
            assert location != null;

            // Recompute the depth per read ...
            depthPerRead = depth - location.getPath().size();
            if (depthPerRead < 1) continue;
            readSubgraph = new ReadBranchRequest(location, workspaceName, depthPerRead);
            try {
                channel.addAndAwait(readSubgraph);
            } catch (InterruptedException e) {
                // Clear the interrupted status of the thread and continue ...
                Thread.interrupted();
View Full Code Here


                    }
                }
            } else if (projectedNode.isProxy()) {
                ProxyNode proxy = projectedNode.asProxy();
                // Create and submit a request for the projection ...
                ReadBranchRequest pushDownRequest = new ReadBranchRequest(proxy.location(), proxy.workspaceName(), maxDepth);
                federatedRequest.add(pushDownRequest, proxy.isSameLocationAsOriginal(), false, proxy.projection());
            }
            projectedNode = projectedNode.next();
        }
    }
View Full Code Here

    @Override
    public void process( ReadBranchRequest request ) {
        CacheableRequest source = (CacheableRequest)federatedRequest.getFirstProjectedRequest().getRequest();
        if (checkErrorOrCancel(request, source)) return;
        if (source instanceof ReadBranchRequest) {
            ReadBranchRequest readSource = (ReadBranchRequest)source;
            request.setActualLocationOfNode(readSource.getActualLocationOfNode());
            for (Location node : readSource) {
                List<Location> children = readSource.getChildren(node);
                if (children != null) request.setChildren(node, children);
                Map<Name, Property> props = readSource.getPropertiesFor(node);
                if (props != null) request.setProperties(node, props.values());
            }
        } else if (source instanceof ReadNodeRequest) {
            ReadNodeRequest readSource = (ReadNodeRequest)source;
            request.setActualLocationOfNode(readSource.getActualLocationOfNode());
            Location parent = readSource.getActualLocationOfNode();
            request.setChildren(parent, readSource.getChildren());
            request.setProperties(parent, readSource.getPropertiesByName().values());
        }
        request.setCachePolicy(getDefaultCachePolicy());
        setCacheableInfo(request, source.getCachePolicy());
    }
View Full Code Here

                return;
            }

            Projection projection = projectedRequest.getProjection();
            if (fromSource instanceof ReadBranchRequest) {
                ReadBranchRequest readFromSource = (ReadBranchRequest)fromSource;
                for (Location parent : readFromSource) {
                    List<Location> children = readFromSource.getChildren(parent);
                    Map<Name, Property> properties = readFromSource.getPropertiesFor(parent);
                    projectToFederated(actualLocation, projection, request, parent, children, properties);
                }
                Location locationOfProxy = readFromSource.getActualLocationOfNode();
                // The location is in terms of the source, so get the projected location ...
                locationOfProxy = determineActualLocation(locationOfProxy, projection);
                actualLocationsOfProxyNodes.put(locationOfProxy.getPath(), locationOfProxy);
            }
            setCacheableInfo(request, fromSource.getCachePolicy());
            projectedRequest = projectedRequest.next();
            ++numMerged;
        }
        // Go through the requests and process the ReadNodeRequests (which were reading children of placeholders)...
        projectedRequest = federatedRequest.getFirstProjectedRequest();
        while (projectedRequest != null) {
            CacheableRequest fromSource = (CacheableRequest)projectedRequest.getRequest();
            Projection projection = projectedRequest.getProjection();
            if (fromSource instanceof ReadNodeRequest) {
                ReadNodeRequest readFromSource = (ReadNodeRequest)fromSource;
                Location parent = readFromSource.getActualLocationOfNode();
                List<Location> children = readFromSource.getChildren();
                for (int i = 0; i != children.size(); ++i) {
                    Location child = children.get(i);
                    if (!child.hasIdProperties()) {
                        // The the child must have been a proxy node ...
                        Location actual = actualLocationsOfProxyNodes.get(child.getPath());
                        assert actual != null;
                        children.set(i, actual);
                    }
                }
                Map<Name, Property> properties = readFromSource.getPropertiesByName();
                projectToFederated(actualLocation, projection, request, parent, children, properties);
            }
            setCacheableInfo(request, fromSource.getCachePolicy());
            projectedRequest = projectedRequest.next();
        }
View Full Code Here

                } else if (request instanceof ReadAllChildrenRequest) {
                    ReadAllChildrenRequest read = (ReadAllChildrenRequest)request;
                    DateTime expires = computeExpirationTime(read);
                    getOrCreateNode(read.getActualLocationOfNode(), expires).setChildren(read.getChildren());
                } else if (request instanceof ReadBranchRequest) {
                    ReadBranchRequest read = (ReadBranchRequest)request;
                    DateTime expires = computeExpirationTime(read);
                    for (Location location : read) {
                        BatchResultsNode node = getOrCreateNode(location, expires);
                        node.setProperties(read.getPropertiesFor(location));
                        node.setChildren(read.getChildren(location));
                    }
                }
            }
            for (Map.Entry<Path, BatchResultsNode> entry : nodes.entrySet()) {
                entry.getValue().freeze();
View Full Code Here

            } else if (request instanceof ReadAllChildrenRequest) {
                ReadAllChildrenRequest read = (ReadAllChildrenRequest)request;
                DateTime expires = computeExpirationTime(read);
                getOrCreateNode(read.getActualLocationOfNode(), expires).setChildren(read.getChildren());
            } else if (request instanceof ReadBranchRequest) {
                ReadBranchRequest read = (ReadBranchRequest)request;
                DateTime expires = computeExpirationTime(read);
                for (Location location : read) {
                    BatchResultsNode node = getOrCreateNode(location, expires);
                    node.setProperties(read.getPropertiesFor(location));
                    node.setChildren(read.getChildren(location));
                }
            }
            for (Map.Entry<Path, BatchResultsNode> entry : nodes.entrySet()) {
                entry.getValue().freeze();
            }
View Full Code Here

                    }
                }
            } else if (projectedNode.isProxy()) {
                ProxyNode proxy = projectedNode.asProxy();
                // Create and submit a request for the projection ...
                ReadBranchRequest pushDownRequest = new ReadBranchRequest(proxy.location(), proxy.workspaceName(), maxDepth);
                federatedRequest.add(pushDownRequest, proxy.isSameLocationAsOriginal(), false, proxy.projection());
            }
            projectedNode = projectedNode.next();
        }
    }
View Full Code Here

                return;
            }

            Projection projection = projectedRequest.getProjection();
            if (fromSource instanceof ReadBranchRequest) {
                ReadBranchRequest readFromSource = (ReadBranchRequest)fromSource;
                for (Location parent : readFromSource) {
                    List<Location> children = readFromSource.getChildren(parent);
                    Map<Name, Property> properties = readFromSource.getPropertiesFor(parent);
                    projectToFederated(actualLocation, projection, request, parent, children, properties);
                }
                Location locationOfProxy = readFromSource.getActualLocationOfNode();
                actualLocationsOfProxyNodes.put(locationOfProxy.getPath(), locationOfProxy);
            }
            setCacheableInfo(request, fromSource.getCachePolicy());
            projectedRequest = projectedRequest.next();
            ++numMerged;
        }
        // Go through the requests and process the ReadNodeRequests (which were reading children of placeholders)...
        projectedRequest = federatedRequest.getFirstProjectedRequest();
        while (projectedRequest != null) {
            CacheableRequest fromSource = (CacheableRequest)projectedRequest.getRequest();
            Projection projection = projectedRequest.getProjection();
            if (fromSource instanceof ReadNodeRequest) {
                ReadNodeRequest readFromSource = (ReadNodeRequest)fromSource;
                Location parent = readFromSource.getActualLocationOfNode();
                List<Location> children = readFromSource.getChildren();
                for (int i = 0; i != children.size(); ++i) {
                    Location child = children.get(i);
                    if (!child.hasIdProperties()) {
                        // The the child must have been a proxy node ...
                        Location actual = actualLocationsOfProxyNodes.get(child.getPath());
                        assert actual != null;
                        children.set(i, actual);
                    }
                }
                Map<Name, Property> properties = readFromSource.getPropertiesByName();
                projectToFederated(actualLocation, projection, request, parent, children, properties);
            }
            setCacheableInfo(request, fromSource.getCachePolicy());
            projectedRequest = projectedRequest.next();
        }
View Full Code Here

    @Override
    public void process( ReadBranchRequest request ) {
        CacheableRequest source = (CacheableRequest)federatedRequest.getFirstProjectedRequest().getRequest();
        if (checkErrorOrCancel(request, source)) return;
        if (source instanceof ReadBranchRequest) {
            ReadBranchRequest readSource = (ReadBranchRequest)source;
            request.setActualLocationOfNode(readSource.getActualLocationOfNode());
            for (Location node : readSource) {
                List<Location> children = readSource.getChildren(node);
                if (children != null) request.setChildren(node, children);
                Map<Name, Property> props = readSource.getPropertiesFor(node);
                if (props != null) request.setProperties(node, props.values());
            }
        } else if (source instanceof ReadNodeRequest) {
            ReadNodeRequest readSource = (ReadNodeRequest)source;
            request.setActualLocationOfNode(readSource.getActualLocationOfNode());
            Location parent = readSource.getActualLocationOfNode();
            request.setChildren(parent, readSource.getChildren());
            request.setProperties(parent, readSource.getPropertiesByName().values());
        }
        request.setCachePolicy(getDefaultCachePolicy());
        setCacheableInfo(request, source.getCachePolicy());
    }
View Full Code Here

                } else if (request instanceof ReadAllChildrenRequest) {
                    ReadAllChildrenRequest read = (ReadAllChildrenRequest)request;
                    DateTime expires = computeExpirationTime(read);
                    getOrCreateNode(read.getActualLocationOfNode(), expires).setChildren(read.getChildren());
                } else if (request instanceof ReadBranchRequest) {
                    ReadBranchRequest read = (ReadBranchRequest)request;
                    DateTime expires = computeExpirationTime(read);
                    for (Location location : read) {
                        BatchResultsNode node = getOrCreateNode(location, expires);
                        node.setProperties(read.getPropertiesFor(location));
                        node.setChildren(read.getChildren(location));
                    }
                }
            }
            for (Map.Entry<Path, BatchResultsNode> entry : nodes.entrySet()) {
                entry.getValue().freeze();
View Full Code Here

TOP

Related Classes of org.jboss.dna.graph.request.ReadBranchRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.