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 class
Heartbeat.AppInfo
static class
Heartbeat.AppType
Type of the application working with TeamCity database.class
Heartbeat.CapturedByAnotherServerError
class
Heartbeat.ExclusiveLockTakenError
class
Heartbeat.MainServerWithDifferentVersionError
class
Heartbeat.OtherNodeUsesDifferentDataDir
class
Heartbeat.OtherNodeWithDifferentVersionError
class
Heartbeat.OtherNodeWithSameIdIsActive
static class
Heartbeat.SessionRecord
static class
Heartbeat.Status
-
Field Summary
Fields Modifier and Type Field Description static String
EXCLUSIVE_LOCK_ATTEMPT_TTL
static String
HEARTBEAT_DIRNAME
static String
HEARTBEAT_SESSION_EXPIRATION_INTERVAL
static String
MAIN_SERVER_ID
static String
STRICT_NODE_VERSION_CHECKING_PROP
static String
UPDATE_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 void
capture()
SessionInfo
getCurrentSession()
Set<NodeResponsibility>
getEffectiveResponsibilities()
Throwable
getException()
static File
getStartingCodeFileDir(ServerPaths serverPaths)
Heartbeat.Status
getStatus()
List<SessionInfo>
getValidSessions()
boolean
isActive()
boolean
isReadOnly()
void
prepareLockForReleasing()
void
release()
void
releaseExclusiveLock()
void
removeResponsibility(NodeResponsibility responsibility)
boolean
switchToMainNode()
boolean
tryGetExclusiveLock()
void
updateEffectiveResponsibilities(Collection<NodeResponsibility> effectiveResponsibilities)
void
updateUrl(String url)
Just set the field; will be updated in DB during nextpulse()
call.void
updateUUID(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()
-
-