-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
experimental introduction of a bounded queue and rejection handler
- Loading branch information
Showing
6 changed files
with
71 additions
and
12 deletions.
There are no files selected for viewing
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
18 changes: 18 additions & 0 deletions
18
src/main/java/org/logstash/beats/CustomRejectedExecutionHandler.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,18 @@ | ||
package org.logstash.beats; | ||
|
||
import io.netty.util.concurrent.RejectedExecutionHandler; | ||
import io.netty.util.concurrent.SingleThreadEventExecutor; | ||
|
||
public class CustomRejectedExecutionHandler implements RejectedExecutionHandler { | ||
|
||
@Override | ||
public void rejected(Runnable task, SingleThreadEventExecutor executor) { | ||
System.out.println("Requeueing the message"); | ||
try { | ||
Thread.sleep(100); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
executor.execute(task); | ||
} | ||
} |
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,30 @@ | ||
package org.logstash.beats; | ||
|
||
import java.util.concurrent.ThreadFactory; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public class DaemonThreadFactory implements ThreadFactory { | ||
|
||
final ThreadGroup group; | ||
final AtomicInteger threadNumber = new AtomicInteger(1); | ||
final String namePrefix; | ||
|
||
DaemonThreadFactory(String namePrefix) { | ||
this.namePrefix = namePrefix; | ||
group = Thread.currentThread().getThreadGroup(); | ||
} | ||
|
||
@Override | ||
public Thread newThread(Runnable r) { | ||
Thread t = new Thread(group, r, | ||
namePrefix + "[T#" + threadNumber.getAndIncrement() + "]", | ||
0); | ||
t.setDaemon(true); | ||
return t; | ||
} | ||
|
||
public static ThreadFactory daemonThreadFactory(String namePrefix) { | ||
return new DaemonThreadFactory(namePrefix); | ||
} | ||
|
||
} |
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
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