Module lettuce.core

Class DefaultEndpoint

java.lang.Object
io.lettuce.core.protocol.DefaultEndpoint
All Implemented Interfaces:
AsyncCloseable, Endpoint, PushHandler, RedisChannelWriter, Closeable, AutoCloseable
Direct Known Subclasses:
PubSubEndpoint

public class DefaultEndpoint
extends Object
implements RedisChannelWriter, Endpoint, PushHandler
Default Endpoint implementation.
Author:
Mark Paluch
  • Field Details

    • channel

      protected volatile Channel channel
  • Constructor Details

    • DefaultEndpoint

      public DefaultEndpoint​(ClientOptions clientOptions, ClientResources clientResources)
      Create a new DefaultEndpoint.
      Parameters:
      clientOptions - client options for this connection, must not be null.
      clientResources - client resources for this connection, must not be null.
  • Method Details

    • setConnectionFacade

      public void setConnectionFacade​(ConnectionFacade connectionFacade)
      Description copied from interface: RedisChannelWriter
      Set the corresponding connection facade in order to notify it about channel active/inactive state.
      Specified by:
      setConnectionFacade in interface RedisChannelWriter
      Parameters:
      connectionFacade - the connection facade (external connection object)
    • getClientResources

      public ClientResources getClientResources()
      Specified by:
      getClientResources in interface RedisChannelWriter
      Returns:
      the ClientResources.
    • setAutoFlushCommands

      public void setAutoFlushCommands​(boolean autoFlush)
      Description copied from interface: RedisChannelWriter
      Disable or enable auto-flush behavior. Default is true. If autoFlushCommands is disabled, multiple commands can be issued without writing them actually to the transport. Commands are buffered until a RedisChannelWriter.flushCommands() is issued. After calling RedisChannelWriter.flushCommands() commands are sent to the transport and executed by Redis.
      Specified by:
      setAutoFlushCommands in interface RedisChannelWriter
      Parameters:
      autoFlush - state of autoFlush.
    • addListener

      public void addListener​(PushListener listener)
      Description copied from interface: PushHandler
      Add a new listener.
      Specified by:
      addListener in interface PushHandler
      Parameters:
      listener - the listener, must not be null.
    • removeListener

      public void removeListener​(PushListener listener)
      Description copied from interface: PushHandler
      Remove an existing listener.
      Specified by:
      removeListener in interface PushHandler
      Parameters:
      listener - the listener, must not be null.
    • getPushListeners

      public List<PushListener> getPushListeners()
      Description copied from interface: PushHandler
      Returns a collection of PushListener.
      Specified by:
      getPushListeners in interface PushHandler
      Returns:
      the collection of listeners.
    • write

      public <K,​ V,​ T> RedisCommand<K,​V,​T> write​(RedisCommand<K,​V,​T> command)
      Description copied from interface: RedisChannelWriter
      Write a command on the channel. The command may be changed/wrapped during write and the written instance is returned after the call.
      Specified by:
      write in interface RedisChannelWriter
      T - result type
      Parameters:
      command - the Redis command.
      Returns:
      the written Redis command.
    • write

      public <K,​ V> Collection<RedisCommand<K,​V,​?>> write​(Collection<? extends RedisCommand<K,​V,​?>> commands)
      Description copied from interface: RedisChannelWriter
      Write multiple commands on the channel. The commands may be changed/wrapped during write and the written instance is returned after the call.
      Specified by:
      write in interface RedisChannelWriter
      Type Parameters:
      K - key type
      V - value type
      Parameters:
      commands - the Redis commands.
      Returns:
      the written redis command
    • writeToBuffer

      protected <C extends RedisCommand<?,​ ?,​ T>,​ T> void writeToBuffer​(C command)
    • notifyChannelActive

      public void notifyChannelActive​(Channel channel)
      Description copied from interface: Endpoint
      Notify about channel activation.
      Specified by:
      notifyChannelActive in interface Endpoint
      Parameters:
      channel - the channel
    • notifyChannelInactive

      public void notifyChannelInactive​(Channel channel)
      Description copied from interface: Endpoint
      Notify about channel deactivation.
      Specified by:
      notifyChannelInactive in interface Endpoint
      Parameters:
      channel - the channel
    • notifyException

      public void notifyException​(Throwable t)
      Description copied from interface: Endpoint
      Notify about an exception occured in channel/command processing
      Specified by:
      notifyException in interface Endpoint
      Parameters:
      t - the Exception
    • registerConnectionWatchdog

      public void registerConnectionWatchdog​(ConnectionWatchdog connectionWatchdog)
      Description copied from interface: Endpoint
      Associate a ConnectionWatchdog with the Endpoint.
      Specified by:
      registerConnectionWatchdog in interface Endpoint
      Parameters:
      connectionWatchdog - the connection watchdog.
    • flushCommands

      public void flushCommands()
      Description copied from interface: RedisChannelWriter
      Flush pending commands. This commands forces a flush on the channel and can be used to buffer ("pipeline") commands to achieve batching. No-op if channel is not connected.
      Specified by:
      flushCommands in interface RedisChannelWriter
    • close

      public void close()
      Close the connection.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface RedisChannelWriter
    • closeAsync

      public CompletableFuture<Void> closeAsync()
      Description copied from interface: RedisChannelWriter
      Asynchronously close the RedisChannelWriter.
      Specified by:
      closeAsync in interface AsyncCloseable
      Specified by:
      closeAsync in interface RedisChannelWriter
      Returns:
      future for result synchronization.
    • disconnect

      public void disconnect()
      Disconnect the channel.
    • reset

      public void reset()
      Reset the writer state. Queued commands will be canceled and the internal state will be reset. This is useful when the internal state machine gets out of sync with the connection.
      Specified by:
      reset in interface RedisChannelWriter
    • initialState

      public void initialState()
      Reset the command-handler to the initial not-connected state.
      Specified by:
      initialState in interface Endpoint
    • notifyDrainQueuedCommands

      public void notifyDrainQueuedCommands​(io.lettuce.core.protocol.HasQueuedCommands queuedCommands)
      Description copied from interface: Endpoint
      Signal the endpoint to drain queued commands from the queue holder.
      Specified by:
      notifyDrainQueuedCommands in interface Endpoint
      Parameters:
      queuedCommands - the queue holder.
    • isClosed

      public boolean isClosed()
    • doExclusive

      protected <T> T doExclusive​(Supplier<T> supplier)
      Execute a Supplier callback guarded by an exclusive lock.
      Type Parameters:
      T -
      Parameters:
      supplier -
      Returns:
    • drainCommands

      protected List<RedisCommand<?,​?,​?>> drainCommands()
    • logPrefix

      protected String logPrefix()
    • getId

      public String getId()
      Specified by:
      getId in interface Endpoint
      Returns:
      the endpoint Id.