KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > controller > core > shutdown > ShutdownThread


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2005 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Emmanuel Cecchet.
22  * Contributor(s): Nicolas Modrzyk.
23  */

24
25 package org.objectweb.cjdbc.controller.core.shutdown;
26
27 import java.util.Date JavaDoc;
28
29 import org.objectweb.cjdbc.common.exceptions.ShutdownException;
30 import org.objectweb.cjdbc.common.i18n.Translate;
31 import org.objectweb.cjdbc.common.log.Trace;
32
33 /**
34  * Skeleton for shutdown threads. This includes <code>Controller</code>,
35  * <code>VirtualDatabase</code> and <code>DatabaseBackend</code> shutdown
36  * threads.
37  *
38  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
39  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
40  */

41 public abstract class ShutdownThread implements Runnable JavaDoc
42 {
43   /** Group to join onto when shutting down */
44   public ThreadGroup JavaDoc shutdownGroup = new ThreadGroup JavaDoc("shutdown" + new Date JavaDoc());
45
46   protected int shutdownLevel;
47
48   /** Logger instance. */
49   Trace logger = Trace
50                                        .getLogger("org.objectweb.cjdbc.controller.shutdown");
51
52   /**
53    * Create a new shutdown thread
54    *
55    * @param level Constants.SHUTDOWN_WAIT, Constants.SHUTDOWN_SAFE or
56    * Constants.SHUTDOWN_FORCE
57    */

58   public ShutdownThread(int level)
59   {
60     this.shutdownLevel = level;
61     logger = Trace.getLogger("org.objectweb.cjdbc.controller.shutdown");
62   }
63
64   /**
65    * Returns the shutdownGroup value.
66    *
67    * @return Returns the shutdownGroup.
68    */

69   public ThreadGroup JavaDoc getShutdownGroup()
70   {
71     return shutdownGroup;
72   }
73
74   /**
75    * Get shutdown level
76    *
77    * @return level
78    */

79   public int getShutdownLevel()
80   {
81     return this.shutdownLevel;
82   }
83
84   /**
85    * Execute the shutdown
86    *
87    * @see java.lang.Runnable#run()
88    */

89   public void run()
90   {
91     try
92     {
93       shutdown();
94     }
95     catch (ShutdownException se)
96     {
97       se.printStackTrace();
98       abortShutdown(se);
99     }
100   }
101
102   /**
103    * If shutdown fails ...
104    *
105    * @param cause why shutdown was aborted
106    */

107   public void abortShutdown(Exception JavaDoc cause)
108   {
109     logger.info(Translate.get("controller.shutdown.aborted", cause));
110   }
111
112   /**
113    * Specific implementation of the shutdown method.
114    *
115    * @throws ShutdownException if fails
116    */

117   public abstract void shutdown() throws ShutdownException;
118
119 }
Popular Tags