本文整理匯總了Java中io.netty.util.concurrent.Future.isSuccess方法的典型用法代碼示例。如果您正苦於以下問題:Java Future.isSuccess方法的具體用法?Java Future.isSuccess怎麽用?Java Future.isSuccess使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.netty.util.concurrent.Future
的用法示例。
在下文中一共展示了Future.isSuccess方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: add
import io.netty.util.concurrent.Future; //導入方法依賴的package包/類
public RFuture<Void> add(final ClientConnectionsEntry entry) {
final RPromise<Void> result = connectionManager.newPromise();
FutureListener<Void> listener = new FutureListener<Void>() {
AtomicInteger counter = new AtomicInteger(2);
@Override
public void operationComplete(Future<Void> future) throws Exception {
if (!future.isSuccess()) {
result.tryFailure(future.cause());
return;
}
if (counter.decrementAndGet() == 0) {
String addr = entry.getClient().getIpAddr();
ip2Entry.put(addr, entry);
result.trySuccess(null);
}
}
};
RFuture<Void> slaveFuture = slaveConnectionPool.add(entry);
slaveFuture.addListener(listener);
RFuture<Void> pubSubFuture = pubSubConnectionPool.add(entry);
pubSubFuture.addListener(listener);
return result;
}
示例2: operationComplete
import io.netty.util.concurrent.Future; //導入方法依賴的package包/類
@Override
public void operationComplete(Future<Channel> cf) throws Exception {
if (cf.isCancelled()) {
promise.cancel(true);
return;
}
if (!cf.isSuccess()) {
promise.completeExceptionally(cf.cause());
return;
}
Channel channel = cf.getNow();
promise.whenComplete((result, error) -> pool.release(channel));
try {
FastdfsOperation<T> fastdfsOperation = new FastdfsOperation<>(channel, requester, replier, promise);
if (LOG.isDebugEnabled()) {
LOG.debug("execute {}", fastdfsOperation);
}
fastdfsOperation.execute();
} catch (Exception e) {
promise.completeExceptionally(e);
}
}
示例3: operationComplete
import io.netty.util.concurrent.Future; //導入方法依賴的package包/類
@Override
public void operationComplete(Future<R> future) throws Exception {
if (future.isSuccess() && task.condition(future)) {
enqueueRunnable(new Runnable() {
@Override
public void run() {
try {
task.execute();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
});
}
}
示例4: operationComplete
import io.netty.util.concurrent.Future; //導入方法依賴的package包/類
@Override
public void operationComplete(Future<T> future) throws Exception {
if (!future.isSuccess()) {
promise.tryFailure(future.cause());
return;
}
promise.trySuccess(future.getNow());
}
示例5: operationComplete
import io.netty.util.concurrent.Future; //導入方法依賴的package包/類
@Override
public void operationComplete(Future<Void> future) throws Exception {
if (!future.isSuccess()) {
res.tryFailure(future.cause());
return;
}
if (counter.decrementAndGet() == 0) {
res.trySuccess(null);
}
}
示例6: operationComplete
import io.netty.util.concurrent.Future; //導入方法依賴的package包/類
@Override
public void operationComplete(Future<Object> future) throws Exception {
if (!future.isSuccess()) {
connection.closeAsync();
connectionPromise.tryFailure(future.cause());
return;
}
if (commandsCounter.decrementAndGet() == 0) {
connectionPromise.trySuccess(connection);
}
}
示例7: readAllAsync
import io.netty.util.concurrent.Future; //導入方法依賴的package包/類
@Override
public <T, R> RFuture<Collection<R>> readAllAsync(RedisCommand<T> command, Object... params) {
final RPromise<Collection<R>> mainPromise = connectionManager.newPromise();
final Collection<MasterSlaveEntry> nodes = connectionManager.getEntrySet();
final List<R> results = new ArrayList<R>();
final AtomicInteger counter = new AtomicInteger(nodes.size());
FutureListener<R> listener = new FutureListener<R>() {
@Override
public void operationComplete(Future<R> future) throws Exception {
if (!future.isSuccess()) {
mainPromise.tryFailure(future.cause());
return;
}
R result = future.getNow();
if (result instanceof Collection) {
synchronized (results) {
results.addAll((Collection) result);
}
} else {
synchronized (results) {
results.add(result);
}
}
if (counter.decrementAndGet() == 0
&& !mainPromise.isDone()) {
mainPromise.trySuccess(results);
}
}
};
for (MasterSlaveEntry entry : nodes) {
RPromise<R> promise = connectionManager.newPromise();
promise.addListener(listener);
async(true, new NodeSource(entry), connectionManager.getCodec(), command, params, promise, 0);
}
return mainPromise;
}
示例8: allAsync
import io.netty.util.concurrent.Future; //導入方法依賴的package包/類
private <T, R> RFuture<R> allAsync(boolean readOnlyMode, RedisCommand<T> command, final SlotCallback<T, R> callback, Object... params) {
final RPromise<R> mainPromise = connectionManager.newPromise();
final Collection<MasterSlaveEntry> nodes = connectionManager.getEntrySet();
final AtomicInteger counter = new AtomicInteger(nodes.size());
FutureListener<T> listener = new FutureListener<T>() {
@Override
public void operationComplete(Future<T> future) throws Exception {
if (!future.isSuccess()) {
mainPromise.tryFailure(future.cause());
return;
}
if (callback != null) {
callback.onSlotResult(future.getNow());
}
if (counter.decrementAndGet() == 0) {
if (callback != null) {
mainPromise.trySuccess(callback.onFinish());
} else {
mainPromise.trySuccess(null);
}
}
}
};
for (MasterSlaveEntry entry : nodes) {
RPromise<T> promise = connectionManager.newPromise();
promise.addListener(listener);
async(readOnlyMode, new NodeSource(entry), connectionManager.getCodec(), command, params, promise, 0);
}
return mainPromise;
}
示例9: evalAllAsync
import io.netty.util.concurrent.Future; //導入方法依賴的package包/類
public <T, R> RFuture<R> evalAllAsync(boolean readOnlyMode, RedisCommand<T> command, final SlotCallback<T, R> callback, String script, List<Object> keys, Object... params) {
final RPromise<R> mainPromise = connectionManager.newPromise();
final Collection<MasterSlaveEntry> entries = connectionManager.getEntrySet();
final AtomicInteger counter = new AtomicInteger(entries.size());
FutureListener<T> listener = new FutureListener<T>() {
@Override
public void operationComplete(Future<T> future) throws Exception {
if (!future.isSuccess()) {
mainPromise.tryFailure(future.cause());
return;
}
callback.onSlotResult(future.getNow());
if (counter.decrementAndGet() == 0
&& !mainPromise.isDone()) {
mainPromise.trySuccess(callback.onFinish());
}
}
};
List<Object> args = new ArrayList<Object>(2 + keys.size() + params.length);
args.add(script);
args.add(keys.size());
args.addAll(keys);
args.addAll(Arrays.asList(params));
for (MasterSlaveEntry entry : entries) {
RPromise<T> promise = connectionManager.newPromise();
promise.addListener(listener);
async(readOnlyMode, new NodeSource(entry), connectionManager.getCodec(), command, args.toArray(), promise, 0);
}
return mainPromise;
}
示例10: invoke
import io.netty.util.concurrent.Future; //導入方法依賴的package包/類
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Future<Channel> channelFuture = null;
try {
RequestWrapper requestWrapper = new RequestWrapper();
requestWrapper.setServiceName(name);
requestWrapper.setMethodName(method.getName());
requestWrapper.setParameters(args);
requestWrapper.setParamTypes(method.getParameterTypes());
requestWrapper.setRequestId(UUIDUtils.getRandomId());
System.out.println("send request: " + requestWrapper);
//獲取一個可用的channel
channelFuture = connectionPool.acquire().sync();
if (!channelFuture.isSuccess()) {
throw new Exception("獲取鏈接失敗!");
}
Promise<ResponseWrapper> promise = eventExecutor.newPromise();
requestWrapper.setPromise(promise);
RpcClient.getRequestWrapperMap().put(requestWrapper.getRequestId(), promise);
//注意channel.write和context.write的區別
channelFuture.getNow().writeAndFlush(requestWrapper);
//如果是同步模式,return結果
return promise.get(5000L, TimeUnit.MILLISECONDS).getResult();
} finally {
if (channelFuture != null && channelFuture.isSuccess()) {
connectionPool.release(channelFuture.getNow());
}
}
}
示例11: startListenerHandle
import io.netty.util.concurrent.Future; //導入方法依賴的package包/類
private void startListenerHandle(Future future, SuccessfulListener listener) {
if (!future.isSuccess()) {
future.cause().printStackTrace();
}
if (listener != null) {
listener.onSuccess(future.isSuccess());
}
}
示例12: startListenerHandle
import io.netty.util.concurrent.Future; //導入方法依賴的package包/類
private void startListenerHandle(Future future, SuccessfulListener listener) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (!future.isSuccess()) future.cause().printStackTrace();
if (listener != null) listener.onSuccess(future.isSuccess());
}
示例13: operationComplete
import io.netty.util.concurrent.Future; //導入方法依賴的package包/類
@Override
public void operationComplete(Future<T> tFuture) throws Exception {
LOGGER.trace("Completing future from thread: {}", Thread.currentThread().getName());
if (tFuture.isSuccess()) {
complete(tFuture.getNow());
} else if (tFuture.isCancelled()) {
cancel(true);
} else {
completeExceptionally(tFuture.cause());
}
}
示例14: operationComplete
import io.netty.util.concurrent.Future; //導入方法依賴的package包/類
@Override
public void operationComplete(Future<Channel> cf) throws Exception {
if (cf.isCancelled()) {
promise.cancel(true);
return;
}
if (!cf.isSuccess()) {
promise.completeExceptionally(cf.cause());
return;
}
Channel channel = cf.getNow();
promise.whenComplete((result, error) -> pool.release(channel));
try {
FastdfsOperation<T> fastdfsOperation = new FastdfsOperation<>(channel, requestor,
replier, promise);
if (LOG.isDebugEnabled()) {
LOG.debug("execute {}", fastdfsOperation);
}
fastdfsOperation.execute();
} catch (Exception e) {
promise.completeExceptionally(e);
}
}
示例15: operationComplete
import io.netty.util.concurrent.Future; //導入方法依賴的package包/類
@Override
public void operationComplete(Future<? super Void> future) throws Exception {
if (!future.isSuccess()) {
logger.error("Unable to maintain connection {}. Closing connection.", connection.getName());
connection.close();
}
}