Last active
April 2, 2016 11:04
-
-
Save guidomedina/b71b81bedd69c64a7b65 to your computer and use it in GitHub Desktop.
Non-blocking LoggerMailbox
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
import akka.actor.ActorRef; | |
import akka.dispatch.*; | |
import akka.event.*; | |
import org.jctools.queues.MpscArrayQueue; | |
/** | |
* A non-blocking, multiple producer, single consumer high performance logger mailbox. | |
*/ | |
public final class LoggerMailbox implements MessageQueue, LoggerMessageQueueSemantics { | |
private final MpscArrayQueue<Envelope> queue = new MpscArrayQueue<>(4096); | |
@Override | |
public void enqueue(ActorRef receiver, Envelope handle) { | |
queue.offer(handle); | |
} | |
@Override | |
public Envelope dequeue() { | |
return queue.poll(); | |
} | |
@Override | |
public int numberOfMessages() { | |
return queue.size(); | |
} | |
@Override | |
public boolean hasMessages() { | |
return !queue.isEmpty(); | |
} | |
@Override | |
public void cleanUp(ActorRef owner, MessageQueue deadLetters) { | |
if (hasMessages()) { | |
Envelope envelope; | |
final Logging.StandardOutLogger standardOutLogger = Logging.StandardOutLogger(); | |
while ((envelope = queue.poll()) != null) { | |
standardOutLogger.tell(envelope.message(), envelope.sender()); | |
} | |
} | |
} | |
} |
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
import akka.actor.*; | |
import akka.dispatch.*; | |
import com.typesafe.config.Config; | |
import scala.Option; | |
/** | |
* A non-blocking, multiple producer, single consumer high performance logger mailbox type. | |
*/ | |
public final class LoggerMailboxType implements MailboxType, ProducesMessageQueue<LoggerMailbox> { | |
@SuppressWarnings("UnusedParameters") | |
public LoggerMailboxType(ActorSystem.Settings settings, Config config) { | |
} | |
@Override | |
public MessageQueue create(Option<ActorRef> owner, Option<ActorSystem> system) { | |
return new LoggerMailbox(); | |
} | |
} |
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
akka.actor.mailbox.logger-queue.mailbox-type = "com.xyz.mailbox.LoggerMailboxType" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment