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