Skip to content
Browse files

java_nats_0.3

  • Loading branch information...
1 parent 7b3649c commit 6c3bc2d18b4b81a8f45eb0c7688ec1926039defb @tyagihas committed Aug 21, 2012
Showing with 706 additions and 253 deletions.
  1. +9 −0 .classpath
  2. +1 −0 .gitignore
  3. +17 −0 .project
  4. +12 −0 .settings/org.eclipse.jdt.core.prefs
  5. +3 −0 .settings/org.eclipse.ltk.core.refactoring.prefs
  6. +110 −6 README.md
  7. BIN bin/nats/Session$1.class
  8. BIN bin/nats/Session$2.class
  9. BIN bin/nats/Session$EventHandler.class
  10. BIN bin/nats/Session$RequestEventHandler.class
  11. BIN bin/nats/Session$SelectorThread.class
  12. BIN bin/nats/Session$Subscription.class
  13. BIN bin/nats/Session.class
  14. BIN bin/nats/benchmark/PubPerf$1.class
  15. BIN bin/nats/benchmark/PubPerf.class
  16. BIN bin/nats/benchmark/PubSubPerf$1.class
  17. BIN bin/nats/benchmark/PubSubPerf$2.class
  18. BIN bin/nats/benchmark/PubSubPerf.class
  19. BIN bin/nats/examples/Pub.class
  20. BIN bin/nats/examples/Request$1.class
  21. BIN bin/nats/examples/Request$2.class
  22. BIN bin/nats/examples/Request.class
  23. BIN bin/nats/examples/Sub$1.class
  24. BIN bin/nats/examples/Sub.class
  25. BIN bin/nats/examples/SubUnsub$1.class
  26. BIN bin/nats/examples/SubUnsub.class
  27. BIN doc.zip
  28. +2 −2 doc/allclasses-frame.html
  29. +2 −2 doc/allclasses-noframe.html
  30. +3 −3 doc/constant-values.html
  31. +2 −2 doc/deprecated-list.html
  32. +2 −2 doc/help-doc.html
  33. +2 −2 doc/index-files/index-1.html
  34. +2 −2 doc/index-files/index-10.html
  35. +6 −2 doc/index-files/index-11.html
  36. +2 −2 doc/index-files/index-12.html
  37. +7 −11 doc/index-files/index-13.html
  38. +2 −2 doc/index-files/index-14.html
  39. +2 −2 doc/index-files/index-15.html
  40. +2 −2 doc/index-files/index-16.html
  41. +2 −4 doc/index-files/index-2.html
  42. +2 −2 doc/index-files/index-3.html
  43. +11 −9 doc/index-files/index-4.html
  44. +2 −2 doc/index-files/index-5.html
  45. +2 −2 doc/index-files/index-6.html
  46. +2 −2 doc/index-files/index-7.html
  47. +2 −2 doc/index-files/index-8.html
  48. +2 −2 doc/index-files/index-9.html
  49. +1 −1 doc/index.html
  50. +66 −55 doc/nats/Session.EventHandler.html
  51. +52 −14 doc/nats/Session.html
  52. +18 −19 doc/nats/class-use/Session.EventHandler.html
  53. +2 −2 doc/nats/class-use/Session.html
  54. +2 −2 doc/nats/package-frame.html
  55. +2 −2 doc/nats/package-summary.html
  56. +3 −7 doc/nats/package-tree.html
  57. +3 −5 doc/nats/package-use.html
  58. +3 −7 doc/overview-tree.html
  59. +35 −0 examples/nats/examples/AutoUnsub.java
  60. +40 −0 examples/nats/examples/Expected.java
  61. +44 −0 examples/nats/examples/MultiConnection.java
  62. +32 −0 examples/nats/examples/QueueSub.java
  63. +3 −3 examples/nats/examples/Request.java
  64. +2 −2 examples/nats/examples/Sub.java
  65. +36 −0 examples/nats/examples/SubTimeout.java
  66. +149 −67 lib/nats/Session.java
View
9 .classpath
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="lib"/>
+ <classpathentry kind="src" path="benchmark"/>
+ <classpathentry kind="src" path="examples"/>
+ <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="output" path="bin"/>
+</classpath>
View
1 .gitignore
@@ -0,0 +1 @@
+*.class
View
17 .project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>java_nats</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
12 .settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,12 @@
+#Tue Aug 21 10:29:37 JST 2012
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.7
View
3 .settings/org.eclipse.ltk.core.refactoring.prefs
@@ -0,0 +1,3 @@
+#Tue Aug 21 10:23:25 JST 2012
+eclipse.preferences.version=1
+org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
View
116 README.md
@@ -7,7 +7,6 @@ A Java client for the [NATS messaging system](https://github.com/derekcollison/n
## Basic Usage
```javascript
-
import java.util.Properties;
import nats.Session;
...
@@ -19,21 +18,23 @@ session.publish("foo", "Hello World!", null, null);
// Simple Subscriber
session.subscribe("foo", session.new EventHandler() {
- public void execute(Object o) {
- System.out.println("Received a message: " + (String)o);
+ public void execute(String msg) {
+ System.out.println("Received a message: " + msg);
}
});
// Unsubscribing
Integer sid = session.subscribe("foo", session.new EventHandler() {
- public void execute(Object o) {}
+ public void execute(String msg) {
+ System.out.println("Received a message: " + msg);
+ }
});
session.unsubscribe(sid);
// Requests
sid = session.request("help", session.new EventHandler() {
- public void execute(Object o) {
- System.out.println("Got a response for help : " + o);
+ public void execute(String response) {
+ System.out.println("Got a response for help : " + reponse);
}
});
@@ -52,6 +53,109 @@ session.flush();
session.stop();
```
+## Wildcard Subcriptions
+
+```javascript
+// "*" matches any token, at any level of the subject.
+session.subscribe("foo.*.baz", session.new EventHandler() {
+ public void execute(String msg, String reply, String subject) {
+ System.out.println("Received a message on [" + subject + "] : " + msg);
+ }
+});
+
+session.subscribe("foo.bar.*", session.new EventHandler() {
+ public void execute(String msg, String reply, String subject) {
+ System.out.println("Received a message on [" + subject + "] : " + msg);
+ }
+});
+
+session.subscribe("*.bar.*", session.new EventHandler() {
+ public void execute(String msg, String reply, String subject) {
+ 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
+// E.g. 'foo.>' will match 'foo.bar', 'foo.bar.baz', 'foo.foo.bar.bax.22'
+session.subscribe("foo.>", session.new EventHandler() {
+ public void execute(String msg, String reply, String subject) {
+ System.out.println("Received a message on [" + subject + "] : " + msg);
+ }
+});
+```
+
+## Queues Groups
+
+```javascript
+// All subscriptions with the same queue name will form a queue group
+// Each message will be delivered to only one subscriber per queue group, queuing semantics
+// You can have as many queue groups as you wish
+// Normal subscribers will continue to work as expected.
+Properties opt = new Properties();
+opt.setProperty("queue", "job.workers");
+session.subscribe(args[0], opt, session.new EventHandler() {
+ public void execute(String msg) {
+ System.out.println("Received update : " + msg);
+ }
+});
+```
+
+## Advanced Usage
+
+```javascript
+// Publish with closure, callback fires when server has processed the message
+session.publish("foo", "You done?", session.new EventHandler() {
+ public void execute() {
+ System.out.println("Message processed!");
+ }
+});
+
+// Timeouts for subscriptions
+Integer sid = session.subscribe("foo", session.new EventHandler() {
+ int received = 0;
+ public void execute() {
+ received++;
+ }
+});
+session.timeout(sid, TIMEOUT_IN_SECS, session.new EventHandler() {
+ public void execute() {
+ timeout_recv = true;
+ }
+});
+
+// Timeout unless a certain number of messages have been received
+Properties opt = new Properties();
+opt.put("expected", new Integer(2));
+session.timeout(sid, 10, opt, session.new EventHandler() {
+ public void execute(Object o) {
+ timeout_recv = true;
+ }
+});
+
+// Auto-unsubscribe after MAX_WANTED messages received
+session.unsubscribe(sid, MAX_WANTED)
+
+// Multiple connections
+session1.subscribe("test", session.new EventHandler() {
+ public void execute(String msg) {
+ System.out.println("received : " + msg);
+ }
+});
+
+// Form second connection to send message on
+Session session2 = Session.connect(new Properties());
+session2.start(session2.new EventHandler() {
+ public void execute(Object o) {
+ Session session = (Session)o;
+ try {
+ session.publish("test", "Hello World!");
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+});
+```
+
See examples and benchmarks for more information..
## License
View
BIN bin/nats/Session$1.class
Binary file not shown.
View
BIN bin/nats/Session$2.class
Binary file not shown.
View
BIN bin/nats/Session$EventHandler.class
Binary file not shown.
View
BIN bin/nats/Session$RequestEventHandler.class
Binary file not shown.
View
BIN bin/nats/Session$SelectorThread.class
Binary file not shown.
View
BIN bin/nats/Session$Subscription.class
Binary file not shown.
View
BIN bin/nats/Session.class
Binary file not shown.
View
BIN bin/nats/benchmark/PubPerf$1.class
Binary file not shown.
View
BIN bin/nats/benchmark/PubPerf.class
Binary file not shown.
View
BIN bin/nats/benchmark/PubSubPerf$1.class
Binary file not shown.
View
BIN bin/nats/benchmark/PubSubPerf$2.class
Binary file not shown.
View
BIN bin/nats/benchmark/PubSubPerf.class
Binary file not shown.
View
BIN bin/nats/examples/Pub.class
Binary file not shown.
View
BIN bin/nats/examples/Request$1.class
Binary file not shown.
View
BIN bin/nats/examples/Request$2.class
Binary file not shown.
View
BIN bin/nats/examples/Request.class
Binary file not shown.
View
BIN bin/nats/examples/Sub$1.class
Binary file not shown.
View
BIN bin/nats/examples/Sub.class
Binary file not shown.
View
BIN bin/nats/examples/SubUnsub$1.class
Binary file not shown.
View
BIN bin/nats/examples/SubUnsub.class
Binary file not shown.
View
BIN doc.zip
Binary file not shown.
View
4 doc/allclasses-frame.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:15 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>All Classes</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
</head>
<body>
View
4 doc/allclasses-noframe.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:15 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>All Classes</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
</head>
<body>
View
6 doc/constant-values.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:14 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>Constant Field Values</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
</head>
<body>
@@ -157,7 +157,7 @@ <h2 title="nats">nats.*</h2>
<!-- -->
</a><code>public&nbsp;static&nbsp;final&nbsp;java.lang.String</code></td>
<td><code><a href="nats/Session.html#version">version</a></code></td>
-<td class="colLast"><code>"0.2.5"</code></td>
+<td class="colLast"><code>"0.3"</code></td>
</tr>
</tbody>
</table>
View
4 doc/deprecated-list.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:15 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>Deprecated List</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
</head>
<body>
View
4 doc/help-doc.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:15 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>API Help</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
</head>
<body>
View
4 doc/index-files/index-1.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:14 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>A-Index</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
</head>
<body>
View
4 doc/index-files/index-10.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:15 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>O-Index</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
</head>
<body>
View
8 doc/index-files/index-11.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:15 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>P-Index</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
</head>
<body>
@@ -84,6 +84,10 @@ <h2 class="title">P</h2>
<dd>
<div class="block">Publish a message to the given subject.</div>
</dd>
+<dt><span class="strong"><a href="../nats/Session.html#publish(java.lang.String, java.lang.String, nats.Session.EventHandler)">publish(String, String, Session.EventHandler)</a></span> - Method in class nats.<a href="../nats/Session.html" title="class in nats">Session</a></dt>
+<dd>
+<div class="block">Publish a message to the given subject.</div>
+</dd>
<dt><span class="strong"><a href="../nats/Session.html#publish(java.lang.String, java.lang.String, java.lang.String, nats.Session.EventHandler)">publish(String, String, String, Session.EventHandler)</a></span> - Method in class nats.<a href="../nats/Session.html" title="class in nats">Session</a></dt>
<dd>&nbsp;</dd>
</dl>
View
4 doc/index-files/index-12.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:15 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>R-Index</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
</head>
<body>
View
18 doc/index-files/index-13.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:15 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>S-Index</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
</head>
<body>
@@ -71,23 +71,19 @@ <h2 class="title">S</h2>
<div class="block">Session represents a bidirectional channel to NATS server.</div>
</dd>
<dt><a href="../nats/Session.EventHandler.html" title="class in nats"><span class="strong">Session.EventHandler</span></a> - Class in <a href="../nats/package-summary.html">nats</a></dt>
-<dd>
-<div class="block">Generic event handler can be passed to various operations and invoked when the operation is processed by the server.</div>
-</dd>
-<dt><span class="strong"><a href="../nats/Session.EventHandler.html#Session.EventHandler()">Session.EventHandler()</a></span> - Constructor for class nats.<a href="../nats/Session.EventHandler.html" title="class in nats">Session.EventHandler</a></dt>
<dd>&nbsp;</dd>
-<dt><a href="../nats/Session.RequestEventHandler.html" title="class in nats"><span class="strong">Session.RequestEventHandler</span></a> - Class in <a href="../nats/package-summary.html">nats</a></dt>
-<dd>
-<div class="block">Event handler specific to request operation</div>
-</dd>
-<dt><span class="strong"><a href="../nats/Session.RequestEventHandler.html#Session.RequestEventHandler()">Session.RequestEventHandler()</a></span> - Constructor for class nats.<a href="../nats/Session.RequestEventHandler.html" title="class in nats">Session.RequestEventHandler</a></dt>
+<dt><span class="strong"><a href="../nats/Session.EventHandler.html#Session.EventHandler()">Session.EventHandler()</a></span> - Constructor for class nats.<a href="../nats/Session.EventHandler.html" title="class in nats">Session.EventHandler</a></dt>
<dd>&nbsp;</dd>
<dt><span class="strong"><a href="../nats/Session.html#SPC">SPC</a></span> - Static variable in class nats.<a href="../nats/Session.html" title="class in nats">Session</a></dt>
<dd>&nbsp;</dd>
<dt><span class="strong"><a href="../nats/Session.html#start()">start()</a></span> - Method in class nats.<a href="../nats/Session.html" title="class in nats">Session</a></dt>
<dd>
<div class="block">Establish a connection to the server and start a background thread for processing incoming and outgoing messages</div>
</dd>
+<dt><span class="strong"><a href="../nats/Session.html#start(nats.Session.EventHandler)">start(Session.EventHandler)</a></span> - Method in class nats.<a href="../nats/Session.html" title="class in nats">Session</a></dt>
+<dd>
+<div class="block">Establish a connection to the server and start a background thread for processing incoming and outgoing messages</div>
+</dd>
<dt><span class="strong"><a href="../nats/Session.html#stop()">stop()</a></span> - Method in class nats.<a href="../nats/Session.html" title="class in nats">Session</a></dt>
<dd>
<div class="block">Close the channel and stopping the background thread.</div>
View
4 doc/index-files/index-14.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:15 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>T-Index</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
</head>
<body>
View
4 doc/index-files/index-15.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:15 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>U-Index</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
</head>
<body>
View
4 doc/index-files/index-16.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:15 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>V-Index</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
</head>
<body>
View
6 doc/index-files/index-2.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:15 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>C-Index</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
</head>
<body>
@@ -66,8 +66,6 @@
</a>
<h2 class="title">C</h2>
<dl>
-<dt><span class="strong"><a href="../nats/Session.EventHandler.html#caller">caller</a></span> - Variable in class nats.<a href="../nats/Session.EventHandler.html" title="class in nats">Session.EventHandler</a></dt>
-<dd>&nbsp;</dd>
<dt><span class="strong"><a href="../nats/Session.html#CONNECT">CONNECT</a></span> - Static variable in class nats.<a href="../nats/Session.html" title="class in nats">Session</a></dt>
<dd>&nbsp;</dd>
<dt><span class="strong"><a href="../nats/Session.html#connect(java.util.Properties)">connect(Properties)</a></span> - Static method in class nats.<a href="../nats/Session.html" title="class in nats">Session</a></dt>
View
4 doc/index-files/index-3.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:15 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>D-Index</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
</head>
<body>
View
20 doc/index-files/index-4.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:15 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>E-Index</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
</head>
<body>
@@ -70,14 +70,16 @@ <h2 class="title">E</h2>
<dd>&nbsp;</dd>
<dt><span class="strong"><a href="../nats/Session.html#ERR">ERR</a></span> - Static variable in class nats.<a href="../nats/Session.html" title="class in nats">Session</a></dt>
<dd>&nbsp;</dd>
+<dt><span class="strong"><a href="../nats/Session.EventHandler.html#execute()">execute()</a></span> - Method in class nats.<a href="../nats/Session.EventHandler.html" title="class in nats">Session.EventHandler</a></dt>
+<dd>&nbsp;</dd>
+<dt><span class="strong"><a href="../nats/Session.EventHandler.html#execute(java.lang.String)">execute(String)</a></span> - Method in class nats.<a href="../nats/Session.EventHandler.html" title="class in nats">Session.EventHandler</a></dt>
+<dd>&nbsp;</dd>
+<dt><span class="strong"><a href="../nats/Session.EventHandler.html#execute(java.lang.String, java.lang.String)">execute(String, String)</a></span> - Method in class nats.<a href="../nats/Session.EventHandler.html" title="class in nats">Session.EventHandler</a></dt>
+<dd>&nbsp;</dd>
+<dt><span class="strong"><a href="../nats/Session.EventHandler.html#execute(java.lang.String, java.lang.String, java.lang.String)">execute(String, String, String)</a></span> - Method in class nats.<a href="../nats/Session.EventHandler.html" title="class in nats">Session.EventHandler</a></dt>
+<dd>&nbsp;</dd>
<dt><span class="strong"><a href="../nats/Session.EventHandler.html#execute(java.lang.Object)">execute(Object)</a></span> - Method in class nats.<a href="../nats/Session.EventHandler.html" title="class in nats">Session.EventHandler</a></dt>
-<dd>
-<div class="block">Invoked when the operation is completed.</div>
-</dd>
-<dt><span class="strong"><a href="../nats/Session.RequestEventHandler.html#execute(java.lang.String, java.lang.String)">execute(String, String)</a></span> - Method in class nats.<a href="../nats/Session.RequestEventHandler.html" title="class in nats">Session.RequestEventHandler</a></dt>
-<dd>
-<div class="block">Invoked when the request operation is completed.</div>
-</dd>
+<dd>&nbsp;</dd>
</dl>
<a href="index-1.html">A</a>&nbsp;<a href="index-2.html">C</a>&nbsp;<a href="index-3.html">D</a>&nbsp;<a href="index-4.html">E</a>&nbsp;<a href="index-5.html">F</a>&nbsp;<a href="index-6.html">G</a>&nbsp;<a href="index-7.html">I</a>&nbsp;<a href="index-8.html">M</a>&nbsp;<a href="index-9.html">N</a>&nbsp;<a href="index-10.html">O</a>&nbsp;<a href="index-11.html">P</a>&nbsp;<a href="index-12.html">R</a>&nbsp;<a href="index-13.html">S</a>&nbsp;<a href="index-14.html">T</a>&nbsp;<a href="index-15.html">U</a>&nbsp;<a href="index-16.html">V</a>&nbsp;</div>
<!-- ======= START OF BOTTOM NAVBAR ====== -->
View
4 doc/index-files/index-5.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:15 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>F-Index</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
</head>
<body>
View
4 doc/index-files/index-6.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:15 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>G-Index</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
</head>
<body>
View
4 doc/index-files/index-7.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:15 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>I-Index</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
</head>
<body>
View
4 doc/index-files/index-8.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:15 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>M-Index</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
</head>
<body>
View
4 doc/index-files/index-9.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:15 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>N-Index</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
</head>
<body>
View
2 doc/index.html
@@ -2,7 +2,7 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc on Thu Aug 16 23:39:15 JST 2012 -->
+<!-- Generated by javadoc on Tue Aug 21 10:59:06 JST 2012 -->
<title>Generated Documentation (Untitled)</title>
<script type="text/javascript">
targetPage = "" + window.location.search;
View
121 doc/nats/Session.EventHandler.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:14 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>Session.EventHandler</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
</head>
<body>
@@ -36,7 +36,7 @@
<div class="subNav">
<ul class="navList">
<li><a href="../nats/Session.html" title="class in nats"><span class="strong">Prev Class</span></a></li>
-<li><a href="../nats/Session.RequestEventHandler.html" title="class in nats"><span class="strong">Next Class</span></a></li>
+<li>Next Class</li>
</ul>
<ul class="navList">
<li><a href="../index.html?nats/Session.EventHandler.html" target="_top">Frames</a></li>
@@ -61,13 +61,13 @@
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
-<li><a href="#field_summary">Field</a>&nbsp;|&nbsp;</li>
+<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor_summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method_summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
-<li><a href="#field_detail">Field</a>&nbsp;|&nbsp;</li>
+<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor_detail">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method_detail">Method</a></li>
</ul>
@@ -94,45 +94,19 @@ <h2 title="Class Session.EventHandler" class="title">Class Session.EventHandler<
<ul class="blockList">
<li class="blockList">
<dl>
-<dt>Direct Known Subclasses:</dt>
-<dd><a href="../nats/Session.RequestEventHandler.html" title="class in nats">Session.RequestEventHandler</a></dd>
-</dl>
-<dl>
<dt>Enclosing class:</dt>
<dd><a href="../nats/Session.html" title="class in nats">Session</a></dd>
</dl>
<hr>
<br>
<pre>public abstract class <span class="strong">Session.EventHandler</span>
extends java.lang.Object</pre>
-<div class="block">Generic event handler can be passed to various operations and invoked when the operation is processed by the server.</div>
-<dl><dt><span class="strong">Author:</span></dt>
- <dd>Teppei Yagihashi</dd></dl>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
-<!-- =========== FIELD SUMMARY =========== -->
-<ul class="blockList">
-<li class="blockList"><a name="field_summary">
-<!-- -->
-</a>
-<h3>Field Summary</h3>
-<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Field Summary table, listing fields, and an explanation">
-<caption><span>Fields</span><span class="tabEnd">&nbsp;</span></caption>
-<tr>
-<th class="colFirst" scope="col">Modifier and Type</th>
-<th class="colLast" scope="col">Field and Description</th>
-</tr>
-<tr class="altColor">
-<td class="colFirst"><code>java.lang.Thread</code></td>
-<td class="colLast"><code><strong><a href="../nats/Session.EventHandler.html#caller">caller</a></strong></code>&nbsp;</td>
-</tr>
-</table>
-</li>
-</ul>
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor_summary">
@@ -164,9 +138,26 @@ <h2 title="Class Session.EventHandler" class="title">Class Session.EventHandler<
</tr>
<tr class="altColor">
<td class="colFirst"><code>void</code></td>
-<td class="colLast"><code><strong><a href="../nats/Session.EventHandler.html#execute(java.lang.Object)">execute</a></strong>(java.lang.Object&nbsp;o)</code>
-<div class="block">Invoked when the operation is completed.</div>
-</td>
+<td class="colLast"><code><strong><a href="../nats/Session.EventHandler.html#execute()">execute</a></strong>()</code>&nbsp;</td>
+</tr>
+<tr class="rowColor">
+<td class="colFirst"><code>void</code></td>
+<td class="colLast"><code><strong><a href="../nats/Session.EventHandler.html#execute(java.lang.Object)">execute</a></strong>(java.lang.Object&nbsp;o)</code>&nbsp;</td>
+</tr>
+<tr class="altColor">
+<td class="colFirst"><code>void</code></td>
+<td class="colLast"><code><strong><a href="../nats/Session.EventHandler.html#execute(java.lang.String)">execute</a></strong>(java.lang.String&nbsp;msg)</code>&nbsp;</td>
+</tr>
+<tr class="rowColor">
+<td class="colFirst"><code>void</code></td>
+<td class="colLast"><code><strong><a href="../nats/Session.EventHandler.html#execute(java.lang.String, java.lang.String)">execute</a></strong>(java.lang.String&nbsp;msg,
+ java.lang.String&nbsp;reply)</code>&nbsp;</td>
+</tr>
+<tr class="altColor">
+<td class="colFirst"><code>void</code></td>
+<td class="colLast"><code><strong><a href="../nats/Session.EventHandler.html#execute(java.lang.String, java.lang.String, java.lang.String)">execute</a></strong>(java.lang.String&nbsp;msg,
+ java.lang.String&nbsp;reply,
+ java.lang.String&nbsp;subject)</code>&nbsp;</td>
</tr>
</table>
<ul class="blockList">
@@ -184,55 +175,75 @@ <h2 title="Class Session.EventHandler" class="title">Class Session.EventHandler<
<div class="details">
<ul class="blockList">
<li class="blockList">
-<!-- ============ FIELD DETAIL =========== -->
+<!-- ========= CONSTRUCTOR DETAIL ======== -->
<ul class="blockList">
-<li class="blockList"><a name="field_detail">
+<li class="blockList"><a name="constructor_detail">
<!-- -->
</a>
-<h3>Field Detail</h3>
-<a name="caller">
+<h3>Constructor Detail</h3>
+<a name="Session.EventHandler()">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
-<h4>caller</h4>
-<pre>public&nbsp;java.lang.Thread caller</pre>
+<h4>Session.EventHandler</h4>
+<pre>public&nbsp;Session.EventHandler()</pre>
</li>
</ul>
</li>
</ul>
-<!-- ========= CONSTRUCTOR DETAIL ======== -->
+<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
-<li class="blockList"><a name="constructor_detail">
+<li class="blockList"><a name="method_detail">
<!-- -->
</a>
-<h3>Constructor Detail</h3>
-<a name="Session.EventHandler()">
+<h3>Method Detail</h3>
+<a name="execute()">
<!-- -->
</a>
-<ul class="blockListLast">
+<ul class="blockList">
<li class="blockList">
-<h4>Session.EventHandler</h4>
-<pre>public&nbsp;Session.EventHandler()</pre>
+<h4>execute</h4>
+<pre>public&nbsp;void&nbsp;execute()</pre>
</li>
</ul>
+<a name="execute(java.lang.String)">
+<!-- -->
+</a>
+<ul class="blockList">
+<li class="blockList">
+<h4>execute</h4>
+<pre>public&nbsp;void&nbsp;execute(java.lang.String&nbsp;msg)</pre>
</li>
</ul>
-<!-- ============ METHOD DETAIL ========== -->
+<a name="execute(java.lang.String, java.lang.String)">
+<!-- -->
+</a>
<ul class="blockList">
-<li class="blockList"><a name="method_detail">
+<li class="blockList">
+<h4>execute</h4>
+<pre>public&nbsp;void&nbsp;execute(java.lang.String&nbsp;msg,
+ java.lang.String&nbsp;reply)</pre>
+</li>
+</ul>
+<a name="execute(java.lang.String, java.lang.String, java.lang.String)">
<!-- -->
</a>
-<h3>Method Detail</h3>
+<ul class="blockList">
+<li class="blockList">
+<h4>execute</h4>
+<pre>public&nbsp;void&nbsp;execute(java.lang.String&nbsp;msg,
+ java.lang.String&nbsp;reply,
+ java.lang.String&nbsp;subject)</pre>
+</li>
+</ul>
<a name="execute(java.lang.Object)">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>execute</h4>
<pre>public&nbsp;void&nbsp;execute(java.lang.Object&nbsp;o)</pre>
-<div class="block">Invoked when the operation is completed.</div>
-<dl><dt><span class="strong">Parameters:</span></dt><dd><code>o</code> - typically String is passed.</dd></dl>
</li>
</ul>
</li>
@@ -261,7 +272,7 @@ <h2 title="Class Session.EventHandler" class="title">Class Session.EventHandler<
<div class="subNav">
<ul class="navList">
<li><a href="../nats/Session.html" title="class in nats"><span class="strong">Prev Class</span></a></li>
-<li><a href="../nats/Session.RequestEventHandler.html" title="class in nats"><span class="strong">Next Class</span></a></li>
+<li>Next Class</li>
</ul>
<ul class="navList">
<li><a href="../index.html?nats/Session.EventHandler.html" target="_top">Frames</a></li>
@@ -286,13 +297,13 @@ <h2 title="Class Session.EventHandler" class="title">Class Session.EventHandler<
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
-<li><a href="#field_summary">Field</a>&nbsp;|&nbsp;</li>
+<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor_summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method_summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
-<li><a href="#field_detail">Field</a>&nbsp;|&nbsp;</li>
+<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor_detail">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method_detail">Method</a></li>
</ul>
View
66 doc/nats/Session.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:14 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>Session</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
</head>
<body>
@@ -122,15 +122,7 @@ <h2 title="Class Session" class="title">Class Session</h2>
</tr>
<tr class="altColor">
<td class="colFirst"><code>class&nbsp;</code></td>
-<td class="colLast"><code><strong><a href="../nats/Session.EventHandler.html" title="class in nats">Session.EventHandler</a></strong></code>
-<div class="block">Generic event handler can be passed to various operations and invoked when the operation is processed by the server.</div>
-</td>
-</tr>
-<tr class="rowColor">
-<td class="colFirst"><code>class&nbsp;</code></td>
-<td class="colLast"><code><strong><a href="../nats/Session.RequestEventHandler.html" title="class in nats">Session.RequestEventHandler</a></strong></code>
-<div class="block">Event handler specific to request operation</div>
-</td>
+<td class="colLast"><code><strong><a href="../nats/Session.EventHandler.html" title="class in nats">Session.EventHandler</a></strong></code>&nbsp;</td>
</tr>
</table>
</li>
@@ -321,19 +313,27 @@ <h2 title="Class Session" class="title">Class Session</h2>
</tr>
<tr class="altColor">
<td class="colFirst"><code>void</code></td>
+<td class="colLast"><code><strong><a href="../nats/Session.html#publish(java.lang.String, java.lang.String, nats.Session.EventHandler)">publish</a></strong>(java.lang.String&nbsp;subject,
+ java.lang.String&nbsp;msg,
+ <a href="../nats/Session.EventHandler.html" title="class in nats">Session.EventHandler</a>&nbsp;handler)</code>
+<div class="block">Publish a message to the given subject.</div>
+</td>
+</tr>
+<tr class="rowColor">
+<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><strong><a href="../nats/Session.html#publish(java.lang.String, java.lang.String, java.lang.String, nats.Session.EventHandler)">publish</a></strong>(java.lang.String&nbsp;subject,
java.lang.String&nbsp;opt_reply,
java.lang.String&nbsp;msg,
<a href="../nats/Session.EventHandler.html" title="class in nats">Session.EventHandler</a>&nbsp;handler)</code>&nbsp;</td>
</tr>
-<tr class="rowColor">
+<tr class="altColor">
<td class="colFirst"><code>java.lang.Integer</code></td>
<td class="colLast"><code><strong><a href="../nats/Session.html#request(java.lang.String, nats.Session.EventHandler)">request</a></strong>(java.lang.String&nbsp;subject,
<a href="../nats/Session.EventHandler.html" title="class in nats">Session.EventHandler</a>&nbsp;handler)</code>
<div class="block">Send a request and have the response delivered to the supplied handler.</div>
</td>
</tr>
-<tr class="altColor">
+<tr class="rowColor">
<td class="colFirst"><code>java.lang.Integer</code></td>
<td class="colLast"><code><strong><a href="../nats/Session.html#request(java.lang.String, java.lang.String, java.util.Properties, nats.Session.EventHandler)">request</a></strong>(java.lang.String&nbsp;subject,
java.lang.String&nbsp;data,
@@ -342,12 +342,18 @@ <h2 title="Class Session" class="title">Class Session</h2>
<div class="block">Send a request and have the response delivered to the supplied handler.</div>
</td>
</tr>
-<tr class="rowColor">
+<tr class="altColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><strong><a href="../nats/Session.html#start()">start</a></strong>()</code>
<div class="block">Establish a connection to the server and start a background thread for processing incoming and outgoing messages</div>
</td>
</tr>
+<tr class="rowColor">
+<td class="colFirst"><code>void</code></td>
+<td class="colLast"><code><strong><a href="../nats/Session.html#start(nats.Session.EventHandler)">start</a></strong>(<a href="../nats/Session.EventHandler.html" title="class in nats">Session.EventHandler</a>&nbsp;handler)</code>
+<div class="block">Establish a connection to the server and start a background thread for processing incoming and outgoing messages</div>
+</td>
+</tr>
<tr class="altColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><strong><a href="../nats/Session.html#stop()">stop</a></strong>()</code>
@@ -718,6 +724,22 @@ <h2 title="Class Session" class="title">Class Session</h2>
<dd><code>java.lang.InterruptedException</code></dd></dl>
</li>
</ul>
+<a name="start(nats.Session.EventHandler)">
+<!-- -->
+</a>
+<ul class="blockList">
+<li class="blockList">
+<h4>start</h4>
+<pre>public&nbsp;void&nbsp;start(<a href="../nats/Session.EventHandler.html" title="class in nats">Session.EventHandler</a>&nbsp;handler)
+ throws java.io.IOException,
+ java.lang.InterruptedException</pre>
+<div class="block">Establish a connection to the server and start a background thread for processing incoming and outgoing messages</div>
+<dl><dt><span class="strong">Parameters:</span></dt><dd><code>handler</code> - EventHanlder invoked when connection is established.</dd>
+<dt><span class="strong">Throws:</span></dt>
+<dd><code>java.io.IOException</code></dd>
+<dd><code>java.lang.InterruptedException</code></dd></dl>
+</li>
+</ul>
<a name="stop()">
<!-- -->
</a>
@@ -757,6 +779,22 @@ <h2 title="Class Session" class="title">Class Session</h2>
<dd><code>java.io.IOException</code></dd></dl>
</li>
</ul>
+<a name="publish(java.lang.String, java.lang.String, nats.Session.EventHandler)">
+<!-- -->
+</a>
+<ul class="blockList">
+<li class="blockList">
+<h4>publish</h4>
+<pre>public&nbsp;void&nbsp;publish(java.lang.String&nbsp;subject,
+ java.lang.String&nbsp;msg,
+ <a href="../nats/Session.EventHandler.html" title="class in nats">Session.EventHandler</a>&nbsp;handler)
+ throws java.io.IOException</pre>
+<div class="block">Publish a message to the given subject.</div>
+<dl><dt><span class="strong">Parameters:</span></dt><dd><code>subject</code> - </dd><dd><code>msg</code> - a message to be delivered to the server</dd><dd><code>handler</code> - event handler is invoked when publish has been processed by the server.</dd>
+<dt><span class="strong">Throws:</span></dt>
+<dd><code>java.io.IOException</code></dd></dl>
+</li>
+</ul>
<a name="publish(java.lang.String, java.lang.String, java.lang.String, nats.Session.EventHandler)">
<!-- -->
</a>
View
37 doc/nats/class-use/Session.EventHandler.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:14 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>Uses of Class nats.Session.EventHandler</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="../../stylesheet.css" title="Style">
</head>
<body>
@@ -72,21 +72,6 @@ <h2 title="Uses of Class nats.Session.EventHandler" class="title">Uses of Class<
<!-- -->
</a>
<h3>Uses of <a href="../../nats/Session.EventHandler.html" title="class in nats">Session.EventHandler</a> in <a href="../../nats/package-summary.html">nats</a></h3>
-<table border="0" cellpadding="3" cellspacing="0" summary="Use table, listing subclasses, and an explanation">
-<caption><span>Subclasses of <a href="../../nats/Session.EventHandler.html" title="class in nats">Session.EventHandler</a> in <a href="../../nats/package-summary.html">nats</a></span><span class="tabEnd">&nbsp;</span></caption>
-<tr>
-<th class="colFirst" scope="col">Modifier and Type</th>
-<th class="colLast" scope="col">Class and Description</th>
-</tr>
-<tbody>
-<tr class="altColor">
-<td class="colFirst"><code>class&nbsp;</code></td>
-<td class="colLast"><code><strong><a href="../../nats/Session.RequestEventHandler.html" title="class in nats">Session.RequestEventHandler</a></strong></code>
-<div class="block">Event handler specific to request operation</div>
-</td>
-</tr>
-</tbody>
-</table>
<table border="0" cellpadding="3" cellspacing="0" summary="Use table, listing methods, and an explanation">
<caption><span>Methods in <a href="../../nats/package-summary.html">nats</a> with parameters of type <a href="../../nats/Session.EventHandler.html" title="class in nats">Session.EventHandler</a></span><span class="tabEnd">&nbsp;</span></caption>
<tr>
@@ -102,19 +87,27 @@ <h2 title="Uses of Class nats.Session.EventHandler" class="title">Uses of Class<
</tr>
<tr class="rowColor">
<td class="colFirst"><code>void</code></td>
+<td class="colLast"><span class="strong">Session.</span><code><strong><a href="../../nats/Session.html#publish(java.lang.String, java.lang.String, nats.Session.EventHandler)">publish</a></strong>(java.lang.String&nbsp;subject,
+ java.lang.String&nbsp;msg,
+ <a href="../../nats/Session.EventHandler.html" title="class in nats">Session.EventHandler</a>&nbsp;handler)</code>
+<div class="block">Publish a message to the given subject.</div>
+</td>
+</tr>
+<tr class="altColor">
+<td class="colFirst"><code>void</code></td>
<td class="colLast"><span class="strong">Session.</span><code><strong><a href="../../nats/Session.html#publish(java.lang.String, java.lang.String, java.lang.String, nats.Session.EventHandler)">publish</a></strong>(java.lang.String&nbsp;subject,
java.lang.String&nbsp;opt_reply,
java.lang.String&nbsp;msg,
<a href="../../nats/Session.EventHandler.html" title="class in nats">Session.EventHandler</a>&nbsp;handler)</code>&nbsp;</td>
</tr>
-<tr class="altColor">
+<tr class="rowColor">
<td class="colFirst"><code>java.lang.Integer</code></td>
<td class="colLast"><span class="strong">Session.</span><code><strong><a href="../../nats/Session.html#request(java.lang.String, nats.Session.EventHandler)">request</a></strong>(java.lang.String&nbsp;subject,
<a href="../../nats/Session.EventHandler.html" title="class in nats">Session.EventHandler</a>&nbsp;handler)</code>
<div class="block">Send a request and have the response delivered to the supplied handler.</div>
</td>
</tr>
-<tr class="rowColor">
+<tr class="altColor">
<td class="colFirst"><code>java.lang.Integer</code></td>
<td class="colLast"><span class="strong">Session.</span><code><strong><a href="../../nats/Session.html#request(java.lang.String, java.lang.String, java.util.Properties, nats.Session.EventHandler)">request</a></strong>(java.lang.String&nbsp;subject,
java.lang.String&nbsp;data,
@@ -123,6 +116,12 @@ <h2 title="Uses of Class nats.Session.EventHandler" class="title">Uses of Class<
<div class="block">Send a request and have the response delivered to the supplied handler.</div>
</td>
</tr>
+<tr class="rowColor">
+<td class="colFirst"><code>void</code></td>
+<td class="colLast"><span class="strong">Session.</span><code><strong><a href="../../nats/Session.html#start(nats.Session.EventHandler)">start</a></strong>(<a href="../../nats/Session.EventHandler.html" title="class in nats">Session.EventHandler</a>&nbsp;handler)</code>
+<div class="block">Establish a connection to the server and start a background thread for processing incoming and outgoing messages</div>
+</td>
+</tr>
<tr class="altColor">
<td class="colFirst"><code>java.lang.Integer</code></td>
<td class="colLast"><span class="strong">Session.</span><code><strong><a href="../../nats/Session.html#subscribe(java.lang.String, java.util.Properties, nats.Session.EventHandler)">subscribe</a></strong>(java.lang.String&nbsp;subject,
View
4 doc/nats/class-use/Session.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:14 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>Uses of Class nats.Session</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="../../stylesheet.css" title="Style">
</head>
<body>
View
4 doc/nats/package-frame.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:14 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>nats</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
</head>
<body>
View
4 doc/nats/package-summary.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:14 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>nats</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
</head>
<body>
View
10 doc/nats/package-tree.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:14 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>nats Class Hierarchy</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
</head>
<body>
@@ -70,11 +70,7 @@ <h2 title="Class Hierarchy">Class Hierarchy</h2>
<li type="circle">java.lang.Object
<ul>
<li type="circle">nats.<a href="../nats/Session.html" title="class in nats"><span class="strong">Session</span></a></li>
-<li type="circle">nats.<a href="../nats/Session.EventHandler.html" title="class in nats"><span class="strong">Session.EventHandler</span></a>
-<ul>
-<li type="circle">nats.<a href="../nats/Session.RequestEventHandler.html" title="class in nats"><span class="strong">Session.RequestEventHandler</span></a></li>
-</ul>
-</li>
+<li type="circle">nats.<a href="../nats/Session.EventHandler.html" title="class in nats"><span class="strong">Session.EventHandler</span></a></li>
</ul>
</li>
</ul>
View
8 doc/nats/package-use.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:14 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>Uses of Package nats</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
</head>
<body>
@@ -81,9 +81,7 @@ <h1 title="Uses of Package nats" class="title">Uses of Package<br>nats</h1>
</td>
</tr>
<tr class="rowColor">
-<td class="colOne"><a href="../nats/class-use/Session.EventHandler.html#nats">Session.EventHandler</a>
-<div class="block">Generic event handler can be passed to various operations and invoked when the operation is processed by the server.</div>
-</td>
+<td class="colOne"><a href="../nats/class-use/Session.EventHandler.html#nats">Session.EventHandler</a>&nbsp;</td>
</tr>
</tbody>
</table>
View
10 doc/overview-tree.html
@@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
-<!-- Generated by javadoc (version 1.7.0_04) on Thu Aug 16 23:39:14 JST 2012 -->
+<!-- Generated by javadoc (version 1.7.0_04) on Tue Aug 21 10:59:06 JST 2012 -->
<title>Class Hierarchy</title>
-<meta name="date" content="2012-08-16">
+<meta name="date" content="2012-08-21">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
</head>
<body>
@@ -74,11 +74,7 @@ <h2 title="Class Hierarchy">Class Hierarchy</h2>
<li type="circle">java.lang.Object
<ul>
<li type="circle">nats.<a href="nats/Session.html" title="class in nats"><span class="strong">Session</span></a></li>
-<li type="circle">nats.<a href="nats/Session.EventHandler.html" title="class in nats"><span class="strong">Session.EventHandler</span></a>
-<ul>
-<li type="circle">nats.<a href="nats/Session.RequestEventHandler.html" title="class in nats"><span class="strong">Session.RequestEventHandler</span></a></li>
-</ul>
-</li>
+<li type="circle">nats.<a href="nats/Session.EventHandler.html" title="class in nats"><span class="strong">Session.EventHandler</span></a></li>
</ul>
</li>
</ul>
View
35 examples/nats/examples/AutoUnsub.java
@@ -0,0 +1,35 @@
+package nats.examples;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.Properties;
+import nats.Session;
+
+public class AutoUnsub {
+
+ public static void main(String[] args) throws Exception {
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
+ Session session = Session.connect(new Properties());
+ session.start();
+
+ System.out.println("Listening on : " + args[0] + ", auto unsubscribing after 5 messages, but will send 10");
+ Properties opt = new Properties();
+ opt.setProperty("max", "5");
+ session.subscribe(args[0], opt, session.new EventHandler() {
+ public void execute(String msg) {
+ System.out.println("Received update : " + msg);
+ }
+ });
+
+ for(int i = 0; i < 10; i++)
+ session.publish(args[0], Integer.toString(i));
+
+ System.out.println("\nPress enter to exit.");
+ bufferedReader.readLine();
+
+ session.flush();
+ session.stop();
+
+ System.exit(0);
+ }
+}
View
40 examples/nats/examples/Expected.java
@@ -0,0 +1,40 @@
+package nats.examples;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.Properties;
+import nats.Session;
+
+public class Expected {
+
+ public static void main(String[] args) throws Exception {
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
+ Session session = Session.connect(new Properties());
+ session.start();
+
+ System.out.println("Listening on : " + args[0]);
+ System.out.println("Will timeout in 10 seconds unless 2 messages are received");
+ Integer sid = session.subscribe(args[0], session.new EventHandler() {
+ int received = 0;
+ public void execute() {
+ received++;
+ System.out.println("Message received : " + received);
+ }
+ });
+ Properties opt = new Properties();
+ opt.put("expected", new Integer(2));
+ session.timeout(sid, 10, opt, session.new EventHandler() {
+ public void execute(Object o) {
+ System.out.println("Timeout waiting for a message!");
+ }
+ });
+
+ System.out.println("\nPress enter to exit.");
+ bufferedReader.readLine();
+
+ session.flush();
+ session.stop();
+
+ System.exit(0);
+ }
+}
View
44 examples/nats/examples/MultiConnection.java
@@ -0,0 +1,44 @@
+package nats.examples;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.Properties;
+import nats.Session;
+import nats.Session.EventHandler;
+
+public class MultiConnection {
+
+ public static void main(String[] args) throws Exception {
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
+ Session session1 = Session.connect(new Properties());
+ session1.start();
+
+ session1.subscribe("test", session1.new EventHandler() {
+ public void execute(String msg, String reply, String subject) {
+ System.out.println("Received update on " + subject + " : " + msg);
+ }
+ });
+
+ Session session2 = Session.connect(new Properties());
+ session2.start(session2.new EventHandler() {
+ public void execute(Object o) {
+ Session session = (Session)o;
+ try {
+ session.publish("test", "Hello World!");
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ });
+
+ System.out.println("\nPress enter to exit.");
+ bufferedReader.readLine();
+
+ session1.flush();
+ session1.stop();
+ session2.flush();
+ session2.stop();
+ System.exit(0);
+ }
+}
View
32 examples/nats/examples/QueueSub.java
@@ -0,0 +1,32 @@
+package nats.examples;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.Properties;
+import nats.Session;
+
+public class QueueSub {
+
+ public static void main(String[] args) throws Exception {
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
+ Session session = Session.connect(new Properties());
+ session.start();
+
+ System.out.println("Listening on : " + args[0]);
+ Properties opt = new Properties();
+ opt.setProperty("queue", "job.workers");
+ session.subscribe(args[0], opt, session.new EventHandler() {
+ public void execute(String msg) {
+ System.out.println("Received update : " + msg);
+ }
+ });
+
+ System.out.println("\nPress enter to exit.");
+ bufferedReader.readLine();
+
+ session.flush();
+ session.stop();
+
+ System.exit(0);
+ }
+}
View
6 examples/nats/examples/Request.java
@@ -12,7 +12,7 @@ public static void main(String[] args) throws Exception {
session.start();
System.out.println("Subscribing...");
- session.subscribe("help", session.new RequestEventHandler() {
+ session.subscribe("help", session.new EventHandler() {
public void execute(String request, String replyTo) {
try {
session.publish(replyTo, "I can help!");
@@ -24,8 +24,8 @@ public void execute(String request, String replyTo) {
System.out.println("Sending a request...");
Integer sid = session.request("help", session.new EventHandler() {
- public void execute(Object o) {
- System.out.println("Got a response for help : " + o);
+ public void execute(String response) {
+ System.out.println("Got a response for help : " + response);
System.exit(0);
}
});
View
4 examples/nats/examples/Sub.java
@@ -14,8 +14,8 @@ public static void main(String[] args) throws Exception {
System.out.println("Listening on : " + args[0]);
session.subscribe(args[0], session.new EventHandler() {
- public void execute(Object o) {
- System.out.println("Received update : " + (String)o);
+ public void execute(String msg) {
+ System.out.println("Received update : " + msg);
}
});
View
36 examples/nats/examples/SubTimeout.java
@@ -0,0 +1,36 @@
+package nats.examples;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.Properties;
+import nats.Session;
+
+public class SubTimeout {
+
+ public static void main(String[] args) throws Exception {
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
+ Session session = Session.connect(new Properties());
+ session.start();
+
+ System.out.println("Listening on : " + args[0]);
+ Integer sid = session.subscribe(args[0], session.new EventHandler() {
+ int received = 0;
+ public void execute() {
+ received++;
+ }
+ });
+ session.timeout(sid, 1, null, session.new EventHandler() {
+ public void execute(Object o) {
+ System.out.println("Timeout waiting for a message!");
+ }
+ });
+
+ System.out.println("\nPress enter to exit.");
+ bufferedReader.readLine();
+
+ session.flush();
+ session.stop();
+
+ System.exit(0);
+ }
+}
View
216 lib/nats/Session.java
@@ -21,7 +21,7 @@
public final class Session {
- public static final String version = "0.2.5";
+ public static final String version = "0.3";
public static final int DEFAULT_PORT = 4222;
public static final String DEFAULT_URI = "nats://localhost:" + Integer.toString(DEFAULT_PORT);
@@ -38,15 +38,6 @@
public static final int MAX_BUFFER_SIZE = 10 * 1024 * 1024;
- /* Protocol
- MSG = "MSG\\s+([^\\s\r\n]+)\\s+([^\\s\r\n]+)\\s+(([^\\s\r\n]+)[^\\S\r\n]+)?(\\d+)\r\n/i"
- OK = "+OK\\s*\r\n/i"
- ERR = "-ERR\\s+('.+')?\r\n/i"
- PING = "PING\r\n/i"
- PONG = "PONG\r\n/i"
- INFO = "INFO\\s+([^\r\n]+)\r\n/i"
- */
-
public static final String CR_LF = "\r\n";
public static final int CR_LF_LEN = CR_LF.length();
public static final String EMPTY = "";
@@ -70,12 +61,10 @@
public static final byte[] PONG_RESPONSE = ("PONG" + CR_LF).getBytes();
public static final int PONG_RESPONSE_LEN = PONG_RESPONSE.length;
- // Pedantic Mode support
- // public static final String Q_SUB = "/^([^\\.\\*>\\s]+|>$|\\*)(\\.([^\\.\\*>\\s]+|>$|\\*))*$/";
- // public static final String Q_SUB_NO_WC = "/^([^\\.\\*>\\s]+)(\\.([^\\.\\*>\\s]+))*$/";
-
private static int numSessions;
private static volatile int ssid;
+ private Session self;
+ private Session.EventHandler connectHandler;
private Selector selector;
private Session.SelectorThread selectorThread;
@@ -92,6 +81,8 @@
private int msgs_sent;
private int bytes_sent;
+ private int msgs_received;
+ private int bytes_received;
static {
ssid = 1;
@@ -123,11 +114,11 @@ public static Session connect(Properties popts) throws IOException, InterruptedE
if (System.getenv("NATS_MAX_RECONNECT_ATTEMPTS") != null) popts.put("max_reconnect_attempts", Integer.parseInt(System.getenv("NATS_MAX_RECONNECT_ATTEMPTS")));
if (System.getenv("NATS_MAX_RECONNECT_TIME_WAIT") != null) popts.put("max_reconnect_time_wait", Integer.parseInt(System.getenv("NATS_MAX_RECONNECT_TIME_WAIT")));
- Session session = new Session(popts);
- return session;
+ return new Session(popts);
}
private Session(Properties popts) throws IOException, InterruptedException {
+ self = this;
selector = SelectorProvider.provider().openSelector();
selectorThread = new SelectorThread();
sendBuffer = ByteBuffer.allocateDirect(MAX_BUFFER_SIZE);
@@ -151,8 +142,7 @@ private boolean connect() throws IOException {
channel.connect(addr);
channel.configureBlocking(false);
sKey = channel.register(selector, SelectionKey.OP_READ | SelectionKey.OP_WRITE);
- }
- catch(IOException ie) {
+ } catch(IOException ie) {
ie.printStackTrace();
return false;
}
@@ -185,7 +175,22 @@ public String createInbox()
* @throws InterruptedException
*/
public void start() throws IOException, InterruptedException {
+ start(null);
+ }
+
+ /**
+ * Establish a connection to the server and start a background thread for processing incoming and outgoing messages
+ * @param handler EventHanlder invoked when connection is established.
+ * @throws IOException
+ * @throws InterruptedException
+ */
+ public void start(EventHandler handler) throws IOException, InterruptedException {
+ if (handler != null) {
+ connectHandler = handler;
+ connectHandler.verifyArity();
+ }
selectorThread.start();
+
this.sendCommand("CONNECT {\"verbose\":" + ((Boolean)opts.get("verbose")).toString() + ",\"pedantic\":" + ((Boolean)opts.get("pedantic")) + "}" + CR_LF);
numSessions++;
}
@@ -197,8 +202,9 @@ public void start() throws IOException, InterruptedException {
public void stop() throws IOException {
channel.close();
numSessions--;
- if (numSessions == 0) selector.close();
+ selector.close();
selectorThread.interrupt();
+ timer.purge();
}
/**
@@ -220,6 +226,17 @@ public void publish(String subject, String msg) throws IOException {
}
/**
+ * Publish a message to the given subject.
+ * @param subject
+ * @param msg a message to be delivered to the server
+ * @param handler event handler is invoked when publish has been processed by the server.
+ * @throws IOException
+ */
+ public void publish(String subject, String msg, EventHandler handler) throws IOException {
+ publish(subject, null, msg, handler);
+ }
+
+ /**
* Publish a message to the given subject, with optional reply and event handler.
* @param subject
* @param opt_reply
@@ -284,21 +301,22 @@ public Integer subscribe(String subject, EventHandler handler) throws IOExceptio
*/
public Integer subscribe(String subject, Properties popts, EventHandler handler) throws IOException {
Integer sid = ssid++;
- Subscription sub = new Subscription(subject, handler);
+ Subscription sub = new Subscription(sid, subject, handler);
if (popts != null) {
sub.queue = (popts.getProperty("queue") == null ? " " : (String)popts.getProperty("queue"));
- sub.max = ((Integer)popts.get("max")).intValue();
+ sub.max = (popts.getProperty("max") == null ? -1 : Integer