mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Matthew Swift
09.53.2012 885865ed67c24feb9535d04392d195da8ca174fd
Wait for cancelation result before closing the connection and exiting.

1 files modified
12 ■■■■■ changed files
opendj3/opendj-ldap-sdk-examples/src/main/java/org/forgerock/opendj/examples/SearchAsync.java 12 ●●●●● patch | view | raw | blame | history
opendj3/opendj-ldap-sdk-examples/src/main/java/org/forgerock/opendj/examples/SearchAsync.java
@@ -178,6 +178,7 @@
    }
    private static final CountDownLatch COMPLETION_LATCH = new CountDownLatch(1);
    private static final CountDownLatch CANCEL_LATCH = new CountDownLatch(1);
    private static final LDIFEntryWriter WRITER = new LDIFEntryWriter(System.out);
    private static String userName;
    private static String password;
@@ -197,11 +198,13 @@
        public void handleErrorResult(final ErrorResultException error) {
            System.err.println("Cancel request failed with result code: "
                    + error.getResult().getResultCode().intValue());
            CANCEL_LATCH.countDown();
        }
        @Override
        public void handleResult(final ExtendedResult result) {
            System.err.println("Cancel request succeeded");
            CANCEL_LATCH.countDown();
        }
    }
@@ -270,6 +273,15 @@
            return;
        }
        // Await completion of the cancel request.
        try {
            CANCEL_LATCH.await();
        } catch (final InterruptedException e) {
            System.err.println(e.getMessage());
            System.exit(ResultCode.CLIENT_SIDE_USER_CANCELLED.intValue());
            return;
        }
        if (connection != null) {
            connection.close();
        }