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

public class JposOutputRequest extends Object implements Runnable
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.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Helper thread for asynchronous method processing.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    If 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

    Constructors
    Constructor
    Description
    Constructor.
    Constructor for internal use.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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
    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.
    Removes output request from queue of pending commands.
    void
    Puts output request into queue of pending commands.
    void
    Enqueue request for synchronous processing.
    boolean
    Finishs asynchronous processing of a request.
    void
    Must be called at the end of each invoke method.
    void
    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
    Resets the object to a pre-run status,
    void
    run()
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • Props

      public JposCommonProperties Props
      Property set of device service that started asynchronous processing.
    • Device

      protected JposDevice Device
      Device implementation of device service that started asynchronous processing.
    • OutputID

      public int OutputID
      OutputID of the asynchronous command.
    • Abort

      public SyncObject Abort
      If set, command shall be aborted as soon as possible. Use abortCommand() to force command abort.
    • EndSync

      public SyncObject EndSync
      For synchronous processing, this object can be used to signal termination of the command invocation.
    • Finished

      protected boolean Finished
      If true, the command has been finished. Must be set to true whenever command processing finishes.
    • Waiting

      public SyncObject 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 Exception
      If set, the exception that terminated command execution. Otherwise, the command terminated normally.
    • AdditionalData

      public Object 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

      public JposOutputRequest(JposDevice device)
      Constructor for internal use. Generates dummy request to be used only to create a request executor thread.
      Parameters:
      device - Device implementation object.
    • JposOutputRequest

      public JposOutputRequest(JposCommonProperties props)
      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.JposException
      Invokes 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.JposException
      Puts 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.JposException
      Enqueue request for synchronous processing. No JposErrorEvent handling, but exception handling will take place.
      Throws:
      jpos.JposException - JposException thrown within command execution thread.
    • dequeue

      protected JposOutputRequest 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.
      This base implementation expects that no output request fulfills these requirements and therefore simply makes nothing.
    • 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.
      This base implementation expects that all output requests fulfill these requirements and therefore simply invokes clearAll.
    • 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()
      Specified by:
      run in interface Runnable
    • 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

      public JposErrorEvent createErrorEvent(jpos.JposException ex)
      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.
      Devices handling asynchronous requests this way, must not buffer more than one request at once. They must end with throwing a StatusUpdateEvent with a specific end-of-request status value instead. This event must be returned by the createIdleEvent method of a device specific class derived from JposOutputRequest.
      Parameters:
      ex - JposException which is the originator of an error event.
      Returns:
      The resulting error event.
    • createOutputEvent

      public JposOutputCompleteEvent 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

      public JposStatusUpdateEvent 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.