当前位置: 首页>>代码示例>>Java>>正文


Java Future.exception方法代码示例

本文整理汇总了Java中com.twitter.util.Future.exception方法的典型用法代码示例。如果您正苦于以下问题:Java Future.exception方法的具体用法?Java Future.exception怎么用?Java Future.exception使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.twitter.util.Future的用法示例。


在下文中一共展示了Future.exception方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createLedger

import com.twitter.util.Future; //导入方法依赖的package包/类
public Future<LedgerHandle> createLedger(int ensembleSize,
                                         int writeQuorumSize,
                                         int ackQuorumSize) {
    BookKeeper bk;
    try {
        bk = get();
    } catch (IOException ioe) {
        return Future.exception(ioe);
    }
    final Promise<LedgerHandle> promise = new Promise<LedgerHandle>();
    bk.asyncCreateLedger(ensembleSize, writeQuorumSize, ackQuorumSize,
            BookKeeper.DigestType.CRC32, passwd, new AsyncCallback.CreateCallback() {
                @Override
                public void createComplete(int rc, LedgerHandle lh, Object ctx) {
                    if (BKException.Code.OK == rc) {
                        promise.updateIfEmpty(new Return<LedgerHandle>(lh));
                    } else {
                        promise.updateIfEmpty(new Throw<LedgerHandle>(BKException.create(rc)));
                    }
                }
            }, null);
    return promise;
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:24,代码来源:BookKeeperClient.java

示例2: tryObtain

import com.twitter.util.Future; //导入方法依赖的package包/类
@Override
public synchronized Future<LedgerHandle> tryObtain(final Transaction<Object> txn,
                                                   final OpListener<LedgerHandle> listener) {
    if (Phase.ERROR == phase) {
        return Future.exception(new AllocationException(Phase.ERROR,
                "Error on allocating ledger under " + allocatePath));
    }
    if (Phase.HANDING_OVER == phase || Phase.HANDED_OVER == phase || null != tryObtainTxn) {
        return Future.exception(new ConcurrentObtainException(phase,
                "Ledger handle is handling over to another thread : " + phase));
    }
    tryObtainTxn = txn;
    tryObtainListener = listener;
    if (null != allocatedLh) {
        completeAllocation(allocatedLh);
    }
    return allocatePromise;
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:19,代码来源:SimpleLedgerAllocator.java

示例3: createStreamAsync

import com.twitter.util.Future; //导入方法依赖的package包/类
@Override
public Future<Void> createStreamAsync(final String stream) {
    final Promise<Void> createPromise = new Promise<Void>();
    java.util.concurrent.Future<?> scheduleFuture = schedule(new Runnable() {
        @Override
        public void run() {
            try {
                dlNamespace.createLog(stream);
                createPromise.setValue(null);
            } catch (Exception e) {
                createPromise.setException(e);
            }
        }
    }, 0);
    if (null == scheduleFuture) {
        return Future.exception(
            new ServiceUnavailableException("Couldn't schedule a create task."));
    }
    return createPromise;
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:21,代码来源:StreamManagerImpl.java

示例4: asyncTryReadLastConfirmed

import com.twitter.util.Future; //导入方法依赖的package包/类
/**
 * Async try read last confirmed.
 *
 * @param ledgerDesc
 *          ledger descriptor
 * @return future presenting read last confirmed result.
 */
public Future<Long> asyncTryReadLastConfirmed(LedgerDescriptor ledgerDesc) {
    RefCountedLedgerHandle refHandle = handlesMap.get(ledgerDesc);
    if (null == refHandle) {
        LOG.error("Accessing ledger {} without opening.", ledgerDesc);
        return Future.exception(BKException.create(BKException.Code.UnexpectedConditionException));
    }
    final Promise<Long> promise = new Promise<Long>();
    refHandle.handle.asyncTryReadLastConfirmed(new AsyncCallback.ReadLastConfirmedCallback() {
        @Override
        public void readLastConfirmedComplete(int rc, long lastAddConfirmed, Object ctx) {
            if (BKException.Code.OK == rc) {
                promise.setValue(lastAddConfirmed);
            } else {
                promise.setException(BKException.create(rc));
            }
        }
    }, null);
    return promise;
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:27,代码来源:LedgerHandleCache.java

示例5: doDeleteAndRemoveAsync

import com.twitter.util.Future; //导入方法依赖的package包/类
private Future<Void> doDeleteAndRemoveAsync(final String streamName) {
    Stream stream = streams.get(streamName);
    if (null == stream) {
        logger.warn("No stream {} to delete.", streamName);
        return Future.exception(new UnexpectedException("No stream " + streamName + " to delete."));
    } else {
        Future<Void> result;
        logger.info("Deleting stream {}, {}", streamName, stream);
        try {
            stream.delete();
            result = stream.requestClose("Stream Deleted");
        } catch (IOException e) {
            logger.error("Failed on removing stream {} : ", streamName, e);
            result = Future.exception(e);
        }
        return result;
    }
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:19,代码来源:StreamManagerImpl.java

示例6: asyncReadEntries

import com.twitter.util.Future; //导入方法依赖的package包/类
/**
 * Async Read Entries
 *
 * @param ledgerDesc
 *          ledger descriptor
 * @param first
 *          first entry
 * @param last
 *          second entry
 */
public Future<Enumeration<LedgerEntry>> asyncReadEntries(
        LedgerDescriptor ledgerDesc, long first, long last) {
    RefCountedLedgerHandle refHandle = handlesMap.get(ledgerDesc);
    if (null == refHandle) {
        LOG.error("Accessing ledger {} without opening.", ledgerDesc);
        return Future.exception(BKException.create(BKException.Code.UnexpectedConditionException));
    }
    final Promise<Enumeration<LedgerEntry>> promise = new Promise<Enumeration<LedgerEntry>>();
    refHandle.handle.asyncReadEntries(first, last, new AsyncCallback.ReadCallback() {
        @Override
        public void readComplete(int rc, LedgerHandle lh, Enumeration<LedgerEntry> entries, Object ctx) {
            if (BKException.Code.OK == rc) {
                promise.setValue(entries);
            } else {
                promise.setException(BKException.create(rc));
            }
        }
    }, null);
    return promise;
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:31,代码来源:LedgerHandleCache.java

示例7: doGetLogSegmentWriter

import com.twitter.util.Future; //导入方法依赖的package包/类
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;
    }
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:23,代码来源:BKAsyncLogWriter.java

示例8: deleteAndRemoveAsync

import com.twitter.util.Future; //导入方法依赖的package包/类
/**
 * Must be enqueued to an executor to avoid deadlocks (close and execute-op both
 * try to acquire the same read-write lock).
 */
@Override
public Future<Void> deleteAndRemoveAsync(final String stream) {
    final Promise<Void> result = new Promise<Void>();
    java.util.concurrent.Future<?> scheduleFuture = schedule(new Runnable() {
        @Override
        public void run() {
            result.become(doDeleteAndRemoveAsync(stream));
        }
    }, 0);
    if (null == scheduleFuture) {
        return Future.exception(
            new ServiceUnavailableException("Couldn't schedule a delete task."));
    }
    return result;
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:20,代码来源:StreamManagerImpl.java

示例9: apply

import com.twitter.util.Future; //导入方法依赖的package包/类
public synchronized Future<T> apply(final Function0<T> fn) {
    Preconditions.checkNotNull(fn);
    if (closed) {
        return Future.exception(new RejectedExecutionException("Operation submitted to closed SafeQueueingFuturePool"));
    }
    ++outstanding;
    queue.add(fn);
    Future<T> result = orderedFuturePool.apply(new Function0<T>() {
        @Override
        public T apply() {
            return queue.poll().apply();
        }
        @Override
        public String toString() {
            return fn.toString();
        }
    }).ensure(new Function0<BoxedUnit>() {
        public BoxedUnit apply() {
            if (decrOutstandingAndCheckDone()) {
                applyAll();
            }
            return null;
        }
    });
    return result;
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:27,代码来源:SafeQueueingFuturePool.java

示例10: rollLogSegmentIfNecessary

import com.twitter.util.Future; //导入方法依赖的package包/类
synchronized protected Future<BKLogSegmentWriter> rollLogSegmentIfNecessary(
        final BKLogSegmentWriter segmentWriter,
        long startTxId,
        boolean bestEffort,
        boolean allowMaxTxID) {
    final BKLogWriteHandler writeHandler;
    try {
        writeHandler = getWriteHandler();
    } catch (IOException e) {
        return Future.exception(e);
    }
    Future<BKLogSegmentWriter> rollPromise;
    if (null != segmentWriter && (writeHandler.shouldStartNewSegment(segmentWriter) || forceRolling)) {
        rollPromise = closeOldLogSegmentAndStartNewOneWithPermit(
                segmentWriter, writeHandler, startTxId, bestEffort, allowMaxTxID);
    } else if (null == segmentWriter) {
        rollPromise = asyncStartNewLogSegment(writeHandler, startTxId, allowMaxTxID);
    } else {
        rollPromise = Future.value(segmentWriter);
    }
    return rollPromise.map(new AbstractFunction1<BKLogSegmentWriter, BKLogSegmentWriter>() {
        @Override
        public BKLogSegmentWriter apply(BKLogSegmentWriter newSegmentWriter) {
            if (segmentWriter == newSegmentWriter) {
                return newSegmentWriter;
            }
            truncateLogSegmentsIfNecessary(writeHandler);
            return newSegmentWriter;
        }
    });
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:32,代码来源:BKAbstractLogWriter.java

示例11: recoverIncompleteLogSegments

import com.twitter.util.Future; //导入方法依赖的package包/类
public Future<Long> recoverIncompleteLogSegments() {
    try {
        FailpointUtils.checkFailPoint(FailpointUtils.FailPointName.FP_RecoverIncompleteLogSegments);
    } catch (IOException ioe) {
        return Future.exception(ioe);
    }
    return asyncGetFilteredLedgerList(false, false).flatMap(recoverLogSegmentsFunction);
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:9,代码来源:BKLogWriteHandler.java

示例12: executeOp

import com.twitter.util.Future; //导入方法依赖的package包/类
@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));
        }
    });
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:28,代码来源:WriteOp.java

示例13: setLogSegmentsOlderThanDLSNTruncated

import com.twitter.util.Future; //导入方法依赖的package包/类
private Future<List<LogSegmentMetadata>> setLogSegmentsOlderThanDLSNTruncated(List<LogSegmentMetadata> logSegments,
                                                                              final DLSN dlsn) {
    LOG.debug("Setting truncation status on logs older than {} from {} for {}",
            new Object[]{dlsn, logSegments, getFullyQualifiedName()});
    List<LogSegmentMetadata> truncateList = new ArrayList<LogSegmentMetadata>(logSegments.size());
    LogSegmentMetadata partialTruncate = null;
    LOG.info("{}: Truncating log segments older than {}", getFullyQualifiedName(), dlsn);
    int numCandidates = getNumCandidateLogSegmentsToTruncate(logSegments);
    for (int i = 0; i < numCandidates; i++) {
        LogSegmentMetadata l = logSegments.get(i);
        if (!l.isInProgress()) {
            if (l.getLastDLSN().compareTo(dlsn) < 0) {
                LOG.debug("{}: Truncating log segment {} ", getFullyQualifiedName(), l);
                truncateList.add(l);
            } else if (l.getFirstDLSN().compareTo(dlsn) < 0) {
                // Can be satisfied by at most one segment
                if (null != partialTruncate) {
                    String logMsg = String.format("Potential metadata inconsistency for stream %s at segment %s", getFullyQualifiedName(), l);
                    LOG.error(logMsg);
                    return Future.exception(new DLIllegalStateException(logMsg));
                }
                LOG.info("{}: Partially truncating log segment {} older than {}.", new Object[] {getFullyQualifiedName(), l, dlsn});
                partialTruncate = l;
            } else {
                break;
            }
        } else {
            break;
        }
    }
    return setLogSegmentTruncationStatus(truncateList, partialTruncate, dlsn);
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:33,代码来源:BKLogWriteHandler.java

示例14: purgeLogSegmentsOlderThanTimestamp

import com.twitter.util.Future; //导入方法依赖的package包/类
Future<List<LogSegmentMetadata>> purgeLogSegmentsOlderThanTimestamp(final long minTimestampToKeep) {
    if (minTimestampToKeep >= Utils.nowInMillis()) {
        return Future.exception(new IllegalArgumentException(
                "Invalid timestamp " + minTimestampToKeep + " to purge logs for " + getFullyQualifiedName()));
    }
    return asyncGetFullLedgerList(false, false).flatMap(
            new Function<List<LogSegmentMetadata>, Future<List<LogSegmentMetadata>>>() {
        @Override
        public Future<List<LogSegmentMetadata>> apply(List<LogSegmentMetadata> logSegments) {
            List<LogSegmentMetadata> purgeList = new ArrayList<LogSegmentMetadata>(logSegments.size());

            int numCandidates = getNumCandidateLogSegmentsToTruncate(logSegments);

            for (int iterator = 0; iterator < numCandidates; iterator++) {
                LogSegmentMetadata l = logSegments.get(iterator);
                // When application explicitly truncates segments; timestamp based purge is
                // only used to cleanup log segments that have been marked for truncation
                if ((l.isTruncated() || !conf.getExplicitTruncationByApplication()) &&
                    !l.isInProgress() && (l.getCompletionTime() < minTimestampToKeep)) {
                    purgeList.add(l);
                } else {
                    // stop truncating log segments if we find either an inprogress or a partially
                    // truncated log segment
                    break;
                }
            }
            LOG.info("Deleting log segments older than {} for {} : {}",
                    new Object[] { minTimestampToKeep, getFullyQualifiedName(), purgeList });
            return deleteLogSegments(purgeList);
        }
    });
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:33,代码来源:BKLogWriteHandler.java

示例15: deleteLedger

import com.twitter.util.Future; //导入方法依赖的package包/类
public Future<Void> deleteLedger(long lid,
                                 final boolean ignoreNonExistentLedger) {
    BookKeeper bk;
    try {
        bk = get();
    } catch (IOException ioe) {
        return Future.exception(ioe);
    }
    final Promise<Void> promise = new Promise<Void>();
    bk.asyncDeleteLedger(lid, new AsyncCallback.DeleteCallback() {
        @Override
        public void deleteComplete(int rc, Object ctx) {
            if (BKException.Code.OK == rc) {
                promise.updateIfEmpty(new Return<Void>(null));
            } else if (BKException.Code.NoSuchLedgerExistsException == rc) {
                if (ignoreNonExistentLedger) {
                    promise.updateIfEmpty(new Return<Void>(null));
                } else {
                    promise.updateIfEmpty(new Throw<Void>(BKException.create(rc)));
                }
            } else {
                promise.updateIfEmpty(new Throw<Void>(BKException.create(rc)));
            }
        }
    }, null);
    return promise;
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:28,代码来源:BookKeeperClient.java


注:本文中的com.twitter.util.Future.exception方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。