Search in sources :

Example 1 with NXCPException

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

the class SessionWorker method run.

@Override
public void run() {
    while (!Thread.currentThread().isInterrupted()) {
        try {
            final NXCPMessage message = messageReceiver.receiveMessage(inputStream, 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 : MessageProcessingResult(com.radensolutions.reporting.service.MessageProcessingResult) NXCPException(org.netxms.base.NXCPException) NXCPMessage(org.netxms.base.NXCPMessage) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 2 with NXCPException

use of org.netxms.base.NXCPException 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)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 NXCPException (org.netxms.base.NXCPException)2 NXCPMessage (org.netxms.base.NXCPMessage)2 NXCPMessageReceiver (org.netxms.base.NXCPMessageReceiver)1