@Override public void processMessages(ByteArrayOutputStream output) { try { if (interfacePort != null) { try { List<BidibCommand> bidibMessages = requestFactory.create(output.toByteArray()); for (BidibCommand message : bidibMessages) { MSG_TX_LOGGER.info(">> {} : {}", message, ByteUtils.bytesToHex(message.getContent())); } } catch (Exception e1) { LOGGER.warn("Prepare logging outgoing messages to interface failed.", e1); } interfacePort.send(output.toByteArray()); } } catch (Exception ex) { LOGGER.warn("Send message from proxy to interface failed.", ex); } finally { output.reset(); } } };
@Override public void sendData(ByteArrayOutputStream data) { try { byte[] bytes = data.toByteArray(); LOGGER.info("Send is called with bytes: {}", ByteUtils.bytesToHex(bytes)); // encode the message SerialMessageEncoder.encodeMessage(data, output); List<BidibCommand> bidibMessages = requestFactory.create(output.toByteArray()); for (BidibCommand bidibMessage : bidibMessages) { byte[] address = ((BidibMessage) bidibMessage).getAddr(); String nodeAddress = NodeUtils.formatAddress(address); SimulatorNode simulator = SimulatorRegistry.getInstance().getSimulator(nodeAddress); if (simulator == null) { LOGGER.warn("No simulator found for nodeAddress: {}", nodeAddress); } else { simulator.processRequest(bidibMessage); } LOGGER.debug("Forwarded message to simulator: {}", bidibMessage); } } catch (Exception ex) { LOGGER.warn("Process request failed.", ex); } finally { output.reset(); } }