001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2006 Continuent Inc.
004: * Contact: sequoia@continuent.org
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.continuent.sequoia.controller.backup.backupers;
018:
019: import java.io.IOException;
020: import java.util.HashMap;
021: import java.util.StringTokenizer;
022:
023: import org.continuent.sequoia.common.exceptions.BackupException;
024: import org.continuent.sequoia.controller.backup.BackupManager;
025: import org.continuent.sequoia.controller.backup.Backuper;
026: import org.continuent.sequoia.controller.backup.DumpTransferInfo;
027:
028: /**
029: * This class defines a AbstractBackuper, which can be used as a base class for
030: * most backupers. This class provides a default implementation for options
031: * parsing/setting and an implementation for dump serving/fetching that
032: * understands the dumpServer option.
033: */
034: public abstract class AbstractBackuper implements Backuper {
035: protected HashMap optionsMap = new HashMap();
036: protected String optionsString = null;
037:
038: /**
039: * @see Backuper#getOptions()
040: */
041: public String getOptions() {
042: return optionsString;
043: }
044:
045: /**
046: * @see Backuper#setOptions(java.lang.String)
047: */
048: public void setOptions(String options) {
049: if (options != null) {
050: StringTokenizer strTok = new StringTokenizer(options, ",");
051: String option = null;
052: String name = null;
053: String value = null;
054:
055: // Parse the string of options, add them to the HashMap
056: while (strTok.hasMoreTokens()) {
057: option = strTok.nextToken();
058: name = option.substring(0, option.indexOf("="));
059: value = option.substring(option.indexOf("=") + 1,
060: option.length());
061: optionsMap.put(name, value);
062: }
063:
064: optionsString = options;
065: }
066: }
067:
068: /**
069: * Returns the value of 'ignoreStdErrOutput' option. This option tells whether
070: * command success should be altered by any output on stderr. Default is
071: * false.
072: *
073: * @return true if ignoreStdErrOutput option is set to true, false otherwise
074: */
075: public boolean getIgnoreStdErrOutput() {
076: try {
077: return Boolean.valueOf(
078: (String) optionsMap.get("ignoreStdErrOutput"))
079: .booleanValue();
080: } catch (Exception e) { // Invalid or non-existing value for ignoreStdErrOutput
081: return false;
082: }
083: }
084:
085: /**
086: * {@inheritDoc}
087: *
088: * @see org.continuent.sequoia.controller.backup.Backuper#setupDumpServer()
089: */
090: public DumpTransferInfo setupDumpServer() throws IOException {
091: if (optionsMap.containsKey("dumpServer"))
092: return BackupManager
093: .setupDumpFileServer((String) optionsMap
094: .get("dumpServer"));
095:
096: return BackupManager.setupDumpFileServer();
097: }
098:
099: /**
100: * @see Backuper#fetchDump(org.continuent.sequoia.controller.backup.DumpTransferInfo,
101: * java.lang.String, java.lang.String)
102: */
103: public void fetchDump(DumpTransferInfo dumpTransferInfo,
104: String path, String dumpName) throws BackupException,
105: IOException {
106: BackupManager.fetchDumpFile(dumpTransferInfo, path, dumpName);
107: }
108:
109: }
|