jdk/test/sample/chatserver/ChatTest.java
author ksrini
Tue, 16 Oct 2012 10:56:25 -0700
changeset 16078 3d5fa54bf734
parent 9254 142881732d3c
child 25859 3317bb8137f4
permissions -rw-r--r--
7200500: Launcher better input validation Reviewed-by: darcy, jjh, mschoene
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9254
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
     1
/*
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
     2
 * Copyright (c) 2011 Oracle and/or its affiliates. All rights reserved.
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
     4
 *
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
     7
 * published by the Free Software Foundation.
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
     8
 *
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    13
 * accompanied this code).
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    14
 *
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    18
 *
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    21
 * questions.
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    22
 */
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    23
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    24
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    25
/* @test
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    26
 * @summary Test chat server chatserver test
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    27
 *
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    28
 * @library ../../../src/share/sample/nio/chatserver
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    29
 * @build ChatTest ChatServer Client ClientReader DataReader MessageReader NameReader
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    30
 * @run main ChatTest
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    31
 */
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    32
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    33
import java.io.*;
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    34
import java.net.InetSocketAddress;
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    35
import java.net.Socket;
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    36
import java.util.ArrayList;
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    37
import java.util.Collections;
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    38
import java.util.List;
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    39
import java.util.concurrent.CyclicBarrier;
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    40
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    41
public class ChatTest {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    42
    public static int listeningPort = 0;
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    43
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    44
    public static void main(String[] args) throws Throwable {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    45
        testStartStop();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    46
        testPortOpen();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    47
        testAsksForName();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    48
        testUseName();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    49
        testConnectDisconnectConnect();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    50
        testUsernameAndMessage();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    51
        testDontReceiveMessageInNameState();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    52
    }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    53
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    54
    private static ChatServer startServer() throws IOException {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    55
        ChatServer server = new ChatServer(0);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    56
        InetSocketAddress address = (InetSocketAddress) server.getSocketAddress();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    57
        listeningPort = address.getPort();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    58
        server.run();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    59
        return server;
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    60
    }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    61
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    62
    public static void testStartStop() throws Exception {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    63
        ChatServer server = startServer();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    64
        server.shutdown();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    65
    }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    66
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    67
    public static void testPortOpen() throws Exception {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    68
        ChatServer server = startServer();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    69
        try {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    70
            Socket socket = new Socket("localhost", listeningPort);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    71
            if (!socket.isConnected()) {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    72
                throw new RuntimeException("Failed to connect to server: port not open");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    73
            }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    74
        } finally {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    75
            server.shutdown();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    76
        }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    77
    }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    78
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    79
    public static void testAsksForName() throws Exception {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    80
        ChatServer server = startServer();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    81
        try {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    82
            Socket socket = new Socket("localhost", listeningPort);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    83
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    84
            Reader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    85
            String string = readAvailableString(reader);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    86
            if (!string.equals("Name: ")) {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    87
                throw new RuntimeException("Server doesn't send Name: ");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    88
            }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    89
        } finally {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    90
            server.shutdown();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    91
        }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    92
    }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    93
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    94
    public static void testUseName() throws Throwable {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    95
        ChatServer server = startServer();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    96
        try {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    97
            performTestUseName();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    98
        } finally {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
    99
            server.shutdown();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   100
        }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   101
    }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   102
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   103
    public static void testConnectDisconnectConnect() throws Exception {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   104
        ChatServer server = startServer();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   105
        try {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   106
            performTestConnectDisconnectConnect();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   107
        } finally {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   108
            server.shutdown();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   109
        }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   110
    }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   111
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   112
    public static void testUsernameAndMessage() throws Exception {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   113
        ChatServer server = startServer();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   114
        try {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   115
            performTestUsernameAndMessage();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   116
        } finally {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   117
            server.shutdown();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   118
        }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   119
    }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   120
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   121
    public static void testDontReceiveMessageInNameState() throws Exception {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   122
        ChatServer server = startServer();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   123
        try {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   124
            performDontReceiveMessageInNameState();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   125
        } finally {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   126
            server.shutdown();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   127
        }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   128
    }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   129
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   130
    private static void assertEqual(List<Exception> exception, Object value, Object expected) {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   131
        if (expected == value) {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   132
            return;
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   133
        }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   134
        if (expected == null) {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   135
            exception.add(new RuntimeException("Expected null, but was: " + value));
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   136
            return;
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   137
        }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   138
        if (!expected.equals(value)) {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   139
            exception.add(new RuntimeException("Expected: " + expected + " but was: " + value));
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   140
            return;
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   141
        }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   142
    }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   143
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   144
    private static void performDontReceiveMessageInNameState() throws Exception {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   145
        final CyclicBarrier barrier1 = new CyclicBarrier(2);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   146
        final CyclicBarrier barrier2 = new CyclicBarrier(2);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   147
        final CyclicBarrier barrier3 = new CyclicBarrier(2);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   148
        final List<Exception> exceptions = Collections.synchronizedList(new ArrayList<Exception>());
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   149
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   150
        ChatConnection chatConnection = new ChatConnection() {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   151
            @Override
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   152
            public void run(Socket socket, BufferedReader reader, Writer writer) throws Exception {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   153
                String string = readAvailableString(reader);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   154
                assertEqual(exceptions, string, "Name: ");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   155
                writer.write("testClient1\n");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   156
                waitForJoin(reader, "testClient1");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   157
                barrier1.await();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   158
                writer.write("Ignore this!\n");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   159
                barrier2.await();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   160
                barrier3.await();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   161
            }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   162
        };
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   163
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   164
        Thread client2 = new Thread(new ChatConnection() {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   165
            @Override
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   166
            public void run(Socket socket, BufferedReader reader, Writer writer) throws Exception {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   167
                barrier1.await();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   168
                barrier2.await();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   169
                String string = readAvailableString(reader);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   170
                assertEqual(exceptions, string, "Name: ");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   171
                string = readAvailableString(reader, true);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   172
                assertEqual(exceptions, string, null);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   173
                writer.write("testClient2\n");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   174
                barrier3.await();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   175
            }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   176
        });
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   177
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   178
        client2.start();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   179
        chatConnection.run();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   180
        if (!exceptions.isEmpty()) {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   181
            throw exceptions.get(0);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   182
        }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   183
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   184
    }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   185
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   186
    private static void waitForJoin(BufferedReader reader, String s) throws IOException {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   187
        String joined;
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   188
        do {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   189
            joined = readAvailableString(reader);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   190
        } while (!(joined != null && joined.contains("Welcome " + s)));
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   191
    }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   192
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   193
    private static void performTestUsernameAndMessage() throws Exception {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   194
        final CyclicBarrier barrier1 = new CyclicBarrier(2);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   195
        final CyclicBarrier barrier2 = new CyclicBarrier(2);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   196
        final CyclicBarrier barrier3 = new CyclicBarrier(2);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   197
        final List<Exception> exceptions = Collections.synchronizedList(new ArrayList<Exception>());
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   198
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   199
        ChatConnection chatConnection = new ChatConnection() {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   200
            @Override
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   201
            public void run(Socket socket, BufferedReader reader, Writer writer) throws Exception {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   202
                String string = readAvailableString(reader);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   203
                assertEqual(exceptions, string, "Name: ");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   204
                writer.write("testClient1\n");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   205
                waitForJoin(reader, "testClient1");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   206
                barrier1.await();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   207
                barrier2.await();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   208
                string = readAvailableString(reader);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   209
                assertEqual(exceptions, string, "testClient2: Hello world!\n");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   210
                barrier3.await();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   211
            }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   212
        };
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   213
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   214
        Thread client2 = new Thread(new ChatConnection() {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   215
            @Override
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   216
            public void run(Socket socket, BufferedReader reader, Writer writer) throws Exception {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   217
                String string = readAvailableString(reader);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   218
                assertEqual(exceptions, string, "Name: ");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   219
                barrier1.await();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   220
                writer.write("testClient2\nHello world!\n");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   221
                barrier2.await();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   222
                barrier3.await();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   223
            }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   224
        });
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   225
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   226
        client2.start();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   227
        chatConnection.run();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   228
        if (!exceptions.isEmpty()) {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   229
            throw exceptions.get(0);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   230
        }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   231
    }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   232
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   233
    private static void performTestConnectDisconnectConnect() throws Exception {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   234
        final CyclicBarrier barrier1 = new CyclicBarrier(2);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   235
        final CyclicBarrier barrier2 = new CyclicBarrier(2);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   236
        final CyclicBarrier barrier3 = new CyclicBarrier(2);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   237
        final List<Exception> exceptions = new ArrayList<Exception>();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   238
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   239
        ChatConnection chatConnection = new ChatConnection() {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   240
            @Override
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   241
            public void run(Socket socket, BufferedReader reader, Writer writer) throws Exception {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   242
                String string = readAvailableString(reader);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   243
                assertEqual(exceptions, string, "Name: ");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   244
                writer.write("testClient1\n");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   245
            }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   246
        };
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   247
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   248
        ChatConnection chatConnection2 = new ChatConnection() {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   249
            @Override
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   250
            public void run(Socket socket, BufferedReader reader, Writer writer) throws Exception {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   251
                readAvailableString(reader);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   252
                writer.write("testClient1\n");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   253
                waitForJoin(reader, "testClient1");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   254
                barrier1.await();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   255
                writer.write("Good morning!\n");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   256
                barrier2.await();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   257
                String string = readAvailableString(reader);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   258
                assertEqual(exceptions, string, "testClient2: Hello world!\n");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   259
                barrier3.await();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   260
            }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   261
        };
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   262
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   263
        Thread client2 = new Thread(new ChatConnection() {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   264
            @Override
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   265
            public void run(Socket socket, BufferedReader reader, Writer writer) throws Exception {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   266
                readAvailableString(reader);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   267
                writer.write("testClient2\n");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   268
                waitForJoin(reader, "testClient2");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   269
                barrier1.await();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   270
                writer.write("Hello world!\n");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   271
                barrier2.await();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   272
                String string = readAvailableString(reader);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   273
                assertEqual(exceptions, string, "testClient1: Good morning!\n");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   274
                barrier3.await();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   275
            }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   276
        });
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   277
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   278
        client2.start();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   279
        chatConnection.run();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   280
        chatConnection2.run();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   281
        if (!exceptions.isEmpty()) {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   282
            throw exceptions.get(0);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   283
        }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   284
    }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   285
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   286
    private static void performTestUseName() throws Exception {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   287
        final CyclicBarrier barrier1 = new CyclicBarrier(2);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   288
        final CyclicBarrier barrier2 = new CyclicBarrier(2);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   289
        final CyclicBarrier barrier3 = new CyclicBarrier(2);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   290
        final List<Exception> exceptions = new ArrayList<Exception>();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   291
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   292
        ChatConnection chatConnection = new ChatConnection() {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   293
            @Override
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   294
            public void run(Socket socket, BufferedReader reader, Writer writer) throws Exception {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   295
                String string = readAvailableString(reader);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   296
                if (!"Name: ".equals(string)) {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   297
                    exceptions.add(new RuntimeException("Expected Name: "));
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   298
                }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   299
                writer.write("testClient1\n");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   300
                waitForJoin(reader, "testClient1");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   301
                barrier1.await();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   302
                barrier2.await();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   303
                string = readAvailableString(reader);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   304
                if (!"testClient2: Hello world!\n".equals(string)) {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   305
                    exceptions.add(new RuntimeException("testClient2: Hello world!\n"));
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   306
                }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   307
                barrier3.await();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   308
            }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   309
        };
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   310
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   311
        Thread client2 = new Thread(new ChatConnection() {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   312
            @Override
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   313
            public void run(Socket socket, BufferedReader reader, Writer writer) throws Exception {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   314
                String string = readAvailableString(reader);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   315
                if (!"Name: ".equals(string)) {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   316
                    exceptions.add(new RuntimeException("Expected Name: "));
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   317
                }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   318
                writer.write("testClient2\n");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   319
                waitForJoin(reader, "testClient2");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   320
                barrier1.await();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   321
                writer.write("Hello world!\n");
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   322
                barrier2.await();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   323
                barrier3.await();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   324
            }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   325
        });
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   326
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   327
        client2.start();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   328
        chatConnection.run();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   329
        if (!exceptions.isEmpty()) {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   330
            throw exceptions.get(0);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   331
        }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   332
    }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   333
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   334
    private static String readAvailableString(Reader reader) throws IOException {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   335
        return readAvailableString(reader, false);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   336
    }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   337
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   338
    private static String readAvailableString(Reader reader, boolean now) throws IOException {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   339
        StringBuilder builder = new StringBuilder();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   340
        int bytes;
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   341
        if (now && !reader.ready()) {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   342
            return null;
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   343
        }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   344
        do {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   345
            char[] buf = new char[256];
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   346
            bytes = reader.read(buf);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   347
            builder.append(buf, 0, bytes);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   348
        } while (bytes == 256);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   349
        return builder.toString();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   350
    }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   351
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   352
    private abstract static class ChatConnection implements Runnable {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   353
        public Exception exception;
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   354
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   355
        @Override
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   356
        public void run() {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   357
            try (Socket socket = new Socket("localhost", listeningPort);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   358
            BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   359
            Writer writer = new FlushingWriter(new OutputStreamWriter(socket.getOutputStream()))) {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   360
                socket.setTcpNoDelay(true);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   361
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   362
                run(socket, reader, writer);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   363
            } catch (Exception e) {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   364
                exception = e;
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   365
            }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   366
        }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   367
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   368
        public abstract void run(Socket socket, BufferedReader reader, Writer writer) throws Exception;
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   369
    }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   370
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   371
    private static class FlushingWriter extends Writer {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   372
        public final Writer delegate;
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   373
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   374
        private FlushingWriter(Writer delegate) {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   375
            this.delegate = delegate;
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   376
        }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   377
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   378
        @Override
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   379
        public void write(char[] cbuf, int off, int len) throws IOException {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   380
            delegate.write(cbuf, off, len);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   381
        }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   382
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   383
        @Override
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   384
        public void flush() throws IOException {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   385
            delegate.flush();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   386
        }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   387
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   388
        @Override
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   389
        public void close() throws IOException {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   390
            delegate.close();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   391
        }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   392
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   393
        @Override
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   394
        public void write(String str) throws IOException {
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   395
            super.write(str);
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   396
            flush();
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   397
        }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   398
    }
142881732d3c 7026287: Asynchronous API sample
rbackman
parents:
diff changeset
   399
}