VPP-330 Track pending map-requests with a fifo
[vpp.git] / vpp-api / java / jvpp / org / openvpp / jvpp / 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 org.openvpp.jvpp.test;
18
19 import static org.openvpp.jvpp.test.NotificationUtils.getChangeInterfaceState;
20 import static org.openvpp.jvpp.test.NotificationUtils.getDisableInterfaceNotificationsReq;
21 import static org.openvpp.jvpp.test.NotificationUtils.getEnableInterfaceNotificationsReq;
22
23 import org.openvpp.jvpp.VppJNIConnection;
24 import org.openvpp.jvpp.future.FutureJVppFacade;
25
26 public class FutureApiNotificationTest {
27
28     private static void testFutureApi() throws Exception {
29         System.out.println("Testing Java future API for notifications");
30
31         final org.openvpp.jvpp.JVppImpl impl =
32                 new org.openvpp.jvpp.JVppImpl(new VppJNIConnection("FutureApiTest"));
33         final FutureJVppFacade jvppFacade = new FutureJVppFacade(impl);
34         System.out.println("Successfully connected to VPP");
35
36         final AutoCloseable notificationListenerReg =
37             jvppFacade.getNotificationRegistry().registerSwInterfaceSetFlagsNotificationCallback(NotificationUtils::printNotification);
38
39         jvppFacade.wantInterfaceEvents(getEnableInterfaceNotificationsReq()).toCompletableFuture().get();
40         System.out.println("Interface events started");
41
42         System.out.println("Changing interface configuration");
43         jvppFacade.swInterfaceSetFlags(getChangeInterfaceState()).toCompletableFuture().get();
44
45         Thread.sleep(1000);
46
47         jvppFacade.wantInterfaceEvents(getDisableInterfaceNotificationsReq()).toCompletableFuture().get();
48         System.out.println("Interface events stopped");
49
50         notificationListenerReg.close();
51
52         System.out.println("Disconnecting...");
53         // TODO we should consider adding jvpp.close(); to the facade
54         impl.close();
55     }
56
57     public static void main(String[] args) throws Exception {
58         testFutureApi();
59     }
60 }