You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by to...@apache.org on 2012/09/11 13:31:58 UTC
svn commit: r1383359 - in /avro/trunk: CHANGES.txt
lang/java/ipc/src/main/java/org/apache/avro/ipc/NettyServer.java
lang/java/ipc/src/test/java/org/apache/avro/ipc/TestNettyServer.java
Author: tomwhite
Date: Tue Sep 11 11:31:57 2012
New Revision: 1383359
URL: http://svn.apache.org/viewvc?rev=1383359&view=rev
Log:
AVRO-1151. Netty Avro server should expose the number of connections currently open. Contributed by Hari Shreedharan.
Modified:
avro/trunk/CHANGES.txt
avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/ipc/NettyServer.java
avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestNettyServer.java
Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1383359&r1=1383358&r2=1383359&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Tue Sep 11 11:31:57 2012
@@ -13,6 +13,9 @@ Avro 1.7.2 (unreleased)
AVRO-1147. Java: Permit stringable map keys in reflect.
(Alexandre Normand)
+ AVRO-1151. Netty Avro server should expose the number of connections
+ currently open. (Hari Shreedharan via tomwhite)
+
BUG FIXES
AVRO-1128. Java: Fix SpecificRecordBase#equals() to work for
Modified: avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/ipc/NettyServer.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/ipc/NettyServer.java?rev=1383359&r1=1383358&r2=1383359&view=diff
==============================================================================
--- avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/ipc/NettyServer.java (original)
+++ avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/ipc/NettyServer.java Tue Sep 11 11:31:57 2012
@@ -146,6 +146,16 @@ public class NettyServer implements Serv
public void join() throws InterruptedException {
closed.await();
}
+
+ /**
+ *
+ * @return The number of clients currently connected to this server.
+ */
+ public int getNumActiveConnections() {
+ //allChannels also contains the server channel, so exclude that from the
+ //count.
+ return allChannels.size() - 1;
+ }
/**
* Avro server handler for the Netty transport
@@ -190,8 +200,18 @@ public class NettyServer implements Serv
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
LOG.warn("Unexpected exception from downstream.", e.getCause());
e.getChannel().close();
+ allChannels.remove(e.getChannel());
}
- }
+ @Override
+ public void channelClosed(
+ ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
+ LOG.info("Connection to {} disconnected.",
+ e.getChannel().getRemoteAddress());
+ super.channelClosed(ctx, e);
+ e.getChannel().close();
+ allChannels.remove(e.getChannel());
+ }
+ }
}
Modified: avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestNettyServer.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestNettyServer.java?rev=1383359&r1=1383358&r2=1383359&view=diff
==============================================================================
--- avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestNettyServer.java (original)
+++ avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestNettyServer.java Tue Sep 11 11:31:57 2012
@@ -127,6 +127,18 @@ public class TestNettyServer {
}
+ @Test
+ public void testConnectionsCount() throws Exception {
+ Transceiver transceiver2 = new NettyTransceiver(new InetSocketAddress(
+ server.getPort()), CONNECT_TIMEOUT_MILLIS);
+ Mail proxy2 = SpecificRequestor.getClient(Mail.class, transceiver2);
+ proxy.fireandforget(createMessage());
+ proxy2.fireandforget(createMessage());
+ Assert.assertEquals(2, ((NettyServer) server).getNumActiveConnections());
+ transceiver2.close();
+ Assert.assertEquals(1, ((NettyServer) server).getNumActiveConnections());
+ }
+
private Message createMessage() {
Message msg = Message.newBuilder().
setTo("wife").