org.jpop.net
Class PoplogCachedClient

java.lang.Object
  extended byorg.jpop.net.PoplogDocClient
      extended byorg.jpop.net.PoplogCachedClient
All Implemented Interfaces:
ClientInterface, java.lang.Runnable

public abstract class PoplogCachedClient
extends PoplogDocClient

A PoplogDocClient that uses a document cache to minimize server requests. All the abstract methods in PoplogDocClient plus some more need to be implemented by any class that extends this client, ut given that they are messages that is alright.

Version:
1.0
Author:
dsm

Field Summary
static java.lang.String CACHE_DEFAULT_DIR
          The directory where the cache is to be stored by default
static java.lang.String DOC_DEFAULT
          common file names
static java.lang.String DOC_DOC_SUBDIR
          Subdirectories for the actual files
static java.lang.String DOC_HELP_SUBDIR
          Subdirectories for the actual files
static java.lang.String DOC_REF_SUBDIR
          Subdirectories for the actual files
static java.lang.String DOC_SUBDIR
          The name of the cache subdirectories
static java.lang.String DOC_TEACH_SUBDIR
          Subdirectories for the actual files
static java.lang.String HELP_DEFAULT
          common file names
static java.lang.String HELP_FILE
          common file names
static java.lang.String INFO_SUBDIR
          The name of the cache subdirectories
static java.lang.String LICENSE_FILE
          common file names
static java.lang.String LIST_ALL_FILE
          common file names
static java.lang.String LIST_DOC_FILE
          common file names
static java.lang.String LIST_HELP_FILE
          common file names
static java.lang.String LIST_REF_FILE
          common file names
static java.lang.String LIST_SUBDIR
          The name of the cache subdirectories
static java.lang.String LIST_TEACH_FILE
          common file names
static java.lang.String REF_DEFAULT
          common file names
static java.lang.String TEACH_DEFAULT
          common file names
 
Fields inherited from class org.jpop.net.PoplogDocClient
ERROR_MESG, SERVER_MESG, TEXT_MESG, WARNING_MESG
 
Constructor Summary
PoplogCachedClient(java.lang.String serverName, int port, java.lang.String cacheDir)
          Constructor for the object.
 
Method Summary
 void close()
          Closes the client
 java.lang.String getCacheDir()
          Gets the cache dir attribute of the PoplogCachedClient object.
 void getDoc(java.lang.String type, java.lang.String docname)
          Gets the doc required from the server
 java.io.File getDocFile(java.lang.String type, java.lang.String name)
          Gets the file for the name requested from section type
 void getHelp()
          Gets the help message from the server
 java.io.File getHelpFile()
          Gets the cached file for the server's help
 void getLicense()
          Get the license from the server
 java.io.File getLicenseFile()
          Gets the cached file for the server's license
 void getList(java.lang.String list)
          Gets the list required from the server or from the cache as required
 java.io.File getListFile(java.lang.String list)
          Gets the file for the list determined by "list"
static void main(java.lang.String[] args)
          Main method.
 void setCache(java.lang.String cacheDir)
          Sets the cache attribute of the PoplogCachedClient object
 
Methods inherited from class org.jpop.net.PoplogDocClient
clientConnected, clientDisconnected, connect, docReceived, errorReceived, exceptionGenerated, getInfo, getPort, getServerName, getVersion, help, helpReceived, info, isConnected, license, licenseReceived, listReceived, messageReceived, parse, println, resolveDocName, run, version, warningReceived
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CACHE_DEFAULT_DIR

public static final java.lang.String CACHE_DEFAULT_DIR
The directory where the cache is to be stored by default


DOC_SUBDIR

public static final java.lang.String DOC_SUBDIR
The name of the cache subdirectories

See Also:
Constant Field Values

LIST_SUBDIR

public static final java.lang.String LIST_SUBDIR
The name of the cache subdirectories

See Also:
Constant Field Values

INFO_SUBDIR

public static final java.lang.String INFO_SUBDIR
The name of the cache subdirectories

See Also:
Constant Field Values

DOC_DOC_SUBDIR

public static final java.lang.String DOC_DOC_SUBDIR
Subdirectories for the actual files

See Also:
Constant Field Values

DOC_HELP_SUBDIR

public static final java.lang.String DOC_HELP_SUBDIR
Subdirectories for the actual files

See Also:
Constant Field Values

DOC_REF_SUBDIR

public static final java.lang.String DOC_REF_SUBDIR
Subdirectories for the actual files

See Also:
Constant Field Values

DOC_TEACH_SUBDIR

public static final java.lang.String DOC_TEACH_SUBDIR
Subdirectories for the actual files

See Also:
Constant Field Values

LICENSE_FILE

public static final java.lang.String LICENSE_FILE
common file names

See Also:
Constant Field Values

HELP_FILE

public static final java.lang.String HELP_FILE
common file names

See Also:
Constant Field Values

LIST_ALL_FILE

public static final java.lang.String LIST_ALL_FILE
common file names

See Also:
Constant Field Values

LIST_REF_FILE

public static final java.lang.String LIST_REF_FILE
common file names

See Also:
Constant Field Values

LIST_DOC_FILE

public static final java.lang.String LIST_DOC_FILE
common file names

See Also:
Constant Field Values

LIST_HELP_FILE

public static final java.lang.String LIST_HELP_FILE
common file names

See Also:
Constant Field Values

LIST_TEACH_FILE

public static final java.lang.String LIST_TEACH_FILE
common file names

See Also:
Constant Field Values

REF_DEFAULT

public static final java.lang.String REF_DEFAULT
common file names

See Also:
Constant Field Values

TEACH_DEFAULT

public static final java.lang.String TEACH_DEFAULT
common file names

See Also:
Constant Field Values

DOC_DEFAULT

public static final java.lang.String DOC_DEFAULT
common file names

See Also:
Constant Field Values

HELP_DEFAULT

public static final java.lang.String HELP_DEFAULT
common file names

See Also:
Constant Field Values
Constructor Detail

PoplogCachedClient

public PoplogCachedClient(java.lang.String serverName,
                          int port,
                          java.lang.String cacheDir)
                   throws java.net.UnknownHostException,
                          java.io.IOException
Constructor for the object. Here we don't need a arg-less constructor because the application of the object is more specialized.

Parameters:
port - The port the server listens to
cacheDir - The local directory in which we will be storing cached pages. If this value is null the client will not use the cache at all and all requests will go through the server
serverName -
Throws:
java.net.UnknownHostException - When the host cannot be reached
java.io.IOException - When communication with the server cannot be established
Method Detail

main

public static void main(java.lang.String[] args)
Main method. Just to test the functionality

Parameters:
args - The commands line arguments

setCache

public void setCache(java.lang.String cacheDir)
              throws java.net.UnknownHostException,
                     java.io.IOException
Sets the cache attribute of the PoplogCachedClient object

Parameters:
cacheDir - The local directory where cache is supposed to go. If null, the client will not use cache and all requests will go through the server
Throws:
java.net.UnknownHostException - When the host cannot be reached
java.io.IOException - When communication with the server cannot be established

getCacheDir

public java.lang.String getCacheDir()
Gets the cache dir attribute of the PoplogCachedClient object.

Returns:
The cacheDir value. If null, the cache is not being used

getListFile

public java.io.File getListFile(java.lang.String list)
                         throws java.io.IOException
Gets the file for the list determined by "list"

Parameters:
list - the name of the list we want the file for
Returns:
The listFile value
Throws:
java.io.IOException - when the list file cannot be gotten because list is not valid

getList

public void getList(java.lang.String list)
Gets the list required from the server or from the cache as required

Specified by:
getList in interface ClientInterface
Overrides:
getList in class PoplogDocClient
Parameters:
list - any one of 'REF', 'HELP', 'TEACH', 'DOC' or ''

getDocFile

public java.io.File getDocFile(java.lang.String type,
                               java.lang.String name)
                        throws java.io.IOException
Gets the file for the name requested from section type

Parameters:
name - the name of the document we want the file for
type - The place the document is to come from, like REF, or HELP
Returns:
The docFile value
Throws:
java.io.IOException - when the file cannot be gotten or its not valid

getDoc

public void getDoc(java.lang.String type,
                   java.lang.String docname)
            throws ClientException
Gets the doc required from the server

Specified by:
getDoc in interface ClientInterface
Overrides:
getDoc in class PoplogDocClient
Parameters:
type - any one of 'REF', 'HELP', 'TEACH' or 'DOC'
docname - either the name of a file or ''
Throws:
ClientException - When the client can't read from the server

getHelpFile

public java.io.File getHelpFile()
Gets the cached file for the server's help

Returns:
The helpFile value

getHelp

public void getHelp()
Gets the help message from the server

Specified by:
getHelp in interface ClientInterface
Overrides:
getHelp in class PoplogDocClient

getLicenseFile

public java.io.File getLicenseFile()
Gets the cached file for the server's license

Returns:
The licenseFile value

getLicense

public void getLicense()
Get the license from the server

Specified by:
getLicense in interface ClientInterface
Overrides:
getLicense in class PoplogDocClient

close

public void close()
           throws java.io.IOException
Closes the client

Specified by:
close in interface ClientInterface
Overrides:
close in class PoplogDocClient
Throws:
java.io.IOException - When we can't close