KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > backupTool > OpenJMSEntryLoader


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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.outerj.daisy.backupTool;
17
18 import java.io.File JavaDoc;
19 import java.net.InetAddress JavaDoc;
20 import java.net.Socket JavaDoc;
21
22 import org.outerj.daisy.backupTool.dbDump.DbDumper;
23 import org.outerj.daisy.backupTool.dbDump.DbDumperFactory;
24 import org.w3c.dom.Element JavaDoc;
25
26 public class OpenJMSEntryLoader extends AbstractEntryLoader {
27
28     public OpenJMSEntryLoader(File JavaDoc openjmsConfig) throws Exception JavaDoc {
29         super(openjmsConfig);
30     }
31
32     public void createEntries(BackupInstance buInstance) throws Exception JavaDoc {
33         Element JavaDoc dbConf = BackupHelper.getElementFromDom(configDocument, "/Configuration/DatabaseConfiguration/RdbmsDatabaseConfiguration");
34         DbDumper dbDumper = DbDumperFactory.createDbDumper(dbConf.getAttribute("url"), dbConf.getAttribute("user"), dbConf.getAttribute("password"));
35
36         buInstance.addEntry(createDbEntry(buInstance, dbDumper, "openjms-dbDump.zip"));
37         buInstance.addEntry(createFileEntry(buInstance, configFile.getParentFile(), configFile.getParentFile(), "openjms-config.zip"));
38     }
39
40     public void reloadEntries(BackupInstance buInstance) throws Exception JavaDoc {
41         String JavaDoc[] entries = new String JavaDoc[] { "openjms-dbDump.zip", "openjms-config.zip" };
42         if (areFilesBackedUp(buInstance, entries)) {
43             // TODO put the openjms server running check elsewhere !!
44
if (isOpenjmsRunning())
45                 throw new Exception JavaDoc("OpenJMS seems to be running. Shut it down & try again.");
46
47             createEntries(buInstance);
48         } else {
49             System.out.println("Openjms backup files were not found. Skipping restore of openjms.");
50         }
51     }
52
53     private boolean isOpenjmsRunning() throws Exception JavaDoc {
54         boolean isRunning;
55         String JavaDoc host = BackupHelper.getStringFromDom(configDocument, "/Configuration/ServerConfiguration/@host");
56         int port = Integer.parseInt(BackupHelper.getStringFromDom(configDocument, "/Configuration/TcpConfiguration/@port"));
57
58         try {
59             Socket JavaDoc socket = new Socket JavaDoc(InetAddress.getByName(host), port);
60             socket.close();
61             isRunning = true;
62         } catch (Exception JavaDoc e) {
63             isRunning = false;
64         }
65         return isRunning;
66     }
67
68 }
69
Popular Tags