/** * Submit a single event to this raw TCP input by opening the connection, * submitting the event, and closing the connection. To submit multiple * events, use {@code attachWith} to open a single connection. * @see #attachWith * * @param eventBody A string that contains the event. */ public void submit(String eventBody) throws IOException { Socket socket = null; OutputStream output = null; try { socket = attach(); output = socket.getOutputStream(); output.write(eventBody.getBytes("UTF-8")); output.flush(); output.close(); socket.close(); } finally { if (output != null) { output.close(); } if (socket != null) { socket.close(); } } }
/** * Submits events to this raw TCP input, reusing the connection. * * This method passes an output stream connected to the index to the * {@code run} method of the {@code ReceiverBehavior} object, then handles * setting up and tearing down the socket. * For an example of how to use this method, see * <a href="http://dev.splunk.com/view/SP-CAAAEJ2" target="_blank">How to * get data into Splunk</a> on * <a href="http://dev.splunk.com/view/SP-CAAAEJ2" * target="_blank">dev.splunk.com</a>. */ public void attachWith(ReceiverBehavior behavior) throws IOException { Socket socket = null; OutputStream output = null; try { socket = attach(); output = socket.getOutputStream(); behavior.run(output); output.flush(); } finally { if (output != null) { output.close(); } if (socket != null) { socket.close(); } } }
@Override public void setup(OperatorContext context) { super.setup(context); tcpInput = (TcpInput)store.getService().getInputs().get(tcpPort); try { socket = tcpInput.attach(); stream = new DataOutputStream(socket.getOutputStream()); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public void setup(OperatorContext context) { super.setup(context); tcpInput = (TcpInput) store.getService().getInputs().get(tcpPort); try { socket = tcpInput.attach(); stream = new DataOutputStream(socket.getOutputStream()); } catch (IOException e) { throw new RuntimeException(e); } }