Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
C
cluster-auto-healer
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tammam.alsoleman
cluster-auto-healer
Commits
baa6879d
Commit
baa6879d
authored
Dec 23, 2025
by
tammam.alsoleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
write common classes
parent
63c02c65
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
0 deletions
+72
-0
LoggerUtil.java
common/src/main/java/common/LoggerUtil.java
+58
-0
ZkConfig.java
common/src/main/java/common/ZkConfig.java
+14
-0
No files found.
common/src/main/java/common/LoggerUtil.java
0 → 100644
View file @
baa6879d
package
common
;
import
java.io.BufferedWriter
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.LinkedBlockingQueue
;
public
class
LoggerUtil
{
private
static
final
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
);
// Memory queue to hold log messages
private
static
final
BlockingQueue
<
String
>
logQueue
=
new
LinkedBlockingQueue
<>();
private
static
BufferedWriter
writer
;
static
{
try
{
// Keep the file open for better performance
writer
=
new
BufferedWriter
(
new
FileWriter
(
ZkConfig
.
CLUSTER_LOG_FILE
,
true
));
// Start a background thread to process logs asynchronously
Thread
logThread
=
new
Thread
(()
->
{
try
{
while
(
true
)
{
String
message
=
logQueue
.
take
();
// Wait for a message in the queue
writer
.
write
(
message
);
writer
.
newLine
();
writer
.
flush
();
// Flush to disk without closing
}
}
catch
(
InterruptedException
|
IOException
e
)
{
Thread
.
currentThread
().
interrupt
();
}
});
logThread
.
setDaemon
(
true
);
// Let it close when the main application stops
logThread
.
start
();
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"Failed to initialize fast logger: "
+
e
.
getMessage
());
}
}
/**
* Rapidly logs an event by adding it to an internal queue.
* This method is non-blocking and returns almost instantly.
*/
public
static
void
log
(
String
message
)
{
String
timestampedMessage
=
String
.
format
(
"[%s] %s"
,
LocalDateTime
.
now
().
format
(
formatter
),
message
);
// Print to console (fast)
System
.
out
.
println
(
timestampedMessage
);
// Offer the message to the background logging thread
logQueue
.
offer
(
timestampedMessage
);
}
}
\ No newline at end of file
common/src/main/java/common/ZkConfig.java
0 → 100644
View file @
baa6879d
package
common
;
public
class
ZkConfig
{
public
static
final
String
ZOOKEEPER_ADDRESS
=
"192.168.98.208:2181"
;
public
static
final
int
SESSION_TIMEOUT
=
5000
;
// Root paths for the cluster components
public
static
final
String
NODES_PARENT_PATH
=
"/nodes"
;
public
static
final
String
WORKERS_PARENT_PATH
=
"/workers"
;
public
static
final
String
TASKS_PARENT_PATH
=
"/tasks"
;
// Shared log file path
public
static
final
String
CLUSTER_LOG_FILE
=
"cluster_events.log"
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment