class PreloadedUriPrecedencePolicy extends BaseUriPrecedencePolicy 
implements Lifecycle {
    private static final long serialVersionUID = -1474685153995064123L;
    
    {
        setDefaultUriPrecedencePolicy(new BaseUriPrecedencePolicy());
    }
    public UriPrecedencePolicy getDefaultUriPrecedencePolicy() {
        return (UriPrecedencePolicy) kp.get("defaultUriPrecedencePolicy");
    }
    /** Backup URI precedence assignment policy to use. */
    public void setDefaultUriPrecedencePolicy(UriPrecedencePolicy policy) {
        kp.put("defaultUriPrecedencePolicy",policy);
    }

    // TODO: refactor to better share code with PersistOnlineProcessor
    protected BdbModule bdb;
    @Autowired
    public void setBdbModule(BdbModule bdb) {
        this.bdb = bdb;
    }

    protected StoredSortedMap<String, ?> store;
    protected Database historyDb;
    
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public void start() {<FILL_FUNCTION_BODY>}
    
    public boolean isRunning() {
        return historyDb != null; 
    }
    
    public void stop() {
        if(!isRunning()) {
            return;
        }
        
        // BdbModule will handle closing of DB
        // XXX happens at finish; move to teardown?
        historyDb = null;         
    }
    
    /* (non-Javadoc)
     * @see org.archive.crawler.frontier.precedence.BaseUriPrecedencePolicy#uriScheduled(org.archive.crawler.datamodel.CrawlURI)
     */
    @Override
    public void uriScheduled(CrawlURI curi) {
        int precedence = calculatePrecedence(curi);
        if(precedence==0) {
            // fall back to configured default policy
            getDefaultUriPrecedencePolicy().uriScheduled(curi);
            return;
        }
        curi.setPrecedence(precedence);
        
    }

    /* (non-Javadoc)
     * @see org.archive.crawler.frontier.precedence.BaseUriPrecedencePolicy#calculatePrecedence(org.archive.crawler.datamodel.CrawlURI)
     */
    @Override
    protected int calculatePrecedence(CrawlURI curi) {
        mergePrior(curi);
        Integer preloadPrecedence = (Integer) curi.getData().get(A_PRECALC_PRECEDENCE);
        if(preloadPrecedence==null) {
            return 0;
        }
        return super.calculatePrecedence(curi) + preloadPrecedence;
    }
    
    /**
     * Merge any data from the Map stored in the URI-history store into the 
     * current instance. 
     * 
     * TODO: ensure compatibility with use of PersistLoadProcessor; suppress
     * double-loading
     * @param curi CrawlURI to receive prior state data
     */
    protected void mergePrior(CrawlURI curi) {
        String key = PersistProcessor.persistKeyFor(curi);
        @SuppressWarnings({ "rawtypes", "unchecked" })
        Map<String,Map> prior = (Map<String, Map>) store.get(key);
        if(prior!=null) {
            // merge in keys
            curi.getData().putAll(prior); 
        }
    }
}

        if(isRunning()) {
            return;
        }
        store = null;
        String dbName = PersistProcessor.URI_HISTORY_DBNAME;
        try {
            StoredClassCatalog classCatalog = bdb.getClassCatalog();
            BdbModule.BdbConfig dbConfig = PersistProcessor.HISTORY_DB_CONFIG;

            historyDb = bdb.openDatabase(dbName, dbConfig, true);
            SerialBinding sb = new SerialBinding(classCatalog, Map.class);
            StoredSortedMap historyMap = new StoredSortedMap(historyDb, new StringBinding(), sb, true);
            store = historyMap;
        } catch (DatabaseException e) {
            throw new RuntimeException(e);
        }
    
<methods>public non-sealed void <init>() ,public int getBasePrecedence() ,public org.archive.spring.KeyedProperties getKeyedProperties() ,public void setBasePrecedence(int) ,public void uriScheduled(org.archive.modules.CrawlURI) <variables>protected org.archive.spring.KeyedProperties kp,private static final long serialVersionUID