1 /**
2 * Copyright 2005 Steve Molloy
3 *
4 * This file is part of OV4J.
5 *
6 * OV4J is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
8 *
9 * OV4J is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
10 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with OV4J; if not, write to the Free Software
13 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14 *
15 */
16 package org.ov4j;
17
18 import java.io.IOException;
19 import java.io.Serializable;
20 import java.util.List;
21 import java.util.logging.Level;
22 import java.util.logging.Logger;
23
24 import org.ov4j.data.Item;
25
26 /**
27 * @author smolloy
28 *
29 */
30 public class LoadThread<T extends Comparable<? super T> & Cloneable & Serializable, C extends Comparable<? super C>>
31 extends Thread {
32 /**
33 * Logger for this class
34 */
35 private static final Logger logger = Logger.getLogger(LoadThread.class.getName());
36
37 /** List in which to add loaded item. */
38 private final List<Item<T, C>> list;
39
40 /** Container to use for loading. */
41 private final IContainer cont;
42
43 /** ID to load . */
44 private final C id;
45
46 /** Whether or not to load all versions. */
47 private final boolean allVersions;
48
49 /**
50 * @param list
51 * @param cont
52 * @param id
53 * @param allVersions
54 */
55 public LoadThread(final List<Item<T, C>> list, final IContainer cont, final C id, final boolean allVersions) {
56 this.list = list;
57 this.cont = cont;
58 this.id = id;
59 this.allVersions = allVersions;
60 }
61
62 /**
63 * @see java.lang.Thread#run()
64 */
65 @Override
66 public void run() {
67 if (LoadThread.logger.isLoggable(Level.FINER)) {
68 LoadThread.logger.entering("LoadThread", "run()", "start");
69 }
70
71 Item<T, C> it = null;
72 try {
73 it = cont.load(id, allVersions);
74 } catch (final IOException e) {
75 if (LoadThread.logger.isLoggable(Level.FINE)) {
76 LoadThread.logger.logp(Level.FINE, "LoadThread", "run()", "exception ignored", e);
77 }
78 }
79 if (it != null) {
80 list.add(it);
81 }
82
83 if (LoadThread.logger.isLoggable(Level.FINER)) {
84 LoadThread.logger.exiting("LoadThread", "run()", "end");
85 }
86 }
87 }