本文整理匯總了Java中io.vertx.core.Future.failedFuture方法的典型用法代碼示例。如果您正苦於以下問題:Java Future.failedFuture方法的具體用法?Java Future.failedFuture怎麽用?Java Future.failedFuture使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.vertx.core.Future
的用法示例。
在下文中一共展示了Future.failedFuture方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parseHeader
import io.vertx.core.Future; //導入方法依賴的package包/類
/**
* 解析報文頭。
*
* @param headerBuffer header Buffer
* @param expectedCommand expectedCommand
* @param expectedBodyLength expectedBodyLength
* @return async result of the length of the packet body
*/
public static Future<Long> parseHeader(Buffer headerBuffer, byte expectedCommand, long expectedBodyLength) {
if (headerBuffer.length() != HEADER_BYTE_LENGTH) {
return Future.failedFuture(new FdfsException("receive packet size" + headerBuffer.length()
+ " is not equal to the expected header size: " + HEADER_BYTE_LENGTH));
}
byte command = headerBuffer.getByte(PROTO_HEADER_CMD_INDEX);
if (command != expectedCommand) {
return Future.failedFuture(new FdfsException(
"receive command: " + command + " is not equal to the expected command: " + expectedCommand));
}
byte status = headerBuffer.getByte(PROTO_HEADER_STATUS_INDEX);
if (status != HEADER_STATUS_SUCCESS) {
return Future.failedFuture(new FdfsException("receive packet errno is: " + status));
}
long bodyLength = headerBuffer.getLong(0);
if (expectedBodyLength > 0 && bodyLength != expectedBodyLength) {
return Future.failedFuture(new FdfsException("receive packet body length: " + bodyLength
+ " is not equal to the expected: " + expectedBodyLength));
}
return Future.succeededFuture(bodyLength);
}
示例2: parseStorage
import io.vertx.core.Future; //導入方法依賴的package包/類
private Future<FdfsStorageOptions> parseStorage(Buffer bodyBuffer, String charset, boolean hasPathIndex) {
try {
FdfsStorageOptions storageOptions = new FdfsStorageOptions(options);
String group = FdfsUtils
.fdfsTrim(bodyBuffer.getString(0, FdfsProtocol.FDFS_GROUP_NAME_MAX_LEN, options.getCharset()));
String ip = FdfsUtils.fdfsTrim(bodyBuffer.getString(FdfsProtocol.FDFS_GROUP_NAME_MAX_LEN,
FdfsProtocol.FDFS_GROUP_NAME_MAX_LEN + FdfsProtocol.FDFS_IPADDR_SIZE - 1, options.getCharset()));
long port = bodyBuffer.getLong(FdfsProtocol.FDFS_GROUP_NAME_MAX_LEN + FdfsProtocol.FDFS_IPADDR_SIZE - 1);
storageOptions.setGroup(group).setAddress(SocketAddress.inetSocketAddress((int) port, ip));
if (hasPathIndex && bodyBuffer.length() > FdfsProtocol.TRACKER_QUERY_STORAGE_FETCH_BODY_LEN) {
byte storePathIndex = bodyBuffer.getByte(FdfsProtocol.TRACKER_QUERY_STORAGE_FETCH_BODY_LEN);
storageOptions.setStorePathIndex(storePathIndex);
}
return Future.succeededFuture(storageOptions);
} catch (Exception e) {
return Future.failedFuture(e);
}
}
示例3: uploadFile
import io.vertx.core.Future; //導入方法依賴的package包/類
private Future<FdfsFileId> uploadFile(byte command, String fileFullPathName, String ext) {
Buffer extBuffer = Buffer.buffer(ext, options.getCharset());
if (extBuffer.length() > FdfsProtocol.FDFS_FILE_EXT_NAME_MAX_LEN) {
return Future.failedFuture("ext is too long ( greater than " + FdfsProtocol.FDFS_FILE_EXT_NAME_MAX_LEN + ")");
}
Future<FdfsFileId> futureFileId = Future.future();
LocalFile.readFile(vertx.fileSystem(), fileFullPathName).setHandler(ar -> {
if (ar.succeeded()) {
LocalFile localFile = ar.result();
uploadFile(command, localFile.getFile(), localFile.getSize(), ext).setHandler(upload -> {
localFile.closeFile();
if (upload.succeeded()) {
futureFileId.complete(upload.result());
} else {
futureFileId.fail(upload.cause());
}
});
} else {
futureFileId.fail(ar.cause());
}
});
return futureFileId;
}
示例4: thenError
import io.vertx.core.Future; //導入方法依賴的package包/類
static <T> Future<T> thenError(
final Class<? extends WebException> clazz,
final Object... args
) {
final WebException error = To.toError(clazz, args);
return Future.failedFuture(error);
}
示例5: fail
import io.vertx.core.Future; //導入方法依賴的package包/類
@Override
void fail(Throwable err) {
Future<PreparedStatement> failure = Future.failedFuture(err);
handler.handle(failure);
if (cached != null) {
cached.fut.handle(failure);
}
}
示例6: failedFuture
import io.vertx.core.Future; //導入方法依賴的package包/類
public static <T> Future<T> failedFuture(String string)
{
return Future.failedFuture(string);
}