View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.impl.wsdl.monitor;
14  
15  import java.util.Vector;
16  
17  import com.eviware.soapui.SoapUI;
18  
19  public class TcpMonMonitorEngine implements SoapMonitorEngine
20  {
21  	private SocketWaiter sw;
22  	private final Vector connections = new Vector();
23  	private int localPort;
24  
25  	public TcpMonMonitorEngine()
26  	{
27  	}
28  	
29     public void start( SoapMonitor monitor, int localPort )
30     {
31     	this.localPort = localPort;
32  		sw = new SocketWaiter( "Monitor on port " + localPort, monitor, localPort );
33     }
34  
35  	public void stop()
36  	{
37  		if( sw.isAlive())
38  		{
39  			try
40  			{
41  				for( int i = 0; i < connections.size(); i++ )
42  				{
43  					Connection conn = ( Connection ) connections.get( i );
44  					conn.halt();
45  				}
46  				sw.halt();
47  			}
48  			catch( Throwable e )
49  			{
50  				SoapUI.log.info( "Error stopping monitor: " + e.toString() );
51  			}
52  			
53  			SoapUI.log.info(  "Stopped SOAP Monitor on local port " + getLocalPort() );
54  		}
55  	}
56  
57  	public int getLocalPort()
58  	{
59  		return localPort;
60  	}
61  	
62  	public boolean isRunning()
63  	{
64  		return sw != null && sw.isAlive();
65  	}
66  }