diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2019-05-08 12:57:47 -0500 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2019-06-03 20:21:23 +0200 |
commit | a8877e19050e05ff7b30b44ca4a0ccd50d33b6af (patch) | |
tree | 3b8ff06377b965355c9f4065634fa431ae9647e1 /server/sonar-process | |
parent | e4c24ddde8ade42edafb6200d3c089db587bf5a9 (diff) | |
download | sonarqube-a8877e19050e05ff7b30b44ca4a0ccd50d33b6af.tar.gz sonarqube-a8877e19050e05ff7b30b44ca4a0ccd50d33b6af.zip |
SONAR-12041 Display warning at startup if list of hosts is not consistent across all cluster nodes
Diffstat (limited to 'server/sonar-process')
3 files changed, 64 insertions, 4 deletions
diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/DistributedCallback.java b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/DistributedCallback.java new file mode 100644 index 00000000000..edf1159a3c9 --- /dev/null +++ b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/DistributedCallback.java @@ -0,0 +1,28 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.process.cluster.hz; + +import com.hazelcast.core.Member; +import java.util.Map; + +@FunctionalInterface +public interface DistributedCallback<T> { + void onComplete(Map<Member, T> response); +} diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMember.java b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMember.java index 951b6a73574..a880da32de2 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMember.java +++ b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMember.java @@ -82,16 +82,29 @@ public interface HazelcastMember extends AutoCloseable { /** * Runs a distributed query on a set of Hazelcast members. * - * @param callable the query that is executed on all target members. Be careful of classloader, don't use classes - * that are not available in classpath of target members. + * @param callable the query that is executed on all target members. Be careful of classloader, don't use classes + * that are not available in classpath of target members. * @param memberSelector the subset of members to target. See {@link com.hazelcast.cluster.memberselector.MemberSelectors} * for utilities. - * @param timeoutMs the total timeout to get responses from all target members, in milliseconds. If timeout is reached, then - * the members that didn't answer on time are marked as timed-out in {@link DistributedAnswer} + * @param timeoutMs the total timeout to get responses from all target members, in milliseconds. If timeout is reached, then + * the members that didn't answer on time are marked as timed-out in {@link DistributedAnswer} + * @throws java.util.concurrent.RejectedExecutionException if no member is selected */ <T> DistributedAnswer<T> call(DistributedCall<T> callable, MemberSelector memberSelector, long timeoutMs) throws InterruptedException; + /** + * Runs asynchronously a distributed query on a set of Hazelcast members. + * + * @param callable the query that is executed on all target members. Be careful of classloader, don't use classes + * that are not available in classpath of target members. + * @param memberSelector the subset of members to target. See {@link com.hazelcast.cluster.memberselector.MemberSelectors} + * for utilities. + * @param callback will be called once we get all responses. + * @throws java.util.concurrent.RejectedExecutionException if no member is selected + */ + <T> void callAsync(DistributedCall<T> callable, MemberSelector memberSelector, DistributedCallback<T> callback); + @Override void close(); } diff --git a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberImpl.java b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberImpl.java index 0d7588f8bb0..a52afe342d9 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberImpl.java +++ b/server/sonar-process/src/main/java/org/sonar/process/cluster/hz/HazelcastMemberImpl.java @@ -26,6 +26,7 @@ import com.hazelcast.core.IAtomicReference; import com.hazelcast.core.IExecutorService; import com.hazelcast.core.Member; import com.hazelcast.core.MemberSelector; +import com.hazelcast.core.MultiExecutionCallback; import java.util.Map; import java.util.Set; import java.util.concurrent.ExecutionException; @@ -106,6 +107,24 @@ class HazelcastMemberImpl implements HazelcastMember { } @Override + public <T> void callAsync(DistributedCall<T> callable, MemberSelector memberSelector, DistributedCallback<T> callback) { + IExecutorService executor = hzInstance.getExecutorService("default"); + + // callback doesn't handle failures, so we need to make sure the callable won't fail! + executor.submitToMembers(callable, memberSelector, new MultiExecutionCallback() { + @Override + public void onResponse(Member member, Object value) { + // nothing to do when each node responds + } + + @Override + public void onComplete(Map<Member, Object> values) { + callback.onComplete((Map<Member, T>) values); + } + }); + } + + @Override public void close() { try { hzInstance.shutdown(); |