package com.gyee.edge.protocol.iec60870;

import java.io.IOException;
import java.util.EventListener;

/**
 * The listener interface for receiving incoming ASDUs and connection closed events. The class that is interested in
 * incoming ASDUs implements this interface. The object of that class is registered as a listener through the
 * {@link Connection#startDataTransfer(ConnectionEventListener, int)} or
 * {@link Connection#waitForStartDT(ConnectionEventListener, int)} method. Incoming ASDUs are queued so that
 * {@link #newASdu(ASdu)} is never called simultaneously for the same connection.
 */
public interface ConnectionEventListener extends EventListener {

    /**
     * Invoked when a new ASDU arrives.
     *
     * @param aSdu the ASDU that arrived.
     */
    void newASdu(ASdu aSdu);

    /**
     * Invoked when an IOException occurred while listening for incoming ASDUs. An IOException implies that the
     * {@link Connection} that feeds this listener was automatically closed and can no longer be used to send commands
     * or receive ASDUs.
     *
     * @param cause the exception that occurred.
     */
    void connectionClosed(IOException cause);

}
