JavaPOSWorkingGroup / javapos-contracts

Hosts the interfaces and data types of the UnifiedPOS reference implementation for Java.
Other
8 stars 9 forks source link

Interface jpos.services.EventCallbacks is lacking Transition event callback method #4

Closed kuniss closed 6 years ago

kuniss commented 7 years ago

The interface jpos.services.EventCallbacks is lacking the call back method

        public void fireTransitionEvent(TransitionEvent e)

The event type Transition was introduced in UnifiedPOS 1.14. It seems this method was forgotten to be added by the original maintainer when implementing UnifiedPOS version 1.14 changes. At least, according to the imported sources taken from http://javapos.com/downloads/JavaPOS-1.14.0-Source-20131024.zip this method is not available there.

kuniss commented 7 years ago

Device Service Side Changes

Just adding the lacking method to the existing interface would break backward compatibility for Device Services implementations based on the 1.14 javapos-contracts. This would hold true for all 1.14 device service implementations of all categories as the EventCallbacks interface is used in the interface jpos.services.BaseService which is inherited by all service interfaces of all categories.

Therefore, I propose to define a second interface jpos.services.EventCallbacks2 which derives from jpos.services.EventCallbacks containing the lacking method only. This will allow legacy 1.14 implementations based on jpos.services.EventCallbacks at compile time to run with the new javapos-contracts library with jpos.services.EventCallbacks2 inside. However, new device service implementations may be based on the new jpos.services.EventCallbacks2 implementing the lacking transition event firing method.

Device Control Side Changes

Additionally, there is a change needed in the Device Control jpos.ElectronicValueRW which does not fire the transition event to the application yet even if it would be delivered by a Device Service implementation. Needed code changes:

  protected class ElectronicValueRWCallbacks
    implements EventCallbacks2
  {
    ...
    public void fireTransitionEvent(TransitionEvent e)
    {
      synchronized(ElectronicValueRW.this.transitionListeners)
      {
        // deliver the event to all registered listeners
        for(int x = 0; x < transitionListeners.size(); x++)
        {
          ((TransitionListener)transitionListeners.elementAt(x)).transitionOccurred(e);
        }
      }
    }
  }

This Device Control implementation does not break Device Service implementation compiled against the current javapos-contract library in version 1.14 as the event callback implementation would be passed as EventCallback typed object and not as EventCallback2 typed object. The new method would siply not be visible. However, new Device Service implementations which want to call the new transition firing method would need to cast the passed object to EventCallback2 type to get the new method visible.

kuniss commented 6 years ago

Solved in release 1.14.2.