/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
*/ package org.apache.catalina.ha.deploy;
/** * The <b>WarWatcher </b> watches the deployDir for changes made to the directory (adding new WAR files->deploy or * remove WAR files->undeploy) and notifies a listener of the changes made. * * @author Peter Rossbach
*/ publicclass WarWatcher {
/** * check for modification and send notification to listener
*/ publicvoid check() { if (log.isDebugEnabled()) {
log.debug(sm.getString("warWatcher.checkingWars", watchDir));
}
File[] list = watchDir.listFiles(new WarFilter()); if (list == null) {
log.warn(sm.getString("warWatcher.cantListWatchDir", watchDir));
list = new File[0];
} // first make sure all the files are listed in our current status for (File file : list) { if (!file.exists()) {
log.warn(sm.getString("warWatcher.listedFileDoesNotExist", file, watchDir));
}
addWarInfo(file);
}
// Check all the status codes and update the FarmDeployer for (Iterator<Map.Entry<String,WarInfo>> i = currentStatus.entrySet().iterator(); i.hasNext();) {
Map.Entry<String,WarInfo> entry = i.next();
WarInfo info = entry.getValue(); if (log.isTraceEnabled()) {
log.trace(sm.getString("warWatcher.checkingWar", info.getWar()));
} int check = info.check(); if (check == 1) {
listener.fileModified(info.getWar());
} elseif (check == -1) {
listener.fileRemoved(info.getWar()); // no need to keep in memory
i.remove();
} if (log.isTraceEnabled()) {
log.trace(sm.getString("warWatcher.checkWarResult", Integer.valueOf(check), info.getWar()));
}
}
}
/** * add cluster war to the watcher state * * @param warfile The WAR to add
*/ protectedvoid addWarInfo(File warfile) {
WarInfo info = currentStatus.get(warfile.getAbsolutePath()); if (info == null) {
info = new WarInfo(warfile);
info.setLastState(-1); // assume file is non existent
currentStatus.put(warfile.getAbsolutePath(), info);
}
}
/** * Returns 1 if the file has been added/modified, 0 if the file is unchanged and -1 if the file has been removed * * @return int 1=file added; 0=unchanged; -1=file removed
*/ publicint check() { // file unchanged by default int result = 0;
if (modified()) { // file has changed - timestamp
result = 1;
lastState = result;
} elseif ((!exists()) && (!(lastState == -1))) { // file was removed
result = -1;
lastState = result;
} elseif ((lastState == -1) && exists()) { // file was added
result = 1;
lastState = result;
} this.lastChecked = System.currentTimeMillis(); return result;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.