private Collection<String> getCandidateNames(MapEntryNode entity) { Collection<MapEntryNode> candidates = ((MapNode)entity.getChild(CANDIDATE_NODE_ID).get()).getValue(); Collection<String> candidateNames = new ArrayList<>(candidates.size()); for(MapEntryNode candidate: candidates) { candidateNames.add(candidate.getChild(CANDIDATE_NAME_NODE_ID).get().getValue().toString()); } return candidateNames; }
private List<Ipv4Prefix> extractPrefixes(final Collection<MapEntryNode> routes) { final List<Ipv4Prefix> prefs = new ArrayList<>(routes.size()); for (final MapEntryNode ipv4Route : routes) { final String prefix = (String) ipv4Route.getChild(this.routeKeyLeaf).get().getValue(); prefs.add(new Ipv4Prefix(prefix)); } return prefs; }
private void searchForEntitiesOwnedBy(final String owner, final EntityWalker walker) { LOG.debug("{}: Searching for entities owned by {}", persistenceId(), owner); searchForEntities((entityTypeNode, entityNode) -> { Optional<DataContainerChild<? extends PathArgument, ?>> possibleOwner = entityNode.getChild(ENTITY_OWNER_NODE_ID); if(possibleOwner.isPresent() && owner.equals(possibleOwner.get().getValue().toString())) { walker.onEntity(entityTypeNode, entityNode); } }); }
private static boolean hasCandidate(MapEntryNode entity, MemberName candidateName) { return ((MapNode)entity.getChild(CANDIDATE_NODE_ID).get()).getChild(candidateNodeKey(candidateName.getName())) .isPresent(); }
private void notifyAllListeners() { searchForEntities((entityTypeNode, entityNode) -> { Optional<DataContainerChild<?, ?>> possibleType = entityTypeNode.getChild(ENTITY_TYPE_NODE_ID); if (possibleType.isPresent()) { final boolean hasOwner; final boolean isOwner; Optional<DataContainerChild<?, ?>> possibleOwner = entityNode.getChild(ENTITY_OWNER_NODE_ID); if (possibleOwner.isPresent()) { isOwner = localMemberName.getName().equals(possibleOwner.get().getValue().toString()); hasOwner = true; } else { isOwner = false; hasOwner = false; } DOMEntity entity = new DOMEntity(possibleType.get().getValue().toString(), (YangInstanceIdentifier) entityNode.getChild(ENTITY_ID_NODE_ID).get().getValue()); listenerSupport.notifyEntityOwnershipListeners(entity, isOwner, isOwner, hasOwner); } }); }
private void searchForEntities(EntityWalker walker) { Optional<NormalizedNode<?, ?>> possibleEntityTypes = getDataStore().readNode(ENTITY_TYPES_PATH); if(!possibleEntityTypes.isPresent()) { return; } for(MapEntryNode entityType: ((MapNode) possibleEntityTypes.get()).getValue()) { Optional<DataContainerChild<?, ?>> possibleEntities = entityType.getChild(ENTITY_NODE_ID); if(!possibleEntities.isPresent()) { // shouldn't happen but handle anyway continue; } for(MapEntryNode entity: ((MapNode) possibleEntities.get()).getValue()) { walker.onEntity(entityType, entity); } } }
@Override public Optional<EntityOwnershipState> getOwnershipState(final DOMEntity forEntity) { Preconditions.checkNotNull(forEntity, "forEntity cannot be null"); DataTree dataTree = getLocalEntityOwnershipShardDataTree(); if (dataTree == null) { return Optional.absent(); } Optional<NormalizedNode<?, ?>> entityNode = dataTree.takeSnapshot().readNode( entityPath(forEntity.getType(), forEntity.getIdentifier())); if (!entityNode.isPresent()) { return Optional.absent(); } // Check if there are any candidates, if there are none we do not really have ownership state final MapEntryNode entity = (MapEntryNode) entityNode.get(); final Optional<DataContainerChild<? extends PathArgument, ?>> optionalCandidates = entity.getChild(CANDIDATE_NODE_ID); final boolean hasCandidates = optionalCandidates.isPresent() && ((MapNode) optionalCandidates.get()).getValue().size() > 0; if(!hasCandidates){ return Optional.absent(); } MemberName localMemberName = context.getCurrentMemberName(); Optional<DataContainerChild<? extends PathArgument, ?>> ownerLeaf = entity.getChild(ENTITY_OWNER_NODE_ID); String owner = ownerLeaf.isPresent() ? ownerLeaf.get().getValue().toString() : null; boolean hasOwner = !Strings.isNullOrEmpty(owner); boolean isOwner = hasOwner && localMemberName.getName().equals(owner); return Optional.of(EntityOwnershipState.from(isOwner, hasOwner)); }
private void onRegisterListenerLocal(final RegisterListenerLocal registerListener) { LOG.debug("{}: onRegisterListenerLocal: {}", persistenceId(), registerListener); listenerSupport.addEntityOwnershipListener(registerListener.getEntityType(), registerListener.getListener()); getSender().tell(SuccessReply.INSTANCE, getSelf()); searchForEntities((entityTypeNode, entityNode) -> { Optional<DataContainerChild<?, ?>> possibleType = entityTypeNode.getChild(ENTITY_TYPE_NODE_ID); String entityType = possibleType.isPresent() ? possibleType.get().getValue().toString() : null; if (registerListener.getEntityType().equals(entityType)) { final boolean hasOwner; final boolean isOwner; Optional<DataContainerChild<?, ?>> possibleOwner = entityNode.getChild(ENTITY_OWNER_NODE_ID); if (possibleOwner.isPresent()) { isOwner = localMemberName.getName().equals(possibleOwner.get().getValue().toString()); hasOwner = true; } else { isOwner = false; hasOwner = false; } DOMEntity entity = new DOMEntity(entityType, (YangInstanceIdentifier) entityNode.getChild(ENTITY_ID_NODE_ID).get().getValue()); listenerSupport.notifyEntityOwnershipListener(entity, false, isOwner, hasOwner, registerListener.getListener()); } }); }
final Optional<? extends NormalizedNode<?, ?>> child = node.getChild(new NodeIdentifier(qname)); if (child.isPresent()) { write(child.get());
final Optional<? extends NormalizedNode<?, ?>> child = node.getChild(new NodeIdentifier(qname)); if (child.isPresent()) { write(child.get());
final Optional<? extends NormalizedNode<?, ?>> child = node.getChild(new NodeIdentifier(qname)); if (child.isPresent()) { write(child.get());