1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.eviware.soapui.impl.wsdl.monitor;
18
19 import java.net.ServerSocket;
20 import java.net.Socket;
21
22 import com.eviware.soapui.SoapUI;
23
24 /***
25 * wait for incoming connections, spawn a connection thread when stuff comes in.
26 */
27
28 class SocketWaiter extends Thread
29 {
30 ServerSocket sSocket = null;
31 SoapMonitor listener;
32 int port;
33 boolean pleaseStop = false;
34
35 public SocketWaiter( String name, SoapMonitor l, int p )
36 {
37 super( name );
38 listener = l;
39 port = p;
40 start();
41 }
42
43 /***
44 * Method run
45 */
46 public void run()
47 {
48 try
49 {
50 sSocket = new ServerSocket( port );
51 for( ;; )
52 {
53 Socket inSocket = sSocket.accept();
54 if( pleaseStop )
55 {
56 break;
57 }
58 new Connection( getName() + " connection from " + inSocket.getRemoteSocketAddress(), listener, inSocket );
59 inSocket = null;
60 }
61 }
62 catch( Exception exp )
63 {
64 if( !"socket closed".equals( exp.getMessage() ) )
65 {
66 listener.stop();
67 }
68
69 SoapUI.log.info( "Error stopping SocketWaiter: " + exp.toString() );
70 }
71 }
72
73 /***
74 * force a halt by connecting to self and then closing the server socket
75 */
76 public void halt()
77 {
78 try
79 {
80 pleaseStop = true;
81 new Socket( "127.0.0.1", port );
82 if( sSocket != null )
83 {
84 sSocket.close();
85 }
86 }
87 catch( Exception e )
88 {
89 e.printStackTrace();
90 }
91 }
92 }