KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mvnforum > user > DeleteOrphanPmAttachmentTask


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/user/DeleteOrphanPmAttachmentTask.java,v 1.4 2006/04/14 17:05:27 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.4 $
5  * $Date: 2006/04/14 17:05:27 $
6  *
7  * ====================================================================
8  *
9  * Copyright (C) 2002-2006 by MyVietnam.net
10  *
11  * All copyright notices regarding mvnForum MUST remain
12  * intact in the scripts and in the outputted HTML.
13  * The "powered by" text/logo with a link back to
14  * http://www.mvnForum.com and http://www.MyVietnam.net in
15  * the footer of the pages MUST remain visible when the pages
16  * are viewed on the internet or intranet.
17  *
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 2 of the License, or
21  * any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31  *
32  * Support can be obtained from support forums at:
33  * http://www.mvnForum.com/mvnforum/index
34  *
35  * Correspondence and Marketing Questions can be sent to:
36  * info at MyVietnam net
37  *
38  * @author: Minh Nguyen
39  * @author: Mai Nguyen
40  */

41 package com.mvnforum.user;
42
43 import java.util.Date JavaDoc;
44 import java.util.TimerTask JavaDoc;
45
46 import org.apache.commons.logging.Log;
47 import org.apache.commons.logging.LogFactory;
48 import net.myvietnam.mvncore.util.TimerUtil;
49
50 class DeleteOrphanPmAttachmentTask extends TimerTask JavaDoc {
51
52     // static variable
53
private static Log log = LogFactory.getLog(DeleteOrphanPmAttachmentTask.class);
54
55     // static variable
56
private static DeleteOrphanPmAttachmentTask instance = null;
57
58     // instance variables
59
private boolean scheduled = false;
60     private int count = 0;
61     private PmAttachmentWebHandler pmAttachmentWebHandler = new PmAttachmentWebHandler();
62
63     // private constructor will prevent any instatiation
64
private DeleteOrphanPmAttachmentTask() {
65     }
66
67     /**
68      * This static method is used to get the Singleton instance of DeleteOrphanPmAttachmentTask
69      * @return the singleton instance of DeleteOrphanPmAttachmentTask
70      */

71     public static synchronized DeleteOrphanPmAttachmentTask getInstance() {
72         if (instance == null) {
73             instance = new DeleteOrphanPmAttachmentTask();
74         }
75         return instance;
76     }
77
78     public boolean cancel() {
79         return super.cancel();
80     }
81
82     public synchronized void schedule(Date JavaDoc firstTime, long period) {
83         if (scheduled == false) {
84             scheduled = true;
85             TimerUtil.getInstance().schedule(this, firstTime, period);
86         }
87     }
88
89     public synchronized void schedule(Date JavaDoc time) {
90         if (scheduled == false) {
91             scheduled = true;
92             TimerUtil.getInstance().schedule(this, time);
93         }
94     }
95
96     public synchronized void schedule(long delay) {
97         if (scheduled == false) {
98             scheduled = true;
99             TimerUtil.getInstance().schedule(this, delay);
100         }
101     }
102
103     public synchronized void schedule(long delay, long period) {
104         if (scheduled == false) {
105             scheduled = true;
106             TimerUtil.getInstance().schedule(this, delay, period);
107         }
108     }
109
110     public synchronized void scheduleAtFixedRate(Date JavaDoc firstTime, long period) {
111         if (scheduled == false) {
112             scheduled = true;
113             TimerUtil.getInstance().schedule(this, firstTime, period);
114         }
115     }
116
117     public synchronized void scheduleAtFixedRate(long delay, long period) {
118         if (scheduled == false) {
119             scheduled = true;
120             TimerUtil.getInstance().schedule(this, delay, period);
121         }
122     }
123
124     public void run() {
125         count++;
126         long start = System.currentTimeMillis();
127         try {
128             log.debug("Begin calling deleteOrphanPmAttachment in DeleteOrphanPmAttachmentTask");
129             pmAttachmentWebHandler.deleteOrphanPmAttachment();
130         } catch (Exception JavaDoc ex) {
131             log.error("Cannot process deleteOrphanPmAttachment in DeleteOrphanPmAttachmentTask", ex);
132         } finally{
133             long duration = System.currentTimeMillis() - start;
134             log.debug("DeleteOrphanPmAttachmentTask:deleteOrphanPmAttachment process " + count + " times, took " + duration + " ms");
135         }
136     }
137 }
138
Popular Tags