Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ShutdownThread.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2005 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Emmanuel Cecchet. 
00022  * Contributor(s): Nicolas Modrzyk.
00023  */
00024 
00025 package org.objectweb.cjdbc.controller.core.shutdown;
00026 
00027 import java.util.Date;
00028 
00029 import org.objectweb.cjdbc.common.exceptions.ShutdownException;
00030 import org.objectweb.cjdbc.common.i18n.Translate;
00031 import org.objectweb.cjdbc.common.log.Trace;
00032 
00033 /**
00034  * Skeleton for shutdown threads. This includes <code>Controller</code>,
00035  * <code>VirtualDatabase</code> and <code>DatabaseBackend</code> shutdown
00036  * threads.
00037  * 
00038  * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
00039  * @author <a href="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
00040  */
00041 public abstract class ShutdownThread implements Runnable
00042 {
00043   /** Group to join onto when shutting down */
00044   public ThreadGroup shutdownGroup = new ThreadGroup("shutdown" + new Date());
00045 
00046   protected int      shutdownLevel;
00047 
00048   /** Logger instance. */
00049   Trace              logger        = Trace
00050                                        .getLogger("org.objectweb.cjdbc.controller.shutdown");
00051 
00052   /**
00053    * Create a new shutdown thread
00054    * 
00055    * @param level Constants.SHUTDOWN_WAIT, Constants.SHUTDOWN_SAFE or
00056    *          Constants.SHUTDOWN_FORCE
00057    */
00058   public ShutdownThread(int level)
00059   {
00060     this.shutdownLevel = level;
00061     logger = Trace.getLogger("org.objectweb.cjdbc.controller.shutdown");
00062   }
00063 
00064   /**
00065    * Returns the shutdownGroup value.
00066    * 
00067    * @return Returns the shutdownGroup.
00068    */
00069   public ThreadGroup getShutdownGroup()
00070   {
00071     return shutdownGroup;
00072   }
00073 
00074   /**
00075    * Get shutdown level
00076    * 
00077    * @return level
00078    */
00079   public int getShutdownLevel()
00080   {
00081     return this.shutdownLevel;
00082   }
00083 
00084   /**
00085    * Execute the shutdown
00086    * 
00087    * @see java.lang.Runnable#run()
00088    */
00089   public void run()
00090   {
00091     try
00092     {
00093       shutdown();
00094     }
00095     catch (ShutdownException se)
00096     {
00097       se.printStackTrace();
00098       abortShutdown(se);
00099     }
00100   }
00101 
00102   /**
00103    * If shutdown fails ...
00104    * 
00105    * @param cause why shutdown was aborted
00106    */
00107   public void abortShutdown(Exception cause)
00108   {
00109     logger.info(Translate.get("controller.shutdown.aborted", cause));
00110   }
00111 
00112   /**
00113    * Specific implementation of the shutdown method.
00114    * 
00115    * @throws ShutdownException if fails
00116    */
00117   public abstract void shutdown() throws ShutdownException;
00118 
00119 }

Generated on Mon Apr 11 22:01:34 2005 for C-JDBC by  doxygen 1.3.9.1