01: /*
02: * Copyright 2004 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.outerj.daisy.backupTool;
17:
18: import java.io.File;
19: import java.net.InetAddress;
20: import java.net.Socket;
21:
22: import org.outerj.daisy.backupTool.dbDump.DbDumper;
23: import org.outerj.daisy.backupTool.dbDump.DbDumperFactory;
24: import org.w3c.dom.Element;
25:
26: public class OpenJMSEntryLoader extends AbstractEntryLoader {
27:
28: public OpenJMSEntryLoader(File openjmsConfig) throws Exception {
29: super (openjmsConfig);
30: }
31:
32: public void createEntries(BackupInstance buInstance)
33: throws Exception {
34: Element dbConf = BackupHelper
35: .getElementFromDom(configDocument,
36: "/Configuration/DatabaseConfiguration/RdbmsDatabaseConfiguration");
37: DbDumper dbDumper = DbDumperFactory.createDbDumper(dbConf
38: .getAttribute("url"), dbConf.getAttribute("user"),
39: dbConf.getAttribute("password"));
40:
41: buInstance.addEntry(createDbEntry(buInstance, dbDumper,
42: "openjms-dbDump.zip"));
43: buInstance.addEntry(createFileEntry(buInstance, configFile
44: .getParentFile(), configFile.getParentFile(),
45: "openjms-config.zip"));
46: }
47:
48: public void reloadEntries(BackupInstance buInstance,
49: boolean checkHashSums) throws Exception {
50: String[] entries = new String[] { "openjms-dbDump.zip",
51: "openjms-config.zip" };
52: if (areFilesBackedUp(buInstance, entries, checkHashSums)) {
53: // TODO put the openjms server running check elsewhere !!
54: if (isOpenjmsRunning())
55: throw new Exception(
56: "OpenJMS seems to be running. Shut it down & try again.");
57:
58: createEntries(buInstance);
59: } else {
60: System.out
61: .println("Openjms backup files were not found. Skipping restore of openjms.");
62: }
63: }
64:
65: private boolean isOpenjmsRunning() throws Exception {
66: boolean isRunning;
67: String host = BackupHelper.getStringFromDom(configDocument,
68: "/Configuration/ServerConfiguration/@host");
69: int port = Integer.parseInt(BackupHelper
70: .getStringFromDom(configDocument,
71: "/Configuration/TcpConfiguration/@port"));
72:
73: try {
74: Socket socket = new Socket(InetAddress.getByName(host),
75: port);
76: socket.close();
77: isRunning = true;
78: } catch (Exception e) {
79: isRunning = false;
80: }
81: return isRunning;
82: }
83:
84: }
|