Search in sources :

Example 1 with NXCPMessageReceiver

use of org.netxms.base.NXCPMessageReceiver in project netxms by netxms.

the class Session method receiverThread.

private void receiverThread() {
    // 256KB, 4MB
    final NXCPMessageReceiver messageReceiver = new NXCPMessageReceiver(262144, 4194304);
    while (!Thread.currentThread().isInterrupted()) {
        try {
            final NXCPMessage message = messageReceiver.receiveMessage(socket.getInputStream(), null);
            if (message != null) {
                if (message.getMessageCode() != NXCPCodes.CMD_KEEPALIVE) {
                    log.debug("Request: " + message.toString());
                }
                final MessageProcessingResult result = session.processMessage(message);
                if (result.response != null) {
                    if (message.getMessageCode() != NXCPCodes.CMD_KEEPALIVE) {
                        log.debug("Reply: " + result.response.toString());
                    }
                    sendMessage(result.response);
                    if (result.file != null) {
                        log.debug("File data found, sending");
                        FileInputStream s = null;
                        try {
                            s = new FileInputStream(result.file);
                            sendFileStream(message.getMessageId(), s);
                        } catch (IOException e) {
                            log.error("Unexpected I/O exception while sending rendered file");
                        }
                        if (s != null)
                            s.close();
                        result.file.delete();
                    }
                }
            }
        } catch (IOException e) {
            log.info("Communication error", e);
            stop();
        } catch (NXCPException e) {
            log.info("Invalid message received", e);
            stop();
        }
    }
}
Also used : NXCPMessageReceiver(org.netxms.base.NXCPMessageReceiver) MessageProcessingResult(com.radensolutions.reporting.service.MessageProcessingResult) NXCPException(org.netxms.base.NXCPException) NXCPMessage(org.netxms.base.NXCPMessage) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Aggregations

MessageProcessingResult (com.radensolutions.reporting.service.MessageProcessingResult)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 NXCPException (org.netxms.base.NXCPException)1 NXCPMessage (org.netxms.base.NXCPMessage)1 NXCPMessageReceiver (org.netxms.base.NXCPMessageReceiver)1