View Javadoc

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.cache;
17  
18  import java.io.IOException;
19  import java.util.TreeMap;
20  import java.util.logging.Level;
21  import java.util.logging.Logger;
22  
23  import org.ov4j.Controler;
24  import org.ov4j.data.ClassComparable;
25  import org.ov4j.data.Version;
26  
27  /**
28   * @author smolloy
29   * 
30   */
31  public class ResultFetcher extends Thread {
32  	/**
33  	 * Logger for this class
34  	 */
35  	private static final Logger										logger	=
36  																				Logger.getLogger(ResultFetcher.class
37  																					.getName());
38  
39  	/** Map in which to add loaded item. */
40  	private final TreeMap<CachedResultId, Version<ClassComparable>>	map;
41  
42  	/** Controler to use for loading. */
43  	private final Controler<ClassComparable, CachedResultId>		ctrl;
44  
45  	/** ID to load . */
46  	private final CachedResultId									id;
47  
48  	/**
49  	 * @param list
50  	 * @param cont
51  	 * @param id
52  	 * @param allVersions
53  	 */
54  	public ResultFetcher(final TreeMap<CachedResultId, Version<ClassComparable>> map,
55  		final Controler<ClassComparable, CachedResultId> ctrl, final CachedResultId id) {
56  		this.map = map;
57  		this.ctrl = ctrl;
58  		this.id = id;
59  	}
60  
61  	/**
62  	 * @see java.lang.Thread#run()
63  	 */
64  	@Override
65  	public void run() {
66  		if (ResultFetcher.logger.isLoggable(Level.FINER)) {
67  			ResultFetcher.logger.entering("ResultFetcher", "run()", "start");
68  		}
69  
70  		Version<ClassComparable> res = null;
71  		try {
72  			res = ctrl.latest(id);
73  		} catch (final IOException e) {
74  			if (ResultFetcher.logger.isLoggable(Level.FINE)) {
75  				ResultFetcher.logger.logp(Level.FINE, "ResultFetcher", "run()", "exception ignored", e);
76  			}
77  		}
78  		map.put(id, res);
79  
80  		if (ResultFetcher.logger.isLoggable(Level.FINER)) {
81  			ResultFetcher.logger.exiting("ResultFetcher", "run()", "end");
82  		}
83  	}
84  }