[
https://issues.apache.org/jira/browse/GOSSIP-49?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15884870#comment-15884870
]
ASF GitHub Bot commented on GOSSIP-49:
--------------------------------------
Github user edwardcapriolo commented on a diff in the pull request:
https://github.com/apache/incubator-gossip/pull/37#discussion_r103113032
--- Diff:
src/main/java/org/apache/gossip/manager/GossipMemberStateRefresher.java ---
@@ -0,0 +1,110 @@
+/*
+ * 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.gossip.manager;
+
+import org.apache.gossip.GossipSettings;
+import org.apache.gossip.LocalGossipMember;
+import org.apache.gossip.event.GossipListener;
+import org.apache.gossip.event.GossipState;
+import org.apache.gossip.model.GossipDataMessage;
+import org.apache.gossip.model.ShutdownMessage;
+import org.apache.log4j.Logger;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiFunction;
+
+public class GossipMemberStateRefresher implements Runnable {
+ public static final Logger LOGGER =
Logger.getLogger(GossipMemberStateRefresher.class);
+
+ private final Map<LocalGossipMember, GossipState> members;
+ private final GossipSettings settings;
+ private final GossipListener listener;
+ private final Clock clock;
+ private final BiFunction<String, String, GossipDataMessage>
findPerNodeGossipData;
+
+ public GossipMemberStateRefresher(Map<LocalGossipMember, GossipState>
members, GossipSettings settings,
+ GossipListener listener,
BiFunction<String, String, GossipDataMessage> findPerNodeGossipData) {
+ this.members = members;
+ this.settings = settings;
+ this.listener = listener;
+ this.findPerNodeGossipData = findPerNodeGossipData;
+ clock = new SystemClock();
+ }
+
+ public void run() {
+ try {
--- End diff --
Please move all this logic into a method named runOnce() so that we can
call it more easily in mock/unit tests
> Refactor Failure detector Lambda into named class
> -------------------------------------------------
>
> Key: GOSSIP-49
> URL: https://issues.apache.org/jira/browse/GOSSIP-49
> Project: Gossip
> Issue Type: Improvement
> Reporter: Edward Capriolo
> Assignee: Maxim Rusak
> Fix For: 0.1.2
>
>
> When receiving a message the PassiveGossipThread updates heartbeats.
> Currently a lambda in the GossipManager, which periodically moves through the
> list and marks hosts as down and fires the event notification listner:
> {noformat}
> scheduledServiced.scheduleAtFixedRate(() -> {
> try {
> for (Entry<LocalGossipMember, GossipState> entry :
> members.entrySet()) {
> Double result = null;
> try {
> result = entry.getKey().detect(clock.nanoTime());
> //System.out.println(entry.getKey() +" "+ result);
> if (result != null) {
> if (result > settings.getConvictThreshold() && entry.getValue()
> == GossipState.UP) {
> members.put(entry.getKey(), GossipState.DOWN);
> listener.gossipEvent(entry.getKey(), GossipState.DOWN);
> }
> if (result <= settings.getConvictThreshold() &&
> entry.getValue() == GossipState.DOWN) {
> members.put(entry.getKey(), GossipState.UP);
> listener.gossipEvent(entry.getKey(), GossipState.UP);
> }
> }
> } catch (IllegalArgumentException ex) {
> //0.0 returns throws exception computing the mean.
> long now = clock.nanoTime();
> long nowInMillis =
> TimeUnit.MILLISECONDS.convert(now,TimeUnit.NANOSECONDS);
> if (nowInMillis - settings.getCleanupInterval() >
> entry.getKey().getHeartbeat() && entry.getValue() == GossipState.UP){
> LOGGER.warn("Marking down");
> members.put(entry.getKey(), GossipState.DOWN);
> listener.gossipEvent(entry.getKey(), GossipState.DOWN);
> }
> } //end catch
> } // end for
> } catch (RuntimeException ex) {
> LOGGER.warn("scheduled state had exception", ex);
> }
> {noformat}
> This should be moved to a named class that is injected with the data members
> it needs. This would make the logic easier to unit/mock test. We need to run
> it periodically in the rare case that no messages are coming to us, but we
> could also run this after receiving a message rather than waiting for the
> scheduled executor to trigger it. In many cases that would alert faster.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)