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

GuiLoggingThread.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2004 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): Nicolas Modrzyk
00022  * Contributor(s): ______________________.
00023  */
00024 
00025 package org.objectweb.cjdbc.console.gui.threads;
00026 
00027 import java.net.Socket;
00028 
00029 import javax.swing.JTextArea;
00030 
00031 import org.apache.log4j.BasicConfigurator;
00032 import org.apache.log4j.Layout;
00033 import org.apache.log4j.LogManager;
00034 import org.apache.log4j.PatternLayout;
00035 import org.apache.log4j.WriterAppender;
00036 import org.apache.log4j.net.SocketNode;
00037 import org.objectweb.cjdbc.console.gui.jtools.JTextAreaWriter;
00038 
00039 /**
00040  * This class defines a GuiLoggingThread
00041  * 
00042  * @author <a href="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
00043  * @version 1.0
00044  */
00045 public class GuiLoggingThread extends Thread
00046 {
00047   private Socket     logSocket;
00048   private SocketNode node;
00049   private JTextArea  loggingTextPane;
00050   private String     host;
00051   private Thread nodeThread;
00052 
00053   /**
00054    * Creates a new <code>GuiLoggingThread.java</code> object
00055    * 
00056    * @param loggingTextPane the text area where to store output
00057    * @param host where the log server is running
00058    */
00059   public GuiLoggingThread(JTextArea loggingTextPane, String host)
00060   {
00061     super();
00062     this.host = host;
00063     this.loggingTextPane = loggingTextPane;
00064   }
00065 
00066   /**
00067    * Returns the host value.
00068    * 
00069    * @return Returns the host.
00070    */
00071   public String getHost()
00072   {
00073     return host;
00074   }
00075   /**
00076    * @see java.lang.Runnable#run()
00077    */
00078   public void run()
00079   {
00080     try
00081     {
00082       BasicConfigurator.configure();
00083       JTextAreaWriter writer = new JTextAreaWriter(loggingTextPane);
00084       Layout layout = new PatternLayout("%d %-5p %c{3} %m\n");
00085       WriterAppender appender = new WriterAppender(layout, writer);
00086       appender.setImmediateFlush(true);
00087       LogManager.getRootLogger().removeAllAppenders();
00088       LogManager.getRootLogger().addAppender(appender);
00089       logSocket = new Socket(host, 9010);
00090       node = new SocketNode(logSocket, LogManager.getLoggerRepository());
00091       nodeThread = new Thread(node);
00092       nodeThread.start();
00093     }
00094     catch (Exception e)
00095     {
00096       // ignore
00097     }
00098   }
00099 
00100   /**
00101    * Quitting
00102    * 
00103    * 
00104    */
00105   public void quit()
00106   {
00107     if(nodeThread!=null)
00108       nodeThread.interrupt();
00109   }
00110 }

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