FileDocCategorySizeDatePackage
AbstractDriver.javaAPI DocExample2630Sun Mar 02 16:20:34 GMT 2003com.mediamania.hotcache

AbstractDriver

public class AbstractDriver extends Object

Fields Summary
protected BufferedReader
requestReader
protected BufferedReader
updateReader
protected CacheAccess
cache
protected int
timeoutMillis
Constructors Summary
protected AbstractDriver(String updateURL, String requestURL, String timeout)

        updateReader = openReader(updateURL);
        requestReader = openReader(requestURL);
        timeoutMillis = Integer.parseInt(timeout);
    
Methods Summary
protected voidhandleRequest()

        String request = requestReader.readLine();
        Movie movie = cache.getMovieByTitle(request);
        System.out.println("Movie: " + movie.getTitle());
    
protected voidhandleUpdate()

        String update = updateReader.readLine();
        StringTokenizer tokenizer = new StringTokenizer(update, ";");
        String movieName = tokenizer.nextToken();
        String webSite = tokenizer.nextToken();
        cache.updateWebSite (movieName, webSite);
    
protected java.io.BufferedReaderopenReader(java.lang.String urlName)

        try {
            URL url = new URL(urlName);
            InputStream is = url.openStream();
            Reader r = new InputStreamReader(is);
            return new BufferedReader(r);
        } catch (Exception ex) {
            return null;
        }
    
protected voidserviceReaders()

        boolean done = false;
        boolean lastTime = false;
        try {
            while (!done) {
                if (updateReader.ready()) {
                    handleUpdate();
                    done = false;
                    lastTime = false;
                } else if (requestReader.ready()) {
                    handleRequest();
                    done = false;
                    lastTime = false;
                } else {
                    try {
                        Thread.sleep (timeoutMillis);
                        if (lastTime) done = true;
                        lastTime = true;
                    } catch (InterruptedException ex) {
                        done = true;
                    }
                }
            }
        } catch (Exception ex) {
            return;
        }