Github user abhishekagarwal87 commented on a diff in the pull request: https://github.com/apache/storm/pull/1195#discussion_r55483738 --- Diff: storm-core/src/jvm/org/apache/storm/pacemaker/Pacemaker.java --- @@ -0,0 +1,248 @@ +/** + * 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.*; +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 java.util.*; +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 heartbeats; + private PacemakerStats pacemakerStats; + private Map conf; + private final long sleepSeconds = 60; + + 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(); + } + + public Pacemaker(Map conf) { + heartbeats = new ConcurrentHashMap(); + pacemakerStats = new PacemakerStats(); + this.conf = conf; + startStatsThread(); + } + + @Override + public HBMessage handleMessage(HBMessage m, boolean authenticated) { + HBMessage response = null; + HBMessageData data = m.get_data(); + switch (m.get_type()) { + case CREATE_PATH: + response = createPath(data.get_path()); + break; + case EXISTS: + response = exists(data.get_path(), authenticated); + break; + case SEND_PULSE: + response = sendPulse(data.get_pulse()); + break; + case GET_ALL_PULSE_FOR_PATH: + response = getAllPulseForPath(data.get_path(), authenticated); + break; + case GET_ALL_NODES_FOR_PATH: + response = getAllNodesForPath(data.get_path(), authenticated); + break; + case GET_PULSE: + response = getPulse(data.get_path(), authenticated); + break; + case DELETE_PATH: + response = deletePath(data.get_path()); + break; + case DELETE_PULSE_ID: + response = deletePulseId(data.get_path()); + break; + default: + LOG.info("Got Unexpected Type: {}", m.get_type()); + break; + } + if (response != null) + response.set_message_id(m.get_message_id()); + return response; + } + + private HBMessage createPath(String path) { + return new HBMessage(HBServerMessageType.CREATE_PATH_RESPONSE, null); + } + + private HBMessage exists(String path, boolean authenticated) { + HBMessage response = null; + if (authenticated) { + boolean itDoes = heartbeats.containsKey(path); + LOG.debug("Checking if path [ {} ] exists... {} .", path, itDoes); + response = new HBMessage(HBServerMessageType.EXISTS_RESPONSE, HBMessageData.boolval(itDoes)); + } else { + response = notAuthorized(); + } + return response; + } + + private HBMessage notAuthorized() { + return new HBMessage(HBServerMessageType.NOT_AUTHORIZED, null); + } + + private HBMessage sendPulse(HBPulse pulse) { + String id = pulse.get_id(); + byte[] details = pulse.get_details(); + LOG.debug("Saving Pulse for id [ {} ] data [ {} ].", id, details); --- End diff -- new String(details) will print the bytes correctly.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---