KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dspace > checker > SimpleDispatcher


1 /*
2  * Copyright (c) 2004-2005, Hewlett-Packard Company and Massachusetts
3  * Institute of Technology. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * - Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * - Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * - Neither the name of the Hewlett-Packard Company nor the name of the
17  * Massachusetts Institute of Technology nor the names of their
18  * contributors may be used to endorse or promote products derived from
19  * this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
32  * DAMAGE.
33  */

34 package org.dspace.checker;
35
36 import java.util.Date JavaDoc;
37
38 /**
39  * An implementation of the selection strategy that selects bitstreams in the
40  * order that they were last checked, looping endlessly.
41  *
42  * @author Jim Downing
43  * @author Grace Carpenter
44  * @author Nathan Sarr
45  *
46  */

47 public class SimpleDispatcher implements BitstreamDispatcher
48 {
49
50     /**
51      * Should this dispatcher keep on dispatching around the collection?
52      */

53     private boolean loopContinuously = false;
54
55     /**
56      * Date this dispatcher started dispatching.
57      */

58     private Date JavaDoc processStartTime = null;
59
60     /**
61      * The next bitstreamId to be returned. -1 is a sentinel value used to
62      * indicate that there are no (more) bitstreams to give.
63      */

64     private int bitstreamId = -1;
65
66     /**
67      * Access for bitstream information
68      */

69     private BitstreamInfoDAO bitstreamInfoDAO;
70
71     /**
72      * Creates a new SimpleDispatcher.
73      *
74      * @param startTime
75      * timestamp for beginning of checker process
76      * @param looping
77      * indicates whether checker should loop infinitely through
78      * most_recent_checksum table
79      */

80     public SimpleDispatcher(BitstreamInfoDAO bitstreamInfoDAO, Date JavaDoc startTime,
81             boolean looping)
82     {
83         this.bitstreamInfoDAO = bitstreamInfoDAO;
84         this.processStartTime = startTime;
85         this.loopContinuously = looping;
86     }
87
88     /**
89      * Blanked off, no-op constructor. Do not use.
90      */

91     private SimpleDispatcher()
92     {
93         ;
94     }
95
96     /**
97      * Selects the next candidate bitstream.
98      *
99      * @see org.dspace.checker.BitstreamDispatcher#next()
100      */

101     public synchronized int next()
102     {
103         // should process loop infinitely through the
104
// bitstreams in most_recent_checksum table?
105
if (!loopContinuously && (processStartTime != null))
106         {
107             return bitstreamInfoDAO.getOldestBitstream(new java.sql.Timestamp JavaDoc(
108                     processStartTime.getTime()));
109         }
110         else
111         {
112             return bitstreamInfoDAO.getOldestBitstream();
113         }
114
115     }
116 }
117
Popular Tags