ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sevdoki...@apache.org
Subject incubator-ignite git commit: # ignite-11 Fix issues found on review.
Date Thu, 26 Feb 2015 15:12:02 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-11 2999d205d -> 6130f7e52


# ignite-11 Fix issues found on review.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/6130f7e5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/6130f7e5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/6130f7e5

Branch: refs/heads/ignite-11
Commit: 6130f7e52214ab0b0d0876d8be0c141e9dc1a2df
Parents: 2999d20
Author: sevdokimov <sevdokimov@gridgain.com>
Authored: Thu Feb 26 18:11:50 2015 +0300
Committer: sevdokimov <sevdokimov@gridgain.com>
Committed: Thu Feb 26 18:11:50 2015 +0300

----------------------------------------------------------------------
 .../spi/discovery/tcp/TcpDiscoverySpi.java      |  7 +---
 .../discovery/tcp/TcpDiscoverySpiAdapter.java   | 42 +++++++++++++-------
 2 files changed, 29 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6130f7e5/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 3fc52b1..df39d6b 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
@@ -1401,9 +1401,7 @@ public class TcpDiscoverySpi extends TcpDiscoverySpiAdapter implements
TcpDiscov
             boolean retry = false;
             Collection<Exception> errs = new ArrayList<>();
 
-            SocketMultiConnector multiConnector = new SocketMultiConnector(addrs, 2);
-
-            try {
+            try (SocketMultiConnector multiConnector = new SocketMultiConnector(addrs, 2))
{
                 GridTuple3<InetSocketAddress, Socket, Exception> tuple;
 
                 while ((tuple = multiConnector.next()) != null) {
@@ -1476,9 +1474,6 @@ public class TcpDiscoverySpi extends TcpDiscoverySpiAdapter implements
TcpDiscov
                     }
                 }
             }
-            finally {
-                multiConnector.close();
-            }
 
             if (retry) {
                 if (log.isDebugEnabled())

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6130f7e5/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpiAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpiAdapter.java
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpiAdapter.java
index 80b793a..1d9559e 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpiAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpiAdapter.java
@@ -1013,7 +1013,7 @@ abstract class TcpDiscoverySpiAdapter extends IgniteSpiAdapter implements
Discov
     /**
      *
      */
-    protected class SocketMultiConnector {
+    protected class SocketMultiConnector implements AutoCloseable {
         /** */
         private int connInProgress;
 
@@ -1068,11 +1068,15 @@ abstract class TcpDiscoverySpiAdapter extends IgniteSpiAdapter implements
Discov
                 return null;
 
             try {
+                Future<GridTuple3<InetSocketAddress, Socket, Exception>> fut
= completionSrvc.take();
+
                 connInProgress--;
 
-                return completionSrvc.take().get();
+                return fut.get();
             }
             catch (InterruptedException e) {
+                Thread.currentThread().interrupt();
+
                 throw new IgniteSpiException("Thread has been interrupted.", e);
             }
             catch (ExecutionException e) {
@@ -1080,33 +1084,43 @@ abstract class TcpDiscoverySpiAdapter extends IgniteSpiAdapter implements
Discov
             }
         }
 
-        /**
-         *
-         */
-        public void close() {
-            executor.shutdown();
+        /** {@inheritDoc} */
+        @Override public void close() {
+            List<Runnable> unstartedTasks = executor.shutdownNow();
+
+            connInProgress -= unstartedTasks.size();
 
             if (connInProgress > 0) {
-                new Thread(new Runnable() {
+                Thread thread = new Thread(new Runnable() {
                     @Override public void run() {
                         try {
-                            for (int i = 0; i < connInProgress; i++) {
+                            executor.awaitTermination(5, TimeUnit.MINUTES);
+
+                            Future<GridTuple3<InetSocketAddress, Socket, Exception>>
fut;
+
+                            while ((fut = completionSrvc.poll()) != null) {
                                 try {
-                                    GridTuple3<InetSocketAddress, Socket, Exception>
take = completionSrvc.take().get();
+                                    GridTuple3<InetSocketAddress, Socket, Exception>
tuple3 = fut.get();
 
-                                    if (take != null)
-                                        IgniteUtils.closeQuiet(take.get2());
+                                    if (tuple3 != null)
+                                        IgniteUtils.closeQuiet(tuple3.get2());
                                 }
-                                catch (ExecutionException ignored) {
+                                catch (ExecutionException ignore) {
 
                                 }
                             }
                         }
                         catch (InterruptedException e) {
+                            Thread.currentThread().interrupt();
+
                             throw new RuntimeException(e);
                         }
                     }
-                }).start();
+                });
+
+                thread.setDaemon(true);
+
+                thread.start();
             }
         }
     }


Mime
View raw message