*
* @return Logical data store type. Guaranteed to be non-null.
*/
- public @Nonnull LogicalDatastoreType getDatastoreType() {
+ @Nonnull
+ public LogicalDatastoreType getDatastoreType() {
return datastoreType;
}
*
* @return Instance identifier corresponding to the root node.
*/
- public @Nonnull InstanceIdentifier<T> getRootIdentifier() {
+ @Nonnull
+ public InstanceIdentifier<T> getRootIdentifier() {
return rootIdentifier;
}
@Nullable
@Override
- public <T extends DataObject> DataTreeWriteCursor createCursor(final DataTreeIdentifier<T> path) {
+ public <P extends DataObject> DataTreeWriteCursor createCursor(final DataTreeIdentifier<P> path) {
final YangInstanceIdentifier yPath = codec.toNormalized(path.getRootIdentifier());
final DOMDataTreeWriteCursor cursor = delegate.createCursor(
new DOMDataTreeIdentifier(path.getDatastoreType(), yPath));
import org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction;
import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
import org.opendaylight.mdsal.dom.api.DOMDataTreeProducer;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeProducerBusyException;
import org.opendaylight.mdsal.dom.api.DOMDataTreeProducerException;
class BindingDOMDataTreeProducerAdapter implements DataTreeProducer {
public void close() throws DataTreeProducerException {
try {
delegate.close();
- } catch (final DOMDataTreeProducerBusyException e) {
- throw new DataTreeProducerException(e.getMessage(), e);
} catch (final DOMDataTreeProducerException e) {
throw new DataTreeProducerException(e.getMessage(), e);
}
}
-
}
return ret.getLastPathArgument();
}
- private <T extends DataObject> Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> convertToNormalized(
- final PathArgument child, final T data) {
+ private <P extends DataObject> Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> convertToNormalized(
+ final PathArgument child, final P data) {
stack.push(child);
final InstanceIdentifier<?> iid = InstanceIdentifier.create(stack);
final Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry
- = codec.toNormalizedNode(new SimpleEntry<>(iid, data));
+ = codec.toNormalizedNode(new SimpleEntry<>(iid, data));
stack.pop();
return entry;
}
}
@Override
- public <T extends DataObject> void merge(final PathArgument child, final T data) {
+ public <P extends DataObject> void merge(final PathArgument child, final P data) {
final Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry = convertToNormalized(child, data);
delegate.merge(entry.getKey().getLastPathArgument(), entry.getValue());
}
@Override
- public <T extends DataObject> void write(PathArgument child, T data) {
+ public <P extends DataObject> void write(final PathArgument child, P data) {
final Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry = convertToNormalized(child, data);
delegate.write(entry.getKey().getLastPathArgument(), entry.getValue());
}
YangInstanceIdentifier domPath = codec.toYangInstanceIdentifierBlocking(mountPoint);
Optional<DOMMountPoint> domMount = mountService.getMountPoint(domPath);
if (domMount.isPresent()) {
- return Optional.<MountPoint>fromNullable(bindingMountpoints.getUnchecked(domMount.get()));
+ return Optional.fromNullable(bindingMountpoints.getUnchecked(domMount.get()));
}
return Optional.absent();
}
@Override
public <T extends MountPointListener> ListenerRegistration<T> registerListener(InstanceIdentifier<?> path,
T listener) {
- return new BindingDOMMountPointListenerAdapter<T>(listener,codec,mountService);
+ return new BindingDOMMountPointListenerAdapter<>(listener, codec, mountService);
}
}
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import org.opendaylight.mdsal.dom.api.DOMRpcException;
import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
public <T extends RpcService> BindingDOMRpcImplementationAdapter(final BindingNormalizedNodeCodecRegistry codec,
final Class<T> type, final Map<SchemaPath, Method> localNameToMethod, final T delegate) {
try {
- this.invoker = SERVICE_INVOKERS.get(type, new Callable<RpcServiceInvoker>() {
- @Override
- public RpcServiceInvoker call() {
- final Map<QName, Method> map = new HashMap<>();
- for (Entry<SchemaPath, Method> e : localNameToMethod.entrySet()) {
- map.put(e.getKey().getLastComponent(), e.getValue());
- }
-
- return RpcServiceInvoker.from(map);
+ this.invoker = SERVICE_INVOKERS.get(type, () -> {
+ final Map<QName, Method> map = new HashMap<>();
+ for (Entry<SchemaPath, Method> e : localNameToMethod.entrySet()) {
+ map.put(e.getKey().getLastComponent(), e.getValue());
}
+
+ return RpcServiceInvoker.from(map);
});
} catch (ExecutionException e) {
throw new IllegalArgumentException("Failed to create invokers for type " + type, e);
final SchemaPath schemaPath = rpc.getType();
final DataObject bindingInput = input != null ? deserilialize(rpc.getType(),input) : null;
final ListenableFuture<RpcResult<?>> bindingResult = invoke(schemaPath,bindingInput);
- return transformResult(schemaPath,bindingResult);
+ return transformResult(bindingResult);
}
private DataObject deserilialize(final SchemaPath rpcPath, final NormalizedNode<?, ?> input) {
return JdkFutureAdapters.listenInPoolThread(invoker.invokeRpc(delegate, schemaPath.getLastComponent(), input));
}
- private CheckedFuture<DOMRpcResult, DOMRpcException> transformResult(final SchemaPath schemaPath,
+ private CheckedFuture<DOMRpcResult, DOMRpcException> transformResult(
final ListenableFuture<RpcResult<?>> bindingResult) {
return LazyDOMRpcResultFuture.create(codec, bindingResult);
}
public class BindingDOMRpcServiceAdapter implements RpcConsumerRegistry {
- protected static final Factory<RpcConsumerRegistry> BUILDER_FACTORY = new Factory<RpcConsumerRegistry>() {
-
- @Override
- public BindingDOMAdapterBuilder<RpcConsumerRegistry> newBuilder() {
- return new Builder();
- }
-
- };
+ protected static final Factory<RpcConsumerRegistry> BUILDER_FACTORY = Builder::new;
private final LoadingCache<Class<? extends RpcService>, RpcServiceAdapter> proxies = CacheBuilder.newBuilder()
.weakKeys()
.build(new CacheLoader<Class<? extends RpcService>, RpcServiceAdapter>() {
+ private RpcServiceAdapter createProxy(final Class<? extends RpcService> key) {
+ Preconditions.checkArgument(BindingReflections.isBindingClass(key));
+ Preconditions.checkArgument(key.isInterface(), "Supplied RPC service type must be interface.");
+ return new RpcServiceAdapter(key, codec, domService);
+ }
+
@Override
public RpcServiceAdapter load(final Class<? extends RpcService> key) throws Exception {
return createProxy(key);
return (T) proxies.getUnchecked(rpcService).getProxy();
}
- private RpcServiceAdapter createProxy(final Class<? extends RpcService> key) {
- Preconditions.checkArgument(BindingReflections.isBindingClass(key));
- Preconditions.checkArgument(key.isInterface(), "Supplied RPC service type must be interface.");
- return new RpcServiceAdapter(key, codec, domService);
- }
-
private static final class Builder extends BindingDOMAdapterBuilder<RpcConsumerRegistry> {
@Override
* return non-null value.
*/
final BindingCodecTreeNode<?> codecContext = currentCodecTree.getSubtreeCodec(bindingPath);
- return new SimpleEntry<InstanceIdentifier<?>, BindingCodecTreeNode<?>>(bindingPath, codecContext);
+ return new SimpleEntry<>(bindingPath, codecContext);
}
@SuppressWarnings("unchecked")
}
};
-
private static final LoadingCache<Class<?>, ContextReferenceExtractor> EXTRACTORS = CacheBuilder.newBuilder()
.weakKeys().build(new CacheLoader<Class<?>, ContextReferenceExtractor>() {
public ContextReferenceExtractor load(final Class<?> key) throws Exception {
return create(key);
}
+
+ @Nonnull
+ private ContextReferenceExtractor create(final Class<?> key) {
+ final Method contextGetter = getContextGetter(key);
+ if (contextGetter == null) {
+ return NULL_EXTRACTOR;
+ }
+ final Class<?> returnType = contextGetter.getReturnType();
+ try {
+ if (InstanceIdentifier.class.isAssignableFrom(returnType)) {
+ return DirectGetterRouteContextExtractor.create(contextGetter);
+ }
+ final Method getValueMethod = findGetValueMethod(returnType, InstanceIdentifier.class);
+ if (getValueMethod != null) {
+ return GetValueRouteContextExtractor.create(contextGetter, getValueMethod);
+ } else {
+ LOG.warn("Class {} can not be used to determine context, falling back to NULL_EXTRACTOR.",
+ returnType);
+ }
+ } catch (final IllegalAccessException e) {
+ LOG.warn(
+ "Class {} does not conform to Binding Specification v1. Falling back to NULL_EXTRACTOR",
+ e);
+ }
+ return NULL_EXTRACTOR;
+ }
+
+ private Method getContextGetter(final Class<?> key) {
+ for (final Method method : key.getMethods()) {
+ if (method.getAnnotation(RoutingContext.class) != null) {
+ return method;
+ }
+ }
+ return null;
+ }
});
* @return Instance Identifier representing context reference
* or null, if data object does not contain context reference.
*/
- abstract @Nullable InstanceIdentifier<?> extract(DataObject obj);
-
- @Nonnull
- private static ContextReferenceExtractor create(final Class<?> key) {
- final Method contextGetter = getContextGetter(key);
- if (contextGetter == null) {
- return NULL_EXTRACTOR;
- }
- final Class<?> returnType = contextGetter.getReturnType();
- try {
- if (InstanceIdentifier.class.isAssignableFrom(returnType)) {
- return DirectGetterRouteContextExtractor.create(contextGetter);
- }
- final Method getValueMethod = findGetValueMethod(returnType,InstanceIdentifier.class);
- if (getValueMethod != null) {
- return GetValueRouteContextExtractor.create(contextGetter, getValueMethod);
- } else {
- LOG.warn("Class {} can not be used to determine context, falling back to NULL_EXTRACTOR.",returnType);
- }
- } catch (final IllegalAccessException e) {
- LOG.warn("Class {} does not conform to Binding Specification v1. Falling back to NULL_EXTRACTOR", e);
- }
- return NULL_EXTRACTOR;
- }
+ @Nullable
+ abstract InstanceIdentifier<?> extract(DataObject obj);
@Nullable
private static Method findGetValueMethod(final Class<?> type, final Class<?> returnType) {
}
return null;
}
-
- private static Method getContextGetter(final Class<?> key) {
- for (final Method method : key.getMethods()) {
- if (method.getAnnotation(RoutingContext.class) != null) {
- return method;
- }
- }
- return null;
- }
-
-
-
}
class FutureSchema implements AutoCloseable {
private final List<FutureSchemaPredicate> postponedOperations = new CopyOnWriteArrayList<>();
+ private final SettableFuture<?> schemaPromise = SettableFuture.create();
private final long duration;
private final TimeUnit unit;
final void cancel() {
schemaPromise.cancel(true);
}
-
- private final SettableFuture<?> schemaPromise = SettableFuture.create();
}
}
proxy = (RpcService) Proxy.newProxyInstance(type.getClassLoader(), new Class[] {type}, this);
}
- private ListenableFuture<RpcResult<?>> invoke0(final SchemaPath schemaPath, final NormalizedNode<?, ?> input) {
- final CheckedFuture<DOMRpcResult, DOMRpcException> result = delegate.invokeRpc(schemaPath, input);
- if (result instanceof LazyDOMRpcResultFuture) {
- return ((LazyDOMRpcResultFuture) result).getBindingFuture();
- }
-
- return transformFuture(schemaPath, result, codec.getCodecFactory());
- }
-
private RpcInvocationStrategy createStrategy(final Method method, final RpcDefinition schema) {
final RpcRoutingStrategy strategy = RpcRoutingStrategy.from(schema);
if (strategy.isContextBasedRouted()) {
private static boolean isObjectMethod(final Method method) {
switch (method.getName()) {
case "toString":
- return (method.getReturnType().equals(String.class) && method.getParameterTypes().length == 0);
+ return method.getReturnType().equals(String.class) && method.getParameterTypes().length == 0;
case "hashCode":
- return (method.getReturnType().equals(int.class) && method.getParameterTypes().length == 0);
+ return method.getReturnType().equals(int.class) && method.getParameterTypes().length == 0;
case "equals":
- return (method.getReturnType().equals(boolean.class) && method.getParameterTypes().length == 1 && method
- .getParameterTypes()[0] == Object.class);
+ return method.getReturnType().equals(boolean.class) && method.getParameterTypes().length == 1
+ && method.getParameterTypes()[0] == Object.class;
default:
return false;
}
case "hashCode":
return System.identityHashCode(self);
case "equals":
- return (self == args[0]);
+ return self == args[0];
default:
return null;
}
}
- private static ListenableFuture<RpcResult<?>> transformFuture(final SchemaPath rpc,
- final ListenableFuture<DOMRpcResult> domFuture, final BindingNormalizedNodeCodecRegistry codec) {
- return Futures.transform(domFuture, new Function<DOMRpcResult, RpcResult<?>>() {
- @Override
- public RpcResult<?> apply(final DOMRpcResult input) {
- final NormalizedNode<?, ?> domData = input.getResult();
- final DataObject bindingResult;
- if (domData != null) {
- final SchemaPath rpcOutput = rpc.createChild(QName.create(rpc.getLastComponent(), "output"));
- bindingResult = codec.fromNormalizedNodeRpcData(rpcOutput, (ContainerNode) domData);
- } else {
- bindingResult = null;
- }
- return RpcResult.class.cast(RpcResultBuilder.success(bindingResult).build());
- }
- });
- }
-
private abstract class RpcInvocationStrategy {
private final SchemaPath rpcName;
return rpcName;
}
+ private ListenableFuture<RpcResult<?>> invoke0(final SchemaPath schemaPath, final NormalizedNode<?, ?> input) {
+ final CheckedFuture<DOMRpcResult, DOMRpcException> result = delegate.invokeRpc(schemaPath, input);
+ if (result instanceof LazyDOMRpcResultFuture) {
+ return ((LazyDOMRpcResultFuture) result).getBindingFuture();
+ }
+
+ return transformFuture(schemaPath, result, codec.getCodecFactory());
+ }
+
+ private ListenableFuture<RpcResult<?>> transformFuture(final SchemaPath rpc,
+ final ListenableFuture<DOMRpcResult> domFuture, final BindingNormalizedNodeCodecRegistry codec) {
+ return Futures.transform(domFuture, (Function<DOMRpcResult, RpcResult<?>>) input -> {
+ final NormalizedNode<?, ?> domData = input.getResult();
+ final DataObject bindingResult;
+ if (domData != null) {
+ final SchemaPath rpcOutput = rpc.createChild(QName.create(rpc.getLastComponent(), "output"));
+ bindingResult = codec.fromNormalizedNodeRpcData(rpcOutput, (ContainerNode) domData);
+ } else {
+ bindingResult = null;
+ }
+ return RpcResult.class.cast(RpcResultBuilder.success(bindingResult).build());
+ });
+ }
+
}
private final class NonRoutedStrategy extends RpcInvocationStrategy {