Skip to content

Commit 4316e6d

Browse files
committed
style: fix spotless formatting violations and remove unwanted files
Signed-off-by: Twiineenock <Twiineenock@users.noreply.github.com>
1 parent 29e2313 commit 4316e6d

16 files changed

Lines changed: 526 additions & 448 deletions

File tree

hiero-enterprise-base/src/main/java/org/hiero/base/mirrornode/MirrorNodeClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ default Optional<Nft> queryNftsByAccountAndTokenIdAndSerial(
184184
* @return a page of transaction information
185185
* @throws HieroException if an error occurs during the query
186186
*/
187-
@NonNull Page<TransactionInfo> queryTransactionsByAccount(@NonNull AccountId accountId, @NonNull Instant after)
188-
throws HieroException;
187+
@NonNull Page<TransactionInfo> queryTransactionsByAccount(
188+
@NonNull AccountId accountId, @NonNull Instant after) throws HieroException;
189189

190190
/**
191191
* Queries all transactions for a specific account and transaction type.

hiero-enterprise-base/src/main/java/org/hiero/base/mirrornode/TopicRepository.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ default Page<TopicMessage> getMessages(String topicId) throws HieroException {
7878
* @return Page of TopicMessage
7979
* @throws HieroException if the search fails
8080
*/
81-
@NonNull default Page<TopicMessage> getMessages(@NonNull String topicId, @NonNull Instant after)
81+
@NonNull
82+
default Page<TopicMessage> getMessages(@NonNull String topicId, @NonNull Instant after)
8283
throws HieroException {
8384
Objects.requireNonNull(topicId, "topicId must not be null");
8485
Objects.requireNonNull(after, "after must not be null");

hiero-enterprise-base/src/main/java/org/hiero/base/mirrornode/TransactionRepository.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ default Page<TransactionInfo> findByAccount(@NonNull String accountId) throws Hi
5858
* @return page of transactions
5959
* @throws HieroException if the search fails
6060
*/
61-
@NonNull default Page<TransactionInfo> findByAccount(@NonNull String accountId, @NonNull Instant after)
61+
@NonNull
62+
default Page<TransactionInfo> findByAccount(@NonNull String accountId, @NonNull Instant after)
6263
throws HieroException {
6364
Objects.requireNonNull(accountId, "accountId must not be null");
6465
Objects.requireNonNull(after, "after must not be null");
Lines changed: 65 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.hiero.base.observer;
22

33
import java.time.Duration;
4-
import java.util.concurrent.Executors;
54
import java.util.concurrent.ScheduledExecutorService;
65
import java.util.concurrent.TimeUnit;
76
import java.util.concurrent.atomic.AtomicBoolean;
@@ -12,90 +11,86 @@
1211
/**
1312
* Base implementation for observers that poll the Mirror Node at regular intervals.
1413
*
15-
* <p>This class handles the lifecycle of the background polling task, including
16-
* starting, stopping, and handling unexpected errors during polling.
14+
* <p>This class handles the lifecycle of the background polling task, including starting, stopping,
15+
* and handling unexpected errors during polling.
1716
*
1817
* @param <T> The type of event being observed.
1918
*/
2019
public abstract class AbstractPollingObserver<T> {
2120

22-
private static final Logger log = LoggerFactory.getLogger(AbstractPollingObserver.class);
21+
private static final Logger log = LoggerFactory.getLogger(AbstractPollingObserver.class);
2322

24-
private final ScheduledExecutorService executorService;
25-
private final Duration pollingInterval;
26-
private final EventObserver<T> listener;
27-
private final AtomicBoolean running = new AtomicBoolean(false);
23+
private final ScheduledExecutorService executorService;
24+
private final Duration pollingInterval;
25+
private final EventObserver<T> listener;
26+
private final AtomicBoolean running = new AtomicBoolean(false);
2827

29-
/**
30-
* Creates a new polling observer.
31-
*
32-
* @param executorService The shared executor service to use for polling.
33-
* @param pollingInterval How often to check for new events.
34-
* @param listener The callback to trigger when an event is found.
35-
*/
36-
protected AbstractPollingObserver(
37-
@NonNull ScheduledExecutorService executorService,
38-
@NonNull Duration pollingInterval,
39-
@NonNull EventObserver<T> listener) {
40-
this.executorService = executorService;
41-
this.pollingInterval = pollingInterval;
42-
this.listener = listener;
43-
}
28+
/**
29+
* Creates a new polling observer.
30+
*
31+
* @param executorService The shared executor service to use for polling.
32+
* @param pollingInterval How often to check for new events.
33+
* @param listener The callback to trigger when an event is found.
34+
*/
35+
protected AbstractPollingObserver(
36+
@NonNull ScheduledExecutorService executorService,
37+
@NonNull Duration pollingInterval,
38+
@NonNull EventObserver<T> listener) {
39+
this.executorService = executorService;
40+
this.pollingInterval = pollingInterval;
41+
this.listener = listener;
42+
}
4443

45-
/**
46-
* Starts the background polling task.
47-
*/
48-
public void start() {
49-
if (running.compareAndSet(false, true)) {
50-
log.info("Starting Hiero observer: {}", getClass().getSimpleName());
51-
scheduleNext(0);
52-
}
44+
/** Starts the background polling task. */
45+
public void start() {
46+
if (running.compareAndSet(false, true)) {
47+
log.info("Starting Hiero observer: {}", getClass().getSimpleName());
48+
scheduleNext(0);
5349
}
50+
}
5451

55-
private void scheduleNext(long delayMs) {
56-
if (running.get()) {
57-
executorService.schedule(this::pollSafe, delayMs, TimeUnit.MILLISECONDS);
58-
}
52+
private void scheduleNext(long delayMs) {
53+
if (running.get()) {
54+
executorService.schedule(this::pollSafe, delayMs, TimeUnit.MILLISECONDS);
5955
}
56+
}
6057

61-
/**
62-
* Stops the background polling task.
63-
*/
64-
public void stop() {
65-
running.set(false);
66-
log.info("Stopping Hiero observer: {}", getClass().getSimpleName());
67-
}
58+
/** Stops the background polling task. */
59+
public void stop() {
60+
running.set(false);
61+
log.info("Stopping Hiero observer: {}", getClass().getSimpleName());
62+
}
6863

69-
private void pollSafe() {
70-
try {
71-
boolean hasMore = poll();
72-
// If there's more data (pagination), poll again immediately.
73-
// Otherwise, wait for the polling interval.
74-
scheduleNext(hasMore ? 0 : pollingInterval.toMillis());
75-
} catch (Exception e) {
76-
log.error("Unexpected error during Hiero polling in {}", getClass().getSimpleName(), e);
77-
scheduleNext(pollingInterval.toMillis());
78-
}
64+
private void pollSafe() {
65+
try {
66+
boolean hasMore = poll();
67+
// If there's more data (pagination), poll again immediately.
68+
// Otherwise, wait for the polling interval.
69+
scheduleNext(hasMore ? 0 : pollingInterval.toMillis());
70+
} catch (Exception e) {
71+
log.error("Unexpected error during Hiero polling in {}", getClass().getSimpleName(), e);
72+
scheduleNext(pollingInterval.toMillis());
7973
}
74+
}
8075

81-
/**
82-
* The actual polling logic to be implemented by subclasses.
83-
*
84-
* @return true if there is more data to poll immediately (pagination), false otherwise.
85-
* @throws Exception if polling fails.
86-
*/
87-
public abstract boolean poll() throws Exception;
76+
/**
77+
* The actual polling logic to be implemented by subclasses.
78+
*
79+
* @return true if there is more data to poll immediately (pagination), false otherwise.
80+
* @throws Exception if polling fails.
81+
*/
82+
public abstract boolean poll() throws Exception;
8883

89-
/**
90-
* Notifies the listener of a new event.
91-
*
92-
* @param event The event to notify.
93-
*/
94-
protected void notifyListener(@NonNull T event) {
95-
try {
96-
listener.onEvent(event);
97-
} catch (Exception e) {
98-
log.error("Error in event listener callback", e);
99-
}
84+
/**
85+
* Notifies the listener of a new event.
86+
*
87+
* @param event The event to notify.
88+
*/
89+
protected void notifyListener(@NonNull T event) {
90+
try {
91+
listener.onEvent(event);
92+
} catch (Exception e) {
93+
log.error("Error in event listener callback", e);
10094
}
95+
}
10196
}

hiero-enterprise-base/src/main/java/org/hiero/base/observer/EventObserver.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
/**
44
* Functional interface for a component that observes events on the Hiero network.
55
*
6-
* <p>Implementations of this interface typically run in a background thread or are
7-
* triggered by a scheduler to check for new network activities.
6+
* <p>Implementations of this interface typically run in a background thread or are triggered by a
7+
* scheduler to check for new network activities.
88
*
99
* @param <T> The type of event being observed (e.g., TransactionInfo, TopicMessage).
1010
*/
1111
@FunctionalInterface
1212
public interface EventObserver<T> {
1313

14-
/**
15-
* Called when a new event is detected.
16-
*
17-
* @param event The detected event.
18-
*/
19-
void onEvent(T event);
14+
/**
15+
* Called when a new event is detected.
16+
*
17+
* @param event The detected event.
18+
*/
19+
void onEvent(T event);
2020
}

hiero-enterprise-base/src/main/java/org/hiero/base/observer/TopicObserver.java

Lines changed: 55 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -13,73 +13,71 @@
1313
import org.slf4j.Logger;
1414
import org.slf4j.LoggerFactory;
1515

16-
/**
17-
* Observer that polls for new messages on a specific Hiero Consensus Service (HCS) topic.
18-
*/
16+
/** Observer that polls for new messages on a specific Hiero Consensus Service (HCS) topic. */
1917
public class TopicObserver extends AbstractPollingObserver<TopicMessage> {
2018

21-
private static final Logger log = LoggerFactory.getLogger(TopicObserver.class);
19+
private static final Logger log = LoggerFactory.getLogger(TopicObserver.class);
2220

23-
private final TopicRepository repository;
24-
private final TopicId topicId;
25-
private Instant lastSeenTimestamp;
21+
private final TopicRepository repository;
22+
private final TopicId topicId;
23+
private Instant lastSeenTimestamp;
2624

27-
/**
28-
* Creates a new topic observer.
29-
*
30-
* @param executorService The shared executor service to use for polling.
31-
* @param repository The repository to use for polling.
32-
* @param topicId The topic to monitor.
33-
* @param pollingInterval How often to poll the mirror node.
34-
* @param listener The callback for new messages.
35-
*/
36-
public TopicObserver(
37-
@NonNull ScheduledExecutorService executorService,
38-
@NonNull TopicRepository repository,
39-
@NonNull TopicId topicId,
40-
@NonNull Duration pollingInterval,
41-
@NonNull EventObserver<TopicMessage> listener) {
42-
super(executorService, pollingInterval, listener);
43-
this.repository = repository;
44-
this.topicId = topicId;
45-
this.lastSeenTimestamp = Instant.now();
46-
}
25+
/**
26+
* Creates a new topic observer.
27+
*
28+
* @param executorService The shared executor service to use for polling.
29+
* @param repository The repository to use for polling.
30+
* @param topicId The topic to monitor.
31+
* @param pollingInterval How often to poll the mirror node.
32+
* @param listener The callback for new messages.
33+
*/
34+
public TopicObserver(
35+
@NonNull ScheduledExecutorService executorService,
36+
@NonNull TopicRepository repository,
37+
@NonNull TopicId topicId,
38+
@NonNull Duration pollingInterval,
39+
@NonNull EventObserver<TopicMessage> listener) {
40+
super(executorService, pollingInterval, listener);
41+
this.repository = repository;
42+
this.topicId = topicId;
43+
this.lastSeenTimestamp = Instant.now();
44+
}
4745

48-
@Override
49-
public boolean poll() throws Exception {
50-
log.trace("Polling messages for topic {} after {}", topicId, lastSeenTimestamp);
46+
@Override
47+
public boolean poll() throws Exception {
48+
log.trace("Polling messages for topic {} after {}", topicId, lastSeenTimestamp);
5149

52-
Page<TopicMessage> page = repository.getMessages(topicId, lastSeenTimestamp);
53-
processPage(page);
50+
Page<TopicMessage> page = repository.getMessages(topicId, lastSeenTimestamp);
51+
processPage(page);
5452

55-
return page.hasNext();
56-
}
53+
return page.hasNext();
54+
}
5755

58-
private void processPage(Page<TopicMessage> page) {
59-
List<TopicMessage> messages = new java.util.ArrayList<>(page.getData());
60-
if (messages.isEmpty()) {
61-
return;
62-
}
56+
private void processPage(Page<TopicMessage> page) {
57+
List<TopicMessage> messages = new java.util.ArrayList<>(page.getData());
58+
if (messages.isEmpty()) {
59+
return;
60+
}
6361

64-
// Sort by timestamp to ensure chronological delivery
65-
messages.sort(Comparator.comparing(TopicMessage::consensusTimestamp));
62+
// Sort by timestamp to ensure chronological delivery
63+
messages.sort(Comparator.comparing(TopicMessage::consensusTimestamp));
6664

67-
for (TopicMessage msg : messages) {
68-
if (msg.consensusTimestamp().isAfter(lastSeenTimestamp)) {
69-
notifyListener(msg);
70-
lastSeenTimestamp = msg.consensusTimestamp();
71-
}
72-
}
65+
for (TopicMessage msg : messages) {
66+
if (msg.consensusTimestamp().isAfter(lastSeenTimestamp)) {
67+
notifyListener(msg);
68+
lastSeenTimestamp = msg.consensusTimestamp();
69+
}
7370
}
71+
}
7472

75-
/**
76-
* Sets the starting timestamp for the observer.
77-
*
78-
* @param timestamp The timestamp to start from.
79-
* @return this observer for chaining.
80-
*/
81-
public TopicObserver startFrom(@NonNull Instant timestamp) {
82-
this.lastSeenTimestamp = timestamp;
83-
return this;
84-
}
73+
/**
74+
* Sets the starting timestamp for the observer.
75+
*
76+
* @param timestamp The timestamp to start from.
77+
* @return this observer for chaining.
78+
*/
79+
public TopicObserver startFrom(@NonNull Instant timestamp) {
80+
this.lastSeenTimestamp = timestamp;
81+
return this;
82+
}
8583
}

0 commit comments

Comments
 (0)