scala.runtime.AbstractFunction1 Java Examples
The following examples show how to use
scala.runtime.AbstractFunction1.
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: FinagleSender.java From zipkin-finagle with Apache License 2.0 | 6 votes |
@Override protected void doEnqueue(Callback<Void> callback) { try { client.apply(makeRequest(spans)).respond(new AbstractFunction1<Try<Rep>, BoxedUnit>() { @Override public BoxedUnit apply(Try<Rep> result) { if (result.isReturn()) { callback.onSuccess(null); } else { callback.onError(result.throwable()); } return BoxedUnit.UNIT; } }); } catch (Exception e) { callback.onError(e); } }
Example #2
Source File: BKAsyncLogWriter.java From distributedlog with Apache License 2.0 | 6 votes |
Future<Long> flushAndCommit() { Future<BKLogSegmentWriter> writerFuture; synchronized (this) { if (null != this.rollingFuture) { writerFuture = this.rollingFuture; } else { writerFuture = getCachedLogWriterFuture(); } } if (null == writerFuture) { return Future.value(getLastTxId()); } return writerFuture.flatMap(new AbstractFunction1<BKLogSegmentWriter, Future<Long>>() { @Override public Future<Long> apply(BKLogSegmentWriter writer) { return writer.flushAndCommit(); } }); }
Example #3
Source File: BKAsyncLogWriter.java From distributedlog with Apache License 2.0 | 6 votes |
private Future<BKLogSegmentWriter> doGetLogSegmentWriter(final long firstTxid, final boolean bestEffort, final boolean rollLog, final boolean allowMaxTxID) { if (encounteredError) { return Future.exception(new WriteException(bkDistributedLogManager.getStreamName(), "writer has been closed due to error.")); } Future<BKLogSegmentWriter> writerFuture = asyncGetLedgerWriter(!disableRollOnSegmentError); if (null == writerFuture) { return rollLogSegmentIfNecessary(null, firstTxid, bestEffort, allowMaxTxID); } else if (rollLog) { return writerFuture.flatMap(new AbstractFunction1<BKLogSegmentWriter, Future<BKLogSegmentWriter>>() { @Override public Future<BKLogSegmentWriter> apply(BKLogSegmentWriter writer) { return rollLogSegmentIfNecessary(writer, firstTxid, bestEffort, allowMaxTxID); } }); } else { return writerFuture; } }
Example #4
Source File: HeartbeatOp.java From distributedlog with Apache License 2.0 | 6 votes |
@Override protected Future<WriteResponse> executeOp(AsyncLogWriter writer, Sequencer sequencer, Object txnLock) { // write a control record if heartbeat is the first request of the recovered log segment. if (writeControlRecord) { long txnId; Future<DLSN> writeResult; synchronized (txnLock) { txnId = sequencer.nextId(); LogRecord hbRecord = new LogRecord(txnId, HEARTBEAT_DATA); hbRecord.setControl(); writeResult = newTFuture(writer.write(hbRecord)); } return writeResult.map(new AbstractFunction1<DLSN, WriteResponse>() { @Override public WriteResponse apply(DLSN value) { return ResponseUtils.writeSuccess().setDlsn(value.serialize(dlsnVersion)); } }); } else { return Future.value(ResponseUtils.writeSuccess()); } }
Example #5
Source File: BKAbstractLogWriter.java From distributedlog with Apache License 2.0 | 6 votes |
private Future<BKLogSegmentWriter> asyncStartNewLogSegment(final BKLogWriteHandler writeHandler, final long startTxId, final boolean allowMaxTxID) { return writeHandler.recoverIncompleteLogSegments() .flatMap(new AbstractFunction1<Long, Future<BKLogSegmentWriter>>() { @Override public Future<BKLogSegmentWriter> apply(Long lastTxId) { return writeHandler.asyncStartLogSegment(startTxId, false, allowMaxTxID) .onSuccess(new AbstractFunction1<BKLogSegmentWriter, BoxedUnit>() { @Override public BoxedUnit apply(BKLogSegmentWriter newSegmentWriter) { cacheLogWriter(newSegmentWriter); return BoxedUnit.UNIT; } }); } }); }
Example #6
Source File: BKAsyncLogWriter.java From distributedlog with Apache License 2.0 | 6 votes |
Future<Long> markEndOfStream() { final Stopwatch stopwatch = Stopwatch.createStarted(); Future<BKLogSegmentWriter> logSegmentWriterFuture; synchronized (this) { logSegmentWriterFuture = this.rollingFuture; } if (null == logSegmentWriterFuture) { logSegmentWriterFuture = getLogSegmentWriterForEndOfStream(); } return logSegmentWriterFuture.flatMap(new AbstractFunction1<BKLogSegmentWriter, Future<Long>>() { @Override public Future<Long> apply(BKLogSegmentWriter w) { return w.markEndOfStream(); } }).addEventListener(new OpStatsListener<Long>(markEndOfStreamOpStatsLogger, stopwatch)); }
Example #7
Source File: BKAsyncLogWriter.java From distributedlog with Apache License 2.0 | 6 votes |
@Override protected Future<Void> asyncCloseAndComplete() { Future<BKLogSegmentWriter> logSegmentWriterFuture; synchronized (this) { logSegmentWriterFuture = this.rollingFuture; } if (null == logSegmentWriterFuture) { return super.asyncCloseAndComplete(); } else { return logSegmentWriterFuture.flatMap(new AbstractFunction1<BKLogSegmentWriter, Future<Void>>() { @Override public Future<Void> apply(BKLogSegmentWriter segmentWriter) { return BKAsyncLogWriter.super.asyncCloseAndComplete(); } }); } }
Example #8
Source File: StreamImpl.java From distributedlog with Apache License 2.0 | 6 votes |
/** * Close the stream and schedule cache eviction at some point in the future. * We delay this as a way to place the stream in a probationary state--cached * in the proxy but unusable. * This mechanism helps the cluster adapt to situations where a proxy has * persistent connectivity/availability issues, because it keeps an affected * stream off the proxy for a period of time, hopefully long enough for the * issues to be resolved, or for whoop to kick in and kill the shard. */ void handleServiceTimeout(String reason) { synchronized (this) { if (StreamStatus.isUnavailable(status)) { return; } // Mark stream in error state setStreamInErrorStatus(); } // Async close request, and schedule eviction when its done. Future<Void> closeFuture = requestClose(reason, false /* dont remove */); closeFuture.onSuccess(new AbstractFunction1<Void, BoxedUnit>() { @Override public BoxedUnit apply(Void result) { streamManager.scheduleRemoval(StreamImpl.this, streamProbationTimeoutMs); return BoxedUnit.UNIT; } }); }
Example #9
Source File: ArtifactSourceUtils.java From rug-cli with GNU General Public License v3.0 | 6 votes |
public static ArtifactSource filterMetaInf(ArtifactSource source) { return source.filter(new AbstractFunction1<DirectoryArtifact, Object>() { @Override public Object apply(DirectoryArtifact dir) { // This is required to remove our maven packaging information if (dir.name().equals("META-INF")) { Optional<Artifact> nonMavenArtifact = JavaConverters .asJavaCollectionConverter(dir.artifacts()).asJavaCollection().stream() .filter(a -> !a.path().startsWith("META-INF/maven")).findAny(); return nonMavenArtifact.isPresent(); } return (!dir.path().equals("META-INF/maven")); } }, new AbstractFunction1<FileArtifact, Object>() { @Override public Object apply(FileArtifact arg0) { return true; } }); }
Example #10
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 #11
Source File: FederatedZKLogMetadataStore.java From distributedlog with Apache License 2.0 | 6 votes |
@Override public Future<Optional<URI>> getLogLocation(final String logName) { if (duplicatedLogFound.get()) { return duplicatedLogException(duplicatedLogName.get()); } URI location = log2Locations.get(logName); if (null != location) { return postStateCheck(Future.value(Optional.of(location))); } if (!forceCheckLogExistence) { Optional<URI> result = Optional.absent(); return Future.value(result); } return postStateCheck(fetchLogLocation(logName).onSuccess( new AbstractFunction1<Optional<URI>, BoxedUnit>() { @Override public BoxedUnit apply(Optional<URI> uriOptional) { if (uriOptional.isPresent()) { log2Locations.putIfAbsent(logName, uriOptional.get()); } return BoxedUnit.UNIT; } })); }
Example #12
Source File: BKLogReadHandler.java From distributedlog with Apache License 2.0 | 6 votes |
public Future<Void> asyncClose() { DistributedLock lockToClose; synchronized (this) { if (null != lockAcquireFuture && !lockAcquireFuture.isDefined()) { FutureUtils.cancel(lockAcquireFuture); } lockToClose = readLock; } return Utils.closeSequence(scheduler, readAheadWorker, lockToClose) .flatMap(new AbstractFunction1<Void, Future<Void>>() { @Override public Future<Void> apply(Void result) { if (null != readAheadCache) { readAheadCache.clear(); } if (null != handleCache) { handleCache.clear(); } return BKLogReadHandler.super.asyncClose(); } }); }
Example #13
Source File: HeartbeatOp.java From distributedlog with Apache License 2.0 | 6 votes |
@Override protected Future<WriteResponse> executeOp(AsyncLogWriter writer, Sequencer sequencer, Object txnLock) { // write a control record if heartbeat is the first request of the recovered log segment. if (writeControlRecord) { long txnId; Future<DLSN> writeResult; synchronized (txnLock) { txnId = sequencer.nextId(); writeResult = ((BKAsyncLogWriter) writer).writeControlRecord(new LogRecord(txnId, HEARTBEAT_DATA)); } return writeResult.map(new AbstractFunction1<DLSN, WriteResponse>() { @Override public WriteResponse apply(DLSN value) { return ResponseUtils.writeSuccess().setDlsn(value.serialize(dlsnVersion)); } }); } else { return Future.value(ResponseUtils.writeSuccess()); } }
Example #14
Source File: DataConverter.java From AsyncDao with MIT License | 6 votes |
public static <T> List<T> queryResultToListObject(QueryResult queryResult, Class<T> clazz, ModelMap resultMap) { final Option<ResultSet> rows = queryResult.rows(); java.util.List<T> list = new ArrayList<T>(); if (rows.isDefined()) { List<String> columnNames = ScalaUtils.toJavaList(rows.get().columnNames().toList()); rows.get().foreach(new AbstractFunction1<RowData, Void>() { @Override public Void apply(RowData row) { try { list.add(rowDataToObject(row, clazz, resultMap, columnNames)); } catch (Exception e) { log.error("convert object error :{}", e); } return null; } }); } return list; }
Example #15
Source File: StreamImpl.java From distributedlog with Apache License 2.0 | 6 votes |
/** * Close the stream and schedule cache eviction at some point in the future. * We delay this as a way to place the stream in a probationary state--cached * in the proxy but unusable. * This mechanism helps the cluster adapt to situations where a proxy has * persistent connectivity/availability issues, because it keeps an affected * stream off the proxy for a period of time, hopefully long enough for the * issues to be resolved, or for whoop to kick in and kill the shard. */ synchronized void handleServiceTimeout(String reason) { if (StreamStatus.isUnavailable(status)) { return; } // Mark stream in error state setStreamInErrorStatus(); // Async close request, and schedule eviction when its done. Future<Void> closeFuture = requestClose(reason, false /* dont remove */); closeFuture.onSuccess(new AbstractFunction1<Void, BoxedUnit>() { @Override public BoxedUnit apply(Void result) { streamManager.scheduleRemoval(StreamImpl.this, streamProbationTimeoutMs); return BoxedUnit.UNIT; } }); }
Example #16
Source File: BulkWriteOp.java From distributedlog with Apache License 2.0 | 5 votes |
@Override public Future<ResponseHeader> responseHeader() { return result().map(new AbstractFunction1<BulkWriteResponse, ResponseHeader>() { @Override public ResponseHeader apply(BulkWriteResponse response) { return response.getHeader(); } }); }
Example #17
Source File: ReleaseOp.java From distributedlog with Apache License 2.0 | 5 votes |
@Override protected Future<WriteResponse> executeOp(AsyncLogWriter writer, Sequencer sequencer, Object txnLock) { Future<Void> result = streamManager.closeAndRemoveAsync(streamName()); return result.map(new AbstractFunction1<Void, WriteResponse>() { @Override public WriteResponse apply(Void value) { return ResponseUtils.writeSuccess(); } }); }
Example #18
Source File: DeleteOp.java From distributedlog with Apache License 2.0 | 5 votes |
@Override protected Future<WriteResponse> executeOp(AsyncLogWriter writer, Sequencer sequencer, Object txnLock) { Future<Void> result = streamManager.deleteAndRemoveAsync(streamName()); return result.map(new AbstractFunction1<Void, WriteResponse>() { @Override public WriteResponse apply(Void value) { return ResponseUtils.writeSuccess(); } }); }
Example #19
Source File: AbstractWriteOp.java From distributedlog with Apache License 2.0 | 5 votes |
@Override public Future<ResponseHeader> responseHeader() { return result().map(new AbstractFunction1<WriteResponse, ResponseHeader>() { @Override public ResponseHeader apply(WriteResponse response) { return response.getHeader(); } }); }
Example #20
Source File: WriteOp.java From distributedlog with Apache License 2.0 | 5 votes |
@Override protected Future<WriteResponse> executeOp(AsyncLogWriter writer, Sequencer sequencer, Object txnLock) { if (!stream.equals(writer.getStreamName())) { logger.error("Write: Stream Name Mismatch in the Stream Map {}, {}", stream, writer.getStreamName()); return Future.exception(new IllegalStateException("The stream mapping is incorrect, fail the request")); } long txnId; Future<DLSN> writeResult; synchronized (txnLock) { txnId = sequencer.nextId(); LogRecord record = new LogRecord(txnId, payload); if (isRecordSet) { record.setRecordSet(); } writeResult = writer.write(record); } return writeResult.map(new AbstractFunction1<DLSN, WriteResponse>() { @Override public WriteResponse apply(DLSN value) { successRecordCounter.inc(); return ResponseUtils.writeSuccess().setDlsn(value.serialize(dlsnVersion)); } }); }
Example #21
Source File: BKLogWriteHandler.java From distributedlog with Apache License 2.0 | 5 votes |
Future<List<LogSegmentMetadata>> setLogSegmentsOlderThanDLSNTruncated(final DLSN dlsn) { if (DLSN.InvalidDLSN == dlsn) { List<LogSegmentMetadata> emptyList = new ArrayList<LogSegmentMetadata>(0); return Future.value(emptyList); } scheduleGetAllLedgersTaskIfNeeded(); return asyncGetFullLedgerList(false, false).flatMap( new AbstractFunction1<List<LogSegmentMetadata>, Future<List<LogSegmentMetadata>>>() { @Override public Future<List<LogSegmentMetadata>> apply(List<LogSegmentMetadata> logSegments) { return setLogSegmentsOlderThanDLSNTruncated(logSegments, dlsn); } }); }
Example #22
Source File: StreamImpl.java From distributedlog with Apache License 2.0 | 5 votes |
Future<Void> requestClose(String reason, boolean uncache) { final boolean abort; closeLock.writeLock().lock(); try { if (StreamStatus.CLOSING == status || StreamStatus.CLOSED == status) { return closePromise; } logger.info("Request to close stream {} : {}", getStreamName(), reason); // if the stream isn't closed from INITIALIZED state, we abort the stream instead of closing it. abort = StreamStatus.INITIALIZED != status; status = StreamStatus.CLOSING; streamManager.notifyReleased(this); } finally { closeLock.writeLock().unlock(); } // we will fail the requests that are coming in between closing and closed only // after the async writer is closed. so we could clear up the lock before redirect // them. close(abort); if (uncache) { closePromise.onSuccess(new AbstractFunction1<Void, BoxedUnit>() { @Override public BoxedUnit apply(Void result) { if (streamManager.notifyRemoved(StreamImpl.this)) { logger.info("Removed cached stream {} after closed.", name); } return BoxedUnit.UNIT; } }); } return closePromise; }
Example #23
Source File: LogSegmentMetadataStoreUpdater.java From distributedlog with Apache License 2.0 | 5 votes |
protected Future<LogSegmentMetadata> updateSegmentMetadata(final LogSegmentMetadata segment) { Transaction<Object> txn = transaction(); metadataStore.updateLogSegment(txn, segment); return txn.execute().map(new AbstractFunction1<Void, LogSegmentMetadata>() { @Override public LogSegmentMetadata apply(Void value) { return segment; } }); }
Example #24
Source File: SimpleLedgerAllocator.java From distributedlog with Apache License 2.0 | 5 votes |
@Override public Future<Void> delete() { return closeInternal(true).flatMap(new AbstractFunction1<Void, Future<Void>>() { @Override public Future<Void> apply(Void value) { return Utils.zkDelete(zkc, allocatePath, getVersion()); } }); }
Example #25
Source File: SimpleLedgerAllocator.java From distributedlog with Apache License 2.0 | 5 votes |
static Future<Versioned<byte[]>> getAndCreateAllocationData(final String allocatePath, final ZooKeeperClient zkc) { return Utils.zkGetData(zkc, allocatePath, false) .flatMap(new AbstractFunction1<Versioned<byte[]>, Future<Versioned<byte[]>>>() { @Override public Future<Versioned<byte[]>> apply(Versioned<byte[]> result) { if (null != result && null != result.getVersion() && null != result.getValue()) { return Future.value(result); } return createAllocationData(allocatePath, zkc); } }); }
Example #26
Source File: ReadAheadWorker.java From distributedlog with Apache License 2.0 | 5 votes |
<T> Function1<T, BoxedUnit> submit(final Function1<T, BoxedUnit> function) { return new AbstractFunction1<T, BoxedUnit>() { @Override public BoxedUnit apply(final T input) { submit(new Runnable() { @Override public void run() { function.apply(input); } }); return BoxedUnit.UNIT; } }; }
Example #27
Source File: ZKSubscriptionsStore.java From distributedlog with Apache License 2.0 | 5 votes |
private void getLastCommitPositions(final Promise<Map<String, DLSN>> result, List<String> subscribers) { List<Future<Pair<String, DLSN>>> futures = new ArrayList<Future<Pair<String, DLSN>>>(subscribers.size()); for (String s : subscribers) { final String subscriber = s; Future<Pair<String, DLSN>> future = // Get the last commit position from zookeeper getSubscriber(subscriber).getLastCommitPositionFromZK().map( new AbstractFunction1<DLSN, Pair<String, DLSN>>() { @Override public Pair<String, DLSN> apply(DLSN dlsn) { return Pair.of(subscriber, dlsn); } }); futures.add(future); } Future.collect(futures).foreach( new AbstractFunction1<List<Pair<String, DLSN>>, BoxedUnit>() { @Override public BoxedUnit apply(List<Pair<String, DLSN>> subscriptions) { Map<String, DLSN> subscriptionMap = new HashMap<String, DLSN>(); for (Pair<String, DLSN> pair : subscriptions) { subscriptionMap.put(pair.getLeft(), pair.getRight()); } result.setValue(subscriptionMap); return BoxedUnit.UNIT; } }); }
Example #28
Source File: BKLogWriteHandler.java From distributedlog with Apache License 2.0 | 5 votes |
@Override public Future<Void> asyncClose() { return Utils.closeSequence(scheduler, lock, ledgerAllocator ).flatMap(new AbstractFunction1<Void, Future<Void>>() { @Override public Future<Void> apply(Void result) { return BKLogWriteHandler.super.asyncClose(); } }); }
Example #29
Source File: BKLogWriteHandler.java From distributedlog with Apache License 2.0 | 5 votes |
Future<List<LogSegmentMetadata>> purgeLogSegmentsOlderThanTxnId(final long minTxIdToKeep) { return asyncGetFullLedgerList(true, false).flatMap( new AbstractFunction1<List<LogSegmentMetadata>, Future<List<LogSegmentMetadata>>>() { @Override public Future<List<LogSegmentMetadata>> apply(List<LogSegmentMetadata> logSegments) { int numLogSegmentsToProcess; if (minTxIdToKeep < 0) { // we are deleting the log, we can remove whole log segments numLogSegmentsToProcess = logSegments.size(); } else { numLogSegmentsToProcess = getNumCandidateLogSegmentsToTruncate(logSegments); } List<LogSegmentMetadata> purgeList = Lists.newArrayListWithExpectedSize(numLogSegmentsToProcess); for (int iterator = 0; iterator < numLogSegmentsToProcess; iterator++) { LogSegmentMetadata l = logSegments.get(iterator); if ((minTxIdToKeep < 0) || ((l.isTruncated() || !conf.getExplicitTruncationByApplication()) && !l.isInProgress() && (l.getLastTxId() < minTxIdToKeep))) { purgeList.add(l); } else { // stop truncating log segments if we find either an inprogress or a partially // truncated log segment break; } } return deleteLogSegments(purgeList); } }); }
Example #30
Source File: DistributedLogClientImpl.java From distributedlog with Apache License 2.0 | 5 votes |
Future<Void> result() { return result.map(new AbstractFunction1<WriteResponse, Void>() { @Override public Void apply(WriteResponse response) { return null; } }); }