001    /*
002     * Copyright 2004 Niclas Hedhman.
003     *
004     * Licensed  under the  Apache License,  Version 2.0  (the "License");
005     * you may not use  this file  except in  compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *   http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed  under the  License is distributed on an "AS IS" BASIS,
012     * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
013     * implied.
014     *
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    
019    package net.dpml.transit.monitor;
020    
021    import java.net.URL;
022    
023    /**
024     * A connection monitor implementation that routes connection notification requests
025     * to registered listeners.
026     *
027     * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
028     * @version 1.1.0
029     */
030    public class ConnectionMonitorRouter extends AbstractMonitorRouter
031        implements ConnectionMonitor, Router
032    {
033        //--------------------------------------------------------------------
034        // ConnectionMonitor
035        //--------------------------------------------------------------------
036    
037       /**
038        * Notify registered monitors of a connection opened event.
039        * @param url the target url
040        */
041        public void connectionOpened( URL url )
042        {
043            Monitor[] monitors = getMonitors();
044            for( int i=0; i < monitors.length; i++ )
045            {
046                ConnectionMonitor monitor = (ConnectionMonitor) monitors[i];
047                monitor.connectionOpened( url );
048            }
049        }
050    
051       /**
052        * Notify registered monitors of a connection started event.
053        * @param url the target url
054        */
055        public void connectStarted( URL url )
056        {
057            Monitor[] monitors = getMonitors();
058            for( int i=0; i < monitors.length; i++ )
059            {
060                ConnectionMonitor monitor = (ConnectionMonitor) monitors[i];
061                monitor.connectStarted( url );
062            }
063        }
064    
065       /**
066        * Notify registered monitors of a connection completed event.
067        * @param url the target url
068        */
069        public void connectCompleted( URL url )
070        {
071            Monitor[] monitors = getMonitors();
072            for( int i=0; i < monitors.length; i++ )
073            {
074                ConnectionMonitor monitor = (ConnectionMonitor) monitors[i];
075                monitor.connectCompleted( url );
076            }
077        }
078    
079       /**
080        * Add a monitor to the set of registered monitors.
081        * @param monitor the monitor to add
082        */
083        public void addMonitor( Monitor monitor )
084        {
085            if( !( monitor instanceof ConnectionMonitor ) )
086            {
087                throw new IllegalArgumentException( "monitor must be ConnectionMonitor type." );
088            }
089            else
090            {
091                super.addMonitor( monitor );
092            }
093        }
094    }
095