jvpp: adding callbacks for all messages (VPP-914)
[vpp.git] / src / vpp-api / java / jvpp-core / io / fd / vpp / jvpp / core / examples / FutureApiNotificationExample.java
index 7460401..3c84fd7 100644 (file)
@@ -24,6 +24,9 @@ import io.fd.vpp.jvpp.JVppRegistry;
 import io.fd.vpp.jvpp.JVppRegistryImpl;
 import io.fd.vpp.jvpp.core.JVppCoreImpl;
 import io.fd.vpp.jvpp.core.future.FutureJVppCoreFacade;
+import io.fd.vpp.jvpp.core.callback.SwInterfaceEventCallback;
+import io.fd.vpp.jvpp.core.dto.SwInterfaceEvent;
+import io.fd.vpp.jvpp.VppCallbackException;
 
 public class FutureApiNotificationExample {
 
@@ -32,8 +35,17 @@ public class FutureApiNotificationExample {
         try (final JVppRegistry registry = new JVppRegistryImpl("FutureApiNotificationExample");
              final FutureJVppCoreFacade jvppFacade = new FutureJVppCoreFacade(registry, new JVppCoreImpl());
              final AutoCloseable notificationListenerReg =
-                 jvppFacade.getNotificationRegistry()
-                     .registerSwInterfaceEventNotificationCallback(NotificationUtils::printNotification)) {
+                 jvppFacade.getEventRegistry()
+                     .registerSwInterfaceEventCallback(new SwInterfaceEventCallback() {
+                         public void onSwInterfaceEvent(SwInterfaceEvent reply) {
+                             System.out.printf("Received interface notification: ifc: %s%n", reply);
+                         }
+
+                         public void onError (VppCallbackException ex) {
+                             System.out.printf("Received onError exception: call=%s, context=%d, retval=%d%n",
+                                     ex.getMethodName(), ex.getCtxId(), ex.getErrorCode());
+                         }
+                     })) {
             System.out.println("Successfully connected to VPP");
             jvppFacade.wantInterfaceEvents(getEnableInterfaceNotificationsReq()).toCompletableFuture().get();
             System.out.println("Interface events started");