/** * Creates the {@code LEASE} frame. * * @param byteBufAllocator the {@code ByteBufAllocator} to use * @param timeToLive the validity of lease from time of reception * @param numberOfRequests the number of requests that may be sent until the next lease * @param metadata the metadata * @return the {@code LEASE} frame * @throws IllegalArgumentException if {@code timeToLive} is not a positive duration * @throws IllegalArgumentException if {@code numberOfRequests} is not positive * @throws NullPointerException if {@code byteBufAllocator} or {@code timeToLive} is {@code null} * @throws IllegalArgumentException if {@code timeToLive} is not a positive duration or {@code * numberOfRequests} is not positive */ public static LeaseFrame createLeaseFrame( ByteBufAllocator byteBufAllocator, Duration timeToLive, int numberOfRequests, @Nullable ByteBuf metadata) { Objects.requireNonNull(byteBufAllocator, "byteBufAllocator must not be null"); Objects.requireNonNull(timeToLive, "timeToLive must not be null"); NumberUtils.requirePositive(timeToLive.toMillis(), "timeToLive must be a positive duration"); NumberUtils.requirePositive(numberOfRequests, "numberOfRequests must be positive"); ByteBuf byteBuf = createFrameTypeAndFlags(byteBufAllocator, LEASE) .writeInt(toIntExact(timeToLive.toMillis())) .writeInt(numberOfRequests); byteBuf = appendMetadata(byteBuf, metadata); return RECYCLER.get().setByteBuf(byteBuf); }
/** * Creates the {@code LEASE} frame. * * @param byteBufAllocator the {@code ByteBufAllocator} to use * @param timeToLive the validity of lease from time of reception * @param numberOfRequests the number of requests that may be sent until the next lease * @param metadata the metadata * @return the {@code LEASE} frame * @throws IllegalArgumentException if {@code timeToLive} is not a positive duration * @throws IllegalArgumentException if {@code numberOfRequests} is not positive * @throws NullPointerException if {@code byteBufAllocator} or {@code timeToLive} is {@code null} * @throws IllegalArgumentException if {@code timeToLive} is not a positive duration or {@code * numberOfRequests} is not positive */ public static LeaseFrame createLeaseFrame( ByteBufAllocator byteBufAllocator, Duration timeToLive, int numberOfRequests, @Nullable ByteBuf metadata) { Objects.requireNonNull(byteBufAllocator, "byteBufAllocator must not be null"); Objects.requireNonNull(timeToLive, "timeToLive must not be null"); NumberUtils.requirePositive(timeToLive.toMillis(), "timeToLive must be a positive duration"); NumberUtils.requirePositive(numberOfRequests, "numberOfRequests must be positive"); ByteBuf byteBuf = createFrameTypeAndFlags(byteBufAllocator, LEASE) .writeInt(toIntExact(timeToLive.toMillis())) .writeInt(numberOfRequests); byteBuf = appendMetadata(byteBuf, metadata); return RECYCLER.get().setByteBuf(byteBuf); }