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 Summary
-
Constructor Summary
Constructors Constructor Description DefaultEndpoint(ClientOptions clientOptions, ClientResources clientResources)Create a newDefaultEndpoint. -
Method Summary
Modifier and Type Method Description voidaddListener(PushListener listener)Add a newlistener.voidclose()Close the connection.CompletableFuture<Void>closeAsync()Asynchronously close theRedisChannelWriter.voiddisconnect()Disconnect the channel.protected <T> TdoExclusive(Supplier<T> supplier)Execute aSuppliercallback guarded by an exclusive lock.protected List<RedisCommand<?,?,?>>drainCommands()voidflushCommands()Flush pending commands.ClientResourcesgetClientResources()StringgetId()List<PushListener>getPushListeners()Returns a collection ofPushListener.voidinitialState()Reset the command-handler to the initial not-connected state.booleanisClosed()protected StringlogPrefix()voidnotifyChannelActive(Channel channel)Notify about channel activation.voidnotifyChannelInactive(Channel channel)Notify about channel deactivation.voidnotifyDrainQueuedCommands(io.lettuce.core.protocol.HasQueuedCommands queuedCommands)Signal the endpoint to drain queued commands from the queue holder.voidnotifyException(Throwable t)Notify about an exception occured in channel/command processingvoidregisterConnectionWatchdog(ConnectionWatchdog connectionWatchdog)Associate aConnectionWatchdogwith theEndpoint.voidremoveListener(PushListener listener)Remove an existinglistener.voidreset()Reset the writer state.voidsetAutoFlushCommands(boolean autoFlush)Disable or enable auto-flush behavior.voidsetConnectionFacade(ConnectionFacade connectionFacade)Set the corresponding connection facade in order to notify it about channel active/inactive state.<K, V, T> RedisCommand<K,V,T>write(RedisCommand<K,V,T> command)Write a command on the channel.<K, V> Collection<RedisCommand<K,V,?>>write(Collection<? extends RedisCommand<K,V,?>> commands)Write multiple commands on the channel.protected <C extends RedisCommand<?, ?, T>, T>
voidwriteToBuffer(C command)
-
Field Details
-
channel
-
-
Constructor Details
-
DefaultEndpoint
Create a newDefaultEndpoint.- Parameters:
clientOptions- client options for this connection, must not benull.clientResources- client resources for this connection, must not benull.
-
-
Method Details
-
setConnectionFacade
Description copied from interface:RedisChannelWriterSet the corresponding connection facade in order to notify it about channel active/inactive state.- Specified by:
setConnectionFacadein interfaceRedisChannelWriter- Parameters:
connectionFacade- the connection facade (external connection object)
-
getClientResources
- Specified by:
getClientResourcesin interfaceRedisChannelWriter- Returns:
- the
ClientResources.
-
setAutoFlushCommands
public void setAutoFlushCommands(boolean autoFlush)Description copied from interface:RedisChannelWriterDisable or enable auto-flush behavior. Default istrue. If autoFlushCommands is disabled, multiple commands can be issued without writing them actually to the transport. Commands are buffered until aRedisChannelWriter.flushCommands()is issued. After callingRedisChannelWriter.flushCommands()commands are sent to the transport and executed by Redis.- Specified by:
setAutoFlushCommandsin interfaceRedisChannelWriter- Parameters:
autoFlush- state of autoFlush.
-
addListener
Description copied from interface:PushHandlerAdd a newlistener.- Specified by:
addListenerin interfacePushHandler- Parameters:
listener- the listener, must not benull.
-
removeListener
Description copied from interface:PushHandlerRemove an existinglistener.- Specified by:
removeListenerin interfacePushHandler- Parameters:
listener- the listener, must not benull.
-
getPushListeners
Description copied from interface:PushHandlerReturns a collection ofPushListener.- Specified by:
getPushListenersin interfacePushHandler- Returns:
- the collection of listeners.
-
write
Description copied from interface:RedisChannelWriterWrite a command on the channel. The command may be changed/wrapped during write and the written instance is returned after the call.- Specified by:
writein interfaceRedisChannelWriterT- 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:RedisChannelWriterWrite multiple commands on the channel. The commands may be changed/wrapped during write and the written instance is returned after the call.- Specified by:
writein interfaceRedisChannelWriter- Type Parameters:
K- key typeV- value type- Parameters:
commands- the Redis commands.- Returns:
- the written redis command
-
writeToBuffer
-
notifyChannelActive
Description copied from interface:EndpointNotify about channel activation.- Specified by:
notifyChannelActivein interfaceEndpoint- Parameters:
channel- the channel
-
notifyChannelInactive
Description copied from interface:EndpointNotify about channel deactivation.- Specified by:
notifyChannelInactivein interfaceEndpoint- Parameters:
channel- the channel
-
notifyException
Description copied from interface:EndpointNotify about an exception occured in channel/command processing- Specified by:
notifyExceptionin interfaceEndpoint- Parameters:
t- the Exception
-
registerConnectionWatchdog
Description copied from interface:EndpointAssociate aConnectionWatchdogwith theEndpoint.- Specified by:
registerConnectionWatchdogin interfaceEndpoint- Parameters:
connectionWatchdog- the connection watchdog.
-
flushCommands
public void flushCommands()Description copied from interface:RedisChannelWriterFlush 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:
flushCommandsin interfaceRedisChannelWriter
-
close
public void close()Close the connection.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceRedisChannelWriter
-
closeAsync
Description copied from interface:RedisChannelWriterAsynchronously close theRedisChannelWriter.- Specified by:
closeAsyncin interfaceAsyncCloseable- Specified by:
closeAsyncin interfaceRedisChannelWriter- 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:
resetin interfaceRedisChannelWriter
-
initialState
public void initialState()Reset the command-handler to the initial not-connected state.- Specified by:
initialStatein interfaceEndpoint
-
notifyDrainQueuedCommands
public void notifyDrainQueuedCommands(io.lettuce.core.protocol.HasQueuedCommands queuedCommands)Description copied from interface:EndpointSignal the endpoint to drain queued commands from the queue holder.- Specified by:
notifyDrainQueuedCommandsin interfaceEndpoint- Parameters:
queuedCommands- the queue holder.
-
isClosed
public boolean isClosed() -
doExclusive
Execute aSuppliercallback guarded by an exclusive lock.- Type Parameters:
T-- Parameters:
supplier-- Returns:
-
drainCommands
-
logPrefix
-
getId
-