-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjbus.html
290 lines (265 loc) · 15.6 KB
/
jbus.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Dizitart | JBus</title>
<meta name="description" content="An event bus for java 1.6">
<meta name="keywords" content="Java, Android, EventBus, Open Source, Github">
<meta name="author" content="Anindya Chatterjee">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="all,follow">
<!-- Bootstrap-->
<link rel="stylesheet" href="css/bootstrap.min.css">
<!-- Google fonts - Open Sans-->
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:400,300,700,400italic">
<!-- Font Awesome CSS-->
<link rel="stylesheet" href="css/font-awesome.min.css">
<!-- owl carousel-->
<link rel="stylesheet" href="css/owl.carousel.css">
<link rel="stylesheet" href="css/owl.theme.css">
<!--Highlighter-->
<link rel="stylesheet" href="css/prism.css" data-noprefix>
<!-- theme stylesheet-->
<link rel="stylesheet" href="css/style.sea.css" id="theme-stylesheet">
<!-- Custom stylesheet - for your changes-->
<link rel="stylesheet" href="css/custom.css">
<!-- Favicon-->
<link rel="shortcut icon" href="favicon.png">
<!-- Tweaks for older IEs--><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script><![endif]-->
</head>
<body>
<div id="all">
<div class="container-fluid">
<div class="row row-offcanvas row-offcanvas-left">
<!-- *** SIDEBAR ***-->
<div id="sidebar" class="col-xs-6 col-sm-4 col-md-3 sidebar-offcanvas">
<div class="sidebar-content">
<a href="index.html">
<img src="img/logo.svg" class="logo-md">
</a>
<table class="table doc-details">
<thead>
<tr>
<th>RELEASE</th>
<th>DOCUMENTATION</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://github.com/dizitart/jbus/releases/tag/1.1">1.1</a> <span class="label label-success label-release xx-small-font">Current</span></td>
<td><a href="https://www.javadoc.io/doc/org.dizitart/jbus/1.1">API</a></td>
</tr>
<tr>
<td><a href="https://github.com/dizitart/jbus/releases/tag/1.0">1.0</a></td>
<td><a href="https://www.javadoc.io/doc/org.dizitart/jbus/1.0">API</a></td>
</tr>
</tbody>
</table>
<p class="sidebar-p">
<i class="fa fa-heart" aria-hidden="true" style="color: red"></i>
from Kolkata, India. </p>
<p class="social">
<a href="https://github.com/dizitart/jbus" data-animate-hover="pulse" class="external github"><i
class="fa fa-github"></i></a>
<a href="https://twitter.com/dizitart" data-animate-hover="pulse" class="external twitter"><i
class="fa fa-twitter"></i></a>
<a href="mailto:[email protected]?subject=JBus Query" data-animate-hover="pulse"
class="email"><i class="fa fa-envelope"></i></a></p>
<div class="copyright">
<p class="credit">© 2018 Dizitart | Template by <a
href="https://bootstrapious.com/tutorials" class="external">Bootstrapious</a></p>
<!-- Please do not remove the backlink to us, unless you support the development at https://bootstrapious.com/donate. It is part of the license conditions. Thanks for understanding :) -->
</div>
</div>
</div>
<!-- *** SIDEBAR END *** -->
<!-- *** DETAIL ***-->
<div class="col-xs-12 col-sm-8 col-md-9 content-column white-background">
<div class="small-navbar visible-xs">
<h1 class="small-navbar-heading"> <a href="index.html">Dizitart </a></h1>
</div>
<div class="github-badge hidden-xs">
<a href="https://github.com/dizitart/jbus">
<img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png">
</a>
</div>
<div class="row">
<div class="col-lg-10">
<div class="content-column-content">
<h1>
JBus
</h1>
<p class="lead">
An event bus for java 1.6+. It dispatches event to registered listeners.
It is a simple but powerful publish-subscribe event system. It requires object
to register themselves with the event bus to receive events. This event bus is
safe for concurrent use.
</p>
<div>
<pre>
<code class="language-xml">
<dependency>
<groupId>org.dizitart</groupId>
<artifactId>jbus</artifactId>
<version>1.1</version>
</dependency>
</code>
</pre>
<h5>It has:</h5>
<ul>
<li>Light-weight but powerful annotation based API</li>
<li>Support for synchronous/asynchronous invocation of subscriber method</li>
<li>Handler chain interruption</li>
<li>Custom error handling</li>
<li>Support for strong/weak references of subscriber</li>
<li>Support for subscriber inheritance</li>
<li>Zero configuration</li>
<li>Optional JVM shutdown hook for graceful shutdown</li>
</ul>
<p></p>
<h4>Usage</h4>
<pre>
<code class="language-java">
// define events
public class UserEvent {
/* Additional fields if required */
}
// create subscriber
public class Listener {
@Subscribe
private void listen(UserEvent event) {
/* Your event handling code goes here */
}
}
// register subscriber
JBus jbus = new JBus();
jbus.register(new Listener());
// or to register with weak reference use jbus.registerWeak(new Listener());
// post event
jbus.post(new UserEvent());
</code>
</pre>
</div>
<p></p>
<h4>Details</h4>
<p>
To receive events from event bus, an object must:
</p>
<ul>
<li>register itself with the event bus via <code>jbus.register(Object)</code> or <code>jbus.registerWeak(Object)</code> method</li>
<li>have at least one method marked with <code>@Subscribe</code> annotation in its class hierarchy</li>
<li>subscribed method should accept <b>only one parameter</b> having the type of the event</li>
</ul>
<p>
Registration will scan the input object for any method which has been marked with
<code>@Subscribe</code> annotation and it will keep track of all such methods found.
If the subscribing method has more than one parameter, runtime will throw a
<code>JBusException</code> during registration. A subscriber method can have any access
modifier. Registration will scan through full class hierarchy of the input object
including any super class and interfaces.
</p>
<p>
Upon successful registration, the runtime will keep track of all subscriber methods
found along with a strong reference of the input object for future invocation. To
store a weak reference of the input object instead of a strong one, use the
<code>jbus.registerWeak(Object)</code> variant.
</p>
<p>
A developer must use <code>jbus.deregister(Object)</code> for the object to stop
receiving events. The behavior of de-registration is not deterministic in the case
of weak registration of the object. As the runtime automatically cleans up any
invalid weak references and any subscriber methods associated with it as it goes,
so a call to <code>jbus.deregister(Object)</code> might not do anything if the object
has already been garbage collected and the event bus runtime has cleared up its
records of subscriber methods already.
</p>
<p>
To post an event to the event bus, simply call <code>jbus.post(Object)</code> passing
the event object. Event bus will automatically route the event depending on its type
to a handler chain. Handler chain is a collection of registered subscribers of the
event. By design, event bus does not support inheritance for the event object.
</p>
<p>
If an event implements <code>HandlerChainAware</code> interface then before each
invocation, the runtime will check if an interruption has been signalled from the
subscriber code via HandlerChain.interrupt() call. If interrupted, further
invocation of the handler chain will be barred until the next <code>jbus.post(Object)</code>
call for the event.
</p>
<p>
Subscriber execution mode can be either synchronous or asynchronous depending on the
<code>@Subscribe</code> annotation declaration.
</p>
<p>
In case of any error from subscriber code during invocation, the runtime will first
search for any <code>ExceptionEvent</code> handler registered into the system and
dispatch the error along with relevant information in <code>ExceptionContext</code> to
the handler if found. If no such error handler is found, runtime will just log the
error and move on.
</p>
</div>
</div>
</div>
<div class="small-navbar visible-xs">
<table class="table doc-details">
<thead>
<tr>
<th>RELEASE</th>
<th>DOCUMENTATION</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://github.com/dizitart/jbus/releases/tag/1.1">1.1</a> <span class="label label-success label-release xx-small-font">Current</span></td>
<td><a href="https://www.javadoc.io/doc/org.dizitart/jbus/1.1">API</a></td>
</tr>
<tr>
<td><a href="https://github.com/dizitart/jbus/releases/tag/1.0">1.0</a></td>
<td><a href="https://www.javadoc.io/doc/org.dizitart/jbus/1.0">API</a></td>
</tr>
</tbody>
</table>
<p class="sidebar-p">
<i class="fa fa-heart" aria-hidden="true" style="color: red"></i>
from Kolkata, India. </p>
<p class="social">
<a href="https://github.com/dizitart/jbus" data-animate-hover="pulse" class="external github"><i
class="fa fa-github"></i></a>
<a href="https://twitter.com/dizitart" data-animate-hover="pulse" class="external twitter"><i
class="fa fa-twitter"></i></a>
<a href="mailto:[email protected]?subject=JBus Query" data-animate-hover="pulse"
class="email"><i class="fa fa-envelope"></i></a></p>
<div class="copyright">
<p class="credit">© 2018 Dizitart | Template by <a
href="https://bootstrapious.com/tutorials" class="external">Bootstrapious</a></p>
<!-- Please do not remove the backlink to us, unless you support the development at https://bootstrapious.com/donate. It is part of the license conditions. Thanks for understanding :) -->
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Javascript files-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.cookie.js"></script>
<script src="js/ekko-lightbox.js"></script>
<script src="js/jquery.scrollTo.min.js"></script>
<script src="js/masonry.pkgd.min.js"></script>
<script src="js/imagesloaded.pkgd.min.js"></script>
<script src="js/owl.carousel.min.js"></script>
<script src="js/front.js"></script>
<script src="js/prism.js"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-98024264-1', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>