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