/** * Returns the Job UUID of that the response event will have. * * @param channel * @param command * @return Job-UUID as a string */ public String sendAsyncCommand(Channel channel, final String command) { /* * Send synchronously to get the Job-UUID to return, the results of the actual * job request will be returned by the server as an async event. */ EslMessage response = sendSyncSingleLineCommand(channel, command); if (response.hasHeader(Name.JOB_UUID)) { return response.getHeaderValue(Name.JOB_UUID); } else { throw new IllegalStateException("Missing Job-UUID header in bgapi response"); } }
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { if (e.getMessage() instanceof EslMessage) { EslMessage message = (EslMessage) e.getMessage(); String contentType = message.getContentType(); if (contentType.equals(Value.TEXT_EVENT_PLAIN) || contentType.equals(Value.TEXT_EVENT_XML)) { // transform into an event EslEvent eslEvent = new EslEvent(message); handleEslEvent(ctx, eslEvent); } else { handleEslMessage(ctx, (EslMessage) e.getMessage()); } } else { throw new IllegalStateException("Unexpected message type: " + e.getMessage().getClass()); } }
protected void handleEslMessage(ChannelHandlerContext ctx, EslMessage message) { log.info("Received message: [{}]", message); String contentType = message.getContentType(); if (contentType.equals(Value.API_RESPONSE)) { log.debug("Api response received [{}]", message); syncCallbacks.poll().handle(message); } else if (contentType.equals(Value.COMMAND_REPLY)) { log.debug("Command reply received [{}]", message); syncCallbacks.poll().handle(message); } else if (contentType.equals(Value.AUTH_REQUEST)) { log.debug("Auth request received [{}]", message); handleAuthRequest(ctx); } else if (contentType.equals(Value.TEXT_DISCONNECT_NOTICE)) { log.debug("Disconnect notice received [{}]", message); handleDisconnectionNotice(); } else { log.warn("Unexpected message content type [{}]", contentType); } }