Class CardTerminals
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().
- Since:
- 1.6
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration of attributes of a CardTerminal. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetTerminal(String name) Returns the terminal with the specified name or null if no such terminal exists.list()Returns an unmodifiable list of all available terminals.abstract List<CardTerminal> list(CardTerminals.State state) Returns an unmodifiable list of all terminals matching the specified state.voidWaits for card insertion or removal in any of the terminals of this object.abstract booleanwaitForChange(long timeout) Waits for card insertion or removal in any of the terminals of this object or until the timeout expires.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.booleanCompares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.May cause performance issues, deadlocks and hangs.getClass()Answers the unique instance of java.lang.Class which represents the class of the receiver.inthashCode()Answers an integer hash code for the receiver.final voidnotify()Causes one thread which iswaiting on the receiver to be made ready to run.final voidCauses all threads which arewaiting on the receiver to be made ready to run.toString()Answers a string containing a concise, human-readable description of the receiver.final voidwait()Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated bynotifyornotifyAll).final voidwait(long time) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.final voidwait(long time, int frac) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.
-
Constructor Details
-
CardTerminals
protected CardTerminals()Constructs a new CardTerminals object.This constructor is called by subclasses only. Application should call TerminalFactory.terminals() to obtain a CardTerminals object.
-
-
Method Details
-
list
Returns an unmodifiable list of all available terminals.- Returns:
- an unmodifiable list of all available terminals.
- Throws:
CardException- if the card operation failed
-
list
Returns an unmodifiable list of all terminals matching the specified state.If state is
State.ALL, this method returns all CardTerminals encapsulated by this object. If state isState.CARD_PRESENTorState.CARD_ABSENT, it returns all CardTerminals where a card is currently present or absent, respectively.If state is
State.CARD_INSERTIONorState.CARD_REMOVAL, it returns all CardTerminals for which an insertion (or removal, respectively) was detected during the last call to waitForChange(). IfwaitForChange()has not been called on this object,CARD_INSERTIONis equivalent toCARD_PRESENTandCARD_REMOVALis equivalent toCARD_ABSENT. For an example of the use ofCARD_INSERTION, seewaitForChange().- Parameters:
state- the State- Returns:
- an unmodifiable list of all terminals matching the specified state.
- Throws:
NullPointerException- if state is nullCardException- if the card operation failed
-
getTerminal
Returns the terminal with the specified name or null if no such terminal exists.- Parameters:
name- the terminal name- Returns:
- the terminal with the specified name or null if no such terminal exists.
- Throws:
NullPointerException- if name is null
-
waitForChange
Waits for card insertion or removal in any of the terminals of this object.This call is equivalent to calling waitForChange(0).
- Throws:
IllegalStateException- if thisCardTerminalsobject does not contain any terminalsCardException- if the card operation failed
-
waitForChange
Waits for card insertion or removal in any of the terminals of this object or until the timeout expires.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 towaitForChange()on this object, it blocks until a card is inserted into or removed from a CardTerminal.If
timeoutis greater than 0, the method returns aftertimeoutmilliseconds even if there is no change in state. In that case, this method returnsfalse; otherwise it returnstrue.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(); }- Parameters:
timeout- if positive, block for up totimeoutmilliseconds; if zero, block indefinitely; must not be negative- Returns:
- false if the method returns due to an expired timeout, true otherwise.
- Throws:
IllegalStateException- if thisCardTerminalsobject does not contain any terminalsIllegalArgumentException- if timeout is negativeCardException- if the card operation failed
-