01: /*
02: * Copyright 2005-2006 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package edu.iu.uis.eden.plugin;
18:
19: import java.util.Collections;
20: import java.util.HashSet;
21: import java.util.Iterator;
22: import java.util.Set;
23:
24: /**
25: * A runnable which continuously polls Reloadable to see if they need to be reloaded.
26: *
27: * @author ewestfal
28: */
29: public class Reloader implements Runnable {
30:
31: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
32: .getLogger(Reloader.class);
33:
34: private final Set<Reloadable> reloadables = Collections
35: .synchronizedSet(new HashSet<Reloadable>());
36:
37: public void run() {
38: try {
39: LOG.debug("Checking if any reloading is necessary...");
40: synchronized (reloadables) {
41: for (Iterator iterator = reloadables.iterator(); iterator
42: .hasNext();) {
43: Reloadable reloadable = (Reloadable) iterator
44: .next();
45: LOG.debug("Checking reloadable: " + reloadable);
46: if (reloadable.isReloadable()
47: && reloadable.isReloadNeeded()) {
48: /*long reloadWaitTime = getPluginReloadWaitTime();
49: LOG.info("Detected that a reload was needed...sleeping for "+(reloadWaitTime/1000)+" seconds...");
50: sleep(getPluginReloadWaitTime());*/
51: LOG.info("Reloading: " + reloadable);
52: reloadable.reload();
53: /*sleep(5000);*/
54: }
55: }
56: }
57: } catch (Throwable t) {
58: LOG.error("Failed to reload plugin.", t);
59: }
60: }
61:
62: public void addReloadable(Reloadable reloadable) {
63: reloadables.add(reloadable);
64: }
65:
66: public void removeReloadable(Reloadable reloadable) {
67: reloadables.remove(reloadable);
68: }
69:
70: public Set<Reloadable> getReloadables() {
71: return reloadables;
72: }
73:
74: }
|