public class RaftSessionService extends Object implements ManagedService, SnapshotAwareService<com.hazelcast.cp.internal.session.RaftSessionRegistry>, SessionAccessor, TermChangeAwareService, RaftNodeLifecycleAwareService, CPSessionManagementService
CPSubsystemConfig.getSessionTimeToLiveSeconds() seconds, its session
is closed. That caller is considered to be alive as long as it is committing
heartbeats.
Blocking Raft services can make use of the session abstraction to attach
resources to sessions. On session termination, its attached resources will
be released automatically.| Modifier and Type | Field and Description |
|---|---|
static String |
SERVICE_NAME |
| Constructor and Description |
|---|
RaftSessionService(NodeEngine nodeEngine) |
| Modifier and Type | Method and Description |
|---|---|
void |
closeInactiveSessions(CPGroupId groupId,
Collection<Long> inactiveSessions) |
boolean |
closeSession(CPGroupId groupId,
long sessionId) |
SessionResponse |
createNewSession(CPGroupId groupId,
Address endpoint,
String endpointName,
CPSession.CPSessionOwnerType endpointType,
long creationTime) |
void |
expireSessions(CPGroupId groupId,
Collection<Tuple2<Long,Long>> sessionsToExpire) |
ICompletableFuture<Boolean> |
forceCloseSession(String groupName,
long sessionId)
If a Hazelcast instance that owns a CP session crashes, its CP session
is not terminated immediately.
|
long |
generateThreadId(CPGroupId groupId) |
ICompletableFuture<Collection<CPSession>> |
getAllSessions(String groupName)
Returns a non-null collection of CP sessions that are currently active
in the given CP group.
|
Collection<CPSession> |
getSessionsLocally(CPGroupId groupId) |
void |
heartbeat(CPGroupId groupId,
long sessionId)
Performs a heartbeat for the given session id in the Raft group.
|
void |
init(NodeEngine nodeEngine,
Properties properties)
Initializes this service.
|
boolean |
isActive(CPGroupId groupId,
long sessionId)
Checks if there is an active session with the given id in the Raft group
|
void |
onNewTermCommit(CPGroupId groupId,
long commitIndex)
Invokes as part of the first commit after a new leader is elected.
|
void |
onRaftGroupDestroyed(CPGroupId groupId)
Called on the thread of the Raft group when the given Raft node is
destroyed, either gracefully or forcefully.
|
void |
onRaftNodeSteppedDown(CPGroupId groupId)
Called on the thread of the Raft group when the given Raft node is
stepped down, either because it is shutting down, or it could not be
added to the Raft group
|
void |
reset()
Resets this service back to its initial state.
|
void |
restoreSnapshot(CPGroupId groupId,
long commitIndex,
com.hazelcast.cp.internal.session.RaftSessionRegistry registry)
Restores the snapshot for specified
CPGroupId. |
void |
shutdown(boolean terminate)
Shuts down this service.
|
com.hazelcast.cp.internal.session.RaftSessionRegistry |
takeSnapshot(CPGroupId groupId,
long commitIndex)
Creates a snapshot for specified
CPGroupId. |
public static final String SERVICE_NAME
public RaftSessionService(NodeEngine nodeEngine)
public void init(NodeEngine nodeEngine, Properties properties)
ManagedServiceinit in interface ManagedServicenodeEngine - the NodeEngine that this service belongs toproperties - the Properties (can be used to pass settings to the service)public void reset()
ManagedServiceTODO: what is the purpose of reset
reset in interface ManagedServicepublic void shutdown(boolean terminate)
ManagedServiceTODO: what is the purpose of the terminate variable
shutdown in interface ManagedServiceterminate - true to shut down this servicepublic com.hazelcast.cp.internal.session.RaftSessionRegistry takeSnapshot(CPGroupId groupId, long commitIndex)
SnapshotAwareServiceCPGroupId.
The snapshot object returned from this method will be stored among
the Raft log and it can be sent to other Raft nodes anytime. Therefore,
this method must not return a snapshot object that can mutate after
the takeSnapshot() call.takeSnapshot in interface SnapshotAwareService<com.hazelcast.cp.internal.session.RaftSessionRegistry>groupId - CPGroupId which is snapshot requested forcommitIndex - commitIndex of the taken snapshotCPGroupId.public void restoreSnapshot(CPGroupId groupId, long commitIndex, com.hazelcast.cp.internal.session.RaftSessionRegistry registry)
SnapshotAwareServiceCPGroupId.restoreSnapshot in interface SnapshotAwareService<com.hazelcast.cp.internal.session.RaftSessionRegistry>groupId - CPGroupId of the snapshot to be restoredcommitIndex - commitIndex of the restored snapshotregistry - snapshot for specified CPGroupIdpublic void onNewTermCommit(CPGroupId groupId, long commitIndex)
TermChangeAwareServiceonNewTermCommit in interface TermChangeAwareServicegroupId - id of the Raft group in which a new leader is electedcommitIndex - index of the commit in the Raft logpublic void onRaftGroupDestroyed(CPGroupId groupId)
RaftNodeLifecycleAwareServiceonRaftGroupDestroyed in interface RaftNodeLifecycleAwareServicepublic void onRaftNodeSteppedDown(CPGroupId groupId)
RaftNodeLifecycleAwareServiceonRaftNodeSteppedDown in interface RaftNodeLifecycleAwareServicepublic ICompletableFuture<Collection<CPSession>> getAllSessions(String groupName)
CPSessionManagementServicegetAllSessions in interface CPSessionManagementServicepublic ICompletableFuture<Boolean> forceCloseSession(String groupName, long sessionId)
CPSessionManagementServiceCPSubsystemConfig.getSessionTimeToLiveSeconds() passes.
If it is known for sure that the session owner is not partitioned and
definitely crashed, this method can be used for closing the session and
releasing its resources immediately.forceCloseSession in interface CPSessionManagementServicepublic SessionResponse createNewSession(CPGroupId groupId, Address endpoint, String endpointName, CPSession.CPSessionOwnerType endpointType, long creationTime)
public void heartbeat(CPGroupId groupId, long sessionId)
SessionAccessorheartbeat in interface SessionAccessorpublic boolean closeSession(CPGroupId groupId, long sessionId)
public void expireSessions(CPGroupId groupId, Collection<Tuple2<Long,Long>> sessionsToExpire)
public void closeInactiveSessions(CPGroupId groupId, Collection<Long> inactiveSessions)
public long generateThreadId(CPGroupId groupId)
public Collection<CPSession> getSessionsLocally(CPGroupId groupId)
public boolean isActive(CPGroupId groupId, long sessionId)
SessionAccessorisActive in interface SessionAccessorCopyright © 2019 Hazelcast, Inc.. All Rights Reserved.