Skip to content

Instantly share code, notes, and snippets.

View guidomedina's full-sized avatar

Guido Medina guidomedina

View GitHub Profile
@guidomedina
guidomedina / CountingLatch.java
Created February 12, 2020 17:06
Countdown latch with increment and decrement functionality
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.AbstractQueuedSynchronizer;
public class CountingLatch
{
/**
* Synchronization control for CountingLatch.
* Uses AQS state to represent count.
*/
private static final class Sync extends AbstractQueuedSynchronizer
@guidomedina
guidomedina / TestClusterSelfLeave.java
Last active November 26, 2017 15:03
Akka cluster self leave example with both Artery and Netty
import akka.actor.*;
import akka.cluster.Cluster;
import akka.event.*;
import akka.japi.Creator;
import com.typesafe.config.ConfigFactory;
import java.util.concurrent.CountDownLatch;
import static akka.cluster.ClusterEvent.*;
import akka.actor.ActorRef;
import akka.dispatch.Envelope;
import akka.dispatch.MessageQueue;
import akka.dispatch.UnboundedMessageQueueSemantics;
import org.jctools.queues.MpscChunkedArrayQueue;
import org.jctools.util.Pow2;
public final class MpscChunkedMailbox implements MessageQueue, UnboundedMessageQueueSemantics {
import sun.misc.Unsafe;
import java.lang.reflect.Field;
public class LazySetLong {
static final Unsafe unsafe;
static final long valueOffset;
volatile long o;
@guidomedina
guidomedina / LoggerMailbox.java
Last active April 2, 2016 11:04
Non-blocking LoggerMailbox
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 {
@guidomedina
guidomedina / MpscBoundedMailbox.java
Last active November 5, 2018 19:27
MpscBoundedMailbox
import akka.actor.ActorRef;
import akka.dispatch.*;
import org.jctools.queues.MpscArrayQueue;
/**
* Non-blocking, multiple producer, single consumer high performance bounded message queue,
* this implementation is similar but simpler than LMAX disruptor.
*/
public final class MpscBoundedMailbox implements MessageQueue {