public final class EClient extends WeakReference<EObject> implements Comparable<EClient>
EClient ties together eBus message routing and message
processing. eBus views an application instance in three ways:
1) an implementation of one or more eBus interfaces
(publisher, subscriber, requester, or replier), 2) the owner
of open feeds and 3) the target of callback
tasks. EClient stores the instance's
open feeds and un-executed callback tasks.
eBus has a client-oriented execution mode rather than
task-oriented. When the client's task list is not empty, the
EClient instance is placed on a run queue where it
appears only once. RQThread threads remove
clients from this run queue and execute the client's tasks.
The Dispatcher continues executing the client's
tasks until the client task queue or run quantum is exhausted.
When the nanosecond run quantum reaches zero, the client is
appended to the run queue if it has pending tasks.
The run quantum reset to the configurable initial quantum
value when a dispatcher thread acquires the client. Note: when
the run quantum expires, eBus cannot preempt the client. It is
possible for the client to run indefinitely, taking over the
Dispatcher thread.
EClient maintains a weak reference to the application
instance. When eBus detects that the application instance is
finalized, all feeds left open by the instance are closed. If
the application instance is a replier, then all active
requests will receive an error reply. The client's un-executed
tasks are cleared.
EClient maintains one or more RQThread
groups where each group has a separate run queue. Each client
is assigned to an executor group based on the encapsulated
application class. If the application class is not assigned to
a particular executor group, then the class is assigned to the
default executor group. The executor groups are defined via
configuration. If no executors are defined,
then there is one Dispatcher thread for each
core using a single,
blocking run queue. Executors block until there is an runnable
EClient posted to group run queue. As stated
previously, an EClient is assigned to only one client
dispatcher thread at a time. This makes an EClient
instance effectively single-threaded if that client
is accessed only by dispatcher threads. While a client may be
accessed by different dispatcher threads over time, it will be
accessed by only one at any given moment in time.
Each EClient is assigned a integer identifier which is
guaranteed unique for the client lifespan. When the client
is disposed, the client identifier is re-used and may be
assigned to a new, future eBus client instance. An
EClient is disposed when the encapsulated application
instance is finalized.
The reason for EClient is because eBus requires
application objects to implement interfaces in order
to interface with eBus, not extend an
eBus abstract class. This class provides the functionality
that an abstract client class would provide.
EFeed,
ESubject| Modifier and Type | Class and Description |
|---|---|
static class |
EClient.ClientLocation
An eBus client is either local to this JVM or in a remote
JVM.
|
| Modifier and Type | Method and Description |
|---|---|
int |
clientId()
Returns the unique eBus client identifier.
|
int |
compareTo(EClient client)
Returns an integer value <, equal to, or > zero
based on whether
this EClient instance's
identifier is <, equal to, or > client's
identifier. |
static void |
dispatch(Runnable task,
EObject client)
Posts
task to client's task queue (this is
the same task queue used for eBus message delivery). |
boolean |
equals(Object o)
Returns
true if o is a
non-null EClient instance with the same client
identifier as this instance; otherwise, returns
false. |
static EClient |
findOrCreateClient(EObject client,
EClient.ClientLocation location)
Returns the eBus proxy for the given eBus client instance.
|
int |
hashCode()
Returns the unique client identifier as the hash code.
|
EClient.ClientLocation |
location()
Returns the client location.
|
EObject |
target()
Returns the target client.
|
String |
toString() |
clear, enqueue, get, isEnqueuedpublic int compareTo(EClient client)
this EClient instance's
identifier is <, equal to, or > client's
identifier.compareTo in interface Comparable<EClient>client - comparison object.public boolean equals(Object o)
true if o is a
non-null EClient instance with the same client
identifier as this instance; otherwise, returns
false.public int hashCode()
public EObject target()
null if the
target client is finalized.public int clientId()
public EClient.ClientLocation location()
public static EClient findOrCreateClient(EObject client, EClient.ClientLocation location)
client - the eBus client.location - EClient.ClientLocation.LOCAL if the client
is local to this JVM and EClient.ClientLocation.REMOTE if
it exists in a remote eBus application.public static void dispatch(Runnable task, EObject client)
task to client's task queue (this is
the same task queue used for eBus message delivery). If
the task queue was originally empty, then the client
posted to its run queue for execution by a
RQThread.
If client is unknown to eBus, then a new
EClient instance will be created with a
weak reference to client.
client does not need to be an eBus
publisher/ subscriber/requestor/replier.
task - post to the client task queue.client - task is for this client.NullPointerException - if either task or client is null.Copyright © 2019. All rights reserved.