Package de.gmxhome.conrad.jpos.jpos_base
Class JposOutputRequest
java.lang.Object
de.gmxhome.conrad.jpos.jpos_base.JposOutputRequest
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
ChangeRequest
,DirectIO
,DispenseCash
,DispenseChange
,DisplayText
,EraseMedium
,GoURLBack
,GoURLForward
,InitializeMedium
,JposInputRequest
,LoadImage
,LoadURL
,OutputRequest
,OutputRequest
,OutputRequest
,OutputRequest
,PlaySound
,PlayVideo
,PrintContent
,PrintContentFile
,PrintWrite
,RFIDRequest
,SetPosition
,SetSpeed
,Sound
,Speak
,StartMotion
,StartPose
,UnitOutputRequest
,UpdateFirmware
,UpdateURLPage
,WriteData
Class to invoke a method asynchronously. Contains all method parameters, a JposDevice
object and a property set as
properties and an invoke method that calls the corresponding method.
For each method that can be invoked asynchronously, one class must be derived that overwrites the invoke method.
To abort a command, call method abortCommand from a different thread. Method abortCommand sets the Abort SyncObject that can be used by a running command to check whether it shall finish. The Run method implements the command processor.
For each method that can be invoked asynchronously, one class must be derived that overwrites the invoke method.
To abort a command, call method abortCommand from a different thread. Method abortCommand sets the Abort SyncObject that can be used by a running command to check whether it shall finish. The Run method implements the command processor.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Helper thread for asynchronous method processing. -
Field Summary
FieldsModifier and TypeFieldDescriptionIf set, command shall be aborted as soon as possible.Additional request data.protected JposDevice
Device implementation of device service that started asynchronous processing.For synchronous processing, this object can be used to signal termination of the command invocation.jpos.JposException
If set, the exception that terminated command execution.protected boolean
If true, the command has been finished.int
OutputID of the asynchronous command.Property set of device service that started asynchronous processing.Object to be used whenever the command must sleep some time. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.JposOutputRequest(JposDevice device)
Constructor for internal use. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Force command to abort processing.void
abortCommand(boolean noEvents)
Force command to abort processing.void
Catches exceptions thrown by method invoke() and stores it in property Exception for further processing by asynchronous request handlers.void
clearAll()
Removes all pending and suspended output requests belonging to the property set of the command.void
Removes all pending and suspended input requests belonging to the property set of the command.void
Removes all pending and suspended output requests belonging to the property set of the command.int
Computes number of all commands enqueued or suspended.createErrorEvent(jpos.JposException ex)
Factory for error events generated from JposExceptions.Factory for status update event with FlagWhenIdle status value.Factory for output complete events.protected JposOutputRequest
dequeue()
Removes output request from queue of pending commands.void
enqueue()
Puts output request into queue of pending commands.void
Enqueue request for synchronous processing.boolean
Finishs asynchronous processing of a request.void
finished()
Must be called at the end of each invoke method.void
invoke()
Invokes the command.void
Reactivate previously suspended requests: Add them to PendingCommands and start handler thread.void
reactivate(boolean input)
Reactivate only those commands that are or are not derived from JposInputRequest.void
reset()
Resets the object to a pre-run status,void
run()
-
Field Details
-
Props
Property set of device service that started asynchronous processing. -
Device
Device implementation of device service that started asynchronous processing. -
OutputID
public int OutputIDOutputID of the asynchronous command. -
Abort
If set, command shall be aborted as soon as possible. Use abortCommand() to force command abort. -
EndSync
For synchronous processing, this object can be used to signal termination of the command invocation. -
Finished
protected boolean FinishedIf true, the command has been finished. Must be set to true whenever command processing finishes. -
Waiting
Object to be used whenever the command must sleep some time. Will be signaled by aborting thread to slow down waiting time. -
Exception
public jpos.JposException ExceptionIf set, the exception that terminated command execution. Otherwise, the command terminated normally. -
AdditionalData
Additional request data. It may contain any request specific data at the time the method was invoked that must be buffered until asynchronous request processing really starts. This might be specific status values or other device specific data.
-
-
Constructor Details
-
JposOutputRequest
Constructor for internal use. Generates dummy request to be used only to create a request executor thread.- Parameters:
device
- Device implementation object.
-
JposOutputRequest
Constructor. Stores given parameters for later use.- Parameters:
props
- Property set of device service.
-
-
Method Details
-
reset
public void reset()Resets the object to a pre-run status, -
abortCommand
public void abortCommand()Force command to abort processing. Waits until command has been finished. -
abortCommand
public void abortCommand(boolean noEvents)Force command to abort processing. Waits until command has been finished.- Parameters:
noEvents
- If true, OutputCompleteEvents and ErrorEvents will be suppressed.
-
finished
public void finished()Must be called at the end of each invoke method. If another thread is waiting for abort completion or termination, this thread will be woken up. -
invoke
public void invoke() throws jpos.JposExceptionInvokes the command. Must be implemented in derived class. Calls finished() to wake up potentially waiting threads.- Throws:
jpos.JposException
- JposException thrown by the command to be executed.
-
enqueue
public void enqueue() throws jpos.JposExceptionPuts output request into queue of pending commands. If not active, a new request processor will be activated.- Throws:
jpos.JposException
- if device is just in error state
-
enqueueSynchronous
public void enqueueSynchronous() throws jpos.JposExceptionEnqueue request for synchronous processing. No JposErrorEvent handling, but exception handling will take place.- Throws:
jpos.JposException
- JposException thrown within command execution thread.
-
dequeue
Removes output request from queue of pending commands.- Returns:
- First output request in request queue, null if request queue is empty.
-
clearInput
public void clearInput()Removes all pending and suspended input requests belonging to the property set of the command. Clears only those requests that are really input requests:- Have no own OutputID,
- Generate no OutputCompleteEvent when finished,
- Generate error events with locus EL_INPUT.
-
clearOutput
public void clearOutput()Removes all pending and suspended output requests belonging to the property set of the command. Clears only those requests that are really output requests:- Have an own OutputID,
- Generate an OutputCompleteEvent when finished,
- Generate error events with locus EL_OUTPUT.
-
clearAll
public void clearAll()Removes all pending and suspended output requests belonging to the property set of the command. -
countCommands
public int countCommands()Computes number of all commands enqueued or suspended.- Returns:
- Computed amount.
-
reactivate
public void reactivate(boolean input)Reactivate only those commands that are or are not derived from JposInputRequest. This default implementation expects that no request has been derived from JposInputRequest.- Parameters:
input
- If true, only JposInputRequests will be reactivated. Otherwise only all other JposOutputRequests will be reactivated.
-
reactivate
public void reactivate()Reactivate previously suspended requests: Add them to PendingCommands and start handler thread. -
run
public void run() -
catchedInvocation
public void catchedInvocation()Catches exceptions thrown by method invoke() and stores it in property Exception for further processing by asynchronous request handlers. -
finishAsyncProcessing
public boolean finishAsyncProcessing()Finishs asynchronous processing of a request.- Returns:
- true if request has been processed, false if suspended.
-
createErrorEvent
Factory for error events generated from JposExceptions. Must be overwritten whenever a device specific error event shall be created. For example, in case of cash printer methods, this method should return a POSPrinterErrorEvent (which is an object derived from JposErrorEvent) that contains additional values to be stored in printer properties before the event will be fired.
If a device supports result code properties instead of error events, this method must return null. The result codes should be buffered for a later call of the createIdleEvent method which must create a device specific StatusUpdateEvent which contains the buffered values.
If null will be returned instead of a JposErrorEvent, it will enforce special request handling instead:- Instead of suspending the request, it will be finished.
- The idle flag will be set.
- Parameters:
ex
- JposException which is the originator of an error event.- Returns:
- The resulting error event.
-
createOutputEvent
Factory for output complete events. Must be overwritten whenever a device specific output complete event shall be created.- Returns:
- The resulting output complete event or null if no output complete event shall be enqueued.
-
createIdleEvent
Factory for status update event with FlagWhenIdle status value. Must be overwritten whenever a device specific status update event shall be created.
If the createErrorEvent method has been overwritten with a method that returns an error event with source = null to enforce special error handling via result properties instead of error events, createIdleEvent must be overwritten as well.- Returns:
- The resulting status update event.
-