Top Description Inners Fields Constructors Methods
net.sf.ehcache.distribution

public final Class MulticastKeepaliveHeartbeatSender

extends Object
Class Inheritance
Imports
net.sf.ehcache.CacheManager, java.io.IOException, java.net.DatagramPacket, .InetAddress, .MulticastSocket, java.util.ArrayList, .Iterator, .List, org.slf4j.Logger, .LoggerFactory

Sends heartbeats to a multicast group containing a compressed list of URLs.

You can control how far the multicast packets propagate by setting the badly misnamed "TTL". Using the multicast IP protocol, the TTL value indicates the scope or range in which a packet may be forwarded. By convention:

You can also control how often the heartbeat sends by setting the interval.
Author
Greg Luck
Version
$Id: MulticastKeepaliveHeartbeatSender.java 10789 2018-04-26 02:08:13Z adahanne $

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
MulticastKeepaliveHeartbeatSender.MulticastServerThread

A thread which sends a multicast heartbeat every second

Field Summary

Modifier and TypeField and Description
private final CacheManager
private static final int
private final InetAddress
private final Integer
private static long
private static long
private InetAddress
private static final Logger
private static final int
private static final int
private static final int
private MulticastKeepaliveHeartbeatSender.MulticastServerThread
private volatile boolean
private final Integer

Constructor Summary

AccessConstructor and Description
public
MulticastKeepaliveHeartbeatSender(CacheManager
the bound CacheManager. Each CacheManager has a maximum of one sender
cacheManager
,
InetAddress multicastAddress, Integer multicastPort, Integer
See class description for the meaning of this parameter.
timeToLive
,
InetAddress hostAddress)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public final synchronized void
dispose()

Shutdown this heartbeat sender

public static long
getHeartBeatInterval()

Returns the heartbeat interval.

public static long
getHeartBeatStaleTime()

Returns the time after which a heartbeat is considered stale.

public Integer

Returns:

the TTL
getTimeToLive
()

public final void
init()

Start the heartbeat thread

public static void
setHeartBeatInterval(long
a time in ms, greater than 1000
heartBeatInterval
)

Sets the heartbeat interval to something other than the default of 5000ms.

public static void
setHeartBeatStaleTime(long
a time in ms
heartBeatStaleTime
)

Sets the heartbeat stale time to something other than the default of ((2 * HeartBeatInterval) + 100)ms.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cacheManagerback to summary
private final CacheManager cacheManager
DEFAULT_HEARTBEAT_INTERVALback to summary
private static final int DEFAULT_HEARTBEAT_INTERVAL
groupMulticastAddressback to summary
private final InetAddress groupMulticastAddress
groupMulticastPortback to summary
private final Integer groupMulticastPort
heartBeatIntervalback to summary
private static long heartBeatInterval
heartBeatStaleTimeback to summary
private static long heartBeatStaleTime
hostAddressback to summary
private InetAddress hostAddress
LOGback to summary
private static final Logger LOG
MAXIMUM_PEERS_PER_SENDback to summary
private static final int MAXIMUM_PEERS_PER_SEND
MINIMUM_HEARTBEAT_INTERVALback to summary
private static final int MINIMUM_HEARTBEAT_INTERVAL
ONE_HUNDRED_MSback to summary
private static final int ONE_HUNDRED_MS
serverThreadback to summary
private MulticastKeepaliveHeartbeatSender.MulticastServerThread serverThread
stoppedback to summary
private volatile boolean stopped
timeToLiveback to summary
private final Integer timeToLive

Constructor Detail

MulticastKeepaliveHeartbeatSenderback to summary
public MulticastKeepaliveHeartbeatSender(CacheManager cacheManager, InetAddress multicastAddress, Integer multicastPort, Integer timeToLive, InetAddress hostAddress)

Constructor.

Parameters
cacheManager:CacheManager

the bound CacheManager. Each CacheManager has a maximum of one sender

timeToLive:Integer

See class description for the meaning of this parameter.

Method Detail

disposeback to summary
public final synchronized void dispose()

Shutdown this heartbeat sender

getHeartBeatIntervalback to summary
public static long getHeartBeatInterval()

Returns the heartbeat interval.

getHeartBeatStaleTimeback to summary
public static long getHeartBeatStaleTime()

Returns the time after which a heartbeat is considered stale.

getTimeToLiveback to summary
public Integer getTimeToLive()
Returns:Integer

the TTL

initback to summary
public final void init()

Start the heartbeat thread

setHeartBeatIntervalback to summary
public static void setHeartBeatInterval(long heartBeatInterval)

Sets the heartbeat interval to something other than the default of 5000ms. This is useful for testing, but not recommended for production. This method is static and so affects the heartbeat interval of all senders. The change takes effect after the next scheduled heartbeat.

Parameters
heartBeatInterval:long

a time in ms, greater than 1000

setHeartBeatStaleTimeback to summary
public static void setHeartBeatStaleTime(long heartBeatStaleTime)

Sets the heartbeat stale time to something other than the default of ((2 * HeartBeatInterval) + 100)ms. This is useful for testing, but not recommended for production. This method is static and so affects the stale time all users.

Parameters
heartBeatStaleTime:long

a time in ms

net.sf.ehcache.distribution back to summary

private final Class MulticastKeepaliveHeartbeatSender.MulticastServerThread

extends Thread
Class Inheritance

A thread which sends a multicast heartbeat every second

Field Summary

Modifier and TypeField and Description
private int
private List<E>
private MulticastSocket
Inherited from java.lang.Thread:
MAX_PRIORITYMIN_PRIORITYNORM_PRIORITY

Constructor Summary

AccessConstructor and Description
public
MulticastServerThread()

Constructor

Method Summary

Modifier and TypeMethod and Description
private void
private List<E>

Returns:

a gzipped byte[]
createCachePeersPayload
()

Creates a gzipped payload.

public final void
interrupt()

Overrides java.lang.Thread.interrupt.

Interrupts this thread.
public final void
run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.run.

This method is run by the thread when it executes.
Inherited from java.lang.Thread:
activeCountcheckAccessclonecountStackFramescurrentThreaddumpStackenumerategetAllStackTracesgetContextClassLoadergetDefaultUncaughtExceptionHandlergetIdgetNamegetPrioritygetStackTracegetStategetThreadGroupgetUncaughtExceptionHandlerholdsLockinterruptedisAliveisDaemonisInterruptedisVirtualjoinjoinjoinjoinofPlatformofVirtualonSpinWaitresumesetContextClassLoadersetDaemonsetDefaultUncaughtExceptionHandlersetNamesetPrioritysetUncaughtExceptionHandlersleepsleepsleepstartstartVirtualThreadstopsuspendthreadIdtoStringyield

Field Detail

cachePeersHashback to summary
private int cachePeersHash
compressedUrlListListback to summary
private List<E> compressedUrlListList
socketback to summary
private MulticastSocket socket

Constructor Detail

MulticastServerThreadback to summary
public MulticastServerThread()

Constructor

Method Detail

closeSocketback to summary
private void closeSocket()
createCachePeersPayloadback to summary
private List<E> createCachePeersPayload()

Creates a gzipped payload.

The last gzipped payload is retained and only recalculated if the list of cache peers has changed.

Returns:List<E>

a gzipped byte[]

interruptback to summary
public final void interrupt()

Overrides java.lang.Thread.interrupt.

Interrupts this thread.

Unless the current thread is interrupting itself, which is always permitted, the checkAccess method of this thread is invoked, which may cause a SecurityException to be thrown.

If this thread is blocked in an invocation of the wait(), wait(long), or wait(long, int) methods of the Object class, or of the join(), join(long), join(long, int), sleep(long), or sleep(long, int), methods of this class, then its interrupt status will be cleared and it will receive an InterruptedException.

If this thread is blocked in an I/O operation upon an interruptible channel then the channel will be closed, the thread's interrupt status will be set, and the thread will receive a java.nio.channels.ClosedByInterruptException.

If this thread is blocked in a java.nio.channels.Selector then the thread's interrupt status will be set and it will return immediately from the selection operation, possibly with a non-zero value, just as if the selector's wakeup method were invoked.

If none of the previous conditions hold then this thread's interrupt status will be set.

Annotations
@Override
Exceptions
SecurityException:
if the current thread cannot modify this thread
runback to summary
public final void run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.run.

Doc from java.lang.Thread.run.

This method is run by the thread when it executes. Subclasses of Thread may override this method.

This method is not intended to be invoked directly. If this thread is a platform thread created with a Runnable task then invoking this method will invoke the task's run method. If this thread is a virtual thread then invoking this method directly does nothing.

Annotations
@Override