Map<String, ModuleMXBeanEntry> result = new HashMap<>();
for (AugmentationSchema augmentation : currentModule.getAugmentations()) {
- Set<DataSchemaNode> childNodes = augmentation.getChildNodes();
+ Collection<DataSchemaNode> childNodes = augmentation.getChildNodes();
if (areAllChildrenChoiceCaseNodes(childNodes)) {
for (ChoiceCaseNode childCase : castChildNodesToChoiceCases(childNodes)) {
// TODO refactor, extract to standalone builder class
return moduleIdentities;
}
- private Collection<ChoiceCaseNode> castChildNodesToChoiceCases(final Set<DataSchemaNode> childNodes) {
+ private Collection<ChoiceCaseNode> castChildNodesToChoiceCases(final Collection<DataSchemaNode> childNodes) {
return Collections2.transform(childNodes, new Function<DataSchemaNode, ChoiceCaseNode>() {
@Nullable
@Override
});
}
- private boolean areAllChildrenChoiceCaseNodes(final Set<DataSchemaNode> childNodes) {
+ private boolean areAllChildrenChoiceCaseNodes(final Iterable<DataSchemaNode> childNodes) {
for (DataSchemaNode childNode : childNodes) {
if (childNode instanceof ChoiceCaseNode == false) {
return false;
* @return either choiceCaseNode or its only child container
*/
private <HAS_CHILDREN_AND_QNAME extends DataNodeContainer & SchemaNode> HAS_CHILDREN_AND_QNAME getDataNodeContainer(final ChoiceCaseNode choiceCaseNode) {
- Set<DataSchemaNode> childNodes = choiceCaseNode.getChildNodes();
+ Collection<DataSchemaNode> childNodes = choiceCaseNode.getChildNodes();
if (childNodes.size() == 1) {
DataSchemaNode onlyChild = childNodes.iterator().next();
if (onlyChild instanceof ContainerSchemaNode) {
final TypeProviderWrapper typeProviderWrapper, final Map<QName, ServiceInterfaceEntry> qNamesToSIEs,
final SchemaContext schemaContext, final String packageName) {
Map<String, AttributeIfc> yangToAttributes = new HashMap<>();
- Set<DataSchemaNode> childNodes = dataNodeContainer.getChildNodes();
- for (DataSchemaNode attrNode : childNodes) {
+ for (DataSchemaNode attrNode : dataNodeContainer.getChildNodes()) {
AttributeIfc attributeValue = getAttributeValue(attrNode, currentModule, qNamesToSIEs, typeProviderWrapper,
schemaContext, packageName);
yangToAttributes.put(attributeValue.getAttributeYangName(), attributeValue);
}
}
- private static Collection<DataSchemaNode> sortAttributes(final Set<DataSchemaNode> childNodes) {
+ private static Collection<DataSchemaNode> sortAttributes(final Collection<DataSchemaNode> childNodes) {
final TreeSet<DataSchemaNode> dataSchemaNodes = new TreeSet<>(new Comparator<DataSchemaNode>() {
@Override
public int compare(final DataSchemaNode o1, final DataSchemaNode o2) {
import java.lang.reflect.Method;
import java.util.AbstractMap.SimpleEntry;
+import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map.Entry;
return Iterables.filter(augmentations, new Predicate<AugmentationSchema>() {
@Override
public boolean apply(final AugmentationSchema schema) {
- final Set<DataSchemaNode> childNodes = schema.getChildNodes();
- return !schema.getChildNodes().isEmpty()
- && module.equals(Iterables.get(childNodes, 0).getQName().getModule());
+ final Collection<DataSchemaNode> childNodes = schema.getChildNodes();
+ return !childNodes.isEmpty() && module.equals(Iterables.get(childNodes, 0).getQName().getModule());
}
});
}
return invoker;
}
- utils.getLock().lock();
- try {
- synchronized (utils) {
- invoker = ClassLoaderUtils.withClassLoader(cls.getClassLoader(), new Supplier<RuntimeGeneratedInvokerPrototype>() {
- @Override
- public RuntimeGeneratedInvokerPrototype get() {
- return generateListenerInvoker(cls);
- }
- });
- }
-
- invokerClasses.put(cls, invoker);
- return invoker;
- } finally {
- utils.getLock().unlock();
+ synchronized (utils) {
+ invoker = ClassLoaderUtils.withClassLoader(cls.getClassLoader(), new Supplier<RuntimeGeneratedInvokerPrototype>() {
+ @Override
+ public RuntimeGeneratedInvokerPrototype get() {
+ return generateListenerInvoker(cls);
+ }
+ });
}
+
+ invokerClasses.put(cls, invoker);
+ return invoker;
}
@Override
@Override
public final <T extends RpcService> T getDirectProxyFor(final Class<T> serviceType) {
- utils.getLock().lock();
- try {
- synchronized (utils) {
- return ClassLoaderUtils.withClassLoader(serviceType.getClassLoader(), directProxySupplier(serviceType));
- }
- } finally {
- utils.getLock().unlock();
+ synchronized (utils) {
+ return ClassLoaderUtils.withClassLoader(serviceType.getClassLoader(), directProxySupplier(serviceType));
}
}
}
});
- utils.getLock().lock();
- try {
- synchronized (utils) {
- final T instance = ClassLoaderUtils.withClassLoader(serviceType.getClassLoader(), routerSupplier(serviceType, metadata));
- return new RpcRouterCodegenInstance<T>(name, serviceType, instance, metadata.getContexts());
- }
- } finally {
- utils.getLock().unlock();
+ synchronized (utils) {
+ final T instance = ClassLoaderUtils.withClassLoader(serviceType.getClassLoader(), routerSupplier(serviceType, metadata));
+ return new RpcRouterCodegenInstance<T>(name, serviceType, instance, metadata.getContexts());
}
}
*
* @param cons
* Consumer to be registered.
- * @param context
* @return a session specific to consumer registration
* @throws IllegalArgumentException
* If the consumer is <code>null</code>.
* @throws IllegalStateException
* If the consumer is already registered.
*/
+ ConsumerSession registerConsumer(Consumer cons);
+
+ /*
+ * @deprecated Use registerConsumer(Consumer cons) instead (BundleContext is no longer used)
+ */
+ @Deprecated
ConsumerSession registerConsumer(Consumer cons, BundleContext context);
/**
*
* @param prov
* Provider to be registered.
- * @param context
* @return a session unique to the provider registration.
* @throws IllegalArgumentException
* If the provider is <code>null</code>.
* @throws IllegalStateException
* If the consumer is already registered.
*/
+ ProviderSession registerProvider(Provider prov);
+
+ /*
+ * @deprecated Use registerProvider(Provider cons) instead (BundleContext is no longer used)
+ */
+ @Deprecated
ProviderSession registerProvider(Provider prov, BundleContext context);
/**
public void onSessionInitiated(ConsumerSession session);
/**
- * Get a set of implementations of consumer functionality to be registered
- * into system during the consumer registration to the SAL.
- *
- * This method is invoked by {@link Broker#registerConsumer(Consumer)}.
- *
- * @return Set of consumer functionality.
+ * @deprecated - no longer used or needed
+ * *
+ * Suggested implementation until removed:
+ * @code {
+ * public Collection<ConsumerFunctionality> getConsumerFunctionality() {
+ * return Collections.emptySet();
+ * }
+ * }
*/
+ @Deprecated
public Collection<ConsumerFunctionality> getConsumerFunctionality();
/**
- * The marker interface for the interfaces describing the consumer
- * functionality contracts.
- *
- *
+ * @deprecated - no longer used or needed
*/
+ @Deprecated
public interface ConsumerFunctionality {
}
public void onSessionInitiated(ProviderSession session);
/**
- * Gets a set of implementations of provider functionality to be registered
- * into system during the provider registration to the SAL.
+ * @deprecated - No longer used or needed
*
- * <p>
- * This method is invoked by {@link Broker#registerProvider(Provider)} to
- * learn the initial provided functionality
- *
- * @return Set of provider's functionality.
+ * Suggested implementation until removed:
+ * @code {
+ * public Collection<ProviderFunctionality> getProviderFunctionality() {
+ * return Collections.emptySet();
+ * }
+ * }
*/
+ @Deprecated
public Collection<ProviderFunctionality> getProviderFunctionality();
/**
- * Functionality provided by the {@link Provider}
- *
- * <p>
- * Marker interface used to mark the interfaces describing specific
- * functionality which could be exposed by providers to other components.
- *
-
- *
+ * @deprecated - no longer used or needed
*/
+ @Deprecated
public interface ProviderFunctionality {
}
@Override
public ConsumerSession registerConsumer(final Consumer consumer,
final BundleContext ctx) {
- checkPredicates(consumer);
- log.trace("Registering consumer {}", consumer);
- final ConsumerContextImpl session = newSessionFor(consumer, ctx);
- consumer.onSessionInitiated(session);
- sessions.add(session);
- return session;
+ return registerConsumer(consumer);
}
@Override
public ProviderSession registerProvider(final Provider provider,
final BundleContext ctx) {
- checkPredicates(provider);
- final ProviderContextImpl session = newSessionFor(provider, ctx);
- provider.onSessionInitiated(session);
- providerSessions.add(session);
- return session;
+ return registerProvider(provider);
}
protected Future<RpcResult<CompositeNode>> invokeRpcAsync(final QName rpc,
}
// Private Factory methods
- private ConsumerContextImpl newSessionFor(final Consumer provider,
- final BundleContext ctx) {
+ private ConsumerContextImpl newSessionFor(final Consumer provider) {
ConsumerContextImpl ret = new ConsumerContextImpl(provider, this);
return ret;
}
- private ProviderContextImpl newSessionFor(final Provider provider,
- final BundleContext ctx) {
+ private ProviderContextImpl newSessionFor(final Provider provider) {
ProviderContextImpl ret = new ProviderContextImpl(provider, this);
return ret;
}
return Optional.fromNullable(services.getInstance(service));
}
+
+ @Override
+ public ConsumerSession registerConsumer(Consumer consumer) {
+ checkPredicates(consumer);
+ log.trace("Registering consumer {}", consumer);
+ final ConsumerContextImpl session = newSessionFor(consumer);
+ consumer.onSessionInitiated(session);
+ sessions.add(session);
+ return session;
+ }
+
+
+ @Override
+ public ProviderSession registerProvider(Provider provider) {
+ checkPredicates(provider);
+ final ProviderContextImpl session = newSessionFor(provider);
+ provider.onSessionInitiated(session);
+ providerSessions.add(session);
+ return session;
+ }
+
}
}
private static DataSchemaNode searchInChoices(final DataNodeContainer node, final QName arg) {
- Set<DataSchemaNode> children = node.getChildNodes();
- for (DataSchemaNode child : children) {
+ for (DataSchemaNode child : node.getChildNodes()) {
if (child instanceof ChoiceNode) {
ChoiceNode choiceNode = (ChoiceNode) child;
DataSchemaNode potential = searchInCases(choiceNode, arg);
import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
this.qName = Preconditions.checkNotNull(qName, "qName");
}
- public NodeContainerProxy(final QName qName, final Set<DataSchemaNode> childNodes) {
+ public NodeContainerProxy(final QName qName, final Collection<DataSchemaNode> childNodes) {
this(qName, asMap(childNodes));
}
- private static Map<QName, DataSchemaNode> asMap(final Set<DataSchemaNode> childNodes) {
+ private static Map<QName, DataSchemaNode> asMap(final Collection<DataSchemaNode> childNodes) {
final Map<QName, DataSchemaNode> mapped = Maps.newHashMap();
for (final DataSchemaNode childNode : childNodes) {
mapped.put(childNode.getQName(), childNode);
import java.io.StringWriter;
import java.util.Collections;
import java.util.List;
-import java.util.Set;
/*
* Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
factory.setIgnoringComments(true);
}
- private static DataSchemaNode findChildNode(Set<DataSchemaNode> children,
+ private static DataSchemaNode findChildNode(Iterable<DataSchemaNode> children,
String name) {
List<DataNodeContainer> containers = Lists.newArrayList();
+ childNodeName);
}
- static DataSchemaNode findChildNode(final Set<DataSchemaNode> children, final String name) {
+ static DataSchemaNode findChildNode(final Iterable<DataSchemaNode> children, final String name) {
List<DataNodeContainer> containers = Lists.newArrayList();
for (DataSchemaNode dataSchemaNode : children) {
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.net.URI;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
final Set<QName> foundLists = new HashSet<>();
- Set<DataSchemaNode> parentSchemaChildNodes = parentSchema == null ? Collections.<DataSchemaNode> emptySet()
+ Collection<DataSchemaNode> parentSchemaChildNodes = parentSchema == null ? Collections.<DataSchemaNode> emptySet()
: parentSchema.getChildNodes();
for (Node<?> child : parent.getValue()) {
}
}
- private static DataSchemaNode findFirstSchemaForNode(final Node<?> node, final Set<DataSchemaNode> dataSchemaNode) {
+ private static DataSchemaNode findFirstSchemaForNode(final Node<?> node, final Iterable<DataSchemaNode> dataSchemaNode) {
for (DataSchemaNode dsn : dataSchemaNode) {
if (node.getNodeType().equals(dsn.getQName())) {
return dsn;
import com.google.common.collect.BiMap;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.HashBiMap;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
+
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicReference;
+
import javax.ws.rs.core.Response.Status;
+
import org.opendaylight.controller.sal.core.api.mount.MountInstance;
import org.opendaylight.controller.sal.core.api.mount.MountService;
import org.opendaylight.controller.sal.rest.api.Draft02;
private static final Splitter SLASH_SPLITTER = Splitter.on('/');
- private static final Splitter COLON_SPLITTER = Splitter.on(':');
-
private final BiMap<URI, String> uriToModuleName = HashBiMap.<URI, String> create();
private final Map<String, URI> moduleNameToUri = uriToModuleName.inverse();
- private final Map<QName, RpcDefinition> qnameToRpc = new ConcurrentHashMap<>();
+ private final AtomicReference<Map<QName, RpcDefinition>> qnameToRpc =
+ new AtomicReference<>(Collections.<QName, RpcDefinition>emptyMap());
private volatile SchemaContext globalSchema;
private volatile MountService mountService;
private void collectInstanceDataNodeContainers(final List<DataSchemaNode> potentialSchemaNodes,
final DataNodeContainer container, final String name) {
- Set<DataSchemaNode> childNodes = container.getChildNodes();
-
Predicate<DataSchemaNode> filter = new Predicate<DataSchemaNode>() {
@Override
public boolean apply(final DataSchemaNode node) {
}
};
- Iterable<DataSchemaNode> nodes = Iterables.filter(childNodes, filter);
+ Iterable<DataSchemaNode> nodes = Iterables.filter(container.getChildNodes(), filter);
// Can't combine this loop with the filter above because the filter is
// lazily-applied by Iterables.filter.
}
private static String toModuleName(final String str) {
- Preconditions.<String> checkNotNull(str);
- if (str.indexOf(':') != -1) {
- final Iterable<String> args = COLON_SPLITTER.split(str);
- if (Iterables.size(args) == 2) {
- return args.iterator().next();
- }
+ final int idx = str.indexOf(':');
+ if (idx == -1) {
+ return null;
}
- return null;
+
+ // Make sure there is only one occurrence
+ if (str.indexOf(':', idx + 1) != -1) {
+ return null;
+ }
+
+ return str.substring(0, idx);
}
private static String toNodeName(final String str) {
- if (str.indexOf(':') != -1) {
- final Iterable<String> args = COLON_SPLITTER.split(str);
- if (Iterables.size(args) == 2) {
- return Iterables.get(args, 1);
- }
+ final int idx = str.indexOf(':');
+ if (idx == -1) {
+ return str;
+ }
+
+ // Make sure there is only one occurrence
+ if (str.indexOf(':', idx + 1) != -1) {
+ return str;
}
- return str;
+
+ return str.substring(idx + 1);
}
private QName toQName(final String name) {
return namespace.isPresent() ? QName.create(namespace.get(), node) : null;
}
- private boolean isListOrContainer(final DataSchemaNode node) {
+ private static boolean isListOrContainer(final DataSchemaNode node) {
return node instanceof ListSchemaNode || node instanceof ContainerSchemaNode;
}
public RpcDefinition getRpcDefinition(final String name) {
final QName validName = this.toQName(name);
- return validName == null ? null : this.qnameToRpc.get(validName);
+ return validName == null ? null : this.qnameToRpc.get().get(validName);
}
@Override
public void onGlobalContextUpdated(final SchemaContext context) {
if (context != null) {
- this.qnameToRpc.clear();
- this.setGlobalSchema(context);
- Set<RpcDefinition> _operations = context.getOperations();
- for (final RpcDefinition operation : _operations) {
- {
- this.qnameToRpc.put(operation.getQName(), operation);
- }
+ final Collection<RpcDefinition> defs = context.getOperations();
+ final Map<QName, RpcDefinition> newMap = new HashMap<>(defs.size());
+
+ for (final RpcDefinition operation : defs) {
+ newMap.put(operation.getQName(), operation);
}
+
+ // FIXME: still not completely atomic
+ this.qnameToRpc.set(ImmutableMap.copyOf(newMap));
+ this.setGlobalSchema(context);
}
}
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
List<Api> apis = new ArrayList<Api>();
- Set<DataSchemaNode> dataSchemaNodes = m.getChildNodes();
+ Collection<DataSchemaNode> dataSchemaNodes = m.getChildNodes();
_logger.debug("child nodes size [{}]", dataSchemaNodes.size());
for (DataSchemaNode node : dataSchemaNodes) {
if ((node instanceof ListSchemaNode) || (node instanceof ContainerSchemaNode)) {
apis.add(api);
if ((node instanceof ListSchemaNode) || (node instanceof ContainerSchemaNode)) {
DataNodeContainer schemaNode = (DataNodeContainer) node;
- Set<DataSchemaNode> dataSchemaNodes = schemaNode.getChildNodes();
- for (DataSchemaNode childNode : dataSchemaNodes) {
+ for (DataSchemaNode childNode : schemaNode.getChildNodes()) {
// We don't support going to leaf nodes today. Only lists and
// containers.
if (childNode instanceof ListSchemaNode || childNode instanceof ContainerSchemaNode) {
JSONException {
String moduleName = module.getName();
- Set<DataSchemaNode> childNodes = module.getChildNodes();
- for (DataSchemaNode childNode : childNodes) {
+ for (DataSchemaNode childNode : module.getChildNodes()) {
JSONObject configModuleJSON = null;
JSONObject operationalModuleJSON = null;
String containerDescription = container.getDescription();
moduleJSON.put(DESCRIPTION_KEY, containerDescription);
- Set<DataSchemaNode> containerChildren = container.getChildNodes();
- JSONObject properties = processChildren(containerChildren, moduleName, models, isConfig);
+ JSONObject properties = processChildren(container.getChildNodes(), moduleName, models, isConfig);
moduleJSON.put(PROPERTIES_KEY, properties);
return moduleJSON;
}
- private JSONObject processChildren(Set<DataSchemaNode> nodes, String moduleName,
+ private JSONObject processChildren(Iterable<DataSchemaNode> nodes, String moduleName,
JSONObject models) throws JSONException, IOException {
return processChildren(nodes, moduleName, models, null);
}
* @throws JSONException
* @throws IOException
*/
- private JSONObject processChildren(Set<DataSchemaNode> nodes, String moduleName,
+ private JSONObject processChildren(Iterable<DataSchemaNode> nodes, String moduleName,
JSONObject models, Boolean isConfig) throws JSONException, IOException {
JSONObject properties = new JSONObject();
private JSONObject processListSchemaNode(ListSchemaNode listNode, String moduleName,
JSONObject models, Boolean isConfig) throws JSONException, IOException {
- Set<DataSchemaNode> listChildren = listNode.getChildNodes();
String fileName = (BooleanUtils.isNotFalse(isConfig)?OperationBuilder.CONFIG:OperationBuilder.OPERATIONAL) +
listNode.getQName().getLocalName();
- JSONObject childSchemaProperties = processChildren(listChildren, moduleName, models);
+ JSONObject childSchemaProperties = processChildren(listNode.getChildNodes(), moduleName, models);
JSONObject childSchema = getSchemaTemplate();
childSchema.put(TYPE_KEY, OBJECT_TYPE);
childSchema.put(PROPERTIES_KEY, childSchemaProperties);
import com.google.common.base.Preconditions;
import java.util.Collections;
import java.util.Iterator;
-import java.util.Set;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
public class OutputDefinition implements Iterable<DataSchemaNode> {
public static final OutputDefinition EMPTY_OUTPUT = new OutputDefinition(Collections.<DataSchemaNode>emptySet());
- private final Set<DataSchemaNode> childNodes;
+ private final Iterable<DataSchemaNode> childNodes;
- public OutputDefinition(final Set<DataSchemaNode> childNodes) {
+ public OutputDefinition(final Iterable<DataSchemaNode> childNodes) {
this.childNodes = childNodes;
}