KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > controller > core > shutdown > ShutdownThread


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
6  * Contact: sequoia@continuent.org
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  * Initial developer(s): Emmanuel Cecchet.
21  * Contributor(s): Nicolas Modrzyk.
22  */

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

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

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

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

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

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

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

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