public abstract class AbstractObservableLocalReader extends AbstractLocalReader implements ObservableReaderNotifier
AbstractLocalReader to manage the observation of card events.
It provides the means to configure the reader's behavior when a card is detected.
The event management implements a ObservableReaderStateService state machine that is composed of four states.
Infinitely waiting for a signal from the application to start card detection by changing to WAIT_FOR_SE_INSERTION state. This signal is given by calling the setDefaultSelectionRequest method.
Note: The system always starts in the WAIT_FOR_START_DETECTION state.
Awaiting the card insertion. After insertion, the processCardInserted method is called.
A number of cases arise:
In the case where an event has been notified to the application, the state machine changes to the WAIT_FOR_SE_PROCESSING state otherwise it remains in the WAIT_FOR_SE_INSERTION state.
The notification consists in calling the "update" methods of the defined observers. In the case where several observers have been defined, it is up to the application developer to ensure that there is no long processing in these methods, by making their execution asynchronous for example.
Waiting for the end of processing by the application. The end signal is triggered by a transmission made with a CLOSE_AFTER parameter.
If the instruction given when defining the default selection request is to stop (ObservableReader.PollingMode.SINGLESHOT) then the logical and physical channels are closed immediately and the machine state changes to WAIT_FOR_START_DETECTION state.
If the instruction given is continue (ObservableReader.PollingMode.REPEATING) then the state machine changes to WAIT_FOR_SE_REMOVAL.
Waiting for the card to be removed. When the card is removed, a CARD_REMOVED event is notified to the application and the state machine changes to the WAIT_FOR_SE_INSERTION or WAIT_FOR_START_DETECTION state according the polling mode (ObservableReader.PollingMode).
| Modifier and Type | Class and Description |
|---|---|
static class |
AbstractObservableLocalReader.InternalEvent
Internal events
|
ObservableReader.NotificationMode, ObservableReader.PollingMode, ObservableReader.ReaderObserver| Modifier and Type | Field and Description |
|---|---|
protected org.eclipse.keyple.core.plugin.ObservableReaderStateService |
stateService |
isRegistered| Modifier | Constructor and Description |
|---|---|
protected |
AbstractObservableLocalReader(java.lang.String pluginName,
java.lang.String readerName)
(protected)
Constructor. |
| Modifier and Type | Method and Description |
|---|---|
void |
addObserver(ObservableReader.ReaderObserver observer)
Add a
ObservableReader.ReaderObserver. |
void |
clearObservers()
Remove all observers at once
|
int |
countObservers()
Gets the number of observers.
|
void |
finalizeCardProcessing()
Terminates the processing of the card, in particular after an interruption by exception
Do nothing if the channel is already closed. Channel closing is nominally managed by using the ChannelControl.CLOSE_AFTER flag
during the last transmission with the card. |
protected abstract ReaderObservationExceptionHandler |
getObservationExceptionHandler()
Allows to call the defined handler when an exception condition needs to be transmitted to the
application level.
|
boolean |
isCardPresent()
Check the presence of a card
|
void |
notifyObservers(ReaderEvent event)
Notify all registered observers with the provided
ReaderEvent |
protected abstract void |
onStartDetection()
Method called when the card detection is started by the Keyple Plugin
|
protected abstract void |
onStopDetection()
Method called when the card detection is stopped by the Keyple Plugin
|
void |
removeObserver(ObservableReader.ReaderObserver observer)
Remove a
ObservableReader.ReaderObserver. |
void |
setDefaultSelectionRequest(AbstractDefaultSelectionsRequest defaultSelectionsRequest,
ObservableReader.NotificationMode notificationMode)
If defined, the prepared DefaultSelectionRequest will be processed as soon as a card is
inserted.
|
void |
setDefaultSelectionRequest(AbstractDefaultSelectionsRequest defaultSelectionsRequest,
ObservableReader.NotificationMode notificationMode,
ObservableReader.PollingMode pollingMode)
A combination of defining the default selection request and starting the card detection.
|
void |
startCardDetection(ObservableReader.PollingMode pollingMode)
Starts the card detection.
|
void |
stopCardDetection()
Stops the card detection.
|
protected void |
unregister()
(package-private)
Change the reader status to unregistered |
activateProtocol, activateReaderProtocol, checkCardPresence, closePhysicalChannel, deactivateProtocol, deactivateReaderProtocol, getATR, isCurrentProtocol, isPhysicalChannelOpen, openPhysicalChannel, processCardRequest, processCardSelectionRequests, releaseChannel, transmitApdugetName, getPluginName, transmitCardRequest, transmitCardSelectionRequestsclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitactivateProtocol, deactivateProtocol, getName, isContactlessprotected final org.eclipse.keyple.core.plugin.ObservableReaderStateService stateService
protected AbstractObservableLocalReader(java.lang.String pluginName,
java.lang.String readerName)
Force the definition of a name through the use of super method.
Initialize the ObservableReaderStateService with the possible states and their implementation. ObservableReaderStateService define the initial state.
pluginName - the name of the plugin that instantiated the readerreaderName - the name of the readerprotected abstract void onStartDetection()
protected abstract void onStopDetection()
public final void addObserver(ObservableReader.ReaderObserver observer)
ObservableReader.ReaderObserver.
The observer will receive all the events produced by this reader (card insertion, removal, etc.)
addObserver in interface ObservableReaderobserver - the observer objectjava.lang.IllegalStateException - If observer is null or no PluginObservationExceptionHandler has been set.public final void removeObserver(ObservableReader.ReaderObserver observer)
ObservableReader.ReaderObserver.
The observer will do not receive any of the events produced by this reader.
removeObserver in interface ObservableReaderobserver - the observer objectpublic final void notifyObservers(ReaderEvent event)
ReaderEventnotifyObservers in interface ObservableReaderNotifierevent - the reader eventpublic final int countObservers()
countObservers in interface ObservableReaderpublic final void clearObservers()
clearObservers in interface ObservableReaderpublic final boolean isCardPresent()
This method is recommended for non-observable readers.
When the card is not present the logical and physical channels status may be refreshed through a call to the processCardRemoved method.
isCardPresent in interface ReaderisCardPresent in class AbstractLocalReaderKeypleReaderIOException - if the communication with the reader or the card has failedjava.lang.IllegalStateException - is called when reader is no longer registeredpublic final void startCardDetection(ObservableReader.PollingMode pollingMode)
This method must be overloaded by readers depending on the particularity of their management of the start of the card detection.
Note: they must call the super method with the argument PollingMode.
startCardDetection in interface ObservableReaderpollingMode - indicates the action to be followed after processing the card: if REPEATING,
the card detection is restarted, if SINGLESHOT, the card detection is stopped until a new
call to startCardDetection is made.public final void stopCardDetection()
This method must be overloaded by readers depending on the particularity of their management of the start of card detection.
stopCardDetection in interface ObservableReaderpublic final void setDefaultSelectionRequest(AbstractDefaultSelectionsRequest defaultSelectionsRequest, ObservableReader.NotificationMode notificationMode)
If it is not defined (set to null), a simple card detection will be notified in the end.
Depending on the notification mode, the observer will be notified whenever a card is inserted, regardless of the selection status, or only if the current card matches the selection criteria.
setDefaultSelectionRequest in interface ObservableReaderdefaultSelectionsRequest - the AbstractDefaultSelectionsRequest to be executed
when a card is insertednotificationMode - the notification mode enum (ALWAYS or MATCHED_ONLY)public final void setDefaultSelectionRequest(AbstractDefaultSelectionsRequest defaultSelectionsRequest, ObservableReader.NotificationMode notificationMode, ObservableReader.PollingMode pollingMode)
setDefaultSelectionRequest in interface ObservableReaderdefaultSelectionsRequest - the selection request to be operatednotificationMode - indicates whether a CARD_INSERTED event should be notified even if the
selection has failed (ALWAYS) or whether the card insertion should be ignored in this case
(MATCHED_ONLY).pollingMode - indicates the action to be followed after processing the card: if CONTINUE,
the card detection is restarted, if STOP, the card detection is stopped until a new call to
startCardDetection is made.public final void finalizeCardProcessing()
ChannelControl.CLOSE_AFTER flag
during the last transmission with the card. However, there are cases where exchanges with the
card are interrupted by an exception, in which case it is necessary to explicitly close the
channel using this method.finalizeCardProcessing in interface ObservableReaderprotected void unregister()
This method may be overridden in order to meet specific needs in certain implementations of readers.
Notifies all observers of the UNREGISTERED event.
Stops the card detection unconditionally.
Shuts down the reader's executor service.
protected abstract ReaderObservationExceptionHandler getObservationExceptionHandler()
PluginObservationExceptionHandler interface.