Skip to content

Instantly share code, notes, and snippets.

Avatar

Kristoffer Sjögren krisskross

View GitHub Profile
View LastOffsetPerPartition.java
List<ConsumerRecord<byte[], byte[]>> lastRecords = new ArrayList<>();
try (KafkaConsumer<byte[], byte[]> consumer = new KafkaConsumer<>(consumerProps)) {
for (PartitionInfo info : consumer.partitionsFor(topic)) {
List<TopicPartition> list = new ArrayList<>();
list.add(new TopicPartition(topic, info.partition()));
consumer.assign(list);
consumer.seekToEnd(list);
ConsumerRecord<byte[], byte[]> last = consumer.poll(10000).iterator().next();
lastRecords.add(last);
View CursorTest.java
ByteBuffer seekKey = ByteBuffer.allocateDirect(4).putInt(4);
try (Cursor cursor = db.openCursor(tx)) {
if (cursor.get(seekKey, MDB_SET_KEY)) {
// regular users
ByteBuffer key = cursor.key();
ByteBuffer val = cursor.val();
do {
// advanced users
long keyAddress = cursor.keyAddress();
View jniJavaCppLmdbMapper.cpp
// Generated by JavaCPP version 1.2: DO NOT EDIT THIS FILE
#ifdef _WIN32
#define _JAVASOFT_JNI_MD_H_
#define JNIEXPORT __declspec(dllexport)
#define JNIIMPORT __declspec(dllimport)
#define JNICALL __stdcall
View RequestStreamAeron.java
import io.reactivesocket.*;
import io.reactivesocket.aeron.client.AeronClientDuplexConnection;
import io.reactivesocket.aeron.client.AeronClientDuplexConnectionFactory;
import io.reactivesocket.aeron.server.ReactiveSocketAeronServer;
import org.reactivestreams.Publisher;
import rx.Observable;
import rx.RxReactiveStreams;
import uk.co.real_logic.aeron.driver.MediaDriver;
import uk.co.real_logic.aeron.driver.ThreadingMode;
import uk.co.real_logic.agrona.concurrent.BackoffIdleStrategy;
View PingPong.java
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.reactivex.netty.RxNetty;
import io.reactivex.netty.channel.ObservableConnection;
import io.reactivex.netty.server.RxServer;
public class RxNettyTest {
public static void main(String[] args) throws Exception {
RxServer<ByteBuf, ByteBuf> tcpServer = RxNetty.createTcpServer(1111, connection -> {
View RxNettyTestWorking.java
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.reactivex.netty.RxNetty;
import io.reactivex.netty.channel.ObservableConnection;
import io.reactivex.netty.server.RxServer;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicInteger;
public class RxNettyTestWorking {
View RxNettyTest.java
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.reactivex.netty.RxNetty;
import io.reactivex.netty.channel.ObservableConnection;
import io.reactivex.netty.server.RxServer;
import rx.Observable;
public class RxNettyTest {
public static void main(String[] args) throws Exception {
RxServer<ByteBuf, ByteBuf> tcpServer = RxNetty.createTcpServer(1111, connection -> {
View Mpsc.java
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Group)
@Measurement(iterations = 5)
@Warmup(iterations = 5)
@Fork(value = 1)
public class Mpsc {
static long NANO_DELAY = 10;
static int SIZE = 4096;
private static final Integer ONE = 777;
View gist.java
public class Agent3 {
public static void main(String[] args) {
premain("", ByteBuddyAgent.installOnOpenJDK());
Service service = new Service();
System.out.println(service);
}
public static void premain(String arguments, Instrumentation instrumentation) {
// System.out.println(Service.class.getCanonicalName());
View gist:33567f6532eaa4aa3a0c
public class Test {
public static class ArrayListWrapper {
int id;
ArrayList<Integer> list = new ArrayList<>();
public ArrayListWrapper(int id) {
this.id = id;
}
public void add(int i) {