net.sourceforge.java.feednread.backend.archive
Class NewsFeedArchive

java.lang.Object
  extended bynet.sourceforge.java.feednread.backend.archive.NewsFeedArchive

public class NewsFeedArchive
extends Object

Manages and organizes an archive of ArchivedNewsFeed instances. The archive itself is separated into two areas communicating among each other: The live archive which resides in memory and the persistent archive which is stored on a persistent medium, e.g. a harddisk or database. The settings controlling the behaviour of these two areas are configurable in the ConfigurationManager.

Use the following snippet to get the singleton NewsFeedArchive and add an arbitrary ArchivedNewsFeed to the archive.

 NewsFeedArchive archive = NewsFeedArchive.getInstance();
 archive.add(newsfeed);
 

Author:
Sebastian Machhausen

Nested Class Summary
private  class NewsFeedArchive.ArchivedFilenameFilter
           
 
Field Summary
private  Map archivedNewsFeeds
           The Map to hold the archived NewsFeeds
private static NewsFeedArchive SINGLETON_INSTANCE
           The single unique NewsFeedArchive instance
 
Constructor Summary
private NewsFeedArchive()
           Creates a new NewsFeedArchive instance.
 
Method Summary
 void add(ArchivedNewsFeed newsFeed)
           Adds the specified NewsFeed to this NewsFeedArchive.
private  void archive(ArchivedNewsFeed newsFeed)
           Archives the specified ArchivedNewsFeed.
private  void cleanupLiveArchive()
           Cleans up the live archive.
 void cleanupPersistentArchive()
           Cleans up the persistent archive.
 void clearPersistentArchive()
           Clears this NewsFeedArchive's persistent archive completely, i.e. removes all ArchivedNewsFeeds.
private  String createId(String newsFeedUrl)
           Creates an unique id for the newsfeed at the specified feedUrl.
private  double deletePersistent(String id)
           Deletes the ArchivedNewsFeed denoted by the specified id from the underlying persistent archive.
private  ArchivedNewsFeed getFromPersistentArchive(String id)
           Gets the ArchivedNewsFeed identified by the specified unique id from the persistent archive.
private  String getId(File f)
           Gets the id of the specified persistent ArchivedNewsFeed.
static NewsFeedArchive getInstance()
           Gets the single unique NewsFeedArchive instance.
 ArchivedNewsFeed getNewsFeed(String newsFeedUrl)
           Gets the ArchivedNewsFeed denoted by the specified newsFeedUrl from this NewsFeedArchive.
private  void makePersistent(ArchivedNewsFeed newsFeed)
           Makes the specified ArchivedNewsFeed persistent by writing it back to the persistent medium, e.g. the local harddisk.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SINGLETON_INSTANCE

private static NewsFeedArchive SINGLETON_INSTANCE

The single unique NewsFeedArchive instance


archivedNewsFeeds

private Map archivedNewsFeeds

The Map to hold the archived NewsFeeds

Constructor Detail

NewsFeedArchive

private NewsFeedArchive()

Creates a new NewsFeedArchive instance.

Method Detail

getInstance

public static NewsFeedArchive getInstance()

Gets the single unique NewsFeedArchive instance.

Returns:
the single unique NewsFeedArchive instance

getNewsFeed

public ArchivedNewsFeed getNewsFeed(String newsFeedUrl)

Gets the ArchivedNewsFeed denoted by the specified newsFeedUrl from this NewsFeedArchive.

Parameters:
newsFeedUrl - the url of the ArchivedNewsFeed to get from this NewsFeedArchive
Returns:
the ArchivedNewsFeed or null if there is no entry in this NewsFeedArchived matching the specified newsFeedUrl

add

public void add(ArchivedNewsFeed newsFeed)

Adds the specified NewsFeed to this NewsFeedArchive.

Parameters:
newsFeed - the ArchivedNewsFeed to add

cleanupPersistentArchive

public void cleanupPersistentArchive()

Cleans up the persistent archive.


clearPersistentArchive

public void clearPersistentArchive()

Clears this NewsFeedArchive's persistent archive completely, i.e. removes all ArchivedNewsFeeds.


archive

private void archive(ArchivedNewsFeed newsFeed)

Archives the specified ArchivedNewsFeed.

Parameters:
newsFeed - the ArchivedNewsFeed to archive

makePersistent

private void makePersistent(ArchivedNewsFeed newsFeed)

Makes the specified ArchivedNewsFeed persistent by writing it back to the persistent medium, e.g. the local harddisk.

Parameters:
newsFeed - the ArchivedNewsFeed to make persistent

getFromPersistentArchive

private ArchivedNewsFeed getFromPersistentArchive(String id)
                                           throws IOException,
                                                  ClassNotFoundException

Gets the ArchivedNewsFeed identified by the specified unique id from the persistent archive.

Parameters:
id - the unique id of the ArchivedNewsFeed
Returns:
the ArchivedNewsFeed from the persistent archive
Throws:
IOException - if an io error occured during the archive retrieval operation
ClassNotFoundException - if a Class mismatch was detected

cleanupLiveArchive

private void cleanupLiveArchive()

Cleans up the live archive.


getId

private String getId(File f)

Gets the id of the specified persistent ArchivedNewsFeed.

Parameters:
f - the persistent ArchivedNewsFeed File
Returns:
the id or null if no valid persistent ArchivedNewsFeed File

deletePersistent

private double deletePersistent(String id)

Deletes the ArchivedNewsFeed denoted by the specified id from the underlying persistent archive.

Parameters:
id - the id of the persistent ArchivedNewsFeed to delete
Returns:
the amount of freed persistent space in kilobytes

createId

private String createId(String newsFeedUrl)

Creates an unique id for the newsfeed at the specified feedUrl.

Parameters:
newsFeedUrl - the url of the newsfeed to generate an unique id for
Returns:
the unique id for the newsfeed at the specified newsFeedUrl