KickJava   Java API By Example, From Geeks To Geeks.

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


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  * <p>
40  * A delegating dispatcher that puts a time limit on the operation of another
41  * dispatcher.
42  * </p>
43  *
44  * <p>
45  * Unit testing this class would be possible by abstracting the system time into
46  * an abstract clock. We decided this was not worth the candle.
47  * </p>
48  *
49  * @author Jim Downing
50  * @author Grace Carpenter
51  * @author Nathan Sarr
52  *
53  */

54 public class LimitedDurationDispatcher implements BitstreamDispatcher
55 {
56     /**
57      * The delegate dispatcher that will actually dispatch the jobs.
58      */

59     private BitstreamDispatcher delegate;
60
61     /**
62      * Milliseconds since epoch after which this dispatcher will stop returning
63      * values.
64      */

65     private long end;
66
67     /**
68      * Blanked off constructor - do not use.
69      */

70     private LimitedDurationDispatcher()
71     {
72         end = 0L;
73         delegate = null;
74     }
75
76     /**
77      * Main constructor.
78      *
79      * @param dispatcher
80      * Delegate dispatcher that will do the heavy lifting of the
81      * dispatching work.
82      * @param endTime
83      * when this dispatcher will stop returning valid bitstream ids.
84      */

85     public LimitedDurationDispatcher(BitstreamDispatcher dispatcher,
86             Date JavaDoc endTime)
87     {
88         delegate = dispatcher;
89         end = endTime.getTime();
90     }
91
92     /**
93      * @see org.dspace.checker.BitstreamDispatcher#next()
94      */

95     public int next()
96     {
97         return (System.currentTimeMillis() > end) ? SENTINEL : delegate.next();
98     }
99 }
100
Popular Tags