Package com.couchbase.client.core.utils
Class Buffers
java.lang.Object
com.couchbase.client.core.utils.Buffers
public class Buffers extends Object
Collection of utilities around
ByteBuf
.- Since:
- 1.1
- Author:
- Simon Baslé, Michael Nitschinger
-
Field Summary
Fields Modifier and Type Field Description static rx.functions.Action1
BYTE_BUF_RELEASER
An rxAction1
that releases (once) a non-nullByteBuf
provided its refCnt is > 0. -
Constructor Summary
Constructors Constructor Description Buffers()
-
Method Summary
Modifier and Type Method Description static <T> rx.Observable<T>
wrapColdWithAutoRelease(rx.Observable<T> source)
Wrap an observable and free a reference counted item if unsubscribed in the meantime.
-
Field Details
-
BYTE_BUF_RELEASER
public static final rx.functions.Action1 BYTE_BUF_RELEASERAn rxAction1
that releases (once) a non-nullByteBuf
provided its refCnt is > 0.
-
-
Constructor Details
-
Buffers
public Buffers()
-
-
Method Details
-
wrapColdWithAutoRelease
public static <T> rx.Observable<T> wrapColdWithAutoRelease(rx.Observable<T> source)Wrap an observable and free a reference counted item if unsubscribed in the meantime. This can and should be used if a hot observable is used as the source but it is not guaranteed that there will always be a subscriber that consumes the reference counted item. If an item is emitted by the source observable and no subscriber is attached (because it unsubscribed) the item will be freed. Note that also non reference counted items can be passed in, but there is no impact other than making it cold (in which case defer could be used). It is very important that if subscribed, the caller needs to release the reference counted item. It wil only be released on behalf of the caller when unsubscribed.- Parameters:
source
- the source observable to wrap.- Returns:
- the wrapped cold observable with refcnt release logic.
-