Move java,lua api and remaining plugins to src/
[vpp.git] / src / vpp-api / java / jvpp-core / io / fd / vpp / jvpp / core / test / FutureApiNotificationTest.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package io.fd.vpp.jvpp.core.test;
18
19 import static io.fd.vpp.jvpp.core.test.NotificationUtils.getChangeInterfaceState;
20 import static io.fd.vpp.jvpp.core.test.NotificationUtils.getDisableInterfaceNotificationsReq;
21 import static io.fd.vpp.jvpp.core.test.NotificationUtils.getEnableInterfaceNotificationsReq;
22
23 import io.fd.vpp.jvpp.JVppRegistry;
24 import io.fd.vpp.jvpp.JVppRegistryImpl;
25 import io.fd.vpp.jvpp.core.JVppCoreImpl;
26 import io.fd.vpp.jvpp.core.future.FutureJVppCoreFacade;
27
28 public class FutureApiNotificationTest {
29
30     private static void testFutureApi() throws Exception {
31         System.out.println("Testing Java future API for notifications");
32         try (final JVppRegistry registry = new JVppRegistryImpl("FutureApiNotificationTest");
33              final FutureJVppCoreFacade jvppFacade = new FutureJVppCoreFacade(registry, new JVppCoreImpl());
34              final AutoCloseable notificationListenerReg =
35                  jvppFacade.getNotificationRegistry()
36                      .registerSwInterfaceSetFlagsNotificationCallback(NotificationUtils::printNotification)) {
37             System.out.println("Successfully connected to VPP");
38             jvppFacade.wantInterfaceEvents(getEnableInterfaceNotificationsReq()).toCompletableFuture().get();
39             System.out.println("Interface events started");
40
41             System.out.println("Changing interface configuration");
42             jvppFacade.swInterfaceSetFlags(getChangeInterfaceState()).toCompletableFuture().get();
43
44             Thread.sleep(1000);
45
46             jvppFacade.wantInterfaceEvents(getDisableInterfaceNotificationsReq()).toCompletableFuture().get();
47             System.out.println("Interface events stopped");
48             System.out.println("Disconnecting...");
49         }
50     }
51
52     public static void main(String[] args) throws Exception {
53         testFutureApi();
54     }
55 }