forked from elastic/logstash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide DLQ writer interface to Java plugins
Fixes elastic#10790
- Loading branch information
1 parent
b093c58
commit 08d2443
Showing
7 changed files
with
85 additions
and
7 deletions.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
logstash-core/src/main/java/co/elastic/logstash/api/Context.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
logstash-core/src/main/java/co/elastic/logstash/api/DeadLetterQueueWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package co.elastic.logstash.api; | ||
|
||
import java.io.IOException; | ||
|
||
public interface DeadLetterQueueWriter { | ||
|
||
void writeEntry(Event event, Plugin plugin, String reason) throws IOException; | ||
|
||
boolean isOpen(); | ||
|
||
long getCurrentQueueSize(); | ||
} |
32 changes: 32 additions & 0 deletions
32
logstash-core/src/main/java/org/logstash/common/DLQWriterAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.logstash.common; | ||
|
||
import co.elastic.logstash.api.DeadLetterQueueWriter; | ||
import co.elastic.logstash.api.Event; | ||
import co.elastic.logstash.api.Plugin; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
public class DLQWriterAdapter implements DeadLetterQueueWriter { | ||
|
||
private final org.logstash.common.io.DeadLetterQueueWriter dlqWriter; | ||
|
||
public DLQWriterAdapter(org.logstash.common.io.DeadLetterQueueWriter dlqWriter) { | ||
this.dlqWriter = Objects.requireNonNull(dlqWriter); | ||
} | ||
|
||
@Override | ||
public void writeEntry(Event event, Plugin plugin, String reason) throws IOException { | ||
dlqWriter.writeEntry((org.logstash.Event) event, plugin.getName(), plugin.getId(), reason); | ||
} | ||
|
||
@Override | ||
public boolean isOpen() { | ||
return dlqWriter != null && dlqWriter.isOpen(); | ||
} | ||
|
||
@Override | ||
public long getCurrentQueueSize() { | ||
return dlqWriter != null ? dlqWriter.getCurrentQueueSize() : 0; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
logstash-core/src/main/java/org/logstash/common/NullDeadLetterQueueWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.logstash.common; | ||
|
||
import co.elastic.logstash.api.DeadLetterQueueWriter; | ||
import co.elastic.logstash.api.Event; | ||
import co.elastic.logstash.api.Plugin; | ||
|
||
import java.io.IOException; | ||
|
||
public class NullDeadLetterQueueWriter implements DeadLetterQueueWriter { | ||
private static final NullDeadLetterQueueWriter INSTANCE = new NullDeadLetterQueueWriter(); | ||
|
||
private NullDeadLetterQueueWriter() { | ||
} | ||
|
||
public static NullDeadLetterQueueWriter getInstance() { | ||
return INSTANCE; | ||
} | ||
|
||
@Override | ||
public void writeEntry(Event event, Plugin plugin, String reason) throws IOException { | ||
// no-op | ||
} | ||
|
||
@Override | ||
public boolean isOpen() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public long getCurrentQueueSize() { | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
logstash-core/src/test/java/org/logstash/plugins/TestContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters