KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > console > gui > threads > GuiLoggingThread


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 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): Nicolas Modrzyk
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.console.gui.threads;
26
27 import java.net.Socket JavaDoc;
28
29 import javax.swing.JTextArea JavaDoc;
30
31 import org.apache.log4j.BasicConfigurator;
32 import org.apache.log4j.Layout;
33 import org.apache.log4j.LogManager;
34 import org.apache.log4j.PatternLayout;
35 import org.apache.log4j.WriterAppender;
36 import org.apache.log4j.net.SocketNode;
37 import org.objectweb.cjdbc.console.gui.jtools.JTextAreaWriter;
38
39 /**
40  * This class defines a GuiLoggingThread
41  *
42  * @author <a HREF="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
43  * @version 1.0
44  */

45 public class GuiLoggingThread extends Thread JavaDoc
46 {
47   private Socket JavaDoc logSocket;
48   private SocketNode node;
49   private JTextArea JavaDoc loggingTextPane;
50   private String JavaDoc host;
51   private Thread JavaDoc nodeThread;
52
53   /**
54    * Creates a new <code>GuiLoggingThread.java</code> object
55    *
56    * @param loggingTextPane the text area where to store output
57    * @param host where the log server is running
58    */

59   public GuiLoggingThread(JTextArea JavaDoc loggingTextPane, String JavaDoc host)
60   {
61     super();
62     this.host = host;
63     this.loggingTextPane = loggingTextPane;
64   }
65
66   /**
67    * Returns the host value.
68    *
69    * @return Returns the host.
70    */

71   public String JavaDoc getHost()
72   {
73     return host;
74   }
75   /**
76    * @see java.lang.Runnable#run()
77    */

78   public void run()
79   {
80     try
81     {
82       BasicConfigurator.configure();
83       JTextAreaWriter writer = new JTextAreaWriter(loggingTextPane);
84       Layout layout = new PatternLayout("%d %-5p %c{3} %m\n");
85       WriterAppender appender = new WriterAppender(layout, writer);
86       appender.setImmediateFlush(true);
87       LogManager.getRootLogger().removeAllAppenders();
88       LogManager.getRootLogger().addAppender(appender);
89       logSocket = new Socket JavaDoc(host, 9010);
90       node = new SocketNode(logSocket, LogManager.getLoggerRepository());
91       nodeThread = new Thread JavaDoc(node);
92       nodeThread.start();
93     }
94     catch (Exception JavaDoc e)
95     {
96       // ignore
97
}
98   }
99
100   /**
101    * Quitting
102    *
103    *
104    */

105   public void quit()
106   {
107     if(nodeThread!=null)
108       nodeThread.interrupt();
109   }
110 }
Popular Tags