| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package diy.middleware.channels; |
| 17 | |
|
| 18 | |
import java.io.IOException; |
| 19 | |
import java.net.InetSocketAddress; |
| 20 | |
import java.net.UnknownHostException; |
| 21 | |
import java.nio.channels.SocketChannel; |
| 22 | |
import java.util.concurrent.BlockingQueue; |
| 23 | |
|
| 24 | |
import diy.middleware.Connector; |
| 25 | |
|
| 26 | 3 | public class ChannelConnector implements Connector { |
| 27 | |
|
| 28 | |
private BlockingQueue<ChannelConnection> channelQueue; |
| 29 | |
|
| 30 | |
public void setChannelQueue(BlockingQueue<ChannelConnection> channelQueue) { |
| 31 | 3 | this.channelQueue = channelQueue; |
| 32 | 3 | } |
| 33 | |
|
| 34 | |
public void connect(String host, int port, String sessionId) throws UnknownHostException, IOException, InterruptedException { |
| 35 | 5 | SocketChannel channel = SocketChannel.open(); |
| 36 | 5 | channel.connect(new InetSocketAddress(host, port)); |
| 37 | 5 | channelQueue.put(new ChannelConnection(sessionId, channel)); |
| 38 | 5 | } |
| 39 | |
} |