Interface FailoverNotifier

All Known Implementing Classes:
SmsFailoverNotifier

public interface FailoverNotifier
The FailoverNotifier interface is used to notify users when a failover occurs in ChatMotor API key usage. Implementations should define the notifyFailover() method to handle actions like logging, sending alerts, or other custom logic.

This interface allows for flexible implementation strategies depending on the specific needs of the application, whether it's simply logging the failover event, sending notifications, or executing more complex recovery procedures.

Default Implementation:

The default implementation logs the failover event using a static logger named 'logger' which is shared among all instances of implementing classes unless overridden.

 public class DefaultFailoverNotifier implements FailoverNotifier {
     private static final Logger logger = LoggerFactory.getLogger(DefaultFailoverNotifier.class);

     @Override
     public void notifyFailover() {
         logger.info("API key switched to the failover key.");
     }
 }
 

Example Implementation:

Below is a simple implementation example that logs the failover event:

 public class MyFailoverNotifier implements FailoverNotifier {
     @Override
     public void notifyFailover() {
         System.out.println("API key switched to the failover key.");
         // Custom logic for failover notification
     }
 }
 
 ChatMotor chatMotor = ChatMotor.builder()
     .failoverNotifier(new MyFailoverNotifier())
     .build();
 

The concrete implementation using Twilio to send SMS notifications is avaliable at: SmsFailoverNotifier.

Since:
1.2
  • Field Summary

    Fields
    Modifier and Type Field Description
    static org.slf4j.Logger logger
    Static logger used by the default implementation to log failover events.
  • Method Summary

    Modifier and Type Method Description
    default void notifyFailover()
    Invoked when a failover occurs, signaling that the ChatMotor API has switched from the primary API key to the failover key.
  • Field Details

    • logger

      static final org.slf4j.Logger logger
      Static logger used by the default implementation to log failover events.
  • Method Details

    • notifyFailover

      default void notifyFailover()
      Invoked when a failover occurs, signaling that the ChatMotor API has switched from the primary API key to the failover key. The implementation should define the actions to be taken upon this event.

      This default implementation logs the event using the above-mentioned static logger.