Here are the examples of the java api class java.util.function.LongSupplier taken from open source projects.
1. CheckedSupplierTest#testCheckedLongSupplierWithCustomHandler()
Project: jOOL
File: CheckedSupplierTest.java
File: CheckedSupplierTest.java
@Test public void testCheckedLongSupplierWithCustomHandler() { final CheckedLongSupplier longSupplier = () -> { throw new Exception("long"); }; final Consumer<Throwable> handler = e -> { throw new IllegalStateException(e); }; LongSupplier test = Unchecked.longSupplier(longSupplier, handler); LongSupplier alias = CheckedLongSupplier.unchecked(longSupplier, handler); assertLongSupplier(test, IllegalStateException.class); assertLongSupplier(alias, IllegalStateException.class); }
2. CheckedSupplierTest#testCheckedLongSupplier()
Project: jOOL
File: CheckedSupplierTest.java
File: CheckedSupplierTest.java
@Test public void testCheckedLongSupplier() { final CheckedLongSupplier longSupplier = () -> { throw new Exception("long"); }; LongSupplier test = Unchecked.longSupplier(longSupplier); LongSupplier alias = CheckedLongSupplier.unchecked(longSupplier); assertLongSupplier(test, UncheckedException.class); assertLongSupplier(alias, UncheckedException.class); }
3. MetricCollectingServiceCodec#decodeRequest()
Project: armeria
File: MetricCollectingServiceCodec.java
File: MetricCollectingServiceCodec.java
@Override public DecodeResult decodeRequest(ServiceConfig cfg, Channel ch, SessionProtocol sessionProtocol, String hostname, String path, String mappedPath, ByteBuf in, Object originalRequest, Promise<Object> promise) throws Exception { final long startTime = System.nanoTime(); final int requestSize = in.readableBytes(); DecodeResult decodeResult = delegate().decodeRequest(cfg, ch, sessionProtocol, hostname, path, mappedPath, in, originalRequest, promise); LongSupplier lazyElapsedTime = () -> System.nanoTime() - startTime; switch(decodeResult.type()) { case SUCCESS: { ServiceInvocationContext context = decodeResult.invocationContext(); context.attr(METRICS).set(new MetricsData(requestSize, startTime)); metricConsumer.invocationStarted(context.scheme(), hostname, path, decodeResult.decodedMethod()); promise.addListener( future -> { if (!future.isSuccess()) { return; } Object result = future.getNow(); if (result instanceof FullHttpResponse) { FullHttpResponse httpResponse = (FullHttpResponse) result; metricConsumer.invocationComplete(context.scheme(), httpResponse.status().code(), lazyElapsedTime.getAsLong(), requestSize, httpResponse.content().readableBytes(), hostname, path, decodeResult.decodedMethod(), true); } }); break; } case FAILURE: { final Object errorResponse = decodeResult.errorResponse(); if (errorResponse instanceof FullHttpResponse) { FullHttpResponse httpResponse = (FullHttpResponse) errorResponse; metricConsumer.invocationComplete(Scheme.of(decodeResult.decodedSerializationFormat(), sessionProtocol), httpResponse.status().code(), lazyElapsedTime.getAsLong(), requestSize, httpResponse.content().readableBytes(), hostname, path, decodeResult.decodedMethod(), false); } else { metricConsumer.invocationComplete(Scheme.of(decodeResult.decodedSerializationFormat(), sessionProtocol), HttpResponseStatus.BAD_REQUEST.code(), lazyElapsedTime.getAsLong(), requestSize, 0, hostname, path, decodeResult.decodedMethod(), false); } break; } case NOT_FOUND: metricConsumer.invocationComplete(Scheme.of(decodeResult.decodedSerializationFormat(), sessionProtocol), HttpResponseStatus.NOT_FOUND.code(), lazyElapsedTime.getAsLong(), requestSize, 0, hostname, path, decodeResult.decodedMethod(), false); break; } return decodeResult; }