io.fluxcapacitor.javaclient.scheduling.DefaultScheduler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-client Show documentation
Show all versions of java-client Show documentation
Default Java client library for interfacing with Flux Capacitor.
package io.fluxcapacitor.javaclient.scheduling;
import io.fluxcapacitor.common.api.Metadata;
import io.fluxcapacitor.common.api.scheduling.ScheduledMessage;
import io.fluxcapacitor.javaclient.common.serialization.MessageSerializer;
import io.fluxcapacitor.javaclient.scheduling.client.SchedulingClient;
import lombok.AllArgsConstructor;
import java.time.Instant;
@AllArgsConstructor
public class DefaultScheduler implements Scheduler {
private final SchedulingClient client;
private final MessageSerializer serializer;
@Override
public void schedule(String scheduleId, Instant timestamp, Object payload, Metadata metadata) {
try {
client.schedule(new ScheduledMessage(scheduleId, timestamp.toEpochMilli(),
serializer.serialize(payload, metadata))).await();
} catch (Exception e) {
throw new SchedulerException(String.format("Failed to schedule message %s for %s", payload, timestamp), e);
}
}
@Override
public void cancelSchedule(String scheduleId) {
try {
client.cancelSchedule(scheduleId).await();
} catch (Exception e) {
throw new SchedulerException(String.format("Failed to cancel schedule with id %s", scheduleId), e);
}
}
}