public void run ( ) { // For log messages. String client = socket . getInetAddress ( ) . getHostAddress ( ) ; if ( log . isDebugEnabled ( ) ) { log . info ( "Accepted Connection From: " + client ) ; } PrintWriter out = null ; BufferedReader in = null ; try { // Set timeout to 1 second. socket . setSoTimeout ( 1000 ) ; out = new PrintWriter ( socket . getOutputStream ( ) , true ) ; in = new BufferedReader ( new InputStreamReader ( socket . getInputStream ( ) ) ) ; String inputLine = in . readLine ( ) ; // Fix for zabbix_get. if ( inputLine . substring ( 0 , 4 ) . equals ( "ZBXD" ) ) { inputLine = inputLine . substring ( 13 , inputLine . length ( ) ) ; } if ( inputLine != null ) { try { Object value = container . getMetric ( inputLine ) ; out . print ( value . toString ( ) ) ; out . flush ( ) ; } catch ( MetricsException me ) { if ( log . isErrorEnabled ( ) ) { log . error ( "Client: " + client + " Sent Unknown Key: " + inputLine ) ; } out . print ( "ZBX_NOTSUPPORTED" ) ; out . flush ( ) ; } } } catch ( SocketTimeoutException ste ) { log . debug ( client + ": Timeout Detected." ) ; } catch ( Exception e ) { log . error ( client + ": Error: " + e . toString ( ) ) ; } finally { if ( log . isDebugEnabled ( ) ) { log . debug ( client + ": Disconnected." ) ; } try { if ( in != null ) { in . close ( ) ; } } catch ( Exception e ) { } try { if ( out != null ) { out . close ( ) ; } } catch ( Exception e ) { } try { socket . close ( ) ; } catch ( Exception e ) { } } }
WorkerThread execution begins .