Skip to content

Instantly share code, notes, and snippets.

View NiteshKant's full-sized avatar

Nitesh Kant NiteshKant

View GitHub Profile
@NiteshKant
NiteshKant / MulticastBug.java
Last active January 26, 2022 01:25
Demonstrates ServiceTalk multicast operator issue where if only one subscriber requests data, nothing is delivered
package com.apple.acs.traffic.servicediscovery.insights.aggregator;
import io.servicetalk.concurrent.PublisherSource;
import io.servicetalk.concurrent.PublisherSource.Processor;
import io.servicetalk.concurrent.api.Publisher;
import io.servicetalk.concurrent.internal.TerminalNotification;
import javax.annotation.Nullable;
import java.util.concurrent.CountDownLatch;
/*
* Copyright © 2018 Apple Inc. and the ServiceTalk project authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@NiteshKant
NiteshKant / RouteGuideStreamingClient.java
Created October 29, 2021 21:23
RoutGuide client with retry and endless stream
/*
* Copyright © 2019 Apple Inc. and the ServiceTalk project authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@NiteshKant
NiteshKant / Client.java
Last active February 1, 2017 23:10
rs-java-issue-229
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import io.reactivesocket.ReactiveSocket;
import io.reactivesocket.client.KeepAliveProvider;
import io.reactivesocket.client.ReactiveSocketClient;
import io.reactivesocket.client.SetupProvider;
@NiteshKant
NiteshKant / SampleAddHandler.java
Created January 12, 2016 00:25
How to add a handler to an HTTP client and read headers.
package io.reactivex.netty.examples.http;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.http.HttpRequest;
import io.reactivex.netty.RxNetty;
import io.reactivex.netty.protocol.http.AbstractHttpContentHolder;
import io.reactivex.netty.protocol.http.client.HttpClient;
@NiteshKant
NiteshKant / Pager.java
Created November 5, 2015 07:33
Pagination with backpressure
import rx.Observable;
public class Pager {
public static void main(String[] args) {
Observable.range(1, 1000)
.window(10)
.doOnNext(nextBatch -> System.out.println("Next page."))
.flatMap(nums -> nums, 1)
.forEach(System.out::println);
/*
* Copyright 2015 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
Observable<WebSocketConnection> source = HttpClient.newClient()
.createGet("/ws")
.requestWebSocketUpgrade()
.doOnNext(resp -> logger.info(resp.toString()))
.map(WebSocketResponse::getWebSocketConnection)
.nest()
.lift(new OperatorCacheSingleWebsocketConnection());
Observable.interval(1, TimeUnit.SECONDS)
.map(aTick -> Observable.<WebSocketFrame>just(new MessageFrame(MessageType.Message,
@NiteshKant
NiteshKant / EchoClient.java
Created June 1, 2015 21:26
Sample for Drew
/*
* Copyright 2015 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
/*
* Copyright 2015 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software