// Path: src/main/java/bbejeck/nio/channels/AsyncServerTestModule.java
// public class AsyncServerTestModule extends AbstractModule {
// 
//     @Override
//     protected void configure() {
//         bind(AsyncServerSocket.class);
//     }
// }
// 
// Path: src/main/java/bbejeck/nio/sockets/PlainServerSocket.java
// public class PlainServerSocket {
// 
//     private ExecutorService executorService;
//     private java.net.ServerSocket server;
//     private int port;
//     private String host;
// 
// 
//     @Inject
//     public PlainServerSocket(@Port int port, @Host String host) {
//         this.port = port;
//         this.host = host;
//     }
// 
// 
//     public void startServer() {
//         try {
//             initServerSocket();
//             this.executorService = Executors.newCachedThreadPool();
//             while (!executorService.isShutdown()) {
//                 Socket socket = server.accept();
//                 executorService.submit(handleSocketRequest(socket));
//             }
//         } catch (Exception e) {
//             if (!executorService.isShutdown()) {
//                 e.printStackTrace();
//             }
//         }
//     }
// 
//     private Callable<Void> handleSocketRequest(final Socket socket) {
//         return new Callable<Void>() {
//             @Override
//             public Void call() throws Exception {
//                 BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
//                 CharBuffer charBuffer = CharBuffer.allocate(1000);
//                 reader.read(charBuffer);
//                 charBuffer.flip();
//                 StringBuilder builder = new StringBuilder("You Said >> \"");
//                 String message = charBuffer.toString();
// //                System.out.println("Plain Socket Message[" + message + "] received @" + new Date());
//                 builder.append(message).append("\"");
//                 BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
//                 bufferedWriter.write(builder.toString());
//                 bufferedWriter.flush();
//                 if (message.equalsIgnoreCase("quit")) {
//                     stopServer();
//                 }
//                 reader.close();
//                 bufferedWriter.close();
//                 socket.close();
//                 return null;
//             }
//         };
//     }
// 
//     public void stopServer() throws Exception {
//         executorService.shutdownNow();
//         server.close();
//     }
// 
// 
//     private void initServerSocket() throws Exception {
//         server = new ServerSocket(port);
//     }
// 
// }
// 
// Path: src/main/java/bbejeck/nio/sockets/PlainSocketMessageSender.java
// public class PlainSocketMessageSender {
// 
//     private Socket socket;
//     private int port;
//     private InetSocketAddress socketAddress;
//     private int messageCount;
// 
//     @Inject
//     public PlainSocketMessageSender(@Port int port, @MessageCount int messageCount, @Host String host) {
//         this.port = port;
//         socketAddress = new InetSocketAddress(host, port);
//         this.messageCount = messageCount;
//     }
// 
//     public void sendMessages() throws Exception {
//         for (int i = 0; i < messageCount; i++) {
//             sendTextMessage("Plain text message from socket");
//         }
//         sendTextMessage("quit");
//     }
// 
//     private void sendTextMessage(String message) throws Exception {
//         socket = new Socket();
//         socket.connect(socketAddress);
//         BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
//         bufferedWriter.write(message);
//         bufferedWriter.flush();
//         BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
//         CharBuffer charBuffer = CharBuffer.allocate(1000);
//         reader.read(charBuffer);
//         charBuffer.flip();
// //        System.out.println("Reply from server "+charBuffer.toString());
//         reader.close();
//         bufferedWriter.close();
//         socket.close();
//     }
// }
// 
// Path: src/main/java/bbejeck/nio/sockets/PlainSocketModule.java
// public class PlainSocketModule extends AbstractModule {
// 
//     @Override
//     protected void configure() {
//         bind(PlainServerSocket.class);
//         bind(PlainSocketMessageSender.class);
//     }
// }


import bbejeck.nio.channels.AsyncServerTestModule;
import bbejeck.nio.sockets.PlainServerSocket;
import bbejeck.nio.sockets.PlainSocketMessageSender;
import bbejeck.nio.sockets.PlainSocketModule;
import com.google.common.base.Stopwatch;
import com.google.inject.Guice;
import com.google.inject.Injector;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
package bbejeck.nio;




/**
 * Created by IntelliJ IDEA.
 * User: bbejeck
 * Date: 3/14/12
 * Time: 9:48 PM
 */
public class PlainSocketTestDriver {


    public static void main(String[] args) throws Exception {
        Injector injector = Guice.createInjector(new SocketModule(), new PlainSocketModule(), new AsyncServerTestModule());
// Path: src/main/java/bbejeck/nio/channels/AsyncServerTestModule.java
// public class AsyncServerTestModule extends AbstractModule {
// 
//     @Override
//     protected void configure() {
//         bind(AsyncServerSocket.class);
//     }
// }
// 
// Path: src/main/java/bbejeck/nio/sockets/PlainServerSocket.java
// public class PlainServerSocket {
// 
//     private ExecutorService executorService;
//     private java.net.ServerSocket server;
//     private int port;
//     private String host;
// 
// 
//     @Inject
//     public PlainServerSocket(@Port int port, @Host String host) {
//         this.port = port;
//         this.host = host;
//     }
// 
// 
//     public void startServer() {
//         try {
//             initServerSocket();
//             this.executorService = Executors.newCachedThreadPool();
//             while (!executorService.isShutdown()) {
//                 Socket socket = server.accept();
//                 executorService.submit(handleSocketRequest(socket));
//             }
//         } catch (Exception e) {
//             if (!executorService.isShutdown()) {
//                 e.printStackTrace();
//             }
//         }
//     }
// 
//     private Callable<Void> handleSocketRequest(final Socket socket) {
//         return new Callable<Void>() {
//             @Override
//             public Void call() throws Exception {
//                 BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
//                 CharBuffer charBuffer = CharBuffer.allocate(1000);
//                 reader.read(charBuffer);
//                 charBuffer.flip();
//                 StringBuilder builder = new StringBuilder("You Said >> \"");
//                 String message = charBuffer.toString();
// //                System.out.println("Plain Socket Message[" + message + "] received @" + new Date());
//                 builder.append(message).append("\"");
//                 BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
//                 bufferedWriter.write(builder.toString());
//                 bufferedWriter.flush();
//                 if (message.equalsIgnoreCase("quit")) {
//                     stopServer();
//                 }
//                 reader.close();
//                 bufferedWriter.close();
//                 socket.close();
//                 return null;
//             }
//         };
//     }
// 
//     public void stopServer() throws Exception {
//         executorService.shutdownNow();
//         server.close();
//     }
// 
// 
//     private void initServerSocket() throws Exception {
//         server = new ServerSocket(port);
//     }
// 
// }
// 
// Path: src/main/java/bbejeck/nio/sockets/PlainSocketMessageSender.java
// public class PlainSocketMessageSender {
// 
//     private Socket socket;
//     private int port;
//     private InetSocketAddress socketAddress;
//     private int messageCount;
// 
//     @Inject
//     public PlainSocketMessageSender(@Port int port, @MessageCount int messageCount, @Host String host) {
//         this.port = port;
//         socketAddress = new InetSocketAddress(host, port);
//         this.messageCount = messageCount;
//     }
// 
//     public void sendMessages() throws Exception {
//         for (int i = 0; i < messageCount; i++) {
//             sendTextMessage("Plain text message from socket");
//         }
//         sendTextMessage("quit");
//     }
// 
//     private void sendTextMessage(String message) throws Exception {
//         socket = new Socket();
//         socket.connect(socketAddress);
//         BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
//         bufferedWriter.write(message);
//         bufferedWriter.flush();
//         BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
//         CharBuffer charBuffer = CharBuffer.allocate(1000);
//         reader.read(charBuffer);
//         charBuffer.flip();
// //        System.out.println("Reply from server "+charBuffer.toString());
//         reader.close();
//         bufferedWriter.close();
//         socket.close();
//     }
// }
// 
// Path: src/main/java/bbejeck/nio/sockets/PlainSocketModule.java
// public class PlainSocketModule extends AbstractModule {
// 
//     @Override
//     protected void configure() {
//         bind(PlainServerSocket.class);
//         bind(PlainSocketMessageSender.class);
//     }
// }


// Path: src/main/java/bbejeck/nio/PlainSocketTestDriver.java
import bbejeck.nio.channels.AsyncServerTestModule;
import bbejeck.nio.sockets.PlainServerSocket;
import bbejeck.nio.sockets.PlainSocketMessageSender;
import bbejeck.nio.sockets.PlainSocketModule;
import com.google.common.base.Stopwatch;
import com.google.inject.Guice;
import com.google.inject.Injector;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

package bbejeck.nio;




/**
 * Created by IntelliJ IDEA.
 * User: bbejeck
 * Date: 3/14/12
 * Time: 9:48 PM
 */
public class PlainSocketTestDriver {


    public static void main(String[] args) throws Exception {
        Injector injector = Guice.createInjector(new SocketModule(), new PlainSocketModule(), new AsyncServerTestModule());
        PlainSocketMessageSender messageSender = injector.getInstance(PlainSocketMessageSender.class);