Skip to content

Commit

Permalink
java_nats_0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
tyagihas committed Aug 31, 2012
1 parent 1c0d7d0 commit 03e289b
Show file tree
Hide file tree
Showing 80 changed files with 7,947 additions and 452 deletions.
2 changes: 1 addition & 1 deletion .classpath
Expand Up @@ -4,6 +4,6 @@
<classpathentry kind="src" path="benchmark"/> <classpathentry kind="src" path="benchmark"/>
<classpathentry kind="src" path="examples"/> <classpathentry kind="src" path="examples"/>
<classpathentry kind="src" path="test"/> <classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>
30 changes: 15 additions & 15 deletions README.md
Expand Up @@ -17,29 +17,29 @@ session.start();
session.publish("foo", "Hello World!", null, null); session.publish("foo", "Hello World!", null, null);


// Simple Subscriber // Simple Subscriber
session.subscribe("foo", session.new EventHandler() { session.subscribe("foo", new MsgHandler() {
public void execute(String msg) { public void execute(String msg) {
System.out.println("Received a message: " + msg); System.out.println("Received a message: " + msg);
} }
}); });


// Unsubscribing // Unsubscribing
Integer sid = session.subscribe("foo", session.new EventHandler() { Integer sid = session.subscribe("foo", new MsgHandler() {
public void execute(String msg) { public void execute(String msg) {
System.out.println("Received a message: " + msg); System.out.println("Received a message: " + msg);
} }
}); });
session.unsubscribe(sid); session.unsubscribe(sid);


// Requests // Requests
sid = session.request("help", session.new EventHandler() { sid = session.request("help", new MsgHandler() {
public void execute(String response) { public void execute(String response) {
System.out.println("Got a response for help : " + reponse); System.out.println("Got a response for help : " + reponse);
} }
}); });


// Replies // Replies
session.subscribe("help", session.new RequestEventHandler() { session.subscribe("help", new MsgHandler() {
public void execute(String request, String replyTo) { public void execute(String request, String replyTo) {
try { try {
session.publish(replyTo, "I can help!"); session.publish(replyTo, "I can help!");
Expand All @@ -57,27 +57,27 @@ session.stop();


```javascript ```javascript
// "*" matches any token, at any level of the subject. // "*" matches any token, at any level of the subject.
session.subscribe("foo.*.baz", session.new EventHandler() { session.subscribe("foo.*.baz", new MsgHandler() {
public void execute(String msg, String reply, String subject) { public void execute(String msg, String reply, String subject) {
System.out.println("Received a message on [" + subject + "] : " + msg); System.out.println("Received a message on [" + subject + "] : " + msg);
} }
}); });


session.subscribe("foo.bar.*", session.new EventHandler() { session.subscribe("foo.bar.*", new MsgHandler() {
public void execute(String msg, String reply, String subject) { public void execute(String msg, String reply, String subject) {
System.out.println("Received a message on [" + subject + "] : " + msg); System.out.println("Received a message on [" + subject + "] : " + msg);
} }
}); });


session.subscribe("*.bar.*", session.new EventHandler() { session.subscribe("*.bar.*", new MsgHandler() {
public void execute(String msg, String reply, String subject) { public void execute(String msg, String reply, String subject) {
System.out.println("Received a message on [" + subject + "] : " + msg); System.out.println("Received a message on [" + subject + "] : " + msg);
} }
}); });


// ">" matches any length of the tail of a subject, and can only be the last token // ">" matches any length of the tail of a subject, and can only be the last token
// E.g. 'foo.>' will match 'foo.bar', 'foo.bar.baz', 'foo.foo.bar.bax.22' // E.g. 'foo.>' will match 'foo.bar', 'foo.bar.baz', 'foo.foo.bar.bax.22'
session.subscribe("foo.>", session.new EventHandler() { session.subscribe("foo.>", new MsgHandler() {
public void execute(String msg, String reply, String subject) { public void execute(String msg, String reply, String subject) {
System.out.println("Received a message on [" + subject + "] : " + msg); System.out.println("Received a message on [" + subject + "] : " + msg);
} }
Expand All @@ -93,7 +93,7 @@ session.subscribe("foo.>", session.new EventHandler() {
// Normal subscribers will continue to work as expected. // Normal subscribers will continue to work as expected.
Properties opt = new Properties(); Properties opt = new Properties();
opt.setProperty("queue", "job.workers"); opt.setProperty("queue", "job.workers");
session.subscribe(args[0], opt, session.new EventHandler() { session.subscribe(args[0], opt, new MsgHandler() {
public void execute(String msg) { public void execute(String msg) {
System.out.println("Received update : " + msg); System.out.println("Received update : " + msg);
} }
Expand All @@ -104,20 +104,20 @@ session.subscribe(args[0], opt, session.new EventHandler() {


```javascript ```javascript
// Publish with closure, callback fires when server has processed the message // Publish with closure, callback fires when server has processed the message
session.publish("foo", "You done?", session.new EventHandler() { session.publish("foo", "You done?", new MsgHandler() {
public void execute() { public void execute() {
System.out.println("Message processed!"); System.out.println("Message processed!");
} }
}); });


// Timeouts for subscriptions // Timeouts for subscriptions
Integer sid = session.subscribe("foo", session.new EventHandler() { Integer sid = session.subscribe("foo", new MsgHandler() {
int received = 0; int received = 0;
public void execute() { public void execute() {
received++; received++;
} }
}); });
session.timeout(sid, TIMEOUT_IN_SECS, session.new EventHandler() { session.timeout(sid, TIMEOUT_IN_SECS, new MsgHandler() {
public void execute() { public void execute() {
timeout_recv = true; timeout_recv = true;
} }
Expand All @@ -126,7 +126,7 @@ session.timeout(sid, TIMEOUT_IN_SECS, session.new EventHandler() {
// Timeout unless a certain number of messages have been received // Timeout unless a certain number of messages have been received
Properties opt = new Properties(); Properties opt = new Properties();
opt.put("expected", new Integer(2)); opt.put("expected", new Integer(2));
session.timeout(sid, 10, opt, session.new EventHandler() { session.timeout(sid, 10, opt, new MsgHandler() {
public void execute(Object o) { public void execute(Object o) {
timeout_recv = true; timeout_recv = true;
} }
Expand All @@ -136,15 +136,15 @@ session.timeout(sid, 10, opt, session.new EventHandler() {
session.unsubscribe(sid, MAX_WANTED) session.unsubscribe(sid, MAX_WANTED)


// Multiple connections // Multiple connections
session1.subscribe("test", session.new EventHandler() { session1.subscribe("test", new MsgHandler() {
public void execute(String msg) { public void execute(String msg) {
System.out.println("received : " + msg); System.out.println("received : " + msg);
} }
}); });


// Form second connection to send message on // Form second connection to send message on
Session session2 = Session.connect(new Properties()); Session session2 = Session.connect(new Properties());
session2.start(session2.new EventHandler() { session2.start(new MsgHandler() {
public void execute(Object o) { public void execute(Object o) {
Session session = (Session)o; Session session = (Session)o;
try { try {
Expand Down
@@ -1,8 +1,8 @@
package nats.benchmark; package org.nats.benchmark;


import java.util.Properties; import java.util.Properties;
import nats.Session;
import nats.Session.EventHandler; import org.nats.*;


public class PubPerf { public class PubPerf {


Expand All @@ -13,26 +13,27 @@ public static void main(String[] args) throws Exception {
String val = ""; String val = "";
for(int l = 0; l < size; l++) val+="a"; for(int l = 0; l < size; l++) val+="a";


Session session = Session.connect(new Properties()); Properties prop = new Properties();
Session session = Session.connect(prop);
session.start(); session.start();


System.out.println("Performing Publish performance test"); System.out.println("Performing Publish performance test");
final long start = System.nanoTime(); final long start = System.nanoTime();
for(int i = 1; i <= loop; i++) { for(int i = 1; i <= loop; i++) {
// session.publish("hello", null, new Integer(i).toString(), null);
session.publish("hello", null, val, null); session.publish("hello", null, val, null);
// session.publish("hello", null, new Integer(i).toString(), null);
if (i % hash == 0) if (i % hash == 0)
System.out.print("+"); System.out.print("+");
} }


session.flush(session.new EventHandler() { session.flush(new MsgHandler() {
public void execute(Object o) { public void execute(Object o) {
double elapsed = System.nanoTime() - start; double elapsed = System.nanoTime() - start;
System.out.println("\nelapsed : " + Double.toString(elapsed / 1000000000) + " seconds"); System.out.println("\nelapsed : " + Double.toString(elapsed / 1000000000) + " seconds");
System.out.println("msg/sec : " + Double.toString(loop / (elapsed / 1000000000))); System.out.println("msg/sec : " + Double.toString(loop / (elapsed / 1000000000)));
} }
}); });

session.stop(); session.stop();
System.exit(0); System.exit(0);
} }
Expand Down
@@ -1,8 +1,9 @@
package nats.benchmark; package org.nats.benchmark;


import java.io.IOException;
import java.util.Properties; import java.util.Properties;
import nats.Session;
import nats.Session.EventHandler; import org.nats.*;


public class PubSubPerf { public class PubSubPerf {


Expand All @@ -21,7 +22,7 @@ public static void main(String[] args) throws Exception {


System.out.println("Performing Publish/Subscribe performance test"); System.out.println("Performing Publish/Subscribe performance test");
final long start = System.nanoTime(); final long start = System.nanoTime();
session1.subscribe("test", session1.new EventHandler() { session1.subscribe("test", new MsgHandler() {
int received = 0; int received = 0;
public void execute(Object o) { public void execute(Object o) {
received++; received++;
Expand All @@ -38,19 +39,18 @@ public void execute(Object o) {
} }
}); });


session1.flush(session1.new EventHandler() { session1.flush(new MsgHandler() {
public void execute(Object o) { public void execute(Object o) {
for(int i = 1; i <= loop; i++) { try {
try { for(int i = 1; i <= loop; i++) {
session2.publish("test", val); session2.publish("test", val);
// session2.publish("test", "aaaa\r\nbbbb\r\ncccc\r\ndddd\r\n"); // session2.publish("test", "aaaa\r\nbbbb\r\ncccc\r\ndddd\r\n");
// session2.publish("test", new Integer(i).toString());
if (i % hash == 0) if (i % hash == 0)
System.out.print("+"); System.out.print("+");
} }
catch(Exception e) { session2.flush();
e.printStackTrace(); } catch(Exception e) {e.printStackTrace();}
}
}
} }
}); });
} }
Expand Down
9 changes: 3 additions & 6 deletions bin/PubPerf.bat
@@ -1,9 +1,6 @@
SET PATH="C:\Program Files\Java\jre6\bin" SET PATH="C:\Program Files\Java\jdk1.7.0_04\bin"
REM SET PATH="C:\Program Files\Java\jdk1.7.0_04\bin"
SET CLASSPATH=. SET CLASSPATH=.


REM java -ms128m -mx128m nats.benchmark.PubPerf java -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -ms512m -mx512m nats.benchmark.PubPerf 100000 1024
java -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -ms512m -mx512m nats.benchmark.PubPerf 500000 16
REM java -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -ms128m -mx128m nats.benchmark.PubPerf


REM pause pause
18 changes: 15 additions & 3 deletions doc/allclasses-frame.html
Expand Up @@ -2,16 +2,28 @@
<!-- NewPage --> <!-- NewPage -->
<html lang="en"> <html lang="en">
<head> <head>
<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 --> <!-- Generated by javadoc (version 1.7.0_04) on Fri Aug 31 19:22:48 JST 2012 -->
<title>All Classes</title> <title>All Classes</title>
<meta name="date" content="2012-08-21"> <meta name="date" content="2012-08-31">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style"> <link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
</head> </head>
<body> <body>
<h1 class="bar">All Classes</h1> <h1 class="bar">All Classes</h1>
<div class="indexContainer"> <div class="indexContainer">
<ul> <ul>
<li><a href="nats/Session.html" title="class in nats" target="classFrame">Session</a></li> <li><a href="org/nats/examples/AutoUnsub.html" title="class in org.nats.examples" target="classFrame">AutoUnsub</a></li>
<li><a href="org/nats/examples/Expected.html" title="class in org.nats.examples" target="classFrame">Expected</a></li>
<li><a href="org/nats/MsgHandler.html" title="class in org.nats" target="classFrame">MsgHandler</a></li>
<li><a href="org/nats/examples/MultiConnection.html" title="class in org.nats.examples" target="classFrame">MultiConnection</a></li>
<li><a href="org/nats/examples/Pub.html" title="class in org.nats.examples" target="classFrame">Pub</a></li>
<li><a href="org/nats/benchmark/PubPerf.html" title="class in org.nats.benchmark" target="classFrame">PubPerf</a></li>
<li><a href="org/nats/benchmark/PubSubPerf.html" title="class in org.nats.benchmark" target="classFrame">PubSubPerf</a></li>
<li><a href="org/nats/examples/QueueSub.html" title="class in org.nats.examples" target="classFrame">QueueSub</a></li>
<li><a href="org/nats/examples/Request.html" title="class in org.nats.examples" target="classFrame">Request</a></li>
<li><a href="org/nats/Session.html" title="class in org.nats" target="classFrame">Session</a></li>
<li><a href="org/nats/examples/Sub.html" title="class in org.nats.examples" target="classFrame">Sub</a></li>
<li><a href="org/nats/examples/SubTimeout.html" title="class in org.nats.examples" target="classFrame">SubTimeout</a></li>
<li><a href="org/nats/examples/SubUnsub.html" title="class in org.nats.examples" target="classFrame">SubUnsub</a></li>
</ul> </ul>
</div> </div>
</body> </body>
Expand Down
18 changes: 15 additions & 3 deletions doc/allclasses-noframe.html
Expand Up @@ -2,16 +2,28 @@
<!-- NewPage --> <!-- NewPage -->
<html lang="en"> <html lang="en">
<head> <head>
<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 --> <!-- Generated by javadoc (version 1.7.0_04) on Fri Aug 31 19:22:48 JST 2012 -->
<title>All Classes</title> <title>All Classes</title>
<meta name="date" content="2012-08-21"> <meta name="date" content="2012-08-31">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style"> <link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
</head> </head>
<body> <body>
<h1 class="bar">All Classes</h1> <h1 class="bar">All Classes</h1>
<div class="indexContainer"> <div class="indexContainer">
<ul> <ul>
<li><a href="nats/Session.html" title="class in nats">Session</a></li> <li><a href="org/nats/examples/AutoUnsub.html" title="class in org.nats.examples">AutoUnsub</a></li>
<li><a href="org/nats/examples/Expected.html" title="class in org.nats.examples">Expected</a></li>
<li><a href="org/nats/MsgHandler.html" title="class in org.nats">MsgHandler</a></li>
<li><a href="org/nats/examples/MultiConnection.html" title="class in org.nats.examples">MultiConnection</a></li>
<li><a href="org/nats/examples/Pub.html" title="class in org.nats.examples">Pub</a></li>
<li><a href="org/nats/benchmark/PubPerf.html" title="class in org.nats.benchmark">PubPerf</a></li>
<li><a href="org/nats/benchmark/PubSubPerf.html" title="class in org.nats.benchmark">PubSubPerf</a></li>
<li><a href="org/nats/examples/QueueSub.html" title="class in org.nats.examples">QueueSub</a></li>
<li><a href="org/nats/examples/Request.html" title="class in org.nats.examples">Request</a></li>
<li><a href="org/nats/Session.html" title="class in org.nats">Session</a></li>
<li><a href="org/nats/examples/Sub.html" title="class in org.nats.examples">Sub</a></li>
<li><a href="org/nats/examples/SubTimeout.html" title="class in org.nats.examples">SubTimeout</a></li>
<li><a href="org/nats/examples/SubUnsub.html" title="class in org.nats.examples">SubUnsub</a></li>
</ul> </ul>
</div> </div>
</body> </body>
Expand Down

0 comments on commit 03e289b

Please sign in to comment.