當前位置: 首頁>>代碼示例>>Java>>正文


Java Future.failedFuture方法代碼示例

本文整理匯總了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);
}
 
開發者ID:gengteng,項目名稱:vertx-fastdfs-client,代碼行數:34,代碼來源:FdfsProtocol.java

示例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);
	}
}
 
開發者ID:gengteng,項目名稱:vertx-fastdfs-client,代碼行數:23,代碼來源:FdfsTrackerImpl.java

示例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;
}
 
開發者ID:gengteng,項目名稱:vertx-fastdfs-client,代碼行數:32,代碼來源:FdfsStorageImpl.java

示例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);
}
 
開發者ID:silentbalanceyh,項目名稱:vertx-zero,代碼行數:8,代碼來源:Fluctuate.java

示例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);
  }
}
 
開發者ID:vietj,項目名稱:reactive-pg-client,代碼行數:9,代碼來源:PrepareStatementCommand.java

示例6: failedFuture

import io.vertx.core.Future; //導入方法依賴的package包/類
public static <T> Future<T> failedFuture(String string)
{
    return Future.failedFuture(string);
}
 
開發者ID:DavidQuan,項目名稱:vertx-ssdb,代碼行數:5,代碼來源:F.java


注:本文中的io.vertx.core.Future.failedFuture方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。