001 /**
002 * Copyright 2005-2012 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.kew.plugin;
017
018 import java.util.Collections;
019 import java.util.HashSet;
020 import java.util.Iterator;
021 import java.util.Set;
022
023 /**
024 * A runnable which continuously polls Reloadable to see if they need to be reloaded.
025 *
026 * @author Kuali Rice Team (rice.collab@kuali.org)
027 */
028 public class Reloader implements Runnable {
029
030 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(Reloader.class);
031
032 private final Set<Reloadable> reloadables = Collections.synchronizedSet(new HashSet<Reloadable>());
033
034 public void run() {
035 try {
036 LOG.debug("Checking if any reloading is necessary...");
037 synchronized (reloadables) {
038 for (Iterator iterator = reloadables.iterator(); iterator.hasNext();) {
039 Reloadable reloadable = (Reloadable) iterator.next();
040 LOG.debug("Checking reloadable: " + reloadable);
041 if (reloadable.isReloadable() && reloadable.isReloadNeeded()) {
042 /*long reloadWaitTime = getPluginReloadWaitTime();
043 LOG.info("Detected that a reload was needed...sleeping for "+(reloadWaitTime/1000)+" seconds...");
044 sleep(getPluginReloadWaitTime());*/
045 LOG.info("Reloading: " + reloadable);
046 reloadable.reload();
047 /*sleep(5000);*/
048 }
049 }
050 }
051 } catch (Throwable t) {
052 LOG.error("Failed to reload plugin.", t);
053 }
054 }
055
056 public void addReloadable(Reloadable reloadable) {
057 reloadables.add(reloadable);
058 }
059
060 public void removeReloadable(Reloadable reloadable) {
061 reloadables.remove(reloadable);
062 }
063
064 public Set<Reloadable> getReloadables() {
065 return reloadables;
066 }
067
068 }