001: /*
002: * Copyright (c) 2004-2005, Hewlett-Packard Company and Massachusetts
003: * Institute of Technology. All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are
007: * met:
008: *
009: * - Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * - Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * - Neither the name of the Hewlett-Packard Company nor the name of the
017: * Massachusetts Institute of Technology nor the names of their
018: * contributors may be used to endorse or promote products derived from
019: * this software without specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
022: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
023: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
024: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
025: * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
026: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
027: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
028: * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
029: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
030: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
031: * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
032: * DAMAGE.
033: */
034: package org.dspace.checker;
035:
036: import java.util.Date;
037:
038: /**
039: * An implementation of the selection strategy that selects bitstreams in the
040: * order that they were last checked, looping endlessly.
041: *
042: * @author Jim Downing
043: * @author Grace Carpenter
044: * @author Nathan Sarr
045: *
046: */
047: public class SimpleDispatcher implements BitstreamDispatcher {
048:
049: /**
050: * Should this dispatcher keep on dispatching around the collection?
051: */
052: private boolean loopContinuously = false;
053:
054: /**
055: * Date this dispatcher started dispatching.
056: */
057: private Date processStartTime = null;
058:
059: /**
060: * The next bitstreamId to be returned. -1 is a sentinel value used to
061: * indicate that there are no (more) bitstreams to give.
062: */
063: private int bitstreamId = -1;
064:
065: /**
066: * Access for bitstream information
067: */
068: private BitstreamInfoDAO bitstreamInfoDAO;
069:
070: /**
071: * Creates a new SimpleDispatcher.
072: *
073: * @param startTime
074: * timestamp for beginning of checker process
075: * @param looping
076: * indicates whether checker should loop infinitely through
077: * most_recent_checksum table
078: */
079: public SimpleDispatcher(BitstreamInfoDAO bitstreamInfoDAO,
080: Date startTime, boolean looping) {
081: this .bitstreamInfoDAO = bitstreamInfoDAO;
082: this .processStartTime = startTime;
083: this .loopContinuously = looping;
084: }
085:
086: /**
087: * Blanked off, no-op constructor. Do not use.
088: */
089: private SimpleDispatcher() {
090: ;
091: }
092:
093: /**
094: * Selects the next candidate bitstream.
095: *
096: * @see org.dspace.checker.BitstreamDispatcher#next()
097: */
098: public synchronized int next() {
099: // should process loop infinitely through the
100: // bitstreams in most_recent_checksum table?
101: if (!loopContinuously && (processStartTime != null)) {
102: return bitstreamInfoDAO
103: .getOldestBitstream(new java.sql.Timestamp(
104: processStartTime.getTime()));
105: } else {
106: return bitstreamInfoDAO.getOldestBitstream();
107: }
108:
109: }
110: }
|