You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by se...@apache.org on 2015/05/15 13:33:44 UTC
incubator-ignite git commit: IGNITE-709 Remove SettableFuture.
Repository: incubator-ignite
Updated Branches:
refs/heads/ignite-709_2 0ba45875f -> 2109bc0fb
IGNITE-709 Remove SettableFuture.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/2109bc0f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/2109bc0f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/2109bc0f
Branch: refs/heads/ignite-709_2
Commit: 2109bc0fb5fe249980cd2e75cce29d723f3a0d85
Parents: 0ba4587
Author: sevdokimov <se...@gridgain.com>
Authored: Fri May 15 14:33:37 2015 +0300
Committer: sevdokimov <se...@gridgain.com>
Committed: Fri May 15 14:33:37 2015 +0300
----------------------------------------------------------------------
.../internal/util/future/SettableFuture.java | 94 --------------------
.../spi/discovery/tcp/TcpDiscoverySpi.java | 21 +++--
2 files changed, 12 insertions(+), 103 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2109bc0f/modules/core/src/main/java/org/apache/ignite/internal/util/future/SettableFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/future/SettableFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/util/future/SettableFuture.java
deleted file mode 100644
index 7fe094d..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/future/SettableFuture.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.util.future;
-
-import java.util.concurrent.*;
-
-/**
- * Simple implementation of {@link Future}
- */
-public class SettableFuture<T> implements Future<T> {
- /** */
- private final CountDownLatch latch = new CountDownLatch(1);
-
- /** Result of computation. */
- private T res;
-
- /** Exception threw during the computation. */
- private ExecutionException err;
-
- /** {@inheritDoc} */
- @Override public boolean cancel(boolean mayInterruptIfRunning) {
- throw new UnsupportedOperationException();
- }
-
- /** {@inheritDoc} */
- @Override public boolean isCancelled() {
- return false;
- }
-
- /** {@inheritDoc} */
- @Override public boolean isDone() {
- return latch.getCount() == 0;
- }
-
- /** {@inheritDoc} */
- @Override public T get() throws InterruptedException, ExecutionException {
- latch.await();
-
- if (err != null)
- throw err;
-
- return res;
- }
-
- /** {@inheritDoc} */
- @Override public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException,
- TimeoutException {
-
- if (!latch.await(timeout, unit))
- throw new TimeoutException();
-
- if (err != null)
- throw err;
-
- return res;
- }
-
- /**
- * Computation is done successful.
- *
- * @param res Result of computation.
- */
- public void set(T res) {
- this.res = res;
-
- latch.countDown();
- }
-
- /**
- * Computation failed.
- *
- * @param throwable Error.
- */
- public void setException(Throwable throwable) {
- err = new ExecutionException(throwable);
-
- latch.countDown();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2109bc0f/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
index 7ee3e3b..fb64764 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
@@ -5327,7 +5327,7 @@ public class TcpDiscoverySpi extends TcpDiscoverySpiAdapter implements TcpDiscov
private volatile ClusterMetrics metrics;
/** */
- private final AtomicReference<SettableFuture<Boolean>> pingFut = new AtomicReference<>();
+ private final AtomicReference<GridFutureAdapter<Boolean>> pingFut = new AtomicReference<>();
/**
* @param sock Socket.
@@ -5403,10 +5403,10 @@ public class TcpDiscoverySpi extends TcpDiscoverySpiAdapter implements TcpDiscov
*
*/
public void pingResult(boolean res) {
- SettableFuture<Boolean> fut = pingFut.getAndSet(null);
+ GridFutureAdapter<Boolean> fut = pingFut.getAndSet(null);
if (fut != null)
- fut.set(res);
+ fut.onDone(res);
}
/**
@@ -5416,7 +5416,7 @@ public class TcpDiscoverySpi extends TcpDiscoverySpiAdapter implements TcpDiscov
if (isNodeStopping())
return false;
- SettableFuture<Boolean> fut;
+ GridFutureAdapter<Boolean> fut;
while (true) {
fut = pingFut.get();
@@ -5424,7 +5424,7 @@ public class TcpDiscoverySpi extends TcpDiscoverySpiAdapter implements TcpDiscov
if (fut != null)
break;
- fut = new SettableFuture<>();
+ fut = new GridFutureAdapter<>();
if (pingFut.compareAndSet(null, fut)) {
TcpDiscoveryPingRequest pingReq = new TcpDiscoveryPingRequest(getLocalNodeId(), nodeId);
@@ -5440,15 +5440,18 @@ public class TcpDiscoverySpi extends TcpDiscoverySpiAdapter implements TcpDiscov
try {
return fut.get(ackTimeout, TimeUnit.MILLISECONDS);
}
- catch (ExecutionException e) {
- throw new IgniteSpiException("Internal error: ping future cannot be done with exception", e);
+ catch (IgniteInterruptedCheckedException ignored) {
+ throw new InterruptedException();
}
- catch (TimeoutException ignored) {
+ catch (IgniteFutureTimeoutCheckedException ignored) {
if (pingFut.compareAndSet(fut, null))
- fut.set(false);
+ fut.onDone(false);
return false;
}
+ catch (IgniteCheckedException e) {
+ throw new IgniteSpiException("Internal error: ping future cannot be done with exception", e);
+ }
}
/** {@inheritDoc} */