use of com.nokia.dempsy.messagetransport.MessageTransportException in project Dempsy by Dempsy.
the class PassthroughTransport method createOutbound.
@Override
public SenderFactory createOutbound(DempsyExecutor executor, final StatsCollector statsCollector) {
return new SenderFactory() {
private volatile boolean isStopped = false;
private StatsCollector sc = statsCollector;
@Override
public Sender getSender(Destination destination) throws MessageTransportException {
if (isStopped == true)
throw new MessageTransportException("getSender called for the destination " + SafeString.valueOf(destination) + " on a stopped " + SafeString.valueOfClass(this));
PassthroughSender ret = (PassthroughSender) (((PassthroughDestination) destination).sender);
ret.statsCollector = sc;
return ret;
}
@Override
public void stop() {
isStopped = true;
}
// There is no 'stop' on a PassthroughSender so there's nothing to do to reclaim it.
@Override
public void reclaim(Destination destination) {
}
};
}
use of com.nokia.dempsy.messagetransport.MessageTransportException in project Dempsy by Dempsy.
the class TcpReceiver method bind.
protected void bind() throws MessageTransportException {
if (serverSocket == null || !serverSocket.isBound()) {
try {
InetSocketAddress inetSocketAddress = new InetSocketAddress(destination.inetAddress, destination.port < 0 ? 0 : destination.port);
serverSocket = new ServerSocket();
// this allows the server port to be bound to even if it's in TIME_WAIT
serverSocket.setReuseAddress(true);
serverSocket.bind(inetSocketAddress);
destination.port = serverSocket.getLocalPort();
} catch (IOException ioe) {
throw new MessageTransportException("Cannot bind to port " + (destination.isEphemeral() ? "(ephemeral port)" : destination.port), ioe);
}
}
}
use of com.nokia.dempsy.messagetransport.MessageTransportException in project Dempsy by Dempsy.
the class TcpSenderFactory method getSender.
@Override
public Sender getSender(Destination destination) throws MessageTransportException {
if (isStopped == true)
throw new MessageTransportException("getSender called for the destination " + SafeString.valueOf(destination) + " on a stopped " + SafeString.valueOfClass(this));
TcpSender sender;
synchronized (senders) {
sender = senders.get(destination);
if (sender == null) {
sender = makeTcpSender((TcpDestination) destination);
senders.put(destination, sender);
}
}
return sender;
}
use of com.nokia.dempsy.messagetransport.MessageTransportException in project Dempsy by Dempsy.
the class TcpTransportTest method transportLargeMessage.
/**
* Test the sending and recieving of a large message (10 meg).
* @throws Throwable
*/
@Test
public void transportLargeMessage() throws Throwable {
int port = -1;
boolean localhost = false;
SenderFactory factory = null;
TcpReceiver adaptor = null;
TcpSenderFactory senderFactory = null;
try {
//===========================================
// setup the sender and receiver
adaptor = new TcpReceiver(null, getFailFast());
// distruptible sender factory
factory = makeSenderFactory(false, null, 500);
receiveLargeMessageLatch = new CountDownLatch(1);
adaptor.setListener(new Listener() {
@Override
public boolean onMessage(byte[] messageBytes, boolean failfast) throws MessageTransportException {
receivedByteArrayMessage = messageBytes;
receiveLargeMessageLatch.countDown();
return true;
}
@Override
public void shuttingDown() {
}
});
if (port <= 0)
adaptor.setUseEphemeralPort(true);
if (port > 0)
adaptor.setPort(port);
if (localhost)
adaptor.setUseLocalhost(localhost);
//===========================================
// start the adaptor
adaptor.start();
// double start ... just want more coverage.
adaptor.start();
// get the destination
Destination destination = adaptor.getDestination();
if (port > 0)
adaptor.setPort(port);
if (localhost)
adaptor.setUseLocalhost(localhost);
senderFactory = makeSenderFactory(false, null, 500);
int size = 1024 * 1024 * 10;
byte[] tosend = new byte[size];
for (int i = 0; i < size; i++) tosend[i] = (byte) i;
TcpSender sender = (TcpSender) senderFactory.getSender(destination);
// extend the timeout because of the larger messages
sender.setTimeoutMillis(100000);
sender.send(tosend);
assertTrue(receiveLargeMessageLatch.await(1, TimeUnit.MINUTES));
assertArrayEquals(tosend, receivedByteArrayMessage);
} finally {
if (factory != null)
factory.stop();
if (senderFactory != null)
senderFactory.stop();
if (adaptor != null)
adaptor.stop();
receivedByteArrayMessage = null;
}
}
Aggregations