use of org.webpieces.nio.api.channels.TCPChannel in project webpieces by deanhiller.
the class ProxyDataListener method applyBackPressure.
@Override
public void applyBackPressure(Channel channel) {
TCPChannel proxy = lookupExistingOrCreateNew(channel);
dataListener.applyBackPressure(proxy);
}
use of org.webpieces.nio.api.channels.TCPChannel in project webpieces by deanhiller.
the class ProxyDataListener method lookupExistingOrCreateNew.
/**
* We have two choices here.
* 1. implement equals and hashCode in ProxyTCPChannel to delegate to TCPChannel so as we
* create new ones, they are equal if the Channel they wrap is equal
* 2. re-use the same proxy we created for this channel by sticking it in the channel session
* which avoids creating new objects that need to be garbage collected every time data
* comes in
*
* @param channel
* @return
*/
private TCPChannel lookupExistingOrCreateNew(Channel channel) {
ChannelSession session = channel.getSession();
//This is garbage collected when the TCPChannel and it's ChannelSession are garbage
//collected...
ProxyTCPChannel existingProxy = (ProxyTCPChannel) session.get(EXISTING_PROXY_CHANNEL);
if (existingProxy == null) {
existingProxy = new ProxyTCPChannel((TCPChannel) channel, connectedChannels);
session.put(EXISTING_PROXY_CHANNEL, existingProxy);
}
return existingProxy;
}
use of org.webpieces.nio.api.channels.TCPChannel in project webpieces by deanhiller.
the class TestBasicSsl method testBasic.
@Test
public void testBasic() throws InterruptedException, ExecutionException {
ChannelManager svrMgr = createSvrChanMgr("server");
SelfSignedSSLEngineFactory sslFactory = new SelfSignedSSLEngineFactory();
TCPServerChannel svrChannel = svrMgr.createTCPServerChannel("svrChan", mockConnListener, sslFactory);
svrChannel.bind(new InetSocketAddress(8444));
int port = svrChannel.getLocalAddress().getPort();
//don't really need to use a separate chan mgr but we will here..
ChannelManager chanMgr = createSvrChanMgr("client");
TCPChannel channel = chanMgr.createTCPChannel("client", sslFactory.createEngineForClient("cvs.xsoftware.biz", port));
CompletableFuture<Channel> future = channel.connect(new InetSocketAddress("localhost", port), mockClientDataListener);
future.get();
byte[] data = new byte[] { 0, 2, 4, 6, 8, 10 };
ByteBuffer buf = ByteBuffer.wrap(data);
channel.write(buf);
ByteBuffer result = mockSvrDataListener.getFirstBuffer().get();
byte[] newData = new byte[result.remaining()];
result.get(newData);
Assert.assertEquals(data.length, newData.length);
for (int i = 0; i < data.length; i++) {
Assert.assertEquals(data[i], newData[i]);
}
//verify sniServerName was used in looking up security cert.
String host = sslFactory.getCachedHost();
Assert.assertEquals("cvs.xsoftware.biz", host);
}
use of org.webpieces.nio.api.channels.TCPChannel in project webpieces by deanhiller.
the class DelayServerAcceptor method connected.
public void connected(Channel channel) throws IOException {
if (log.isTraceEnabled())
log.trace(channel + "about to accept");
currentChannel = clientSideChanMgr.createTCPChannel("xxx", null);
currentChannel.setName("<not known yet>");
InetSocketAddress addr = new InetSocketAddress(delaySvrAddr, 0);
currentChannel.bind(addr);
currentChannel.oldConnect(realSvr);
if (log.isTraceEnabled())
log.trace(channel + "connected to real server");
if (log.isTraceEnabled())
log.trace(channel + ":" + currentChannel + "connected all links");
sockets.add((TCPChannel) channel);
sockets.add(currentChannel);
currentChannel.registerForReads(new Delayer((TCPChannel) channel));
channel.registerForReads(new Delayer(currentChannel));
}
use of org.webpieces.nio.api.channels.TCPChannel in project webpieces by deanhiller.
the class IntegTestLocalhostThroughput method createClientChannel.
private TCPChannel createClientChannel(BufferPool pool2, Executor executor) {
ChannelManagerFactory factory = ChannelManagerFactory.createFactory();
ChannelManager mgr = factory.createMultiThreadedChanMgr("client", pool2, executor);
TCPChannel channel = mgr.createTCPChannel("clientChan");
return channel;
}
Aggregations