KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > server > log > ConnectionListener


1 /*
2  * ConnectionListener.java
3  *
4  * Created on September 7, 2003, 5:01 PM
5  */

6
7 package com.quikj.server.log;
8
9 import java.net.*;
10 import java.io.*;
11
12 import com.quikj.server.framework.*;
13
14 /**
15  *
16  * @author amit
17  */

18 public class ConnectionListener extends AceThread
19 {
20     private String JavaDoc name;
21     private ServerSocket socket;
22     private Object JavaDoc userParm;
23     
24     /** Creates a new instance of ConnectionListener */
25     public ConnectionListener(String JavaDoc name, ServerSocket socket, Object JavaDoc user_parm)
26     throws SocketException, IOException
27     {
28         super(name, true);
29         this.name = name;
30         userParm = user_parm;
31         this.socket = socket;
32         socket.setSoTimeout(1000);
33     }
34     
35     public void dispose()
36     {
37         interrupt();
38         
39         if (socket != null)
40         {
41             try
42             {
43                 socket.close();
44                 socket = null;
45             }
46             catch (IOException ex)
47             {
48                 ;
49             }
50         }
51         
52         super.dispose();
53     }
54     
55     public void run()
56     {
57         try
58         {
59             while (true)
60             {
61                 try
62                 {
63                     Socket sock = socket.accept();
64                     
65                     // a new connection has been received, send the message to the LogProcessor
66
LogProcessor.Instance().sendMessage(new ConnectionEvent(socket, sock, userParm));
67                 }
68                 catch (InterruptedIOException ex)
69                 {
70                     if (isInterrupted() == true)
71                     {
72                         break;
73                     }
74                     continue;
75                 }
76             }
77         }
78         catch (IOException ex)
79         {
80             dispose();
81         }
82     }
83 }
84
Popular Tags