Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.Close
Alex, I've completed a prototype refactoring of free.chessclub.ChessclubConnection to allow plugins to register as DatagramListeners. The changes to the free.chessclub.* package is largely as we discussed. These changes necessarily impacted JinChessclubConnection, so I made the necessary updates to JinChessclubConnection to preserve compatibility. In an effort to keep the net impact of the redesign small, I took a minimalist approach when updating JinChessclubConnection. As a result, I expect that JinChessclubConnection could benefit from further redesign work. In the present design, the JinChessclubConnection object serves three distinct responsibilities: (a) Represents the underlying connection to the chess server (Connection Pattern), (b) Listens to the platform specific DatagramEvents converts them to subscribable JinEvents (Adapter Pattern), and (c) Aggregates key model data, such as info on current games, active seeks etc. Responsibilities (a) and (b) create a multiple inheritance problem in the new design as JinChessclubConnection requires behavior from both ChessclubConnection and DispatchingDatagramListener. I resolved this multiple inheritance problem through the use of an inner class. The use of inner class shouldn't interfere with Java 1.1 JVM compatibility as the binary formats are backwards compatible and I noticed JinChessclubConnection already has a GameInfo inner class. This works localizes as impact to within JinChessclubConnection. However, it is ugly looking and I'd rather find a cleaner approach. I'd really like your input here. One way to avoid the need for the inner class would be to divide JinConnection's responsibilities into 2 objects, one to represent the Connection Adapter and one to represent the Event Adapter. Attached below is a summary of the changes made... Doug ---Change Summary---- Primary Objectives: + Refactor free.chessclub.ChessclubConnection to allow plugins to register as DatagramListeners. + Controll setDGState based on the existence of registered DatagramListeners. + Ensure DatagramListeners only receieve the datagrams for which they have registered. + Minimize the impact of these changes on the rest of the application. + Allow for JinChessclubConnection to be refactored over time to make better use of the support for multiple DatagramListeners. New Classes Added: + public interface free.chessclub.DatagramListener. + public class free.chessclub.DatagramEvent extends java.util.EventObject. + public class free.chessclub.DispatchingDatagramEvent implements DatagramListener. Changes to free.chessclub.ChessclubConnection: + Added public void addDatagramListener(DatagramListener l, int dgNumber). + Added public void removeDatagramListener(DatagramListener l, int dgNumber). + Added private void fireDatagramEvent(DatagramEvent evt, int dgType). + Moved processXXX() methods to DispatchingDatagramListener. + Modified handleDatagram(Datagram) to call fireDatagramEvent() rather than processDatagram(). + Added private EventListenerList getDatagramListenerList(int dgNumber). + Added private EventListenerList datagramListeners. + Added private final int MAX_DATAGRAM_NUMBER = 200 (for max array size). + Changed access modifier of setDGState() to private. Callers should use addDatagramListener() instead. + Changed access modifier of convertXXX() helpers to public so DatagramListener's may use them. Changes to free.chessclub.PlayerManagingConnection: + Renamed to PlayerManagingLister. + Changed constructor to PlayerManagingListener(ChessclubConnection conn, int trackedDGs). + Changed base class to DispatchingDatagramListener. + Replaced calls to setDGState() with calls to addDatagramListener(). Changes to free.jin.chessclub.JinChessclubConnection: + Added inner class JinDatagramListener extends DispatchingDatagramListener + Moved processXXX() methods to inner class JinDatagramListener + Made required edits to processXXX() methods, replacing "this" with "JinChessclubConnection.this" + Provided a subsitute setDGState() helper method to preserve compatability which simply registers and unregisters the datagrams via add/removeDatagramListener(jinDatagramListiner, dgType) Changes to free.jin.chessclub.ChessclubListenerManager: + No changes necessary as this class now invokes the subsitute setDGState() helper to add/remove listeners.