public SenderResult send(List<DataObject> dataObjectList, long clock) throws IOException {
        //TODO Need refacing the method using XNIO
        SenderResult senderResult = new SenderResult();

        Socket socket = null;
        InputStream inputStream = null;
        OutputStream outputStream = null;
        try {
            socket = new Socket();

            socket.setSoTimeout(socketTimeout);
            socket.connect( new InetSocketAddress( host, port), connectTimeout);

            inputStream = socket.getInputStream();
            outputStream = socket.getOutputStream();

            SenderRequest senderRequest = new SenderRequest();
            senderRequest.setData(dataObjectList);
            senderRequest.setClock(clock);

            outputStream.write(senderRequest.toBytes());

            outputStream.flush();

            // normal responseData.length < 100
            byte[] responseData = new byte[512];

            int readCount = 0;

            while (true) {
                int read = inputStream.read(responseData, readCount, responseData.length - readCount);
                if (read <= 0) {
                    break;
                }
                readCount += read;
            }

            if (readCount < 13) {
                // seems zabbix server return "[]"?
                senderResult.setbReturnEmptyArray(true);
            }

            // header('ZBXD\1') + len + 0
            // 5 + 4 + 4
            String jsonString = new String( responseData, 13, readCount - 13, Charset.forName( "UTF-8"));
            logger.info( "jsonString : " +jsonString );
            ObjectMapper mapper = new ObjectMapper();
            JsonNode json =  mapper.readTree( jsonString );

//            JSONObject json = JSON.parseObject(jsonString);
            String info = json.get("info").asText();
            // example info: processed: 1; failed: 0; total: 1; seconds spent:
            // 0.000053
            // after split: [, 1, 0, 1, 0.000053]
            String[] split = PATTERN.split(info);
            senderResult.setProcessed(Integer.parseInt(split[1]));
            senderResult.setFailed(Integer.parseInt(split[2]));
            senderResult.setTotal(Integer.parseInt(split[3]));
            senderResult.setSpentSeconds(Float.parseFloat(split[4]));

        } finally {
            if (socket != null) {
                socket.close();
            }
            if (inputStream != null) {
                    inputStream.close();
            }
            if (outputStream != null) {
                outputStream.close();
            }
        }

        return senderResult;
    }
public SenderResult send ( List < DataObject > dataObjectList , long clock ) throws IOException { SenderResult senderResult = new SenderResult ( ) ; Socket socket = null ; InputStream inputStream = null ; OutputStream outputStream = null ; try { socket = new Socket ( ) ; socket . setSoTimeout ( socketTimeout ) ; socket . connect ( new InetSocketAddress ( host , port ) , connectTimeout ) ; inputStream = socket . getInputStream ( ) ; outputStream = socket . getOutputStream ( ) ; SenderRequest senderRequest = new SenderRequest ( ) ; senderRequest . setData ( dataObjectList ) ; senderRequest . setClock ( clock ) ; outputStream . write ( senderRequest . toBytes ( ) ) ; outputStream . flush ( ) ; byte [ ] responseData = new byte [ 512 ] ; int readCount = 0 ; while ( true ) { int read = inputStream . read ( responseData , readCount , responseData . length - readCount ) ; if ( read <= 0 ) { break ; } readCount += read ; } if ( readCount < 13 ) { senderResult . setbReturnEmptyArray ( true ) ; } String jsonString = new String ( responseData , 13 , readCount - 13 , Charset . forName ( "UTF-8" ) ) ; logger . info ( "jsonString : " + jsonString ) ; ObjectMapper mapper = new ObjectMapper ( ) ; JsonNode json = mapper . readTree ( jsonString ) ; String info = json . get ( "info" ) . asText ( ) ; String [ ] split = PATTERN . split ( info ) ; senderResult . setProcessed ( Integer . parseInt ( split [ 1 ] ) ) ; senderResult . setFailed ( Integer . parseInt ( split [ 2 ] ) ) ; senderResult . setTotal ( Integer . parseInt ( split [ 3 ] ) ) ; senderResult . setSpentSeconds ( Float . parseFloat ( split [ 4 ] ) ) ; } finally { if ( socket != null ) { socket . close ( ) ; } if ( inputStream != null ) { inputStream . close ( ) ; } if ( outputStream != null ) { outputStream . close ( ) ; } } return senderResult ; }
@param dataObjectList
@param clock
TimeUnit is SECONDS.
@return
@throws IOException