Search in sources :

Example 1 with SchemaPath

use of org.opendaylight.yangtools.yang.model.api.SchemaPath in project controller by opendaylight.

the class NormalizedNodeStreamReaderWriterTest method testSchemaPathSerialization.

@Test
public void testSchemaPathSerialization() throws Exception {
    final SchemaPath expected = SchemaPath.create(true, TestModel.ANY_XML_QNAME);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(ByteStreams.newDataOutput(bos));
    nnout.writeSchemaPath(expected);
    NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bos.toByteArray()));
    SchemaPath actual = nnin.readSchemaPath();
    assertEquals(expected, actual);
}
Also used : SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 2 with SchemaPath

use of org.opendaylight.yangtools.yang.model.api.SchemaPath in project controller by opendaylight.

the class RpcUtil method decomposeRpcService.

static Collection<SchemaPath> decomposeRpcService(final Class<RpcService> service, final SchemaContext schemaContext, final Predicate<RpcRoutingStrategy> filter) {
    final QNameModule moduleName = BindingReflections.getQNameModule(service);
    final Module module = schemaContext.findModule(moduleName).get();
    LOG.debug("Resolved service {} to module {}", service, module);
    final Collection<RpcDefinition> rpcs = module.getRpcs();
    final Collection<SchemaPath> ret = new ArrayList<>(rpcs.size());
    for (RpcDefinition rpc : rpcs) {
        final RpcRoutingStrategy strategy = RpcRoutingStrategy.from(rpc);
        if (filter.test(strategy)) {
            ret.add(rpc.getPath());
        }
    }
    return ret;
}
Also used : RpcRoutingStrategy(org.opendaylight.controller.md.sal.dom.broker.spi.rpc.RpcRoutingStrategy) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) ArrayList(java.util.ArrayList) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Module(org.opendaylight.yangtools.yang.model.api.Module) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule)

Example 3 with SchemaPath

use of org.opendaylight.yangtools.yang.model.api.SchemaPath in project controller by opendaylight.

the class HeliumNotificationProviderServiceWithInterestListeners method registerNotificationListener.

@Override
public <T extends Notification> ListenerRegistration<NotificationListener<T>> registerNotificationListener(final Class<T> type, final NotificationListener<T> listener) {
    final FunctionalNotificationListenerAdapter<T> adapter = new FunctionalNotificationListenerAdapter<>(codec, type, listener);
    final SchemaPath domType = SchemaPath.create(true, BindingReflections.findQName(type));
    final ListenerRegistration<?> domReg = domService.registerNotificationListener(adapter, domType);
    return new AbstractListenerRegistration<NotificationListener<T>>(listener) {

        @Override
        protected void removeRegistration() {
            domReg.close();
        }
    };
}
Also used : AbstractListenerRegistration(org.opendaylight.yangtools.concepts.AbstractListenerRegistration) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath)

Example 4 with SchemaPath

use of org.opendaylight.yangtools.yang.model.api.SchemaPath in project controller by opendaylight.

the class BindingDOMNotificationListenerAdapter method createInvokerMapFor.

public static Map<SchemaPath, NotificationListenerInvoker> createInvokerMapFor(final Class<? extends NotificationListener> implClz) {
    final Map<SchemaPath, NotificationListenerInvoker> builder = new HashMap<>();
    for (final TypeToken<?> ifaceToken : TypeToken.of(implClz).getTypes().interfaces()) {
        Class<?> iface = ifaceToken.getRawType();
        if (NotificationListener.class.isAssignableFrom(iface) && BindingReflections.isBindingClass(iface)) {
            @SuppressWarnings("unchecked") final Class<? extends NotificationListener> listenerType = (Class<? extends NotificationListener>) iface;
            final NotificationListenerInvoker invoker = NotificationListenerInvoker.from(listenerType);
            for (final SchemaPath path : getNotificationTypes(listenerType)) {
                builder.put(path, invoker);
            }
        }
    }
    return ImmutableMap.copyOf(builder);
}
Also used : SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) HashMap(java.util.HashMap) NotificationListenerInvoker(org.opendaylight.yangtools.yang.binding.util.NotificationListenerInvoker) DOMNotificationListener(org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener) NotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener)

Example 5 with SchemaPath

use of org.opendaylight.yangtools.yang.model.api.SchemaPath in project controller by opendaylight.

the class BindingDOMNotificationListenerAdapter method getNotificationTypes.

private static Set<SchemaPath> getNotificationTypes(final Class<? extends NotificationListener> type) {
    // TODO: Investigate possibility and performance impact if we cache this or expose
    // it from NotificationListenerInvoker
    final Set<SchemaPath> ret = new HashSet<>();
    for (final Method method : type.getMethods()) {
        if (BindingReflections.isNotificationCallback(method)) {
            final Class<?> notification = method.getParameterTypes()[0];
            final QName name = BindingReflections.findQName(notification);
            ret.add(SchemaPath.create(true, name));
        }
    }
    return ret;
}
Also used : SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) QName(org.opendaylight.yangtools.yang.common.QName) Method(java.lang.reflect.Method) HashSet(java.util.HashSet)

Aggregations

SchemaPath (org.opendaylight.yangtools.yang.model.api.SchemaPath)15 DOMRpcResult (org.opendaylight.controller.md.sal.dom.api.DOMRpcResult)4 Method (java.lang.reflect.Method)3 Test (org.junit.Test)3 QName (org.opendaylight.yangtools.yang.common.QName)3 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)3 RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 DOMNotificationListener (org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener)2 DOMRpcException (org.opendaylight.controller.md.sal.dom.api.DOMRpcException)2 DOMRpcService (org.opendaylight.controller.md.sal.dom.api.DOMRpcService)2 RpcRoutingStrategy (org.opendaylight.controller.md.sal.dom.broker.spi.rpc.RpcRoutingStrategy)2 AbstractListenerRegistration (org.opendaylight.yangtools.concepts.AbstractListenerRegistration)2 DataObject (org.opendaylight.yangtools.yang.binding.DataObject)2 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)2 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)2 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)2 ActorRef (akka.actor.ActorRef)1 Preconditions (com.google.common.base.Preconditions)1