public final class Utils extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
APPEND_ENTRIES_THREADS_SEND
Default jraft append-entries executor(send) pool size.
|
static String |
IP_ANY
ANY IP address 0.0.0.0
|
static String |
IPV6_END_MARK |
static String |
IPV6_START_MARK |
static int |
MAX_APPEND_ENTRIES_TASKS_PER_THREAD
Default jraft max pending tasks of append-entries per thread, 65536 by default.
|
static int |
MAX_CLOSURE_EXECUTOR_POOL_SIZE
Default jraft closure executor pool maximum size.
|
static int |
MAX_COLLECTOR_SIZE_PER_THREAD
Default max
ByteBufferCollector size per thread for recycle, it can be set by
-Djraft.max_collector_size_per_thread, default 256 |
static int |
MIN_CLOSURE_EXECUTOR_POOL_SIZE
Default jraft closure executor pool minimum size, CPUs by default.
|
static int |
RAFT_DATA_BUF_SIZE
Default init and expand buffer size, it can be set by -Djraft.byte_buf.size=n, default 1024.
|
static boolean |
USE_MPSC_SINGLE_THREAD_EXECUTOR
Whether use
MpscSingleThreadExecutor, true by
default. |
| 构造器和说明 |
|---|
Utils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static ByteBuffer |
allocate()
Allocate a byte buffer with
RAFT_DATA_BUF_SIZE |
static ByteBuffer |
allocate(int size)
Allocate a byte buffer with size.
|
static boolean |
atomicMoveFile(File source,
File target,
boolean sync) |
static int |
closeQuietly(Closeable closeable)
Close a closeable.
|
static int |
cpus()
Get system CPUs count.
|
static ByteBuffer |
expandByteBuffer(ByteBuffer buf)
Expand byte buffer for 1024 bytes.
|
static ByteBuffer |
expandByteBufferAtLeast(ByteBuffer buf,
int minLength)
Expand byte buffer at least minLength.
|
static ByteBuffer |
expandByteBufferAtMost(ByteBuffer buf,
int maxLength)
Expand byte buffer at most maxLength.
|
static void |
fsync(File file)
Calls fsync on a file or directory.
|
static byte[] |
getBytes(String s)
Get string bytes in UTF-8 charset.
|
static long |
getProcessId(long fallback)
Get java process id.
|
static String |
getString(byte[] bs,
int off,
int len) |
static boolean |
isIPv6(String addr)
check whether the ip address is IPv6.
|
static long |
monotonicMs()
Gets the current monotonic time in milliseconds.
|
static long |
monotonicUs()
Gets the current monotonic time in microseconds.
|
static long |
nowMs()
Returns the current time in milliseconds, it's not monotonic, would be forwarded/backward by
clock synchronous.
|
static String[] |
parsePeerId(String s)
Parse peerId from string that generated by
Object.toString()
This method can support parameter string values are below:
PeerId.parse("a:b") = new PeerId("a", "b", 0 , -1)
PeerId.parse("a:b:c") = new PeerId("a", "b", "c", -1)
PeerId.parse("a:b::d") = new PeerId("a", "b", 0, "d")
PeerId.parse("a:b:c:d") = new PeerId("a", "b", "c", "d")
|
static void |
registerClosureExecutorMetrics(com.codahale.metrics.MetricRegistry registry)
Register CLOSURE_EXECUTOR into metric registry.
|
static Future<?> |
runClosureInThread(Closure done)
Run closure with OK status in thread pool.
|
static Future<?> |
runClosureInThread(Closure done,
Status status)
Run closure with status in thread pool.
|
static Future<?> |
runInThread(Runnable runnable)
Run a task in thread pool,returns the future object.
|
static void |
unmap(MappedByteBuffer cb)
Unmap mappedByteBuffer
See https://stackoverflow.com/questions/2972986/how-to-unmap-a-file-from-memory-mapped-using-filechannel-in-java
|
static void |
verifyGroupId(String groupId) |
static <T> T |
withLockObject(T obj) |
public static final int MIN_CLOSURE_EXECUTOR_POOL_SIZE
public static final int MAX_CLOSURE_EXECUTOR_POOL_SIZE
public static final int APPEND_ENTRIES_THREADS_SEND
public static final int MAX_APPEND_ENTRIES_TASKS_PER_THREAD
public static final boolean USE_MPSC_SINGLE_THREAD_EXECUTOR
MpscSingleThreadExecutor, true by
default.public static final int RAFT_DATA_BUF_SIZE
public static final int MAX_COLLECTOR_SIZE_PER_THREAD
ByteBufferCollector size per thread for recycle, it can be set by
-Djraft.max_collector_size_per_thread, default 256public static void verifyGroupId(String groupId)
public static void registerClosureExecutorMetrics(com.codahale.metrics.MetricRegistry registry)
public static Future<?> runClosureInThread(Closure done)
public static Future<?> runInThread(Runnable runnable)
public static Future<?> runClosureInThread(Closure done, Status status)
public static int closeQuietly(Closeable closeable)
public static int cpus()
public static long getProcessId(long fallback)
public static ByteBuffer expandByteBuffer(ByteBuffer buf)
public static ByteBuffer allocate(int size)
public static ByteBuffer allocate()
RAFT_DATA_BUF_SIZEpublic static ByteBuffer expandByteBufferAtLeast(ByteBuffer buf, int minLength)
public static ByteBuffer expandByteBufferAtMost(ByteBuffer buf, int maxLength)
public static long monotonicMs()
public static long nowMs()
public static long monotonicUs()
public static byte[] getBytes(String s)
public static <T> T withLockObject(T obj)
public static boolean atomicMoveFile(File source, File target, boolean sync) throws IOException
IOExceptionpublic static void fsync(File file) throws IOException
file - file or directoryIOException - if an I/O error occurspublic static void unmap(MappedByteBuffer cb)
public static String getString(byte[] bs, int off, int len)
public static boolean isIPv6(String addr)
addr - ip addresspublic static String[] parsePeerId(String s)
Object.toString()
This method can support parameter string values are below:
PeerId.parse("a:b") = new PeerId("a", "b", 0 , -1)
PeerId.parse("a:b:c") = new PeerId("a", "b", "c", -1)
PeerId.parse("a:b::d") = new PeerId("a", "b", 0, "d")
PeerId.parse("a:b:c:d") = new PeerId("a", "b", "c", "d")
Copyright © 2021. All rights reserved.