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.io.File;
022    
023    import java.net.URL;
024    
025    import net.dpml.transit.Artifact;
026    
027    /**
028     * Adapts cache events to logging messages.
029     *
030     *
031     * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
032     * @version 1.0.3
033     * @see net.dpml.transit.monitor.Monitor
034     */
035    public class CacheMonitorAdapter extends AbstractAdapter
036        implements CacheMonitor
037    {
038        // ------------------------------------------------------------------------
039        // constructor
040        // ------------------------------------------------------------------------
041    
042       /**
043        * Creation of a new adaptive cache monitor.
044        * @param adapter the adapter to assign to the monitor
045        */
046        public CacheMonitorAdapter( Adapter adapter )
047        {
048            super( adapter );
049        }
050    
051        // ------------------------------------------------------------------------
052        // CacheMonitor
053        // ------------------------------------------------------------------------
054    
055       /**
056        * Notify the monitor that an artifact has been requested.
057        * @param artifact the requested artifact
058        */
059        public void resourceRequested( Artifact artifact )
060        {
061        }
062    
063       /**
064        * Notify the monitor that an artifact has been added to the local cache.
065        * @param resource the url of the resource added to the local cache
066        * @param localFile the local file resident in the cache
067        */
068        public void addedToLocalCache( URL resource, File localFile )
069        {
070        }
071    
072       /**
073        * Notify the monitor that an artifact in the local cache has been updated.
074        * @param resource the url of the resource updating the local cache
075        * @param localFile the local file that has been updated
076        */
077        public void updatedLocalCache( URL resource, File localFile )
078        {
079        }
080    
081       /**
082        * Notify the monitor that an artifact has been removed from the local cache.
083        * @param resource the url of the resource removed from the local cache
084        * @param localFile the local file removed from the cache
085        */
086        public void removedFromLocalCache( URL resource, File localFile )
087        {
088            if( getAdapter().isDebugEnabled() )
089            {
090                getAdapter().debug( "removed [" + localFile + "] representing [" + resource + "]" );
091            }
092        }
093    
094       /**
095        * Notify the monitor of a failed download attempt relative to an identified host.
096        * @param host the host raising the fail status
097        * @param artifact the requested artifact
098        * @param e the exception causing the failure
099        */
100        public void failedDownloadFromHost( String host, Artifact artifact, Throwable e )
101        {
102            if( getAdapter().isDebugEnabled() )
103            {
104                getAdapter().debug(
105                  "download failure on ["
106                  + host + "] for ["
107                  + artifact
108                  + "] due to: "
109                  + e.getMessage() );
110            }
111        }
112    
113       /**
114        * Notify the monitor of a failed download attempt.
115        * @param artifact the requested artifact
116        */
117        public void failedDownload( Artifact artifact )
118        {
119            if( getAdapter().isDebugEnabled() )
120            {
121                getAdapter().warn( "failed to download " + artifact );
122            }
123        }
124    }