KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > server > framework > AceCommandConnectionListener


1 /*
2  * AceCommandConnectionListener.java
3  *
4  * Created on August 22, 2002, 5:36 PM
5  */

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

16 public class AceCommandConnectionListener extends Thread JavaDoc
17 {
18     private ServerSocket sock;
19     
20     /** Creates a new instance of AceCommandConnectionListener */
21     public AceCommandConnectionListener(int port)
22     throws IOException
23     {
24         sock = new ServerSocket(port);
25     }
26     
27     public void dispose()
28     {
29         try
30         {
31             sock.close();
32         }
33         catch (IOException ex)
34         {
35             ; // ignore
36
}
37         
38         interrupt();
39     }
40     
41     public void run()
42     {
43         try
44         {
45             while (isInterrupted() == false)
46             {
47                 Socket session_socket = sock.accept();
48                 
49                 if (AceCommandService.getInstance().getCommandSessionThreadGrup().activeCount()
50                 >= AceCommandService.getInstance().getMaxUsers())
51                 {
52                     try
53                     {
54                         session_socket.close();
55                         continue;
56                     }
57                     catch (SocketException ex)
58                     {
59                         continue;
60                     }
61                     catch (IOException ex)
62                     {
63                         continue; // ignore
64
}
65
66                 }
67                 
68                 try
69                 {
70                     // a new connection has been received, start a new session
71
AceCommandSession session = new AceCommandSession(
72                     AceCommandService.getInstance().getCommandSessionThreadGrup(),
73                     session_socket,
74                     AceCommandService.getInstance().getCommandPrompt());
75                     session.start();
76                 }
77                 catch (IOException ex1)
78                 {
79                     try
80                     {
81                         session_socket.close();
82                     }
83                     catch (IOException ex2)
84                     {
85                         ;
86                     }
87                     continue;
88                 }
89             }
90         }
91         catch (IOException ex)
92         {
93             ;
94         }
95         
96         dispose();
97     }
98 }
99
Popular Tags