com.github.nkzawa.emitter
Class Emitter

java.lang.Object
  extended by com.github.nkzawa.emitter.Emitter
Direct Known Subclasses:
PollingXHR.Request, Socket, Transport

public class Emitter
extends Object

The event emitter which is ported from the JavaScript module. This class is thread-safe.

See Also:
https://github.com/component/emitter

Nested Class Summary
static interface Emitter.Listener
           
 
Constructor Summary
Emitter()
           
 
Method Summary
 Emitter emit(String event, Object... args)
          Executes each of listeners with the given args.
 boolean hasListeners(String event)
          Check if this emitter has listeners for the specified event.
 List<Emitter.Listener> listeners(String event)
          Returns a list of listeners for the specified event.
 Emitter off()
          Removes all registered listeners.
 Emitter off(String event)
          Removes all listeners of the specified event.
 Emitter off(String event, Emitter.Listener fn)
          Removes the listener.
 Emitter on(String event, Emitter.Listener fn)
          Listens on the event.
 Emitter once(String event, Emitter.Listener fn)
          Adds a one time listener for the event.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Emitter

public Emitter()
Method Detail

on

public Emitter on(String event,
                  Emitter.Listener fn)
Listens on the event.

Parameters:
event - event name.
fn -
Returns:
a reference to this object.

once

public Emitter once(String event,
                    Emitter.Listener fn)
Adds a one time listener for the event.

Parameters:
event - an event name.
fn -
Returns:
a reference to this object.

off

public Emitter off()
Removes all registered listeners.

Returns:
a reference to this object.

off

public Emitter off(String event)
Removes all listeners of the specified event.

Parameters:
event - an event name.
Returns:
a reference to this object.

off

public Emitter off(String event,
                   Emitter.Listener fn)
Removes the listener.

Parameters:
event - an event name.
fn -
Returns:
a reference to this object.

emit

public Emitter emit(String event,
                    Object... args)
Executes each of listeners with the given args.

Parameters:
event - an event name.
args -
Returns:
a reference to this object.

listeners

public List<Emitter.Listener> listeners(String event)
Returns a list of listeners for the specified event.

Parameters:
event - an event name.
Returns:
a reference to this object.

hasListeners

public boolean hasListeners(String event)
Check if this emitter has listeners for the specified event.

Parameters:
event - an event name.
Returns:
a reference to this object.


Copyright © 2014. All rights reserved.