| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Reloader | 
  | 
  | 2.0;2 | 
| 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 | 0 |  public class Reloader implements Runnable { | 
| 30 | ||
| 31 | 0 |      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(Reloader.class); | 
| 32 | ||
| 33 | 0 |      private final Set<Reloadable> reloadables = Collections.synchronizedSet(new HashSet<Reloadable>()); | 
| 34 | ||
| 35 | public void run() {  | |
| 36 |              try { | |
| 37 | 0 |                      LOG.debug("Checking if any reloading is necessary..."); | 
| 38 | 0 |                      synchronized (reloadables) { | 
| 39 | 0 |                              for (Iterator iterator = reloadables.iterator(); iterator.hasNext();) { | 
| 40 | 0 |                                      Reloadable reloadable = (Reloadable) iterator.next(); | 
| 41 | 0 |                                      LOG.debug("Checking reloadable: " + reloadable); | 
| 42 | 0 |                                      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 | 0 |                                              LOG.info("Reloading: " + reloadable); | 
| 47 | 0 |                                              reloadable.reload(); | 
| 48 |                              /*sleep(5000);*/ | |
| 49 | }  | |
| 50 | 0 |                              } | 
| 51 | 0 |                      } | 
| 52 | 0 |              } catch (Throwable t) { | 
| 53 | 0 |                      LOG.error("Failed to reload plugin.", t); | 
| 54 | 0 |              } | 
| 55 | 0 |      } | 
| 56 | ||
| 57 | public void addReloadable(Reloadable reloadable) {  | |
| 58 | 0 |          reloadables.add(reloadable); | 
| 59 | 0 |      } | 
| 60 | ||
| 61 | public void removeReloadable(Reloadable reloadable) {  | |
| 62 | 0 |          reloadables.remove(reloadable); | 
| 63 | 0 |      } | 
| 64 | ||
| 65 |      public Set<Reloadable> getReloadables() { | |
| 66 | 0 |              return reloadables; | 
| 67 | }  | |
| 68 | ||
| 69 | }  |