scala.runtime.AbstractFunction0 Java Examples
The following examples show how to use
scala.runtime.AbstractFunction0.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: topicTest.java From zipkin-finagle with Apache License 2.0 | 6 votes |
@Test public void letOverridesDefault() { final String override = "zipkin-dev"; final AtomicBoolean ran = new AtomicBoolean(); Function0<BoxedUnit> fn0 = new AbstractFunction0<BoxedUnit>() { @Override public BoxedUnit apply() { ran.set(true); // used to verify this block is executed. assertThat(topic$.Flag.isDefined()).isTrue(); assertThat(topic$.Flag.apply()).isEqualTo(override); return BoxedUnit.UNIT; } }; topic$.Flag.let(override, fn0); assertThat(ran.get()).isTrue(); }
Example #2
Source File: BKDistributedLogManager.java From distributedlog with Apache License 2.0 | 6 votes |
private Future<DLSN> getDLSNNotLessThanTxId(long fromTxnId, final List<LogSegmentMetadata> segments) { if (segments.isEmpty()) { return getLastDLSNAsync(); } final int segmentIdx = DLUtils.findLogSegmentNotLessThanTxnId(segments, fromTxnId); if (segmentIdx < 0) { return Future.value(new DLSN(segments.get(0).getLogSegmentSequenceNumber(), 0L, 0L)); } final LedgerHandleCache handleCache = LedgerHandleCache.newBuilder().bkc(readerBKC).conf(conf).build(); return getDLSNNotLessThanTxIdInSegment( fromTxnId, segmentIdx, segments, handleCache ).ensure(new AbstractFunction0<BoxedUnit>() { @Override public BoxedUnit apply() { handleCache.clear(); return BoxedUnit.UNIT; } }); }
Example #3
Source File: TestReadUtils.java From distributedlog with Apache License 2.0 | 6 votes |
private Future<Optional<LogRecordWithDLSN>> getLogRecordNotLessThanTxId( BKDistributedLogManager bkdlm, int logsegmentIdx, long transactionId) throws Exception { List<LogSegmentMetadata> logSegments = bkdlm.getLogSegments(); final LedgerHandleCache handleCache = LedgerHandleCache.newBuilder() .bkc(bkdlm.getWriterBKC()) .conf(conf) .build(); return ReadUtils.getLogRecordNotLessThanTxId( bkdlm.getStreamName(), logSegments.get(logsegmentIdx), transactionId, Executors.newSingleThreadExecutor(), handleCache, 10 ).ensure(new AbstractFunction0<BoxedUnit>() { @Override public BoxedUnit apply() { handleCache.clear(); return BoxedUnit.UNIT; } }); }
Example #4
Source File: TestReadUtils.java From distributedlog with Apache License 2.0 | 6 votes |
private Future<LogRecordWithDLSN> getFirstGreaterThanRecord(BKDistributedLogManager bkdlm, int ledgerNo, DLSN dlsn) throws Exception { List<LogSegmentMetadata> ledgerList = bkdlm.getLogSegments(); final LedgerHandleCache handleCache = LedgerHandleCache.newBuilder() .bkc(bkdlm.getWriterBKC()) .conf(conf) .build(); return ReadUtils.asyncReadFirstUserRecord( bkdlm.getStreamName(), ledgerList.get(ledgerNo), 2, 16, new AtomicInteger(0), Executors.newFixedThreadPool(1), handleCache, dlsn ).ensure(new AbstractFunction0<BoxedUnit>() { @Override public BoxedUnit apply() { handleCache.clear(); return BoxedUnit.UNIT; } }); }
Example #5
Source File: BKLogHandler.java From distributedlog with Apache License 2.0 | 6 votes |
private Future<LogRecordWithDLSN> asyncReadFirstUserRecord(LogSegmentMetadata ledger, DLSN beginDLSN) { final LedgerHandleCache handleCache = LedgerHandleCache.newBuilder().bkc(bookKeeperClient).conf(conf).build(); return ReadUtils.asyncReadFirstUserRecord( getFullyQualifiedName(), ledger, firstNumEntriesPerReadLastRecordScan, maxNumEntriesPerReadLastRecordScan, new AtomicInteger(0), scheduler, handleCache, beginDLSN ).ensure(new AbstractFunction0<BoxedUnit>() { @Override public BoxedUnit apply() { handleCache.clear(); return BoxedUnit.UNIT; } }); }
Example #6
Source File: TestReadUtils.java From distributedlog with Apache License 2.0 | 6 votes |
private Future<LogRecordWithDLSN> getLastUserRecord(BKDistributedLogManager bkdlm, int ledgerNo) throws Exception { BKLogReadHandler readHandler = bkdlm.createReadHandler(); List<LogSegmentMetadata> ledgerList = readHandler.getLedgerList(false, false, LogSegmentMetadata.COMPARATOR, false); final LedgerHandleCache handleCache = LedgerHandleCache.newBuilder() .bkc(bkdlm.getWriterBKC()) .conf(conf) .build(); return ReadUtils.asyncReadLastRecord( bkdlm.getStreamName(), ledgerList.get(ledgerNo), false, false, false, 2, 16, new AtomicInteger(0), Executors.newFixedThreadPool(1), handleCache ).ensure(new AbstractFunction0<BoxedUnit>() { @Override public BoxedUnit apply() { handleCache.clear(); return BoxedUnit.UNIT; } }); }
Example #7
Source File: TestKafkaSystemProducerJava.java From samza with Apache License 2.0 | 6 votes |
@Test public void testInstantiateProducer() { KafkaSystemProducer ksp = new KafkaSystemProducer("SysName", new ExponentialSleepStrategy(2.0, 200, 10000), new AbstractFunction0<Producer<byte[], byte[]>>() { @Override public Producer<byte[], byte[]> apply() { return new KafkaProducer<>(new HashMap<String, Object>()); } }, new KafkaSystemProducerMetrics("SysName", new MetricsRegistryMap()), new AbstractFunction0<Object>() { @Override public Object apply() { return System.currentTimeMillis(); } }, false); long now = System.currentTimeMillis(); assertTrue((Long) ksp.clock().apply() >= now); }
Example #8
Source File: SimpleLedgerAllocator.java From distributedlog with Apache License 2.0 | 6 votes |
void deleteLedger(final long ledgerId) { final Future<Void> deleteFuture = bkc.deleteLedger(ledgerId, true); synchronized (ledgerDeletions) { ledgerDeletions.add(deleteFuture); } deleteFuture.onFailure(new AbstractFunction1<Throwable, BoxedUnit>() { @Override public BoxedUnit apply(Throwable cause) { LOG.error("Error deleting ledger {} for ledger allocator {}, retrying : ", new Object[] { ledgerId, allocatePath, cause }); if (!isClosing()) { deleteLedger(ledgerId); } return BoxedUnit.UNIT; } }).ensure(new AbstractFunction0<BoxedUnit>() { @Override public BoxedUnit apply() { synchronized (ledgerDeletions) { ledgerDeletions.remove(deleteFuture); } return BoxedUnit.UNIT; } }); }
Example #9
Source File: ServerTracingFilterInterceptorTest.java From skywalking with Apache License 2.0 | 6 votes |
private void runWithContext(final TestFunction function) { ContextCarrier contextCarrier = new ContextCarrier(); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); if (next.getHeadKey().equals(SW8CarrierItem.HEADER_NAME)) { next.setHeadValue("1-My40LjU=-MS4yLjM=-3-c2VydmljZQ==-aW5zdGFuY2U=-L2FwcA==-MTI3LjAuMC4xOjgwODA="); } } SWContextCarrier swContextCarrier = new SWContextCarrier(); swContextCarrier.setContextCarrier(contextCarrier); swContextCarrier.setOperationName(rpc); Contexts.broadcast().let(SWContextCarrier$.MODULE$, swContextCarrier, new AbstractFunction0<Void>() { @Override public Void apply() { try { function.apply(); } catch (Throwable throwable) { throw new RuntimeException(throwable); } return null; } }); }
Example #10
Source File: bootstrapServersTest.java From zipkin-finagle with Apache License 2.0 | 6 votes |
@Test public void letOverridesDefault() { final List<InetSocketAddress> override = singletonList(new InetSocketAddress("zipkin", 9092)); final AtomicBoolean ran = new AtomicBoolean(); Function0<BoxedUnit> fn0 = new AbstractFunction0<BoxedUnit>() { @Override public BoxedUnit apply() { ran.set(true); // used to verify this block is executed. assertThat(bootstrapServers$.Flag.isDefined()).isTrue(); assertThat(bootstrapServers$.Flag.apply()).isEqualTo(override); return BoxedUnit.UNIT; } }; bootstrapServers$.Flag.let(override, fn0); assertThat(ran.get()).isTrue(); }
Example #11
Source File: initialSampleRateTest.java From zipkin-finagle with Apache License 2.0 | 6 votes |
@Test public void letOverridesDefault() { final float override = 1.0f; final AtomicBoolean ran = new AtomicBoolean(); Function0<BoxedUnit> fn0 = new AbstractFunction0<BoxedUnit>() { @Override public BoxedUnit apply() { ran.set(true); // used to verify this block is executed. assertThat(initialSampleRate$.Flag.isDefined()).isTrue(); assertThat(initialSampleRate$.Flag.apply()).isEqualTo(override); return BoxedUnit.UNIT; } }; initialSampleRate$.Flag.let(override, fn0); assertThat(ran.get()).isTrue(); }
Example #12
Source File: localServiceNameTest.java From zipkin-finagle with Apache License 2.0 | 6 votes |
@Test public void letOverridesDefault() { final String override = "favstar"; final AtomicBoolean ran = new AtomicBoolean(); Function0<BoxedUnit> fn0 = new AbstractFunction0<BoxedUnit>() { @Override public BoxedUnit apply() { ran.set(true); // used to verify this block is executed. assertThat(localServiceName$.Flag.isDefined()).isTrue(); assertThat(localServiceName$.Flag.apply()).isEqualTo(override); return BoxedUnit.UNIT; } }; localServiceName$.Flag.let(override, fn0); assertThat(ran.get()).isTrue(); }
Example #13
Source File: compressionEnabledTest.java From zipkin-finagle with Apache License 2.0 | 6 votes |
@Test public void letOverridesDefault() { final boolean override = false; final AtomicBoolean ran = new AtomicBoolean(); Function0<BoxedUnit> fn0 = new AbstractFunction0<BoxedUnit>() { @Override public BoxedUnit apply() { ran.set(true); // used to verify this block is executed. assertThat(compressionEnabled$.Flag.isDefined()).isTrue(); assertThat(compressionEnabled$.Flag.apply()).isEqualTo(override); return BoxedUnit.UNIT; } }; compressionEnabled$.Flag.let(override, fn0); assertThat(ran.get()).isTrue(); }
Example #14
Source File: hostTest.java From zipkin-finagle with Apache License 2.0 | 6 votes |
@Test public void letOverridesDefault() { final String override = "foo:9411"; final AtomicBoolean ran = new AtomicBoolean(); Function0<BoxedUnit> fn0 = new AbstractFunction0<BoxedUnit>() { @Override public BoxedUnit apply() { ran.set(true); // used to verify this block is executed. assertThat(host$.Flag.isDefined()).isTrue(); assertThat(host$.Flag.apply()).isEqualTo(override); return BoxedUnit.UNIT; } }; host$.Flag.let(override, fn0); assertThat(ran.get()).isTrue(); }
Example #15
Source File: hostHeaderTest.java From zipkin-finagle with Apache License 2.0 | 6 votes |
@Test public void letOverridesDefault() { final String override = "amazon"; final AtomicBoolean ran = new AtomicBoolean(); Function0<BoxedUnit> fn0 = new AbstractFunction0<BoxedUnit>() { @Override public BoxedUnit apply() { ran.set(true); // used to verify this block is executed. assertThat(hostHeader$.Flag.isDefined()).isTrue(); assertThat(hostHeader$.Flag.apply()).isEqualTo(override); return BoxedUnit.UNIT; } }; hostHeader$.Flag.let(override, fn0); assertThat(ran.get()).isTrue(); }
Example #16
Source File: tlsEnabledTest.java From zipkin-finagle with Apache License 2.0 | 6 votes |
@Test public void letOverridesDefault() { final boolean override = true; final AtomicBoolean ran = new AtomicBoolean(); Function0<BoxedUnit> fn0 = new AbstractFunction0<BoxedUnit>() { @Override public BoxedUnit apply() { ran.set(true); // used to verify this block is executed. assertThat(tlsEnabled$.Flag.isDefined()).isTrue(); assertThat(tlsEnabled$.Flag.apply()).isEqualTo(override); return BoxedUnit.UNIT; } }; tlsEnabled$.Flag.let(override, fn0); assertThat(ran.get()).isTrue(); }
Example #17
Source File: tlsValidationEnabledTest.java From zipkin-finagle with Apache License 2.0 | 6 votes |
@Test public void letOverridesDefault() { final boolean override = false; final AtomicBoolean ran = new AtomicBoolean(); Function0<BoxedUnit> fn0 = new AbstractFunction0<BoxedUnit>() { @Override public BoxedUnit apply() { ran.set(true); // used to verify this block is executed. assertThat(tlsValidationEnabled$.Flag.isDefined()).isTrue(); assertThat(tlsValidationEnabled$.Flag.apply()).isEqualTo(override); return BoxedUnit.UNIT; } }; tlsValidationEnabled$.Flag.let(override, fn0); assertThat(ran.get()).isTrue(); }
Example #18
Source File: hostTest.java From zipkin-finagle with Apache License 2.0 | 6 votes |
@Test public void letOverridesDefault() { final String override = "localhost:9410"; final AtomicBoolean ran = new AtomicBoolean(); Function0<BoxedUnit> fn0 = new AbstractFunction0<BoxedUnit>() { @Override public BoxedUnit apply() { ran.set(true); // used to verify this block is executed. assertThat(host$.Flag.isDefined()).isTrue(); assertThat(host$.Flag.apply()).isEqualTo(override); return BoxedUnit.UNIT; } }; host$.Flag.let(override, fn0); assertThat(ran.get()).isTrue(); }
Example #19
Source File: ZKDistributedLock.java From distributedlog with Apache License 2.0 | 5 votes |
void doAsyncAcquireWithSemaphore(final Promise<ZKDistributedLock> acquirePromise, final long lockTimeout) { lockSemaphore.acquireAndRun(new AbstractFunction0<Future<ZKDistributedLock>>() { @Override public Future<ZKDistributedLock> apply() { doAsyncAcquire(acquirePromise, lockTimeout); return acquirePromise; } }); }
Example #20
Source File: TestMetricsSnapshotReporter.java From samza with Apache License 2.0 | 5 votes |
private AbstractFunction0<Object> getClock() { return new AbstractFunction0<Object>() { @Override public Object apply() { return System.currentTimeMillis(); } }; }
Example #21
Source File: CucumberReportAdapterTest.java From openCypher with Apache License 2.0 | 5 votes |
private AbstractFunction0<Graph> graph() { FakeGraph fakeGraph = new FakeGraph(); return new AbstractFunction0<Graph>() { @Override public Graph apply() { return fakeGraph; } }; }
Example #22
Source File: JavaStreamingQueryTestHarness.java From elasticsearch-hadoop with Apache License 2.0 | 5 votes |
public StreamingQuery start(final DataStreamWriter<?> writer, final String path) { Function0<StreamingQuery> runFunction = new AbstractFunction0<StreamingQuery>() { @Override public StreamingQuery apply() { return writer.start(path); } }; return harness.startTest(runFunction); }
Example #23
Source File: JavaStreamingQueryTestHarness.java From elasticsearch-hadoop with Apache License 2.0 | 5 votes |
public StreamingQuery start(final DataStreamWriter<?> writer) { Function0<StreamingQuery> runFunction = new AbstractFunction0<StreamingQuery>() { @Override public StreamingQuery apply() { return writer.start(); } }; return harness.startTest(runFunction); }
Example #24
Source File: JavaStreamingQueryTestHarness.java From elasticsearch-hadoop with Apache License 2.0 | 5 votes |
public void run(final DataStreamWriter<?> writer, final String path) { Function0<StreamingQuery> runFunction = new AbstractFunction0<StreamingQuery>() { @Override public StreamingQuery apply() { return writer.start(path); } }; harness.runTest(runFunction); }
Example #25
Source File: BKDistributedLogManager.java From distributedlog with Apache License 2.0 | 5 votes |
protected Future<List<LogSegmentMetadata>> getLogSegmentsAsync() { final BKLogReadHandler readHandler = createReadHandler(); return readHandler.asyncGetFullLedgerList(true, false).ensure(new AbstractFunction0<BoxedUnit>() { @Override public BoxedUnit apply() { readHandler.asyncClose(); return BoxedUnit.UNIT; } }); }
Example #26
Source File: BKLogHandler.java From distributedlog with Apache License 2.0 | 5 votes |
public Future<LogRecordWithDLSN> asyncReadLastRecord(final LogSegmentMetadata l, final boolean fence, final boolean includeControl, final boolean includeEndOfStream) { final AtomicInteger numRecordsScanned = new AtomicInteger(0); final Stopwatch stopwatch = Stopwatch.createStarted(); final LedgerHandleCache handleCache = LedgerHandleCache.newBuilder().bkc(bookKeeperClient).conf(conf).build(); return ReadUtils.asyncReadLastRecord( getFullyQualifiedName(), l, fence, includeControl, includeEndOfStream, firstNumEntriesPerReadLastRecordScan, maxNumEntriesPerReadLastRecordScan, numRecordsScanned, scheduler, handleCache ).addEventListener(new FutureEventListener<LogRecordWithDLSN>() { @Override public void onSuccess(LogRecordWithDLSN value) { recoverLastEntryStats.registerSuccessfulEvent(stopwatch.stop().elapsed(TimeUnit.MICROSECONDS)); recoverScannedEntriesStats.registerSuccessfulEvent(numRecordsScanned.get()); } @Override public void onFailure(Throwable cause) { recoverLastEntryStats.registerFailedEvent(stopwatch.stop().elapsed(TimeUnit.MICROSECONDS)); } }).ensure(new AbstractFunction0<BoxedUnit>() { @Override public BoxedUnit apply() { handleCache.clear(); return BoxedUnit.UNIT; } }); }
Example #27
Source File: JavaStreamingQueryTestHarness.java From elasticsearch-hadoop with Apache License 2.0 | 5 votes |
public void run(final DataStreamWriter<?> writer) { Function0<StreamingQuery> runFunction = new AbstractFunction0<StreamingQuery>() { @Override public StreamingQuery apply() { return writer.start(); } }; harness.runTest(runFunction); }
Example #28
Source File: ZKDistributedLock.java From distributedlog with Apache License 2.0 | 5 votes |
synchronized void unlockInternalLock(final Promise<Void> closePromise) { if (internalLock == null) { FutureUtils.setValue(closePromise, null); } else { internalLock.asyncUnlock().ensure(new AbstractFunction0<BoxedUnit>() { @Override public BoxedUnit apply() { FutureUtils.setValue(closePromise, null); return BoxedUnit.UNIT; } }); } }
Example #29
Source File: JavaToScalaConverter.java From fasten with Apache License 2.0 | 5 votes |
/** * Imitate a scala function0 in case of passing Optional for String as an scala function. * @param defaultString String. * @return An scala function including the results. */ public static Function0<String> asScalaFunction0OptionString(final String defaultString) { return new AbstractFunction0<>() { @Override public String apply() { return defaultString; } }; }
Example #30
Source File: Lambdas.java From ts-reaktive with MIT License | 5 votes |
/** Converts the given Supplier to a scala Function0 */ public static <T> scala.Function0<T> toScala(Supplier<T> f) { return new AbstractFunction0<T>() { @Override public T apply() { return f.get(); } }; }