File tree Expand file tree Collapse file tree
src/main/java/com/teragrep/jla_04 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3535
3636public class RelpHandler extends Handler {
3737 private RelpConnection relpConnection ;
38- private final RelpBatch batch = new RelpBatch () ;
38+ private RelpBatch batch ;
3939 private RelpConfig config ;
4040
4141 // No arguments defaults to 'default' logger
@@ -92,6 +92,11 @@ public synchronized void publish(LogRecord logRecord) {
9292 .withSDElement (origin_48577 );
9393 }
9494
95+ // Initialize the batch for every set of messages
96+ if (this .batch == null ) {
97+ this .batch = new RelpBatch ();
98+ }
99+
95100 // Add to batch and send
96101 this .batch .insert (syslog .toRfc5424SyslogMessage ().getBytes (StandardCharsets .UTF_8 ));
97102 flush ();
@@ -120,6 +125,8 @@ public synchronized void flush() {
120125 allSent = true ;
121126 }
122127 }
128+ // Clean the batch
129+ this .batch = null ;
123130 }
124131
125132 private void reconnect () throws IOException , TimeoutException {
@@ -153,8 +160,6 @@ private void connect() {
153160
154161 @ Override
155162 public synchronized void close () {
156- // Flush the batches before disconnecting
157- flush ();
158163 try {
159164 disconnect ();
160165 } catch (IOException | TimeoutException e ) {
You can’t perform that action at this time.
0 commit comments