[
https://issues.apache.org/jira/browse/STORM-1611?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15204473#comment-15204473
]
ASF GitHub Bot commented on STORM-1611:
---------------------------------------
Github user knusbaum commented on a diff in the pull request:
https://github.com/apache/storm/pull/1195#discussion_r56844493
--- Diff: storm-core/src/jvm/org/apache/storm/pacemaker/Pacemaker.java ---
@@ -0,0 +1,374 @@
+/**
+ * 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.storm.pacemaker;
+
+import org.apache.storm.generated.HBMessage;
+import org.apache.storm.generated.HBMessageData;
+import org.apache.storm.generated.HBPulse;
+import org.apache.storm.generated.HBNodes;
+import org.apache.storm.generated.HBServerMessageType;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.Utils;
+import org.apache.storm.utils.VersionInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import uk.org.lidalia.sysoutslf4j.context.SysOutOverSLF4J;
+
+import javax.management.*;
+import java.lang.management.ManagementFactory;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Map;
+
+import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class Pacemaker implements IServerMessageHandler {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(Pacemaker.class);
+
+ private Map<String, byte[]> heartbeats;
+ private PacemakerStats lastOneMinStats;
+ private PacemakerStats pacemakerStats;
+ private Map conf;
+ private final long sleepSeconds = 60;
+
+ private boolean isDaemon = true;
+ private boolean startImmediately = true;
+
+ private static class PacemakerStats {
+ public AtomicInteger sendPulseCount = new AtomicInteger();
+ public AtomicInteger totalReceivedSize = new AtomicInteger();
+ public AtomicInteger getPulseCount = new AtomicInteger();
+ public AtomicInteger totalSentSize = new AtomicInteger();
+ public AtomicInteger largestHeartbeatSize = new AtomicInteger();
+ public AtomicInteger averageHeartbeatSize = new AtomicInteger();
+ private AtomicInteger totalKeys = new AtomicInteger();
+ }
+ private static class PacemakerDynamicMBean implements DynamicMBean {
+
+ private final MBeanInfo mBeanInfo;
+ private final static String [] attributeNames = new String []{
+ "send-pulse-count",
+ "total-received-size",
+ "get-pulse-count",
+ "total-sent-size",
+ "largest-heartbeat-size",
+ "average-heartbeat-size",
+ "total-keys"
+ };
+ private static String attributeType =
"java.util.concurrent.atomic.AtomicInteger";
+
+ private static final MBeanAttributeInfo[] attributeInfos = new
MBeanAttributeInfo[] {
+ new MBeanAttributeInfo("send-pulse-count",
attributeType, "send-pulse-count", true, false, false),
+ new MBeanAttributeInfo("total-received-size",
attributeType, "total-received-size", true, false, false),
+ new MBeanAttributeInfo("get-pulse-count",
attributeType, "get-pulse-count", true, false, false),
+ new MBeanAttributeInfo("total-sent-size",
attributeType, "total-sent-size", true, false, false),
+ new MBeanAttributeInfo("largest-heartbeat-size",
attributeType, "largest-heartbeat-size", true, false, false),
+ new MBeanAttributeInfo("average-heartbeat-size",
attributeType, "average-heartbeat-size", true, false, false),
+ new MBeanAttributeInfo("total-keys",
attributeType, "total-keys", true, false, false)
+ };
+ private PacemakerStats stats;
+
+ public PacemakerDynamicMBean(PacemakerStats stats) {
+ this.stats = stats;
+ this.mBeanInfo = new
MBeanInfo("org.apache.storm.pacemaker.PaceMakerDynamicMBean", "Java Pacemaker
Dynamic MBean",
+ PacemakerDynamicMBean.attributeInfos, null, null,
null);
+ }
+
+ @Override
+ public MBeanInfo getMBeanInfo() {
+ return mBeanInfo;
+ }
+
+ @Override
+ public AttributeList getAttributes(String[] attributes) {
+ AttributeList list = new AttributeList();
+ if (attributes == null)
+ return list;
+ final int len = attributes.length;
+ try {
+ for (int i = 0; i < len; i++) {
+ final Attribute a = new Attribute(attributes[i],
getAttribute(attributes[i]));
+ list.add(a);
+
+ }
+ } catch (Exception e) {
+ throw Utils.wrapInRuntime(e);
+ }
+ return list;
+ }
+
+ @Override
+ public Object getAttribute(String attribute) throws
AttributeNotFoundException, MBeanException, ReflectionException {
+ if (attribute == null)
+ throw new AttributeNotFoundException("null");
+ if (attribute.equals("send-pulse-count"))
+ return stats.sendPulseCount.get();
+ else if (attribute.equals("total-received-size"))
+ return stats.totalReceivedSize.get();
+ else if (attribute.equals("get-pulse-count"))
+ return stats.getPulseCount.get();
+ else if (attribute.equals("total-sent-size"))
+ return stats.totalSentSize.get();
+ else if (attribute.equals("largest-heartbeat-size"))
+ return stats.largestHeartbeatSize.get();
+ else if (attribute.equals("average-heartbeat-size"))
+ return stats.averageHeartbeatSize.get();
+ else if (attribute.equals("total-keys"))
+ return stats.totalKeys.get();
+ else
+ throw new AttributeNotFoundException("null");
+ }
+
+ @Override
+ public void setAttribute(Attribute attribute) throws
AttributeNotFoundException, InvalidAttributeValueException, MBeanException,
ReflectionException {
+
+ }
+
+ @Override
+ public AttributeList setAttributes(AttributeList attributes) {
+ return null;
+ }
+
+ @Override
+ public Object invoke(String actionName, Object[] params, String[]
signature) throws MBeanException, ReflectionException {
+ return null;
+ }
+ }
+
+ public Pacemaker(Map conf, boolean isRegisterJmx) {
--- End diff --
registering jmx isn't something we want in the constructor. I know stack
traces bubble up, but I don't think anything bad actually happens from double
registering. If we really want to avoid double-registering, we need a better
mechanism than this, but I'm in favor of just letting double-registration occur.
> port org.apache.storm.pacemaker.pacemaker to java
> -------------------------------------------------
>
> Key: STORM-1611
> URL: https://issues.apache.org/jira/browse/STORM-1611
> Project: Apache Storm
> Issue Type: New Feature
> Reporter: John Fang
> Assignee: John Fang
>
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)