Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial commit for dual publishing TopologyRefreshEvent to EventBus #2819

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,38 @@

import io.lettuce.core.RedisURI;
import io.lettuce.core.event.Event;
import io.lettuce.core.event.DurationalEvent;

import static io.lettuce.core.event.DurationalEvent.EventStatus.COMPLETED;
import static io.lettuce.core.event.DurationalEvent.EventStatus.IN_PROGRESS;

/**
* Event for initiating a topology refresh.
*
* @author Mark Paluch
* @since 6.1
*/
public class TopologyRefreshEvent implements Event {
public class TopologyRefreshEvent implements DurationalEvent, Event {

private final List<RedisURI> topologyRefreshSource;
private EventStatus status;

public TopologyRefreshEvent(List<RedisURI> topologyRefreshSource) {
this.topologyRefreshSource = topologyRefreshSource;
this.status = IN_PROGRESS;
}

public List<RedisURI> getTopologyRefreshSource() {
return topologyRefreshSource;
}

@Override
public void completeEvent() {
this.status = COMPLETED;
}

@Override
public DurationalEvent.EventStatus getEventStatus() {
return status;
}
}
18 changes: 18 additions & 0 deletions src/main/java/io/lettuce/core/event/DurationalEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.lettuce.core.event;


public interface DurationalEvent {
enum EventStatus {
/**
* An IN_PROGRESS event indicates the start of series actions and might have future event indicating the completion.
*/
IN_PROGRESS,
/**
* A COMPLETED event is in its final status and indicates the completion of previous event
* and will not have future event indicating status change.
*/
COMPLETED
}
void completeEvent();
EventStatus getEventStatus();
}
23 changes: 22 additions & 1 deletion src/main/java/io/lettuce/core/event/jfr/EventRecorder.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package io.lettuce.core.event.jfr;

import io.lettuce.core.event.DurationalEvent;
import io.lettuce.core.event.Event;
import io.lettuce.core.event.EventBus;
import io.lettuce.core.event.RecordableEvent;

/**
* Event recorder that can delegate events from the {@link io.lettuce.core.event.EventBus} into a recording facility such as
* JFR. Transforming an {@link Event} into a recordable event is subject to the actual {@link EventRecorder} implementation.
* JFR and make dual publishing for {@link io.lettuce.core.event.DurationalEvent} to {@link io.lettuce.core.event.EventBus}.
* Transforming an {@link Event} into a recordable event is subject to the actual {@link EventRecorder} implementation.
* <p>
* You can record data by launching the application with recording enabled:
* {@code java -XX:StartFlightRecording:filename=recording.jfr,duration=10s -jar app.jar}.
Expand All @@ -30,6 +34,14 @@ static EventRecorder getInstance() {
*/
void record(Event event);

/**
* Record an event and publish an {@link DurationalEvent.EventStatus#COMPLETED} event to bus.
*
* @param event the event to record, must not be {@code null}.
* @param eventBus the event bus for dual publishing, must not be {@code null}.
*/
<T extends DurationalEvent & Event> void record(T event, EventBus eventBus);

/**
* Start recording an event. This method returns a {@link RecordableEvent} that can be recorded by calling
* {@link RecordableEvent#record()}. These events can be used to measure time between start and record.
Expand All @@ -38,6 +50,15 @@ static EventRecorder getInstance() {
*/
RecordableEvent start(Event event);

/**
* Start recording an event and publish an {@link DurationalEvent.EventStatus#IN_PROGRESS} event to bus. This method returns a {@link RecordableEvent} that can be recorded by calling
* {@link RecordableEvent#record()}. These events can be used to measure time between start and record.
*
* @param event the event to record, must not be {@code null}.
* @param eventBus the event bus for dual publishing, must not be {@code null}.
*/
<T extends DurationalEvent & Event> RecordableEvent start(T event, EventBus eventBus);

/**
* Interface defining a recordable event that is recorded on calling {@link #record()}.
*/
Expand Down