public abstract class CardTerminals extends Object
This class is multi-threading safe and can be used by multiple threads concurrently. However, this object keeps track of the card presence state of each of its terminals. Multiple objects should be used if independent calls to waitForChange() are required.
Applications can obtain instances of this class by calling TerminalFactory.terminals().
Modifier and Type | Class | Description |
---|---|---|
static enum |
CardTerminals.State |
Enumeration of attributes of a CardTerminal. |
Modifier | Constructor | Description |
---|---|---|
protected |
Constructs a new CardTerminals object. |
Modifier and Type | Method | Description |
---|---|---|
CardTerminal |
getTerminal |
Returns the terminal with the specified name or null if no such terminal exists. |
List |
list() |
Returns an unmodifiable list of all available terminals. |
abstract List |
list |
Returns an unmodifiable list of all terminals matching the specified state. |
void |
waitForChange() |
Waits for card insertion or removal in any of the terminals of this object. |
abstract boolean |
waitForChange |
Waits for card insertion or removal in any of the terminals of this object or until the timeout expires. |
protected CardTerminals()
This constructor is called by subclasses only. Application should call TerminalFactory.terminals() to obtain a CardTerminals object.
public List<CardTerminal> list() throws CardException
CardException
- if the card operation failedpublic abstract List<CardTerminal> list(CardTerminals.State state) throws CardException
If state is State.ALL
, this method returns all CardTerminals encapsulated by this object. If state is State.CARD_PRESENT
or State.CARD_ABSENT
, it returns all CardTerminals where a card is currently present or absent, respectively.
If state is State.CARD_INSERTION
or State.CARD_REMOVAL
, it returns all CardTerminals for which an insertion (or removal, respectively) was detected during the last call to waitForChange(). If waitForChange()
has not been called on this object, CARD_INSERTION
is equivalent to CARD_PRESENT
and CARD_REMOVAL
is equivalent to CARD_ABSENT
. For an example of the use of CARD_INSERTION
, see waitForChange()
.
state
- the StateNullPointerException
- if state is nullCardException
- if the card operation failedpublic CardTerminal getTerminal(String name)
name
- the terminal nameNullPointerException
- if name is nullpublic void waitForChange() throws CardException
This call is equivalent to calling waitForChange(0).
IllegalStateException
- if this CardTerminals
object does not contain any terminalsCardException
- if the card operation failedpublic abstract boolean waitForChange(long timeout) throws CardException
This method examines each CardTerminal of this object. If a card was inserted into or removed from a CardTerminal since the previous call to waitForChange()
, it returns immediately. Otherwise, or if this is the first call to waitForChange()
on this object, it blocks until a card is inserted into or removed from a CardTerminal.
If timeout
is greater than 0, the method returns after timeout
milliseconds even if there is no change in state. In that case, this method returns false
; otherwise it returns true
.
This method is often used in a loop in combination with list(State.CARD_INSERTION)
, for example:
TerminalFactory factory = ...; CardTerminals terminals = factory.terminals(); while (true) { for (CardTerminal terminal : terminals.list(CARD_INSERTION)) { // examine Card in terminal, return if it matches } terminals.waitForChange(); }
timeout
- if positive, block for up to timeout
milliseconds; if zero, block indefinitely; must not be negativeIllegalStateException
- if this CardTerminals
object does not contain any terminalsIllegalArgumentException
- if timeout is negativeCardException
- if the card operation failed
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/java.smartcardio/javax/smartcardio/CardTerminals.html