Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5A93018234 for ; Mon, 1 Jun 2015 14:33:13 +0000 (UTC) Received: (qmail 26194 invoked by uid 500); 1 Jun 2015 14:33:13 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 26165 invoked by uid 500); 1 Jun 2015 14:33:13 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 26156 invoked by uid 99); 1 Jun 2015 14:33:13 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Jun 2015 14:33:13 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id B240A1A414C for ; Mon, 1 Jun 2015 14:33:12 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.79 X-Spam-Level: X-Spam-Status: No, score=0.79 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id ZGSjZOI-5JMY for ; Mon, 1 Jun 2015 14:32:57 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with SMTP id 642DE47C18 for ; Mon, 1 Jun 2015 14:32:49 +0000 (UTC) Received: (qmail 24189 invoked by uid 99); 1 Jun 2015 14:32:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Jun 2015 14:32:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 84F37E0520; Mon, 1 Jun 2015 14:32:48 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.incubator.apache.org Date: Mon, 01 Jun 2015 14:33:03 -0000 Message-Id: <23355837591c4f098d81ad05e850de92@git.apache.org> In-Reply-To: <3a9e6eb848ce42ed88f3ac501c2637c4@git.apache.org> References: <3a9e6eb848ce42ed88f3ac501c2637c4@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [16/50] incubator-ignite git commit: # IGNITE-943 Remove SocketMultiConnector # IGNITE-943 Remove SocketMultiConnector Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/6adc9743 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/6adc9743 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/6adc9743 Branch: refs/heads/ignite-876-2 Commit: 6adc9743d4912ad59a50832f4869e8e41f5f9a04 Parents: 154bd9e Author: sevdokimov Authored: Thu May 28 17:03:39 2015 +0300 Committer: sevdokimov Committed: Thu May 28 17:03:39 2015 +0300 ---------------------------------------------------------------------- .../ignite/spi/discovery/tcp/ServerImpl.java | 21 +-- .../spi/discovery/tcp/SocketMultiConnector.java | 144 ------------------- 2 files changed, 13 insertions(+), 152 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6adc9743/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java index a966363..59e25fc 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java @@ -810,17 +810,22 @@ class ServerImpl extends TcpDiscoveryImpl { boolean retry = false; Collection errs = new ArrayList<>(); - try (SocketMultiConnector multiConnector = new SocketMultiConnector(spi, addrs, 2)) { - GridTuple3 tuple; + for (int j = 2; --j >= 0;) { + for (InetSocketAddress addr : addrs) { + Socket sock = null; + Exception ex = null; - while ((tuple = multiConnector.next()) != null) { - InetSocketAddress addr = tuple.get1(); - Socket sock = tuple.get2(); - Exception ex = tuple.get3(); + try { + sock = spi.openSocket(addr); + } + catch (Exception e) { + if (j > 0) + continue; - if (ex == null) { - assert sock != null; + ex = e; + } + if (ex == null) { try { Integer res = sendMessageDirectly(joinReq, addr, sock); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6adc9743/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/SocketMultiConnector.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/SocketMultiConnector.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/SocketMultiConnector.java deleted file mode 100644 index 698735e..0000000 --- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/SocketMultiConnector.java +++ /dev/null @@ -1,144 +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.spi.discovery.tcp; - -import org.apache.ignite.internal.util.*; -import org.apache.ignite.internal.util.lang.*; -import org.apache.ignite.spi.*; -import org.jetbrains.annotations.*; - -import java.net.*; -import java.util.*; -import java.util.concurrent.*; - -/** - * Allow to connect to addresses parallel. - */ -class SocketMultiConnector implements AutoCloseable { - /** */ - private int connInProgress; - - /** */ - private final ExecutorService executor; - - /** */ - private final CompletionService> completionSrvc; - - /** - * @param spi Discovery SPI. - * @param addrs Addresses. - * @param retryCnt Retry count. - */ - SocketMultiConnector(final TcpDiscoverySpi spi, Collection addrs, - final int retryCnt) { - connInProgress = addrs.size(); - - executor = Executors.newFixedThreadPool(Math.min(1, addrs.size())); - - completionSrvc = new ExecutorCompletionService<>(executor); - - for (final InetSocketAddress addr : addrs) { - completionSrvc.submit(new Callable>() { - @Override public GridTuple3 call() { - Exception ex = null; - Socket sock = null; - - for (int i = 0; i < retryCnt; i++) { - if (Thread.currentThread().isInterrupted()) - return null; // Executor is shutdown. - - try { - sock = spi.openSocket(addr); - - break; - } - catch (Exception e) { - ex = e; - } - } - - return new GridTuple3<>(addr, sock, ex); - } - }); - } - } - - /** - * - */ - @Nullable public GridTuple3 next() { - if (connInProgress == 0) - return null; - - try { - Future> fut = completionSrvc.take(); - - connInProgress--; - - return fut.get(); - } - catch (InterruptedException e) { - Thread.currentThread().interrupt(); - - throw new IgniteSpiException("Thread has been interrupted.", e); - } - catch (ExecutionException e) { - throw new IgniteSpiException(e); - } - } - - /** {@inheritDoc} */ - @Override public void close() { - List unstartedTasks = executor.shutdownNow(); - - connInProgress -= unstartedTasks.size(); - - if (connInProgress > 0) { - Thread thread = new Thread(new Runnable() { - @Override public void run() { - try { - executor.awaitTermination(5, TimeUnit.MINUTES); - - Future> fut; - - while ((fut = completionSrvc.poll()) != null) { - try { - GridTuple3 tuple3 = fut.get(); - - if (tuple3 != null) - IgniteUtils.closeQuiet(tuple3.get2()); - } - catch (ExecutionException ignore) { - - } - } - } - catch (InterruptedException e) { - Thread.currentThread().interrupt(); - - throw new RuntimeException(e); - } - } - }); - - thread.setDaemon(true); - - thread.start(); - } - } -}