Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (309)
Collections:
Other Resources:
Apache ZooKeeper 3.7.0 Server Source Code
Apache ZooKeeper is an open-source server which enables highly
reliable distributed coordination.
Apache ZooKeeper Server Source Code files are provided in the source packge (apache-zookeeper-3.7.0.tar.gz). You can download it at Apache ZooKeeper Website.
You can also browse Apache ZooKeeper Server Source Code below:
✍: FYIcenter.com
⏎ org/apache/zookeeper/server/util/MessageTracker.java
/** * 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.zookeeper.server.util; import java.text.SimpleDateFormat; import java.util.Date; import org.apache.zookeeper.server.quorum.Leader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * This class provides a way of buffering sentBuffer and receivedBuffer messages in order. * It uses EvictingQueue of size BUFFERED_MESSAGE_SIZE to store the messages. * When the queue is full it overrides the oldest in a circular manner. * This class does doe not provide thread safety. */ public class MessageTracker { private static final Logger LOG = LoggerFactory.getLogger(MessageTracker.class); private final CircularBuffer<BufferedMessage> sentBuffer; private final CircularBuffer<BufferedMessage> receivedBuffer; public static final String MESSAGE_TRACKER_BUFFER_SIZE = "zookeeper.messageTracker.BufferSize"; public static final String MESSAGE_TRACKER_ENABLED = "zookeeper.messageTracker.Enabled"; public static final int BUFFERED_MESSAGE_SIZE; private static final boolean enabled; static { BUFFERED_MESSAGE_SIZE = Integer.getInteger(MESSAGE_TRACKER_BUFFER_SIZE, 10); enabled = Boolean.getBoolean(MESSAGE_TRACKER_ENABLED); } public MessageTracker(int buffer_size) { this.sentBuffer = new CircularBuffer<>(BufferedMessage.class, buffer_size); this.receivedBuffer = new CircularBuffer<>(BufferedMessage.class, buffer_size); } public void trackSent(long timestamp) { if (enabled) { sentBuffer.write(new BufferedMessage(timestamp)); } } public void trackSent(int packetType) { if (enabled) { sentBuffer.write(new BufferedMessage(packetType)); } } public void trackReceived(long timestamp) { if (enabled) { receivedBuffer.write(new BufferedMessage(timestamp)); } } public void trackReceived(int packetType) { if (enabled) { receivedBuffer.write(new BufferedMessage(packetType)); } } public final BufferedMessage peekSent() { return sentBuffer.peek(); } public final BufferedMessage peekReceived() { return receivedBuffer.peek(); } public final long peekSentTimestamp() { return enabled ? sentBuffer.peek().getTimestamp() : 0; } public final long peekReceivedTimestamp() { return enabled ? receivedBuffer.peek().getTimestamp() : 0; } public void dumpToLog(String serverAddress) { if (!enabled) { return; } logMessages(serverAddress, receivedBuffer, Direction.RECEIVED); logMessages(serverAddress, sentBuffer, Direction.SENT); } private static void logMessages( String serverAddr, CircularBuffer<BufferedMessage> messages, Direction direction) { String sentOrReceivedText = direction == Direction.SENT ? "sentBuffer to" : "receivedBuffer from"; if (messages.isEmpty()) { LOG.info("No buffered timestamps for messages {} {}", sentOrReceivedText, serverAddr); } else { LOG.warn("Last {} timestamps for messages {} {}:", messages.size(), sentOrReceivedText, serverAddr); while (!messages.isEmpty()) { LOG.warn("{} {} {}", sentOrReceivedText, serverAddr, messages.take().toString()); } } } /** * Direction for message track. */ private enum Direction { SENT, RECEIVED } private static class BufferedMessage { private long timestamp; private int messageType; private long getTimestamp() { return timestamp; } BufferedMessage(int messageType) { this.messageType = messageType; this.timestamp = System.currentTimeMillis(); } BufferedMessage(long timestamp) { this.messageType = -1; this.timestamp = timestamp; } @Override /** * ToString examples are as follows: * TimeStamp: 2016-06-06 11:07:58,594 Type: PROPOSAL * TimeStamp: 2016-06-06 11:07:58,187 */ public String toString() { if (messageType == -1) { return "TimeStamp: " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS") .format(new Date(timestamp)); } else { return "TimeStamp: " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS") .format(new Date(timestamp)) + " Type: " + Leader.getPacketType(messageType); } } } }
⏎ org/apache/zookeeper/server/util/MessageTracker.java
Or download all of them as a single archive file:
File name: zookeeper-server-3.7.0-fyi.zip File size: 871011 bytes Release date: 2021-05-17 Download
⇒ Apache ZooKeeper 3.7.0 Jute Source Code
⇐ Download Apache ZooKeeper 3.7.0 Source Package
2022-11-16, 25556👍, 0💬
Popular Posts:
The Jakarta-ORO Java classes are a set of text-processing Java classes that provide Perl5 compatible...
The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms, it was develo...
JDK 11 jdk.jshell.jmod is the JMOD file for JDK 11 JShell tool, which can be invoked by the "jshell"...
maven-core-3.8.6.jar is the JAR file for Apache Maven 3.8.6 Core module. Apache Maven is a software ...
The Jakarta-ORO Java classes are a set of text-processing Java classes that provide Perl5 compatible...