You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by ke...@apache.org on 2010/04/09 20:38:59 UTC
svn commit: r932540 -
/openejb/trunk/openejb3/server/openejb-multicast/src/main/java/org/apache/openejb/server/discovery/EchoNet.java
Author: kevan
Date: Fri Apr 9 18:38:59 2010
New Revision: 932540
URL: http://svn.apache.org/viewvc?rev=932540&view=rev
Log:
Copy just what you need and not one byte more... Also, made the number of servers an optional parameter
Modified:
openejb/trunk/openejb3/server/openejb-multicast/src/main/java/org/apache/openejb/server/discovery/EchoNet.java
Modified: openejb/trunk/openejb3/server/openejb-multicast/src/main/java/org/apache/openejb/server/discovery/EchoNet.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-multicast/src/main/java/org/apache/openejb/server/discovery/EchoNet.java?rev=932540&r1=932539&r2=932540&view=diff
==============================================================================
--- openejb/trunk/openejb3/server/openejb-multicast/src/main/java/org/apache/openejb/server/discovery/EchoNet.java (original)
+++ openejb/trunk/openejb3/server/openejb-multicast/src/main/java/org/apache/openejb/server/discovery/EchoNet.java Fri Apr 9 18:38:59 2010
@@ -46,13 +46,27 @@ import java.util.concurrent.CountDownLat
public class EchoNet {
public static void main(String[] args) throws Exception {
- Server a = new Server(4444).start();
- Server b = new Server(5555).start();
- Server c = new Server(6666).start();
- a.connect(b);
- c.connect(b);
- // A and C should hookup through B
+ final int INITIAL_PORT = 3000;
+ int maxServers = 3;
+
+ if (args.length > 0)
+ maxServers = Integer.parseInt(args[0]);
+
+ if (maxServers < 1) {
+ System.out.println("number of servers must be greater than zero");
+ return;
+ }
+
+ Server lastServer = new Server(INITIAL_PORT).start();
+ for (int i=1; i<maxServers; i++) {
+ Server newServer = new Server(INITIAL_PORT+i).start();
+
+ if (lastServer != null)
+ newServer.connect(lastServer);
+
+ lastServer = newServer;
+ }
new CountDownLatch(1).await();
}
@@ -226,7 +240,8 @@ public class EchoNet {
String text = new String(buf, 0, end, "UTF-8");
int newPos = read.position() - end;
- System.arraycopy(buf, end + 1, buf, 0, newPos);
+ System.arraycopy(buf, end + 1, buf, 0, newPos-1);
+
read.position(newPos - 1);
return text;