Created
June 8, 2016 18:27
-
-
Save cyberterror/4ea8d92a8344f877735d9df11770c000 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Acceptor implements Runnable{ | |
private SelectionKey selectionKey; | |
private ServerSocketChannel serverSocketChannel; | |
private final Boolean isWithThreadPool; | |
private final String sessionName = "Acceptor"; | |
private String sessionAdress; | |
public Acceptor(final SelectionKey selectionKey, Boolean isWithThreadPool) throws IOException { | |
this.selectionKey = selectionKey; | |
this.serverSocketChannel = (ServerSocketChannel) selectionKey.channel(); | |
this.sessionAdress = serverSocketChannel.getLocalAddress().toString(); | |
this.isWithThreadPool = isWithThreadPool; | |
} | |
@Override | |
public void run() { | |
try { | |
SocketChannel socketChannel = serverSocketChannel.accept(); | |
if (socketChannel != null) { | |
if (isWithThreadPool) { | |
// new HandlerWithThreadPool(selector, socketChannel); | |
System.out.println("not implemented"); | |
} | |
else { | |
new Handler(selectionKey.selector(), socketChannel); | |
} | |
} | |
System.out.println("Connection Accepted by Command Center"); | |
System.out.println("New client ip=" + socketChannel.getRemoteAddress()); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
@Override | |
public String toString() { | |
return sessionName + "@" + sessionAdress; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment