FileDocCategorySizeDatePackage
NNTPSpooler.javaAPI DocApache James 2.3.113484Fri Jan 12 12:56:24 GMT 2007org.apache.james.nntpserver.repository

NNTPSpooler

public class NNTPSpooler extends org.apache.avalon.framework.logger.AbstractLogEnabled implements org.apache.avalon.framework.activity.Initializable, org.apache.avalon.framework.context.Contextualizable, org.apache.avalon.framework.configuration.Configurable
Processes entries and sends to appropriate groups. Eats up inappropriate entries.

Fields Summary
private org.apache.avalon.framework.context.Context
context
The spooler context
private SpoolerRunnable[]
worker
The array of spooler runnables, each associated with a Worker thread
private File
spoolPath
The directory containing entries to be spooled.
private String
spoolPathString
The String form of the spool directory.
private int
threadIdleTime
The time the spooler threads sleep between processing
Constructors Summary
Methods Summary
public voidconfigure(org.apache.avalon.framework.configuration.Configuration configuration)

see
org.apache.avalon.framework.configuration.Configurable#configure(Configuration)

        int threadCount = configuration.getChild("threadCount").getValueAsInteger(1);
        threadIdleTime = configuration.getChild("threadIdleTime").getValueAsInteger(60 * 1000);
        spoolPathString = configuration.getChild("spoolPath").getValue();
        worker = new SpoolerRunnable[threadCount];
    
public voidcontextualize(org.apache.avalon.framework.context.Context context)

see
org.apache.avalon.framework.context.Contextualizable#contextualize(Context)


           
        
              
        this.context = context;
    
java.io.FilegetSpoolPath()
Returns (and creates, if the directory doesn't already exist) the spool directory

return
the spool directory

        return spoolPath;
    
public voidinitialize()

see
org.apache.avalon.framework.activity.Initializable#initialize()

        //System.out.println(getClass().getName()+": init");

        try {
            spoolPath = AvalonContextUtilities.getFile(context, spoolPathString);
            if ( spoolPath.exists() == false ) {
                spoolPath.mkdirs();
            } else if (!(spoolPath.isDirectory())) {
                StringBuffer errorBuffer =
                    new StringBuffer(128)
                        .append("Spool directory is improperly configured.  The specified path ")
                        .append(spoolPathString)
                        .append(" is not a directory.");
                throw new ConfigurationException(errorBuffer.toString());
            }
        } catch (Exception e) {
            getLogger().fatalError(e.getMessage(), e);
            throw e;
        }

        for ( int i = 0 ; i < worker.length ; i++ ) {
            worker[i] = new SpoolerRunnable(threadIdleTime,spoolPath);
            if ( worker[i] instanceof LogEnabled ) {
                ((LogEnabled)worker[i]).enableLogging(getLogger());
            }
        }

        // TODO: Replace this with a standard Avalon thread pool
        for ( int i = 0 ; i < worker.length ; i++ ) {
            new Thread(worker[i],"NNTPSpool-"+i).start();
        }
    
voidsetArticleIDRepository(ArticleIDRepository articleIDRepo)
Sets the article id repository used by this spooler.

param
articleIDRepo the article id repository to be used

        for ( int i = 0 ; i < worker.length ; i++ ) {
            worker[i].setArticleIDRepository(articleIDRepo);
        }
    
voidsetRepository(NNTPRepository repo)
Sets the repository used by this spooler.

param
repo the repository to be used

        for ( int i = 0 ; i < worker.length ; i++ ) {
            worker[i].setRepository(repo);
        }