[Apt-got-cvs-commits] apt-got/src/com/debianmirror/mirror/data DebianMirrorPurger.java,NONE,1.1 Link
Status: Beta
Brought to you by:
dun3
Update of /var/lib/cvs/apt-got/apt-got/src/com/debianmirror/mirror/data In directory btfmx2:/tmp/cvs-serv13208/src/com/debianmirror/mirror/data Modified Files: BasicFileInfo.java DebianMirror.java DebianMirrorFile.java DebianMirrorFilePool.java DebianMirrorInfo.java DebianMirrorObserver.java DebianMirrorSubject.java DebianPackageListMirrorFile.java FileCache.java LocalMirrorFile.java MirrorFile.java MirrorFilePool.java MirrorInfo.java RemoteMirrorFile.java XmlMirrorConf.java Added Files: DebianMirrorPurger.java LinkStructureChangedException.java Log Message: Jump to 0.8pre4 Started documentation. Created a brute force purger based on package lists. created hidden urls to trigger updates. --- NEW FILE: DebianMirrorPurger.java --- package com.debianmirror.mirror.data; import java.io.File; import java.io.FileFilter; import java.util.logging.Logger; public class DebianMirrorPurger extends Thread { private DebianMirrorFilePool _filePool; private DebianMirrorInfo _mirrorInfo; private FileCache _fileCache; private boolean _mirrorStateChange; private FileFilter _dirFilter; private FileFilter _filesFilter; private Logger _logger; public DebianMirrorPurger(DebianMirrorFilePool dmfp, FileCache fc) { _filePool = dmfp; _fileCache = fc; _logger = _filePool.getLogger(); _mirrorInfo = (DebianMirrorInfo)_filePool.getMirrorInfo(); _dirFilter = new DirectoryFilter(); _filesFilter = new ReadableFileFilter(); _mirrorStateChange = true; start(); try { setPriority(Thread.MIN_PRIORITY + 1); } catch(Exception e) { //ignore } } public void run() { // wait until info is consistent to start // the first run. while(!_mirrorInfo.isConsistent()) { try { wait(1019); } catch(Exception e) {} } while(true) { if(_mirrorStateChange) { _mirrorStateChange = false; // do SOMETHING ;) startSubDir(_filePool.getRootDir()); } synchronized(this) { try { wait(24*60*60*1000); } catch(Exception e) {} } } } private void startSubDir(File dir) { _logger.finest("Entering; dir = " + dir.getAbsolutePath()); if(_mirrorInfo.isConsistent()) { int i; try { sleep(10); } catch(Exception e) {} File[] list = dir.listFiles(_filesFilter); // check files if(list.length > 0) { for(i = 0; i < list.length; i++) { checkFile(list[i]); } } list = dir.listFiles(_dirFilter); // recurse into subdirs if(list.length > 0) { for(i = 0; i < list.length; i++) { startSubDir(list[i]); } } } } private void checkFile(File file) { try { _logger.finest("Entering; file = " + file.getAbsolutePath()); try { sleep(10); } catch(Exception e) {} if(_mirrorInfo.isConsistent()) { String filePath = _filePool.translateFileToPath(file); _logger.finer("Got " + filePath + " as path"); // test if still in use if(!_fileCache.has(filePath)) { if((!_mirrorInfo.isDebianPackageList(filePath)) && (!_mirrorInfo.isDebianReleaseFile(filePath)) && (!_mirrorInfo.isDebianMirrorFile(filePath))) { // it is a simplemirrorfile that is not in use // or an old debian file. // delete file.delete(); } } } } catch(Exception e) { //either a security exception or a nullpointer } } } class DirectoryFilter implements FileFilter { DirectoryFilter() { } public boolean accept(File pathname) { //if its a normal file -> ignore //is the most common fall through criteria -> test first if(pathname.isFile()) { return false; } if(pathname.isHidden()) { return false; } if(!pathname.canRead()) { return false; } return pathname.isDirectory(); } } class ReadableFileFilter implements FileFilter { ReadableFileFilter() { } public boolean accept(File pathname) { return (pathname.isFile() && pathname.canRead() && !pathname.getAbsolutePath().endsWith(".tmp")); } } Index: DebianMirrorFilePool.java =================================================================== RCS file: /var/lib/cvs/apt-got/apt-got/src/com/debianmirror/mirror/data/DebianMirrorFilePool.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** DebianMirrorFilePool.java 25 May 2004 23:28:56 -0000 1.9 --- DebianMirrorFilePool.java 1 Jun 2004 18:23:44 -0000 1.10 *************** *** 11,14 **** --- 11,26 ---- import java.util.logging.Level; + /** + * A <code>MirrorFilePool</code> with some specialisations for the Debian archive. + * <br />This Class employes a <code>FileCache</code> to be able to reuse Objects. + * <p>It uses a namespace mechanism (the identifier found + * in the <code>DebianMirrorModuleConf</code>) to create instances. These + * instances are accessable through the <code>getInstance</code> method. + * + * @author Tobias Hertkorn + * @see FileCache + * @see DebianMirrorModuleConf + * @see MirrorFilePool + */ public class DebianMirrorFilePool implements MirrorFilePool { *************** *** 19,22 **** --- 31,35 ---- private FileCache _fileCache; private DebianMirror _debianMirror; + private DebianMirrorPurger _purger; static { *************** *** 24,27 **** --- 37,47 ---- } + /** + * Creates a file pool representation with the given configuration. + * <br />Should never be used directly. Use {@link #getInstance}. + * + * @param mmc the configuration to use. + * @exception IOException is thrown if the root directory could not get created. + */ protected DebianMirrorFilePool(DebianMirrorModuleConf mmc) throws IOException { _config = mmc; *************** *** 31,36 **** --- 51,64 ---- _debianMirror = new DebianMirror(this, _config.getRemoteServer()); + _purger = new DebianMirrorPurger(this, _fileCache); } // end of constructor + /** + * Returns (and if necessary creates) the file pool instance. + * + * @param mmc the configuration to use. + * @return the file pool instance for that configuration. + * @exception IOException is thrown, if the constructure threw one. + */ public static DebianMirrorFilePool getInstance(DebianMirrorModuleConf mmc) throws IOException { DebianMirrorFilePool instance = null; *************** *** 58,61 **** --- 86,92 ---- _logger.finer(fileName + ": returning as a package list."); mf = _debianMirror.getDebianPackageListMirrorFile(fileName); + } else if(_debianMirror.isDebianReleaseFile(fileName)) { + _logger.finer(fileName + ": returning as a release file."); + mf = _debianMirror.getDebianReleaseMirrorFile(fileName); } else { _logger.finer(fileName + " is a cacheable file."); *************** *** 89,95 **** return _debianMirror; } - public DebianMirrorInfo getDebianMirrorInfo() { - return _debianMirror; - } public Logger getLogger() { return _logger; --- 120,123 ---- *************** *** 110,113 **** --- 138,151 ---- } return f; + } + + public String translateFileToPath(File path) { + _logger.finest("Entering; path = " + path.getAbsolutePath()); + + if(!path.getAbsolutePath().startsWith(_rootDir.getAbsolutePath())) { + // whot?!? + return null; + } + return new String(path.getAbsolutePath().substring(_rootDir.getAbsolutePath().length())); } Index: DebianMirrorInfo.java =================================================================== RCS file: /var/lib/cvs/apt-got/apt-got/src/com/debianmirror/mirror/data/DebianMirrorInfo.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DebianMirrorInfo.java 25 May 2004 23:28:56 -0000 1.2 --- DebianMirrorInfo.java 1 Jun 2004 18:23:44 -0000 1.3 *************** *** 3,14 **** --- 3,87 ---- import com.debianmirror.debian.DebianPackageListInfo; + /** + * Interface to more Debian specific information about the mirror. + * + * @author Tobias Hertkorn + */ public interface DebianMirrorInfo extends MirrorInfo { + + /** + * Tests whether a file denoted by the path parameter looks like a Debian package list. + * @param path the file path relative to the root of the mirror module. + * @return <code>true</code> if the file looks like a Debian package list. + */ public boolean isDebianPackageList(String path); + + /** + * Tests whether a file denoted by the path parameter looks like a Debian package. + * @param path the file path relative to the root of the mirror module. + * @return <code>true</code> if the file looks like a Debian package. + */ public boolean isDebianMirrorFile(String path); + + /** + * Tests whether a file denoted by the path parameter looks like a Debian Release file. + * @param path the file path relative to the root of the mirror module. + * @return <code>true</code> if the file looks like a Debian Release file. + */ + public boolean isDebianReleaseFile(String path); + + /** + * Returns the size the file is supposed to have. + * <br /><code>-1</code> if no information is available. + * + * @param path the file path relative to the root of the mirror module. + * @return the file size of <code>-1</code> if no info is available. + */ public long getFileSize(String path); + + /** + * Returns the md5sum the file is supposed to have. + * <br /><code>null</code> if no information is available. + * + * @param path the file path relative to the root of the mirror module. + * @return the file's md5sum or <code>null</code> if no info is available. + */ public String getMd5sum(String path); + + /** + * not yet implemented. + */ public String getPackage(String path); + + /** + * not yet implemented. + */ public String getVersion(String path); + + /** + * Returns the Debian package list representation denoted by the path parameter. + * <br /><code>null</code> if there is no such Debian package list. + * + * @param path the file path relative to the root of the mirror module. + * @return the Debian package list or <code>null</code>. + */ public MirrorFile getDebianPackageListMirrorFile(String path); + + /** + * Returns the Debian Release file representation denoted by the path parameter. + * <br /><code>null</code> if there is no such Debian Release file. + * + * @param path the file path relative to the root of the mirror module. + * @return the Debian Release file or <code>null</code>. + */ + public MirrorFile getDebianReleaseMirrorFile(String path); + + /** + * Returns the Debian package list info representation denoted by the path parameter. + * <br /><code>null</code> if there is no such Debian package list info. + * + * @param path the file path relative to the root of the mirror module. + * @return the Debian package list info or <code>null</code>. + */ public DebianPackageListInfo getDebianPackageListInfo(String path); } Index: DebianMirrorSubject.java =================================================================== RCS file: /var/lib/cvs/apt-got/apt-got/src/com/debianmirror/mirror/data/DebianMirrorSubject.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DebianMirrorSubject.java 19 May 2004 01:30:37 -0000 1.1 --- DebianMirrorSubject.java 1 Jun 2004 18:23:44 -0000 1.2 *************** *** 1,7 **** --- 1,28 ---- package com.debianmirror.mirror.data; + /** + * The <code>DebianMirrorSubject</code> is used as counterpart of the {@link DebianMirrorObserver}. + * <br />Through this interface Observer can attach themselfs to get information about + * statechanges. + * + * @see DebianMirrorObserver + * @author Tobias Hertkorn + */ public interface DebianMirrorSubject { + /** + * Attach the given <code>DebianMirrorObserver</code> to this instance. + * @param dmo the observer to attach + */ public void attach(DebianMirrorObserver dmo); + + /** + * Detach the given <code>DebianMirrorObserver</code> from this instance. + * @param dmo the observer to detach + */ public void detach(DebianMirrorObserver dmo); + + /** + * Notify the attached observer. + */ public void notifyDebianMirrorObserver(); } Index: DebianPackageListMirrorFile.java =================================================================== RCS file: /var/lib/cvs/apt-got/apt-got/src/com/debianmirror/mirror/data/DebianPackageListMirrorFile.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DebianPackageListMirrorFile.java 24 May 2004 09:22:56 -0000 1.2 --- DebianPackageListMirrorFile.java 1 Jun 2004 18:23:44 -0000 1.3 *************** *** 41,45 **** public DebianPackageListMirrorFile(DebianMirrorFilePool mfp, String path, BasicFileInfo bfi, DebianMirror dm) throws IOException, FileInfoException { super(mfp, path, (path.indexOf("binary-i386") > 0)); ! _knownFiles = new HashMap(); _deletedFiles = new TreeSet(); --- 41,45 ---- public DebianPackageListMirrorFile(DebianMirrorFilePool mfp, String path, BasicFileInfo bfi, DebianMirror dm) throws IOException, FileInfoException { super(mfp, path, (path.indexOf("binary-i386") > 0)); ! _knownFiles = new HashMap(1024); _deletedFiles = new TreeSet(); --- NEW FILE: LinkStructureChangedException.java --- package com.debianmirror.mirror.data; public class LinkStructureChangedException extends Exception { public LinkStructureChangedException() { super(); } public LinkStructureChangedException(String message) { super(message); } public LinkStructureChangedException(String message, Throwable cause) { super(message, cause); } public LinkStructureChangedException(Throwable cause) { super(cause); } } Index: DebianMirrorFile.java =================================================================== RCS file: /var/lib/cvs/apt-got/apt-got/src/com/debianmirror/mirror/data/DebianMirrorFile.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DebianMirrorFile.java 25 May 2004 23:28:56 -0000 1.4 --- DebianMirrorFile.java 1 Jun 2004 18:23:44 -0000 1.5 *************** *** 11,14 **** --- 11,20 ---- import java.io.FileNotFoundException; + /** + * This is a specialized <code>MirrorFile</code> to mirror Debian package files. + * <br />As of 0.8 it does not provide verification. + * + * @author Tobias Hertkorn + */ public class DebianMirrorFile implements MirrorFile { *************** *** 30,33 **** --- 36,45 ---- private Object _stateLock; + /** + * Creates an instance for a specific configuration and filepath. + * + * @param dmfp the <code>DebianMirrorFilePool</code> to get the configuration information from. + * @param myFileName the filepath the instance should mirror. + */ public DebianMirrorFile(DebianMirrorFilePool dmfp, String myFileName) throws IOException { _filePool = dmfp; *************** *** 42,45 **** --- 54,61 ---- } + /** + * The old way to start the mirroring. + * @deprecated as of 0.7 + */ public void connect() throws java.io.FileNotFoundException, java.net.MalformedURLException,java.io.IOException { mysite = _filePool.getMirrorInfo().translatePathToURL(fileName); *************** *** 65,69 **** return new FileInputStream(localFile); } catch(FileNotFoundException fnfex) { ! if(checkStatus()) {; return getInputStream(); } else { --- 81,85 ---- return new FileInputStream(localFile); } catch(FileNotFoundException fnfex) { ! if(checkStatus()) { return getInputStream(); } else { *************** *** 95,102 **** --- 111,129 ---- } + /** + * @deprecated as of 0.7 + * @exception IllegalStateException is always thrown. + */ public void setIfModifiedSince(long ifModifiedSince) throws IllegalStateException { throw new IllegalStateException("MirrorFile already connected!"); } + /** + * Should get deprecated soon. + * <br />Once the <code>DebianMirrorFile</code> is fully compliant to the new + * interfaces this method will get obsolete. + * + * @return <code>true</code> if the status check created readable files. <code>false</code> otherwise. + */ public boolean checkStatus() { synchronized(_stateLock) { Index: DebianMirror.java =================================================================== RCS file: /var/lib/cvs/apt-got/apt-got/src/com/debianmirror/mirror/data/DebianMirror.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DebianMirror.java 25 May 2004 23:28:56 -0000 1.3 --- DebianMirror.java 1 Jun 2004 18:23:44 -0000 1.4 *************** *** 40,50 **** _remoteURL = new URL(remoteURL); _logger = _filePool.getLogger(); ! _debianMirrorFiles = new HashMap(); ! _debianPackageLists = new HashMap(); ! _debianReleaseFiles = new HashMap(); _logger.info("Starting the debian mirror representation"); - // start the maintenance thread _newLists = new LinkedList(); _stateChangePossible = false; start(); } --- 40,50 ---- _remoteURL = new URL(remoteURL); _logger = _filePool.getLogger(); ! _debianMirrorFiles = new HashMap(8192); ! _debianPackageLists = new HashMap(128); ! _debianReleaseFiles = new HashMap(64); _logger.info("Starting the debian mirror representation"); _newLists = new LinkedList(); _stateChangePossible = false; + // start the maintenance thread start(); } *************** *** 67,78 **** } catch(Exception e) {} } - workPendingListChanges(); // implement maintenance if(_stateChangePossible) { _stateChangePossible = false; _logger.fine("Need to check for state changes"); ! // if(releaseFilesChanged()) { ! // restartMirror(); ! // } } } --- 67,93 ---- } catch(Exception e) {} } // implement maintenance if(_stateChangePossible) { _stateChangePossible = false; + synchronized(_stateLock) { + _state = INITIALIZING; + _stateLock.notifyAll(); + } + _logger.fine("Need to check for state changes"); ! try { ! if(releaseFilesChanged()) { ! updatePackageLists(); ! } ! } catch(LinkStructureChangedException lsce) { ! _logger.log(Level.INFO, "The link structure of the remote archive changed -> deep restart of the server", lsce); ! completeRestartMirror(); ! } ! ! } ! workPendingListChanges(); ! synchronized(_stateLock) { ! _state = RUNNING; ! _stateLock.notifyAll(); } } *************** *** 125,128 **** --- 140,149 ---- + public boolean isConsistent() { + synchronized(_stateLock) { + // not initializing and no pending lists + return ((_state != INITIALIZING) && (_newLists.size() == 0)); + } + } public long getLocalMirrorSize() { return -1; *************** *** 158,162 **** } } ! public MirrorFile getDebianPackageListMirrorFile(String path) { try { --- 179,188 ---- } } ! public boolean isDebianReleaseFile(String path) { ! synchronized(_debianReleaseFiles) { ! return _debianReleaseFiles.containsKey(path); ! } ! } ! public MirrorFile getDebianPackageListMirrorFile(String path) { try { *************** *** 177,180 **** --- 203,217 ---- } } + public MirrorFile getDebianReleaseMirrorFile(String path) { + try { + synchronized(_debianReleaseFiles) { + return (MirrorFile)_debianReleaseFiles.get(path); + } + } catch(Exception e) { + _logger.log(Level.INFO, path + " threw an exception", e); + return null; + } + } + public String getMd5sum(String path) { return null; *************** *** 220,225 **** downloadMissingPackageLists(); } - // save memory by creating a hashmap that is EXACTLY the right size for this mirror - _debianReleaseFiles = new HashMap(_debianReleaseFiles); System.gc(); } --- 257,260 ---- *************** *** 315,320 **** private void sortKnownFiles() { _logger.finest("Entering;"); ! _debianPackageLists = new HashMap(); ! _debianMirrorFiles = new HashMap(); DebianReleaseMirrorFile drmf = null; for(Iterator i = _debianReleaseFiles.values().iterator(); i.hasNext(); ) { --- 350,355 ---- private void sortKnownFiles() { _logger.finest("Entering;"); ! _debianPackageLists = new HashMap(128); ! _debianMirrorFiles = new HashMap(8192); DebianReleaseMirrorFile drmf = null; for(Iterator i = _debianReleaseFiles.values().iterator(); i.hasNext(); ) { *************** *** 466,468 **** --- 501,516 ---- } + private boolean releaseFilesChanged() throws LinkStructureChangedException { + // redownload all of them for now + throw new LinkStructureChangedException("Nothing else implemented yet"); + } + private void updatePackageLists() { + } + private void completeRestartMirror() { + try { + startDebianMirror(true); + } catch(Exception e) { + _logger.log(Level.SEVERE, "Something very wrong happened while restarting the Mirror representation", e); + } + } } Index: XmlMirrorConf.java =================================================================== RCS file: /var/lib/cvs/apt-got/apt-got/src/com/debianmirror/mirror/data/XmlMirrorConf.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** XmlMirrorConf.java 25 May 2004 23:28:56 -0000 1.12 --- XmlMirrorConf.java 1 Jun 2004 18:23:44 -0000 1.13 *************** *** 18,22 **** * Contains all configuration values used to run the mirror/mirrorcontrol. * ! * $Id$ * @author Tobias Hertkorn */ --- 18,22 ---- * Contains all configuration values used to run the mirror/mirrorcontrol. * ! * <p>$Id$ * @author Tobias Hertkorn */ *************** *** 38,48 **** // initiates a mirrorconfig from the given filename /** ! *<p> Creates a XmlMirrorConf object for the given file name</p> ! * ! * @param myFileName name of the file that is being worked with. */ public XmlMirrorConf() { } public void setExtraInfo(String extrainfo) { fileName = extrainfo; --- 38,50 ---- // initiates a mirrorconfig from the given filename /** ! * Creates an empty XmlMirrorConf object. */ public XmlMirrorConf() { } + /** + * In case of the <code>XmlMirrorConf</code> this extrainfo is the path to the XML document to parse. + * @param extrainfo the path to the XML to parse. + */ public void setExtraInfo(String extrainfo) { fileName = extrainfo; Index: MirrorFile.java =================================================================== RCS file: /var/lib/cvs/apt-got/apt-got/src/com/debianmirror/mirror/data/MirrorFile.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MirrorFile.java 19 May 2004 01:28:56 -0000 1.2 --- MirrorFile.java 1 Jun 2004 18:23:44 -0000 1.3 *************** *** 7,11 **** /** ! * <p> The MirrorFile Class is responsible for the framework that is used in both the <code>LocalMirrorFile</code> and the <code>RemoteMirrorFile</code> </p> * * @author E01 - Tobias Hertkorn, Jonas Jagerhok, Jamie Fitz-Gerald --- 7,14 ---- /** ! * Every file that should be send to the client through the engine ! * must inplement this interface. ! * <br />It works as an abstraction layer to present the file to the ! * server, without revealing the details how the data is stored. * * @author E01 - Tobias Hertkorn, Jonas Jagerhok, Jamie Fitz-Gerald *************** *** 18,22 **** /** ! * <p>Returns the InputStream of this File</p> * * @return the InputStream that contains the data of the File --- 21,25 ---- /** ! * Returns the data for this file as an <code>InputStream</code>. * * @return the InputStream that contains the data of the File *************** *** 25,49 **** /** ! * <p>Returns the length of the file</p> */ public long getLength(); /** ! * <p>Returns the mime-type of the file</p> */ public String getMimeType(); /** ! * <p>Returns the last modified date of the file</p> */ public long getLastModified(); public void purge(); public void setState(MirrorFileState mfs); public MirrorFileState getState(); public void checkState(); public boolean forceVerify() throws IOException; public boolean isVerified(); public String getMd5sum(); --- 28,100 ---- /** ! * Returns the length of the file. ! * ! * @return the file length or <code>-1</code> if unknown/unpredictable. */ public long getLength(); /** ! * Returns the mime-type of the file. ! * ! * @return the mime type of the file or <code>null</code> if unknown. */ public String getMimeType(); /** ! * Returns the last modified date of the file. ! *<br />See <code>java.lang.Date</code> for details on the nature ! * of this long number. ! * ! * @return the date of the last modification. */ public long getLastModified(); + /** + * Try to delete itself. + * <br />If this method is called the <code>MirrorFile</code> + * should try to purge itself from any local storage device. + */ public void purge(); + /** + * Set the internal state of the <code>MirrorFile</code>. + * + * @param mfs the new <code>MirrorFileState</code>. + */ public void setState(MirrorFileState mfs); + + /** + * Returns the internal state of the <code>MirrorFile</code>. + * + * @return the internal state. + */ public MirrorFileState getState(); + + /** + * If executed the <code>MirrorFile</code> must check its internal state. + * <br />If it finds a divergence it must try to reset or alter the internal state. + */ public void checkState(); + + /** + * Should be used after a {@link #isVerified()} returned false. + * <br />If this method returns false something substancially is wrong. + * + * @exception IOException if an io error occured while reverifying. + * @return <code>true</code>, if the verification succeeded. <code>false</code> otherwise. + */ public boolean forceVerify() throws IOException; + + /** + * Tests whether the <code>MirrorFile</code> seems to be verified. + * @return <code>true</code>, if it seems to be verified. <code>false</code> otherwise. + */ public boolean isVerified(); + + /** + * Get the Md5sum calculated by the last verification. + * + * @return the md5sum. + */ public String getMd5sum(); Index: FileCache.java =================================================================== RCS file: /var/lib/cvs/apt-got/apt-got/src/com/debianmirror/mirror/data/FileCache.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FileCache.java 25 May 2004 23:28:56 -0000 1.2 --- FileCache.java 1 Jun 2004 18:23:44 -0000 1.3 *************** *** 1,13 **** package com.debianmirror.mirror.data; ! import java.util.TreeMap; public class FileCache implements MirrorFileStateObserver, FileCacheSubject, DebianMirrorObserver { ! private TreeMap _fileList; private MirrorFile _fileNotFoundMirrorFile; public FileCache() { ! _fileList = new TreeMap(); _fileNotFoundMirrorFile = new FileNotFoundMirrorFile(); } --- 1,15 ---- package com.debianmirror.mirror.data; ! import java.util.HashMap; ! import java.lang.ref.Reference; ! import java.lang.ref.WeakReference; public class FileCache implements MirrorFileStateObserver, FileCacheSubject, DebianMirrorObserver { ! private HashMap _fileList; private MirrorFile _fileNotFoundMirrorFile; public FileCache() { ! _fileList = new HashMap(8192); _fileNotFoundMirrorFile = new FileNotFoundMirrorFile(); } *************** *** 19,23 **** // there is a key registered // test if WeakReference got lost ! if(_fileList.get(path) == null) { return false; } else { --- 21,26 ---- // there is a key registered // test if WeakReference got lost ! if(((Reference)_fileList.get(path)).get() == null) { ! _fileList.remove(path); return false; } else { *************** *** 31,36 **** --- 34,41 ---- } } catch(ClassCastException cce) { + _fileList.remove(path); return false; } catch(NullPointerException npe) { + _fileList.remove(path); return false; } *************** *** 39,46 **** public MirrorFile get(String path) { try { ! return (MirrorFile)_fileList.get(path); } catch(ClassCastException cce) { return null; } catch(NullPointerException npe) { return null; } --- 44,55 ---- public MirrorFile get(String path) { try { ! synchronized(_fileList) { ! return ((MirrorFile)((Reference)_fileList.get(path)).get()); ! } } catch(ClassCastException cce) { + _fileList.remove(path); return null; } catch(NullPointerException npe) { + _fileList.remove(path); return null; } *************** *** 55,59 **** public void put(String path, MirrorFile mf) { ! _fileList.put(path, mf); } // end put --- 64,70 ---- public void put(String path, MirrorFile mf) { ! synchronized(_fileList) { ! _fileList.put(path, new WeakReference(mf)); ! } } // end put Index: MirrorFilePool.java =================================================================== RCS file: /var/lib/cvs/apt-got/apt-got/src/com/debianmirror/mirror/data/MirrorFilePool.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** MirrorFilePool.java 19 May 2004 01:28:56 -0000 1.6 --- MirrorFilePool.java 1 Jun 2004 18:23:44 -0000 1.7 *************** *** 7,15 **** --- 7,78 ---- import java.util.logging.Logger; + /** + * The MirrorFilePool is the abstraction of the local file repository. + * <br />That means in particular, that it knows how to translate request path names into + * filesystem <code>File</code> objects and back. + * <br />In addition it knows which <code>MirrorFile</code> is appropriated to create for + * that specific request-path (if it should get stored locally, etc.) by asking the + * <code>MirrorInfo</code>. + * + * @author Tobias Hertkorn + * @see MirrorInfo + */ public interface MirrorFilePool { + + /** + * Creates/reuses the requested <code>MirrorFile</code>. + * + * @param fileName the request path. + * @return the <code>MirrorFile</code> associated with <code>fileName</code>. + */ public MirrorFile getMirrorFile(String fileName); + + /** + * Should get phased out. + * <br />As soon as all <code>MirrorFile</code> are altered to fit new interaction profile. + * + * @return the configuration used to start this file pool instance. + */ + public MirrorModuleConf getConfig(); + + /** + * <code>MirrorFile</code> should use {@link #translatePathToFile} and {@link #translateFileToPath}. + * <br />This direct access is still necessary for the <code>Purger</code>. + * + * @return the abstraction of the root of the local repository. + */ public File getRootDir(); + + /** + * Returns the mirror info for this file pool. + * + * @return the mirror info for this file pool. + * @see MirrorInfo + */ public MirrorInfo getMirrorInfo(); + + /** + * Translates a request path name into a <code>File</code> object. + * <br />In addition it creates all directories nescessary to store the file. + * + * @exception IOException is thrown, if the creation of the subdirectories failed. + * @return the location to store/access the file locally. + */ public File translatePathToFile(String path) throws IOException; + + /** + * Translates a <code>File</code> object back into a request path. + * + * @return the request path as a <code>String</code>. <code>null</code>, if the path couldn't be translated. + */ + public String translateFileToPath(File path); + + /** + * Returns the <code>Logger</code> object associated with this file pool. + * <br />Every instance of e.g. <code>MirrorFile</code> should use this method to get a + * <code>Logger</code>. + * + * @return the <code>Logger</code>. + */ public Logger getLogger(); } Index: BasicFileInfo.java =================================================================== RCS file: /var/lib/cvs/apt-got/apt-got/src/com/debianmirror/mirror/data/BasicFileInfo.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** BasicFileInfo.java 19 May 2004 01:30:37 -0000 1.1 --- BasicFileInfo.java 1 Jun 2004 18:23:44 -0000 1.2 *************** *** 1,8 **** --- 1,20 ---- package com.debianmirror.mirror.data; + /** + * Data class to store basic file infos (size and md5sum) in lists. + * <br />These objects are read-only and comparable. Size and md5 are not checked. + * + * @author Tobias Hertkorn + */ public class BasicFileInfo { private String _md5; private long _size; private int _hash; + + /** + * creates a read-only objects with the given size and md5 stored. + * @param size of the file as long + * @param md5 of the file as String + */ public BasicFileInfo(long size, String md5) { _hash = 0; *************** *** 10,19 **** --- 22,54 ---- _md5 = md5; } + /** + * Get the Md5sum stored. + * + * @return the internally stored md5sum + */ public String getMd5() { return _md5; } + /** + * Get the size stored. + * + * @return the internally stored size + */ public long getSize() { return _size; } + /** + * Indicates whether another BasicFileInfo object is equal to this one. + * <br />This <code>equals</code> method returns true, if and only if one of the + * following is true: + * <ul> + * <li>reference points to this object (this == o)</li> + * <li>o.getClass() == this.getClass()<br /> + * and both md5 match<br /> + * and both sizes match</li> + * </ul> + * @param o the reference object with which to compare. + * @return <code>true</code> if this object matches the o argument; <code>false</code> otherwise. + */ public boolean equals(Object o) { try { *************** *** 28,31 **** --- 63,71 ---- return false; } + /** + * Returns a hash code value for the object. + * <br />Uses the <code>hashCode</code> methode of the <code>String</code> class. + * @return the hashCode computed by (new String(_size + _md5)).hashCode(). + */ public int hashCode() { if(_hash == 0) { Index: RemoteMirrorFile.java =================================================================== RCS file: /var/lib/cvs/apt-got/apt-got/src/com/debianmirror/mirror/data/RemoteMirrorFile.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RemoteMirrorFile.java 19 May 2004 01:28:56 -0000 1.2 --- RemoteMirrorFile.java 1 Jun 2004 18:23:44 -0000 1.3 *************** *** 10,14 **** /** ! * <p> The RemoteMiorrFile connects to a remote URL to produce an InputFileStream for a given filename from the remote server. </p> * * @author E01 - Tobias Hertkorn, Jamie Fitz-Gerald --- 10,17 ---- /** ! * The RemoteMiorrFile connects to a remote URL to produce an ! * InputStream for a given filename from the remote server. ! * <br />The data does not get stored locally. ! * <p>Should get depreciated soon in favour of {@link UncachedMirrorFile}. * * @author E01 - Tobias Hertkorn, Jamie Fitz-Gerald *************** *** 69,74 **** /** ! * <p>Creates a new RemoteMirrorFile instance</p> * * @param myFileName The name of the file that will be connected to from the remote mirror site. */ --- 72,78 ---- /** ! * Creates a new RemoteMirrorFile instance. * + * @deprecated this is the old way to get <code>MirrorFile</code> instances. * @param myFileName The name of the file that will be connected to from the remote mirror site. */ *************** *** 80,85 **** } ! public RemoteMirrorFile(DebianMirrorFilePool dmfp, String myFileName) { ! this(dmfp.getConfig(),myFileName); } --- 84,95 ---- } ! /** ! * Create a <code>RemoteMirrorFile</code> instance for this MirrorFilePool. ! * ! * @param mfp the MirrorFilePool to use. (To get the config from) ! * @param myFileName the path to the file. ! */ ! public RemoteMirrorFile(MirrorFilePool mfp, String myFileName) { ! this(mfp.getConfig(),myFileName); } *************** *** 140,144 **** return true; } - } // end RemoteMirrorFile --- 150,153 ---- Index: DebianMirrorObserver.java =================================================================== RCS file: /var/lib/cvs/apt-got/apt-got/src/com/debianmirror/mirror/data/DebianMirrorObserver.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DebianMirrorObserver.java 19 May 2004 01:30:37 -0000 1.1 --- DebianMirrorObserver.java 1 Jun 2004 18:23:44 -0000 1.2 *************** *** 1,8 **** --- 1,41 ---- package com.debianmirror.mirror.data; + /** + * The <code>DebianMirrorObserver</code> is used as counterpart of the {@link DebianMirrorSubject}. + * <br />All classes implementing this interfaces are interested in a specific type of state + * changes the <code>DebianMirrorSubject</code> goes through. + * + * @see DebianMirrorSubject + * @author Tobias Hertkorn + */ public interface DebianMirrorObserver { + + /** + * Called, if the statechange produced information about new packages. + * + * @param delta the path names of the new Debian packages. + */ public void newDebianPackages(String[] delta); + + /** + * Called, if the statechange produced information about changed packages. + * <br />That means the md5sum and/or the size of the package changed. + * + *@param delta the path names of the changed Debian packages. + */ public void changedDebianPackages(String[] delta); + + /** + * Called, if the statechange produced information about deleted packages. + * <br />That means these packages are no longer listed in any one of the package lists. + * + * @param delta the path names of the deleted Debian packages. + */ public void deletedDebianPackages(String[] delta); + + /** + * Called, if there have been statechanges. + * <br />Used for observer, that do not need the detailed infos. + */ public void possibleMirrorChanges(); } Index: LocalMirrorFile.java =================================================================== RCS file: /var/lib/cvs/apt-got/apt-got/src/com/debianmirror/mirror/data/LocalMirrorFile.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** LocalMirrorFile.java 19 May 2004 01:28:56 -0000 1.2 --- LocalMirrorFile.java 1 Jun 2004 18:23:44 -0000 1.3 *************** *** 8,12 **** /** ! * <p>The LocalMirrorFile creates an InputStream given a file name that corresponds to a local file.</p> * * @author E01 - Tobias Hertkorn, Jonas Jagerhok, Jamie Fitz-Gerald --- 8,13 ---- /** ! * The LocalMirrorFile creates an InputStream given a file name that corresponds to a local file. ! * <p>Should get depreciated soon, as it is an old-style mirror file. * * @author E01 - Tobias Hertkorn, Jonas Jagerhok, Jamie Fitz-Gerald *************** *** 22,30 **** /** ! * <p>Creates a new instance of the LocalMirrorFile class</p> * * @param myFile This is a File object that corresponds to the local file in the server cache. */ - public LocalMirrorFile(File myFile) { file = myFile; --- 23,30 ---- /** ! * Creates a new instance of the LocalMirrorFile class. * * @param myFile This is a File object that corresponds to the local file in the server cache. */ public LocalMirrorFile(File myFile) { file = myFile; Index: MirrorInfo.java =================================================================== RCS file: /var/lib/cvs/apt-got/apt-got/src/com/debianmirror/mirror/data/MirrorInfo.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MirrorInfo.java 19 May 2004 01:30:38 -0000 1.1 --- MirrorInfo.java 1 Jun 2004 18:23:44 -0000 1.2 *************** *** 4,11 **** --- 4,50 ---- import java.net.MalformedURLException; + /** + * Interface to basic information about mirrors. + * + * @author Tobias Hertkorn + */ public interface MirrorInfo { + /** + * Tests if the infos are consistent. + * <br />That means, if the mirror is done working on pending info changes. + * + * @return <code>true</code> if no <u>immediate</u> changes are expected. + */ + public boolean isConsistent(); + + /** + * Tests whether a file denoted by the path parameter fits into this mirror. + * + * @param path is the file path relative to the root of the mirror module. + * @return <code>true</code> if the file should be cached. + */ public boolean isCacheable(String path); + + /** + * Try to use {@link #translatePathToURL} instead. + * <br />Makes the root of the remote archive to mirror available as <code>URL</code>. + * + * @return the root of the remote archive. + */ public URL getRemoteURL(); + + /** + * Gives an estimate about the mirror size if available. + * @return the size or -1 if not available. + */ public long getLocalMirrorSize(); + + /** + * Translates a local path representation into a remote URL. + * <br />That URL can then be used to fetch the file from the remote archive. + * + * @param path is the file path relative to the root of the mirror module. + * @return the <code>URL</code> of the remote file. + */ public URL translatePathToURL(String path) throws MalformedURLException; } |