colin-lee / ganymed-ssh-2

Automatically exported from code.google.com/p/ganymed-ssh-2
Other
0 stars 0 forks source link

Please add Connection.removeConnectionMonitor() method #19

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
For symmetry with addConnectionMonitor(), please add a 
removeConnectionMonitor() method, so I don't have to get connectionLost() 
events when I close my own connection.

Semantics:

1. addConnectionMonitor() should throw NPE if monitor is null.
2. addConnectionMonitor() should throw IllegalArgumentException if monitor 
already exists.
3. removeConnectionMonitor() should throw IllegalArgumentException if the 
monitor doesn't already exist in the list. Note that this case also covers the 
case where the monitor to remove is null.

Original issue reported on code.google.com by EsmondP...@gmail.com on 20 Jun 2012 at 1:38

GoogleCodeExporter commented 8 years ago
Implementation in Channel.java:

    /**
     * Add a {@link ConnectionMonitor} to this connection. Can be invoked at any time,
     * but it is best to add connection monitors before invoking
     * <code>connect()</code> to avoid glitches (e.g., you add a connection monitor after
     * a successful connect(), but the connection has died in the mean time. Then,
     * your connection monitor won't be notified.) 
     * <p>
     * You can add as many monitors as you like.
     * 
     * @see ConnectionMonitor
     * @see #removeConnectionMonitor
     * 
     * @param cmon An object implementing the <code>ConnectionMonitor</code> interface.
     */
    public synchronized void addConnectionMonitor(ConnectionMonitor cmon)
    {
        if (cmon == null)
            throw new NullPointerException("cmon argument is null");
        if (connectionMonitors.contains(cmon))
            throw new IllegalArgumentException("monitor already exists");

        connectionMonitors.addElement(cmon);

        if (tm != null)
            tm.setConnectionMonitors(connectionMonitors);
    }

    /**
     * Remove a {@link ConnectionMonitor} from this connection.
     *
     * @see ConnectionMonitor
     * @see #addConnectionMonitor
     *
     * @param cmon An object implementing the <code>ConnectionMonitor</code> interface.
     */
    public synchronized void removeConnectionMonitor(ConnectionMonitor cmon)
    {
        if (!connectionMonitors.removeElement(cmon))
            throw new IllegalArgumentException("no such monitor");

        if (tm != null)
            tm.setConnectionMonitors(connectionMonitors);
    }

Original comment by EsmondP...@gmail.com on 21 Jun 2012 at 4:04

GoogleCodeExporter commented 8 years ago
Fixed in SVN

Original comment by cleondris on 1 Aug 2013 at 12:50