Class AbstractDomainManager
- java.lang.Object
-
- org.opennms.features.distributed.coordination.common.AbstractDomainManager
-
- All Implemented Interfaces:
DomainManager
- Direct Known Subclasses:
ConnectionBasedDomainManager
public abstract class AbstractDomainManager extends java.lang.Object implements DomainManager
A skeleton implementation ofDomainManager
.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractDomainManager(java.lang.String domain)
Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
becomeActive()
Executed when becoming ACTIVE for the managed domain.protected void
becomeStandby()
Executed when becoming STANDBY for the managed domain.void
deregister(java.lang.String id)
Deregister with the domain being managed.protected Role
getCurrentRole()
protected java.lang.String
getDomain()
java.util.Map<java.lang.String,RoleChangeHandler>
getRoleChangeHandlers()
Check the current view of the registered change handlers.boolean
isAnythingRegistered()
Checks if anything is currently registered with the domain being managed.boolean
isRegistered(java.lang.String id)
Checks if a given Id is registered.protected abstract void
onFirstRegister()
Implementations must handle any specific logic for dealing with a registration that adds to the map of handlers for the first time (such as connecting).protected abstract void
onLastDeregister()
Implementations must handle any specific logic for dealing with a deregistration that empties the map of handlers (such as disconnecting).void
register(java.lang.String id, RoleChangeHandler roleChangeHandler)
Register with the domain being managed.java.lang.String
toString()
-
-
-
Method Detail
-
getRoleChangeHandlers
public final java.util.Map<java.lang.String,RoleChangeHandler> getRoleChangeHandlers()
Check the current view of the registered change handlers.- Returns:
- an immutable copy of the currently registered change handlers
-
becomeActive
protected final void becomeActive()
Executed when becoming ACTIVE for the managed domain. This blocks until all registrants have processed the becomeActive() in their handler.
-
becomeStandby
protected final void becomeStandby()
Executed when becoming STANDBY for the managed domain. This blocks until all registrants have processed the becomeStandby() in their handler.
-
getCurrentRole
protected final Role getCurrentRole()
-
getDomain
protected final java.lang.String getDomain()
-
onFirstRegister
protected abstract void onFirstRegister()
Implementations must handle any specific logic for dealing with a registration that adds to the map of handlers for the first time (such as connecting).
-
onLastDeregister
protected abstract void onLastDeregister()
Implementations must handle any specific logic for dealing with a deregistration that empties the map of handlers (such as disconnecting).
-
register
public final void register(java.lang.String id, RoleChangeHandler roleChangeHandler)
Description copied from interface:DomainManager
Register with the domain being managed. This is a non-blocking call.Ids must be unique to this manager. Attempting to register the same Id twice will result in an exception.
The methods specified by the
RoleChangeHandler
passed to this method must not block.- Specified by:
register
in interfaceDomainManager
- Parameters:
id
- the Id to registerroleChangeHandler
- the role change handler to register
-
deregister
public final void deregister(java.lang.String id)
Description copied from interface:DomainManager
Deregister with the domain being managed. This is a non-blocking call.- Specified by:
deregister
in interfaceDomainManager
- Parameters:
id
- the Id to register
-
isRegistered
public final boolean isRegistered(java.lang.String id)
Description copied from interface:DomainManager
Checks if a given Id is registered.- Specified by:
isRegistered
in interfaceDomainManager
- Parameters:
id
- the Id to check- Returns:
- true if registered, false otherwise
-
isAnythingRegistered
public final boolean isAnythingRegistered()
Description copied from interface:DomainManager
Checks if anything is currently registered with the domain being managed.- Specified by:
isAnythingRegistered
in interfaceDomainManager
- Returns:
- true if one or more registrants are currently registered, false otherwise
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-