https://github.com/casidiablo/java-bloomd-client
Java client for bloomd
https://github.com/casidiablo/java-bloomd-client
bloomd rxjava-extension
Last synced: 7 months ago
JSON representation
Java client for bloomd
- Host: GitHub
- URL: https://github.com/casidiablo/java-bloomd-client
- Owner: casidiablo
- License: other
- Created: 2016-04-26T04:05:51.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-06-24T11:33:43.000Z (over 5 years ago)
- Last Synced: 2025-06-11T23:12:34.564Z (7 months ago)
- Topics: bloomd, rxjava-extension
- Language: Java
- Homepage:
- Size: 105 KB
- Stars: 10
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
## java-bloomd-client
Java client for [armon's bloomd](https://github.com/armon/bloomd) built atop [netty](https://github.com/netty/netty).
### Usage
Interactions with a `bloomd` server are done through the `BloomdClient` interface which
can be created using the `BloomdClient.newInstance("host", port)` method. The API is
purely asynchronous so all methods provided by the interface, including `newInstance`,
return a `Future`.
```java
// get bloomd client implementation
BloomdClient client = BloomdClient.newInstance("localhost", port).get();
// create a filter
assert client.create("someFilterName").get() == CreateResult.DONE;
// set and check for an item
assert client.set("someFilterName", "nishtiman").get() == StateResult.YES;
assert client.check("someFilterName", "nishtiman").get() == StateResult.YES;
assert client.check("someFilterName", "non-extant").get() == StateResult.NO;
```
### RxJava extension
Using `Future`s, though a common practice for asynchronous APIs, is cumbersome due to the limitations of this interface. A RxJava extension is provided that provides a better way to chain computations as well as centralize error handling and timeouts, etc. Here's the same example presented above but using RxJava:
```java
RxBloomdClient client = RxBloomdClient.newInstance("localhost", 8673);
// make sure filters can be created
TestSubscriber subscriber = new TestSubscriber<>();
client.create("someFilterName")
.flatMap(createResult -> {
// filter should have been created
assert createResult == CreateResult.DONE;
return client.set("someFilterName", "nishtiman");
})
.flatMap(setResult -> {
// should be YES because the filter didn't have the item
assert setResult == StateResult.YES;
return client.check("someFilterName", "nishtiman");
})
.flatMap(checkResult -> {
// should be YES because the filter had the item
assert checkResult == StateResult.YES;
return client.check("someFilterName", "non-extant");
})
.doOnNext(checkResult -> {
// should be NO because the filter does not have "non-extant"
assert checkResult == StateResult.NO;
})
.doOnError(throwable -> {
// should never hit this
assert false;
})
.subscribe(subscriber);
```
### Connection pooling
A pooling mechanism is provided to allow concurrent connections to a single server:
```java
int poolSize = 20;
BloomdClientPool bloomdClientPool = new BloomdClientPool("host", 8673, poolSize);
// acquire a new client from the pool
Future clientFuture = bloomdClientPool.acquire();
BloomdClient client = clientFuture.get();
// do some cool stuff...
// release client
Future releaseFuture = bloomdClientPool.release(client);
```
The RxJava extension also offers a pooling implementation atop `BloomdClientPool`:
```java
RxBloomdClientPool rxClientPool = new RxBloomdClientPool("host", 8673, 5);
Observable clientObservable = rxClientPool.acquire();
```
### Installation
Gradle:
```groovy
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
compile 'com.github.casidiablo.java-bloomd-client:bloomd-client:0.13'
compile 'com.github.casidiablo.java-bloomd-client:rx-bloomd-client:0.13'
}
```
Leiningen:
```clojure
:repositories [["jitpack" "https://jitpack.io"]]
:dependencies [[com.github.casidiablo.java-bloomd-client/bloomd-client "0.13"]]
```
Maven:
```xml
jitpack.io
https://jitpack.io
com.github.casidiablo.java-bloomd-client
bloomd-client
0.13
compile
```