public class SimEntityBaseA extends BasicSimEntity
Another implementation of SimEntity. This one follows the approach of SimEntityBase, but rather than requiring a naming convention for SimEvent-completion methods, annotations are used to map methods of any name to an event name.
The annotation type is SimEventMethod which must contain
one argument "<Name of the event>". This name establishes
the mapping, and is used along with the eventName property of a
SimEvent to find the appropriate method.
Methods are also referenced by signature. In a subclass, a method annotated with the same event name as a method in a superclass will override that method if the signature of the subclass method is the same as that superclass method. This is true even if the method names differ. For example:
class A extends SimEntityA {
...
@SimEventMethod("Arrival") public void foo(int x) { ...}
}
class B extends A {
...
@SimEventMethod("Arrival") public void bar(int x) { ...}
}
Will result in class B's bar method being called when it receives a SimEvent who's eventName is "Arrival" with an int argument. So, somewhat strangely, foo is effectively overridden by bar from the perspective of the EventList.
However, if the signature doesn't match, then both methods will be available in B.
class A extends SimEntityA {
...
@SimEventMethod("Arrival") public void foo() { ...}
}
class B extends A {
...
@SimEventMethod("Arrival") public void bar(int x) { ...}
}
In the above case foo or bar might be called for an arrival event on an instance of class B, depending on the argument. If there is no argument then foo is called, if there is an int argument then bar is called.
Currently, based on BasicSimEntity, so most of the SimEntityBase behaviors
operate the same. However many of the the added things in SimEntityBase are purposefully
omitted (like the debug property and some of the dump methods). You can
get a string description similar to the ones provided in SimEntityBase
with the method describeSimEventMethods()}. The debugging and
verbosity is replaced with our more recent practice of using the logging
package and setting logging levels to control such output.
| Modifier and Type | Field and Description |
|---|---|
private static java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.util.Map<java.lang.Class<?>[],java.lang.reflect.Method>>> |
eventMethodMap |
private boolean |
eventNamesProcessed |
private static java.util.logging.Logger |
LOGGER |
eventList, propertyDEFAULT_ENTITY_NAME, DEFAULT_EVENT_NAME, DEFAULT_PRIORITY, EVENT_METHOD_PREFIX, NL| Constructor and Description |
|---|
SimEntityBaseA() |
SimEntityBaseA(Priority priority) |
SimEntityBaseA(java.lang.String name) |
SimEntityBaseA(java.lang.String name,
Priority priority) |
| Modifier and Type | Method and Description |
|---|---|
private static boolean |
callableArgTypes(java.lang.Class<?>[] argTypesForMethod,
java.lang.Class<?>[] argTypesForCall)
As in SimEntityBase#isAssignableFrom(), compares two arrays that represent method
signatures to establish whether one signature is call-compatible with another.
|
java.lang.String |
describeSimEventMethods() |
void |
handleSimEvent(SimEvent event)
Typically an Event is handled (as opposed to processed, as in SimEventListener)
by actually executing a method.
|
boolean |
isReRunnable()
A BasicSimEntity is "ReRunnable" if it has a doRun method.
|
protected java.lang.reflect.Method |
lookupMethodForSimEvent(SimEvent event) |
protected void |
mapEventNames() |
void |
processSimEvent(SimEvent event)
Process the given SimEvent.
|
addPropertyChangeListener, addPropertyChangeListener, attemptSchedule, clearAddedProperty, compareTo, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAddedProperties, getEventList, getEventListID, getName, getPriority, getPropertiesString, getProperty, getProperty, getPropertyChangeListeners, getSerial, interrupt, interrupt, interruptAll, interruptAll, interruptAll, interruptAllWithArgs, interruptAllWithArgs, isClearAddedPropertiesOnReset, isJustDefinedProperties, isPersistant, isVerbose, parametersMatch, removePropertyChangeListener, removePropertyChangeListener, reset, resetNextSerial, setClearAddedPropertiesOnReset, setEventList, setEventListID, setJustDefinedProperties, setName, setPersistant, setPriority, setProperty, setVerbose, toString, waitDelay, waitDelay, waitDelay, waitDelayaddSimEventListener, getSimEventListeners, notifyListeners, removeSimEventListenerclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddSimEventListener, getSimEventListeners, notifyListeners, removeSimEventListenerprivate static final java.util.logging.Logger LOGGER
private boolean eventNamesProcessed
private static java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,java.util.Map<java.lang.Class<?>[],java.lang.reflect.Method>>> eventMethodMap
public SimEntityBaseA(java.lang.String name,
Priority priority)
public SimEntityBaseA()
public SimEntityBaseA(java.lang.String name)
public SimEntityBaseA(Priority priority)
protected void mapEventNames()
public void handleSimEvent(SimEvent event)
SimEventSchedulerhandleSimEvent in interface SimEventSchedulerhandleSimEvent in class BasicSimEntityevent - The SimEvent to be handled.public java.lang.String describeSimEventMethods()
protected java.lang.reflect.Method lookupMethodForSimEvent(SimEvent event)
public void processSimEvent(SimEvent event)
BasicSimEntityprocessSimEvent in interface SimEventListenerprocessSimEvent in class BasicSimEntityevent - The SimEvent to process.public boolean isReRunnable()
BasicSimEntityisReRunnable in interface ReRunnableisReRunnable in class BasicSimEntityprivate static boolean callableArgTypes(java.lang.Class<?>[] argTypesForMethod,
java.lang.Class<?>[] argTypesForCall)
Naming convention of isXXX is not used because this is not a property of this class, but a utility method.
argTypesForMethod - The argument types in the method definitionargTypesForCall - The argument types in the proposed method call