Class Heartbeat
- java.lang.Object
-
- jetbrains.buildServer.serverSide.db.Heartbeat
-
public final class Heartbeat extends Object
Incapsulates functionality for preventing connecting several servers to one data dir/database.- Author:
- Leonid Bushuev from JetBrains
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHeartbeat.AppInfostatic classHeartbeat.AppTypeType of the application working with TeamCity database.classHeartbeat.CapturedByAnotherServerErrorclassHeartbeat.ExclusiveLockTakenErrorclassHeartbeat.MainServerWithDifferentVersionErrorclassHeartbeat.OtherNodeUsesDifferentDataDirclassHeartbeat.OtherNodeWithDifferentVersionErrorclassHeartbeat.OtherNodeWithSameIdIsActivestatic classHeartbeat.SessionRecordstatic classHeartbeat.Status
-
Field Summary
Fields Modifier and Type Field Description static StringEXCLUSIVE_LOCK_ATTEMPT_TTLstatic StringHEARTBEAT_DIRNAMEstatic StringHEARTBEAT_SESSION_EXPIRATION_INTERVALstatic StringMAIN_SERVER_IDstatic StringSTRICT_NODE_VERSION_CHECKING_PROPstatic StringUPDATE_INTERVAL_PROPERTY
-
Constructor Summary
Constructors Constructor Description Heartbeat(DataSource dataSource, File dataDir, SQLDialect sql, Logger logger, Heartbeat.AppInfo appInfo)Heartbeat(DataSource dataSource, ServerPaths serverPaths, SQLDialect sql, Logger logger, Heartbeat.AppInfo appInfo, long startingTime)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcapture()SessionInfogetCurrentSession()Set<NodeResponsibility>getEffectiveResponsibilities()ThrowablegetException()static FilegetStartingCodeFileDir(ServerPaths serverPaths)Heartbeat.StatusgetStatus()List<SessionInfo>getValidSessions()booleanisActive()booleanisReadOnly()voidprepareLockForReleasing()voidrelease()voidreleaseExclusiveLock()voidremoveResponsibility(NodeResponsibility responsibility)booleanswitchToMainNode()booleantryGetExclusiveLock()voidupdateEffectiveResponsibilities(Collection<NodeResponsibility> effectiveResponsibilities)voidupdateUrl(String url)Just set the field; will be updated in DB during nextpulse()call.voidupdateUUID(String uuid)Just set the field; will be updated in DB during nextpulse()call.
-
-
-
Field Detail
-
UPDATE_INTERVAL_PROPERTY
public static final String UPDATE_INTERVAL_PROPERTY
- See Also:
- Constant Field Values
-
HEARTBEAT_SESSION_EXPIRATION_INTERVAL
public static final String HEARTBEAT_SESSION_EXPIRATION_INTERVAL
- See Also:
- Constant Field Values
-
STRICT_NODE_VERSION_CHECKING_PROP
public static final String STRICT_NODE_VERSION_CHECKING_PROP
- See Also:
- Constant Field Values
-
HEARTBEAT_DIRNAME
public static final String HEARTBEAT_DIRNAME
- See Also:
- Constant Field Values
-
EXCLUSIVE_LOCK_ATTEMPT_TTL
public static final String EXCLUSIVE_LOCK_ATTEMPT_TTL
- See Also:
- Constant Field Values
-
MAIN_SERVER_ID
public static final String MAIN_SERVER_ID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Heartbeat
public Heartbeat(@NotNull DataSource dataSource, @NotNull File dataDir, @NotNull SQLDialect sql, @NotNull Logger logger, @NotNull Heartbeat.AppInfo appInfo)- Parameters:
dataSource- non-pooled data source.
-
Heartbeat
public Heartbeat(@NotNull DataSource dataSource, @NotNull ServerPaths serverPaths, @NotNull SQLDialect sql, @NotNull Logger logger, @NotNull Heartbeat.AppInfo appInfo, long startingTime)- Parameters:
dataSource- non-pooled data source.
-
-
Method Detail
-
getStartingCodeFileDir
@NotNull public static File getStartingCodeFileDir(@NotNull ServerPaths serverPaths)
-
switchToMainNode
public boolean switchToMainNode() throws jetbrains.buildServer.serverSide.db.Heartbeat.CaptureError- Returns:
- true if the node was switched in main server mode or if the node already was in mainserver mode
- Throws:
jetbrains.buildServer.serverSide.db.Heartbeat.CaptureError- if node was unable to capture main server lock and then was unable to switch back into secondary node mode
-
capture
public void capture() throws jetbrains.buildServer.serverSide.db.Heartbeat.CaptureError- Throws:
jetbrains.buildServer.serverSide.db.Heartbeat.CaptureError
-
tryGetExclusiveLock
public boolean tryGetExclusiveLock()
-
releaseExclusiveLock
public void releaseExclusiveLock()
-
updateUUID
public void updateUUID(@Nullable String uuid)Just set the field; will be updated in DB during nextpulse()call.
-
updateUrl
public void updateUrl(@Nullable String url)Just set the field; will be updated in DB during nextpulse()call.
-
updateEffectiveResponsibilities
public void updateEffectiveResponsibilities(@NotNull Collection<NodeResponsibility> effectiveResponsibilities)
-
removeResponsibility
public void removeResponsibility(@NotNull NodeResponsibility responsibility)
-
release
public void release()
-
prepareLockForReleasing
public void prepareLockForReleasing()
-
getStatus
@NotNull public Heartbeat.Status getStatus()
-
isActive
public boolean isActive()
-
getException
@Nullable public Throwable getException()
-
getCurrentSession
public SessionInfo getCurrentSession()
-
getValidSessions
@NotNull public List<SessionInfo> getValidSessions()
- Returns:
- list of currently active heartbeat sessions; the first session in the list always corresponds to current server.
-
isReadOnly
public boolean isReadOnly()
-
getEffectiveResponsibilities
@NotNull public Set<NodeResponsibility> getEffectiveResponsibilities()
-
-