KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > bluecubs > xinco > archive > XincoArchiveThread


1 /**
2  *Copyright 2005 blueCubs.com
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  *************************************************************
17  * This project supports the blueCubs vision of giving back
18  * to the community in exchange for free software!
19  * More information on: http://www.bluecubs.org
20  *************************************************************
21  *
22  * Name: XincoArchiveThread
23  *
24  * Description: handle document indexing in thread
25  *
26  * Original Author: Alexander Manes
27  * Date: 2005/01/16
28  *
29  * Modifications:
30  *
31  * Who? When? What?
32  * - - -
33  *
34  *************************************************************
35  */

36
37 package com.bluecubs.xinco.archive;
38
39 import java.util.Calendar JavaDoc;
40 import java.util.GregorianCalendar JavaDoc;
41
42 import com.bluecubs.xinco.core.server.XincoDBManager;
43
44 /**
45  * This class runs document archiving in a separate thread
46  * (only one archiving thread is allowed)
47  */

48 public class XincoArchiveThread extends Thread JavaDoc {
49     
50     public static XincoArchiveThread instance = null;
51     
52     public Calendar JavaDoc firstRun = null;
53     public Calendar JavaDoc lastRun = null;
54     
55     public void run() {
56         long archive_period = 14400000;
57         firstRun = new GregorianCalendar JavaDoc();
58         while (true) {
59             try {
60                 XincoDBManager dbm = null;
61                 dbm = new XincoDBManager();
62                 archive_period = dbm.config.FileArchivePeriod;
63                 //exit archiver if period = 0
64
if (archive_period == 0) {
65                     break;
66                 }
67                 XincoArchiver.archiveData(dbm);
68                 lastRun = new GregorianCalendar JavaDoc();
69                 dbm.con.close();
70                 dbm = null;
71             } catch (Exception JavaDoc e){
72                 //continue, wait and try again...
73
archive_period = 14400000;
74             }
75             try {
76                 Thread.sleep(archive_period);
77             } catch (Exception JavaDoc se) {
78                 break;
79             }
80         }
81     }
82     
83     public static XincoArchiveThread getInstance() {
84         if (instance == null) {
85             instance = new XincoArchiveThread();
86         }
87         return instance;
88     }
89     
90     private XincoArchiveThread() {
91     }
92     
93 }
94
Popular Tags