public class Happening extends AsyncEvent implements ActiveEvent<Happening,HappeningDispatcher>
Happenings
can be identified by an application-provided name
or a system-provided id
, both of which must be unique. A
system Happening
has a name provided by the system which
is a string beginning with @
.Constructor and Description |
---|
Happening(java.lang.String name)
Creates a happening with the given
name and the default dispatcher. |
Happening(java.lang.String name,
HappeningDispatcher dispatcher)
Creates a happening with the given name.
|
Modifier and Type | Method and Description |
---|---|
void |
addHandler(AsyncBaseEventHandler handler)
Adds a handler to the set of handlers associated with this event.
|
static int |
createId(java.lang.String name)
Sets up a mapping between a
name and a system-dependent ID. |
void |
disable()
Changes the state of the event so that associated handlers are
skipped on fire.
|
void |
enable()
Changes the state of the event so that associated handlers are
released on fire.
|
static Happening |
get(int id)
Gets the external event corresponding to a given
id . |
static Happening |
get(java.lang.String name)
Gets the external event corresponding to a given name.
|
HappeningDispatcher |
getDispatcher()
Obtain the current dispatcher for this event.
|
static Happening |
getHappening(java.lang.String name)
Finds an active happening by its name.
|
int |
getId()
Gets the number of this happening.
|
static int |
getId(java.lang.String name)
Obtains the ID of
name , when one exists or
-1, when name is not registered. |
java.lang.String |
getName()
Gets the name of this happening.
|
boolean |
isActive()
Determines the activation state of this happening,
i.e., if it has been started.
|
static boolean |
isHappening(java.lang.String name)
Determines whether or not there is an active happening with
name
given as parameter. |
boolean |
isRunning()
Determines whether or not this
happening is both active an enabled. |
void |
removeHandler(AsyncBaseEventHandler handler)
Removes a handler from the set associated with this event.
|
HappeningDispatcher |
setDispatcher(HappeningDispatcher dispatcher)
Change the current dispatcher for this event.
|
void |
setHandler(AsyncBaseEventHandler handler)
Associates a new handler with this event and removes all existing
handlers.
|
void |
start()
Starts this
happening , i.e., changes its state to the active and enabled. |
void |
start(boolean disabled)
Starts this
happening , but leaves it in the disabled state. |
boolean |
stop()
Stops this
happening from responding to the fire
and trigger methods. |
void |
trigger()
Causes the event dispatcher associated with
this
to be scheduled for execution. |
static boolean |
trigger(int id)
Causes the event dispatcher corresponding to
happeningId
to be scheduled for execution. |
addHandler, bindTo, fire, handledBy, removeHandler, setHandler, unbindTo
createReleaseParameters, handledBy, hasHandlers
public Happening(java.lang.String name, HappeningDispatcher dispatcher) throws StaticIllegalArgumentException
name
- A string to name the happening.dispatcher
- To use when being triggered.StaticIllegalArgumentException
- when
name
is null
or does not match the pattern
full identifier naming convention, i.e., package plus
name
. An implementation may throw this exception for
all names starting with java. and javax.public Happening(java.lang.String name) throws StaticIllegalArgumentException
name
and the default dispatcher.name
- A string to name the happening.StaticIllegalArgumentException
- when
name
is null
or does not match the pattern full
type naming convention, i.e., package plus name
.
An implementation may throw this exception for all names
starting with java. and javax.public static Happening getHappening(java.lang.String name)
name
- Identifies the happening to get.name
,
or null
, if no happening with the given name is found.StaticIllegalArgumentException
- when
name
is null
.public static boolean isHappening(java.lang.String name)
name
given as parameter.name
- A string that might name an active happening.true
only when there is a registered happening with the
given name
.StaticIllegalArgumentException
- when
name
is null
.public static int createId(java.lang.String name) throws StaticIllegalStateException
name
and a system-dependent ID.
This can be called either in native code that
sets up an interrupt service routine to link it with a
happening
. Once created, it cannot be removed.
This must take no more than linear time in the number of ID
(n
) registered, but should be O(log2(n))
.
name
- A string to name a happening.StaticIllegalStateException
- when
name
is already registered.StaticIllegalArgumentException
- when
name
is null
.public static int getId(java.lang.String name)
name
, when one exists or
-1, when name
is not registered.
This must take no more than linear time in the number of ID
(n
) registered, but should be O(log2(n))
.
name
- A happening name string.StaticIllegalArgumentException
- when
name
is null
.public static Happening get(int id)
id
.id
- The identifier of a registered signal.id
.public static Happening get(java.lang.String name)
name
- The name of a registered signal.name
.StaticIllegalArgumentException
- when
name
is null
.public static boolean trigger(int id)
happeningId
to be scheduled for execution. The implementation should be simple enough
so that it can be done in the context of an
interrupt service routine.
trigger()
and any native code analog to it interact
with other ActiveEvent
code effectively as
if trigger()
signals a POSIX counting semaphore that the
happening is waiting on.
The implementation is encouraged to create (and document) a native code analog to this method that can be used without a Java context.
This method must execute in constant time.
id
- Identifies which happening to trigger.true
when a happening with ID happeningId
was found, false
otherwise.public final int getId()
public java.lang.String getName()
public boolean isActive()
isActive
in interface ActiveEvent<Happening,HappeningDispatcher>
true
when active; false
otherwise.public boolean isRunning()
happening
is both active an enabled.isRunning
in interface ActiveEvent<Happening,HappeningDispatcher>
isRunning
in class AsyncBaseEvent
true
when this happening
is both active and
enabled; false
otherwise.public void enable()
AsyncBaseEvent
enable
in interface ActiveEvent<Happening,HappeningDispatcher>
enable
in class AsyncBaseEvent
public void disable()
AsyncBaseEvent
disable
in interface ActiveEvent<Happening,HappeningDispatcher>
disable
in class AsyncBaseEvent
public void start() throws StaticIllegalStateException
happening
, i.e., changes its state to the active and enabled.
Once a happening is started for the first time, when it is in a scoped
memory it increments the scope count of that scope; otherwise, it becomes
a member of the root set. An active and enabled happening dispatches its
handlers when fired.start
in interface ActiveEvent<Happening,HappeningDispatcher>
StaticIllegalStateException
- when this
happening
has already been started or its
name
is already in use by another happening that has
been started.stop()
public void start(boolean disabled) throws StaticIllegalStateException
happening
, but leaves it in the disabled state.
When fired before being enabled, it does not dispatch its handlers.start
in interface ActiveEvent<Happening,HappeningDispatcher>
disabled
- true for starting in a disabled state.StaticIllegalStateException
- when this
happening
has already been started.stop()
public boolean stop() throws StaticIllegalStateException
happening
from responding to the fire
and trigger
methods.stop
in interface ActiveEvent<Happening,HappeningDispatcher>
true
when this
is in the
enabled state; false
otherwise.StaticIllegalStateException
- when this
happening
is not active.public void trigger()
this
to be scheduled for execution. The implementation should be simple
enough so that it can be done in the context of an
interrupt service routine.
This method must execute in constant time.
public HappeningDispatcher getDispatcher()
ActiveEvent
getDispatcher
in interface ActiveEvent<Happening,HappeningDispatcher>
getDispatcher
in interface Releasable<Happening,HappeningDispatcher>
public HappeningDispatcher setDispatcher(HappeningDispatcher dispatcher)
ActiveEvent
dispatcher
is null
, the default dispatcher is restored.setDispatcher
in interface ActiveEvent<Happening,HappeningDispatcher>
public void addHandler(AsyncBaseEventHandler handler)
AsyncBaseEvent
may have more than one
associated handler. However, adding a handler to an event has no
effect when the handler is already attached to the event.
The execution of this method is atomic with respect to the execution of the
fire()
method.
Note that there is an implicit reference to the handler stored in
this
. The assignment must be valid under any applicable memory
assignment rules.
addHandler
in class AsyncBaseEvent
handler
- The new handler to add to the list of handlers already
associated with this.
When handler
is already associated with
the event, the call has no effect.public void setHandler(AsyncBaseEventHandler handler)
fire()
method.setHandler
in class AsyncBaseEvent
handler
- The instance of AsyncBaseEventHandler
to be
associated with this
. When handler
is
null
then no handler will be associated with this
,
i.e., it behaves effectively as if setHandler(null)
invokes AsyncBaseEvent.removeHandler(AsyncBaseEventHandler)
for each
associated handler.public void removeHandler(AsyncBaseEventHandler handler)
fire()
method.
A removed handler continues to execute until its fireCount becomes zero and it completes.
When handler
has a scoped non-default initial memory area and
execution of this method causes handler
to become
unfirable, this method shall not return until all related finalization
has completed.
removeHandler
in class AsyncBaseEvent
handler
- The handler to be disassociated from this
. When
null
nothing happens.
When the handler
is not already associated with
this
then nothing happens.