View Javadoc

1   /*
2    * Copyright 2005-2008 The Kuali Foundation
3    *
4    *
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.opensource.org/licenses/ecl2.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 org.kuali.rice.kew.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 Kuali Rice Team (rice.collab@kuali.org)
28   */
29  public class Reloader implements Runnable {
30  
31      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(Reloader.class);
32  
33      private final Set<Reloadable> reloadables = Collections.synchronizedSet(new HashSet<Reloadable>());
34  
35      public void run() {
36      	try {
37      		LOG.debug("Checking if any reloading is necessary...");
38      		synchronized (reloadables) {
39      			for (Iterator iterator = reloadables.iterator(); iterator.hasNext();) {
40      				Reloadable reloadable = (Reloadable) iterator.next();
41      				LOG.debug("Checking reloadable: " + reloadable);
42      				if (reloadable.isReloadable() && reloadable.isReloadNeeded()) {
43      					/*long reloadWaitTime = getPluginReloadWaitTime();
44      					 LOG.info("Detected that a reload was needed...sleeping for "+(reloadWaitTime/1000)+" seconds...");
45      					 sleep(getPluginReloadWaitTime());*/
46      					LOG.info("Reloading: " + reloadable);
47      					reloadable.reload();
48                      	/*sleep(5000);*/
49      				}
50      			}
51      		}
52      	} catch (Throwable t) {
53      		LOG.error("Failed to reload plugin.", t);
54      	}
55      }
56  
57      public void addReloadable(Reloadable reloadable) {
58          reloadables.add(reloadable);
59      }
60  
61      public void removeReloadable(Reloadable reloadable) {
62          reloadables.remove(reloadable);
63      }
64  
65      public Set<Reloadable> getReloadables() {
66      	return reloadables;
67      }
68  
69  }