/** * Add a request to read the properties and number of children of a node at the supplied location. * * @param at the location of the node to be read * @param workspaceName the name of the workspace containing the node * @return the request; never null * @throws IllegalArgumentException if the location or workspace name is null */ public ReadNodeRequest readNode( Location at, String workspaceName ) { return process(new ReadNodeRequest(at, workspaceName)); }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.ReadNodeRequest) */ @Override public void process( ReadNodeRequest request ) { ReadNodeRequest source = (ReadNodeRequest)federatedRequest.getFirstProjectedRequest().getRequest(); if (checkErrorOrCancel(request, source)) return; request.setActualLocationOfNode(source.getActualLocationOfNode()); for (Location childInSource : source.getChildren()) { request.addChild(childInSource); } for (Property propertyInSource : source.getProperties()) { request.addProperties(propertyInSource); } request.setCachePolicy(getDefaultCachePolicy()); setCacheableInfo(request, source.getCachePolicy()); }
if (request == null) return; ReadAllPropertiesRequest readProperties = new ReadAllPropertiesRequest(request.at(), request.inWorkspace()); process(readProperties); if (readProperties.hasError()) { request.setError(readProperties.getError()); return; request.setActualLocationOfNode(readProperties.getActualLocationOfNode()); ReadAllChildrenRequest readChildren = new ReadAllChildrenRequest(request.at(), request.inWorkspace()); process(readChildren); if (readChildren.hasError()) { request.setError(readChildren.getError()); return; if (request.isCancelled()) return; request.addProperty(property); request.addChild(child);
/** * {@inheritDoc} * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals( Object obj ) { if (obj == this) return true; if (this.getClass().isInstance(obj)) { ReadNodeRequest that = (ReadNodeRequest)obj; if (!this.at().isSame(that.at())) return false; if (!this.inWorkspace().equals(that.inWorkspace())) return false; return true; } return false; }
@Test public void shouldCancelFederatedRequestIfOneOfSeveralMultipleReadNodeRequestIsCancelled() { // Create the original read node request ... final ReadNodeRequest original = new ReadNodeRequest(location("/a/b/c"), "workspaceM"); // Create a single federated request using the mirror projection... final FederatedRequest request = new FederatedRequest(original); // And "fork" the original request into the first source request ... final ReadNodeRequest projected1 = new ReadNodeRequest(location("/b/c"), "workspaceM"); projected1.setActualLocationOfNode(Location.create(projected1.at().getPath(), UUID.randomUUID())); projected1.addProperty(property("propA", "valueA")); projected1.addProperty(property("propB", "valueB")); projected1.addChild(child(projected1.getActualLocationOfNode(), "child1")); projected1.addChild(child(projected1.getActualLocationOfNode(), "child2")); request.add(projected1, false, false, projectionA); // And a second source request (that was cancelled)... final ReadNodeRequest projected2 = new ReadNodeRequest(location("/a/b/c"), "workspaceM"); projected2.cancel(); request.add(projected2, true, false, mirrorProjection); request.freeze(); request.getLatch().countDown(); request.getLatch().countDown(); joinQueue.add(request); // Add a terminating request and join the request... joinQueue.add(new NoMoreFederatedRequests()); joinProcessor.process(joinQueue); // Check the results of the original has the same results of the projected... assertThat(original.getProperties().isEmpty(), is(true)); assertThat(original.getChildren().isEmpty(), is(true)); assertThat(original.isCancelled(), is(true)); }
@Test public void shouldJoinSingleMirroredReadNodeRequest() { // Create the original read node request ... final ReadNodeRequest original = new ReadNodeRequest(location("/a/b/c"), "workspaceM"); // Create a single federated request... final FederatedRequest request = new FederatedRequest(original); // And "fork" the original request ... final ReadNodeRequest projected = new ReadNodeRequest(location("/a/b/c"), "workspaceM"); projected.setActualLocationOfNode(Location.create(projected.at().getPath(), UUID.randomUUID())); projected.addProperty(property("propA", "valueA")); projected.addProperty(property("propB", "valueB")); projected.addChild(child(projected.getActualLocationOfNode(), "child1")); projected.addChild(child(projected.getActualLocationOfNode(), "child2")); request.add(projected, true, false, mirrorProjection); request.freeze(); request.getLatch().countDown(); joinQueue.add(request); // Add a terminating request and join the request... joinQueue.add(new NoMoreFederatedRequests()); joinProcessor.process(joinQueue); // Check the results of the original has the same results of the projected... assertThat(original.getChildren(), is(projected.getChildren())); assertThat(original.getPropertiesByName(), is(projected.getPropertiesByName())); assertThat(original.getActualLocationOfNode(), is(projected.getActualLocationOfNode())); }
Path federatedPath = request.at().getPath(); Map<Name, Property> properties = request.getPropertiesByName(); Map<Name, Integer> childSnsIndexes = new HashMap<Name, Integer>(); ProjectedRequest projectedRequest = federatedRequest.getFirstProjectedRequest(); request.setCachePolicy(getDefaultCachePolicy()); Location actualLocation = request.at(); int numMerged = 0; while (projectedRequest != null) { request.cancel(); return; request.addChild(childInRepos); if (federatedPath == null) federatedPath = childInRepos.getPath().getParent(); } else { ReadNodeRequest readFromSource = (ReadNodeRequest)sourceRequest; Location sourceLocation = readFromSource.getActualLocationOfNode(); if (sourceLocation.hasIdProperties()) { for (Location childInSource : readFromSource.getChildren()) { request.addChild(getChildLocationWithCorrectSnsIndex(childInSource, federatedPath, childSnsIndexes, for (Property propertyInSource : readFromSource.getProperties()) { Name name = propertyInSource.getName(); Property existing = properties.get(name);
ReadNodeRequest readNode = new ReadNodeRequest(read.location, request.inWorkspace()); process(readNode); if (readNode.hasError()) { request.setError(readNode.getError()); return; Location actualLocation = readNode.getActualLocationOfNode(); if (first) { request.setChildren(actualLocation, readNode.getChildren()); request.setProperties(actualLocation, readNode.getProperties()); if (includeChildrenInSubgraph(actualLocation, readNode.getPropertiesByName(), first)) { for (Location child : readNode.getChildren()) { locationsToRead.add(new LocationWithDepth(child, read.depth + 1));
@Test public void shouldCreateValidRequestWithValidLocation() { request = new ReadNodeRequest(validPathLocation1, workspace1); assertThat(request.at(), is(sameInstance(validPathLocation1))); assertThat(request.inWorkspace(), is(sameInstance(workspace1))); assertThat(request.hasError(), is(false)); assertThat(request.getError(), is(nullValue())); }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.ReadNodeRequest) */ @Override public void process( ReadNodeRequest request ) { WorkspaceType workspace = getWorkspace(request, request.inWorkspace()); NodeType node = getTargetNode(workspace, request, request.at()); if (node == null) { assert request.hasError(); return; } Location actualLocation = getActualLocation(workspace, request.at(), node); assert actualLocation != null; // Get the locations of the children ... List<Location> childLocations = txn.getChildrenLocations(workspace, node); request.addChildren(childLocations); // Get the properties of the node ... request.addProperty(propertyFactory.create(ModeShapeLexicon.UUID, node.getUuid())); request.addProperties(node.getProperties().values()); request.setActualLocationOfNode(actualLocation); setCacheableInfo(request); }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.ReadBranchRequest) */ @Override public void process( ReadBranchRequest request ) { CacheableRequest source = (CacheableRequest)federatedRequest.getFirstProjectedRequest().getRequest(); if (checkErrorOrCancel(request, source)) return; if (RequestType.READ_BRANCH == source.getType()) { 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 (RequestType.READ_NODE == source.getType()) { 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()); }
@Override public void process( ReadNodeRequest request ) { PathWorkspace workspace = getWorkspace(request, request.inWorkspace()); if (workspace == null) return; PathNode node = getTargetNode(workspace, request, request.at()); if (node == null) { request.setError(new PathNotFoundException(request.at(), workspace.getLowestExistingPath(request.at().getPath()))); return; } // Get the names of the children ... for (Path.Segment childSegment : node.getChildSegments()) { request.addChild(Location.create(pathFactory.create(node.getPath(), childSegment))); } // Get the properties of the node ... request.addProperties(node.getProperties().values()); request.setActualLocationOfNode(Location.create(node.getPath(), node.getUuid())); setCacheableInfo(request); }
public void process( ReadNodeRequest request ) { ProjectedNode projectedNode = project(request.at(), request.inWorkspace(), request, false); if (!children.isEmpty()) { ReadNodeRequest placeholderRequest = new ReadNodeRequest(placeholder.location(), request.inWorkspace()); placeholderRequest.addChildren(children); if (firstRequest) { firstRequest = false; placeholderRequest.addProperties(placeholder.properties().values()); placeholderRequest.setActualLocationOfNode(placeholder.location()); federatedRequest.add(placeholderRequest, true, true, null); children = new LinkedList<Location>(); ReadNodeRequest placeholderRequest = new ReadNodeRequest(placeholder.location(), request.inWorkspace()); placeholderRequest.addChildren(children); if (firstRequest) { firstRequest = false; placeholderRequest.addProperties(placeholder.properties().values()); placeholderRequest.setActualLocationOfNode(placeholder.location()); federatedRequest.add(placeholderRequest, true, true, null); ReadNodeRequest pushDownRequest = new ReadNodeRequest(proxy.location(), proxy.workspaceName()); federatedRequest.add(pushDownRequest, proxy.isSameLocationAsOriginal(), false, proxy.projection());
when(workspace.project(context, locationInFed, false)).thenReturn(projectedNode); ReadNodeRequest request = new ReadNodeRequest(locationInFed, workspaceName); processor.process(request); assertThat(request.hasError(), is(false)); assertThat(projectedRequest.at(), is(locationInFed)); List<Location> expectedChildren = new ArrayList<Location>(); for (ProjectedNode child : children) { expectedChildren.add(child.location()); assertThat(projectedRequest.getChildren(), is(expectedChildren)); assertThat(projectedRequest.getPropertiesByName(), is(properties)); assertThat(fedRequest.getFirstProjectedRequest().hasNext(), is(false));
@Test public void shouldAllowAddingProperties() { request = new ReadNodeRequest(validPathLocation, workspace1); request.addProperty(validProperty1); request.addProperty(validProperty2); assertThat(request.getProperties().size(), is(2)); assertThat(request.getProperties(), hasItems(validProperty1, validProperty2)); assertThat(request.getPropertiesByName().get(validProperty1.getName()), is(validProperty1)); assertThat(request.getPropertiesByName().get(validProperty2.getName()), is(validProperty2)); } }
@Test public void shouldNotForkReadNodeRequestIfWorkspaceNameIsInvalid() { // Stub the workspace to have no projection ... Location locationInFed = location("/a/b"); when(workspace.project(context, locationInFed, false)).thenReturn(null); ReadNodeRequest request = new ReadNodeRequest(locationInFed, nonExistantWorkspaceName); processor.process(request); assertThat(request.hasError(), is(true)); assertThat(request.getError(), is(instanceOf(InvalidWorkspaceException.class))); }
@Test public void shouldAllowAddingChildren() { request = new ReadNodeRequest(validPathLocation, workspace1); request.addChild(validPathLocation1); request.addChild(validPathLocation2); assertThat(request.getChildren().size(), is(2)); assertThat(request.getChildren(), hasItems(validPathLocation1, validPathLocation2)); }
PlaceholderNode placeholder = projectedNode.asPlaceholder(); ReadNodeRequest placeholderRequest = new ReadNodeRequest(placeholder.location(), workspace.getName()); List<Location> children = new ArrayList<Location>(placeholder.children().size()); for (ProjectedNode child : placeholder.children()) { placeholderRequest.addChildren(children); placeholderRequest.addProperties(placeholder.properties().values()); placeholderRequest.setActualLocationOfNode(placeholder.location()); federatedRequest.add(placeholderRequest, true, true, null); if (maxDepth > 1) {
@Test public void shouldSubmitSingleSourceRequestWhenProcessingSingleReadNodeRequest() throws Exception { // Stub the workspace to have a projection ... Location locationInFed = location("/a/x/y"); Location locationInSource = location("/x/y"); ProjectedNode projectedNode = new ProxyNode(projectionA, locationInSource, locationInFed, false); when(workspace.project(context, locationInFed, false)).thenReturn(projectedNode); ReadNodeRequest request = new ReadNodeRequest(locationInFed, workspaceName); processor.process(request); assertThat(request.hasError(), is(false)); // Check that the federated request has the right information ... FederatedRequest fedRequest = federatedRequests.poll(); ReadNodeRequest projectedRequest = (ReadNodeRequest)fedRequest.getFirstProjectedRequest().getRequest(); assertThat(projectedRequest.at(), is(locationInSource)); assertThat(fedRequest.getFirstProjectedRequest().hasNext(), is(false)); // Close the processor ... processor.close(); processor.await(); // Verify the source saw the expected read ... ReadNodeRequest sourceRequest = (ReadNodeRequest)connectionForSourceA.getProcessedRequests().poll(); assertThat(sourceRequest.at().getPath(), is(locationInSource.getPath())); assertThat(connectionForSourceB.getProcessedRequests().isEmpty(), is(true)); assertThat(connectionForSourceC.getProcessedRequests().isEmpty(), is(true)); }