View Javadoc
1 package net.sf.panoptes.model.node.log4j; 2 3 import java.io.IOException; 4 import java.io.ObjectInputStream; 5 import java.net.InetAddress; 6 import java.net.ServerSocket; 7 import java.net.Socket; 8 9 import org.apache.log4j.spi.LoggingEvent; 10 11 /*** 12 * SocketAppenderListener.java 13 * 14 * @author Dag Liodden 15 * @version 0.1 16 */ 17 public class SocketAppenderListener implements Runnable { 18 19 private int port; 20 private volatile boolean running = false; 21 private LoggerRepository repository; 22 23 /*** 24 * Constructor for SocketAppenderListener. 25 */ 26 public SocketAppenderListener(int port, LoggerRepository repository) { 27 this.port = port; 28 this.repository = repository; 29 } 30 31 public void startListening() { 32 running = true; 33 (new Thread(this)).start(); 34 } 35 36 /*** 37 * @see java.lang.Runnable#run() 38 */ 39 public void run() { 40 ServerSocket serverSocket; 41 try { 42 serverSocket = new ServerSocket(port); 43 while (true) { 44 Socket sock = serverSocket.accept(); 45 ObjectInputStream in = new ObjectInputStream(sock.getInputStream()); 46 Thread t = new Worker(in, sock.getInetAddress()); 47 t.start(); 48 } 49 50 } catch (IOException e) { 51 // TODO Auto-generated catch block 52 e.printStackTrace(); 53 } 54 55 } 56 57 class Worker extends Thread { 58 private volatile boolean running = true; 59 private ObjectInputStream in; 60 private InetAddress host; 61 62 Worker(ObjectInputStream in, InetAddress host) { 63 this.in = in; 64 this.host = host; 65 } 66 67 public void run() { 68 while (running) { 69 try { 70 Object o = in.readObject(); 71 repository.addEvent((LoggingEvent) o, host); 72 } catch (IOException e) { 73 // TODO Auto-generated catch block 74 break; 75 } catch (ClassNotFoundException e) { 76 break; 77 } 78 79 } 80 } 81 } 82 }

This page was automatically generated by Maven