Class PollingRemoteAgentConnection
- java.lang.Object
-
- jetbrains.buildServer.serverSide.impl.agent.PollingRemoteAgentConnection
-
- All Implemented Interfaces:
RemoteAgentConnection
@ThreadSafe public class PollingRemoteAgentConnection extends Object implements RemoteAgentConnection
Implementation ofRemoteAgentConnection
that can send commands to the agents who don't have web server. Such agents periodically come to the server and ask whether there is a new command for them. Current limitations: - all methods can block for a long time (up to timeout of 30 sec) - only one commands can be queued at the given moment, all other commands wait.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PollingRemoteAgentConnection.Command
-
Nested classes/interfaces inherited from interface jetbrains.buildServer.serverSide.impl.agent.RemoteAgentConnection
RemoteAgentConnection.Listener
-
-
Field Summary
Fields Modifier and Type Field Description static String
DESCRIPTION
static String
TEAMCITY_AGENT_CONNECTION_MULTI_NODE_ENABLED
static String
TEAMCITY_POLLING_AGENT_ACCEPTABLE_AGENT_INACTIVITY
static String
TEAMCITY_POLLING_AGENT_LONG_COMMAND_WARNING_TIMEOUT
static String
TYPE
-
Constructor Summary
Constructors Constructor Description PollingRemoteAgentConnection(ExecutorServices executorServices, MultiNodeTasks multiNodeTasks, MultiNodeAgentCommandsListener multiNodeAgentCommandsListener)
PollingRemoteAgentConnection(ExecutorServices executorServices, MultiNodeTasks multiNodeTasks, MultiNodeAgentCommandsListener multiNodeAgentCommandsListener, Supplier<Long> timeSupplier)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
describeAgent()
void
dispose()
Close this connection.void
done(String result, int commandId)
void
failed(Error error, int commandId)
static long
getAcceptableAgentInactivityMillis()
<T> T
getCustomHandler(Class<T> clazz)
Extension point allowing to send custom commands to agent.static long
getLongCommandWarningMillis()
PollingRemoteAgentConnection.Command
getNextCommand()
String
getProtocolDescription()
String
getType()
It's different fromRemoteAgentConnection.getProtocolDescription()
in a way that the returned value will not change in the future and can be used to determine type of the connection.boolean
hasActiveSubscriptions()
void
inProgress(int commandId)
void
isLocal(Action<Boolean> callback)
The following algorithm is used: - Server creates random file and writes random data into it.static boolean
isMultiNodeAgentConnectionEnabled()
boolean
isMultiNodeAware()
void
onAgentRequest()
Called when agent comes to the server.AgentBuildResult
runBuild(AgentBuild agentBuild)
Run build on the Agent.void
setListener(RemoteAgentConnection.Listener listener)
boolean
stopBuild(long buildId)
Send stop build command to agent.com.google.common.util.concurrent.ListenableFuture<PollingRemoteAgentConnection.Command>
subscribeToNextCommand()
Allows to subscribe to the next command for the agent.void
unsubscribeFromNextCommand(com.google.common.util.concurrent.ListenableFuture<PollingRemoteAgentConnection.Command> future)
Remove listener returned bysubscribeToNextCommand()
method.void
updateAgentInfo(int agentId, String agentName)
Updates information about the agent in the connectionboolean
upgrade(Action<Boolean> callback)
Sends upgrade command on agent
-
-
-
Field Detail
-
TEAMCITY_POLLING_AGENT_ACCEPTABLE_AGENT_INACTIVITY
public static final String TEAMCITY_POLLING_AGENT_ACCEPTABLE_AGENT_INACTIVITY
- See Also:
- Constant Field Values
-
TEAMCITY_POLLING_AGENT_LONG_COMMAND_WARNING_TIMEOUT
public static final String TEAMCITY_POLLING_AGENT_LONG_COMMAND_WARNING_TIMEOUT
- See Also:
- Constant Field Values
-
TEAMCITY_AGENT_CONNECTION_MULTI_NODE_ENABLED
public static final String TEAMCITY_AGENT_CONNECTION_MULTI_NODE_ENABLED
- See Also:
- Constant Field Values
-
DESCRIPTION
public static final String DESCRIPTION
- See Also:
- Constant Field Values
-
TYPE
public static final String TYPE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PollingRemoteAgentConnection
public PollingRemoteAgentConnection(@NotNull ExecutorServices executorServices, @NotNull MultiNodeTasks multiNodeTasks, @NotNull MultiNodeAgentCommandsListener multiNodeAgentCommandsListener)
-
PollingRemoteAgentConnection
@TestOnly public PollingRemoteAgentConnection(@NotNull ExecutorServices executorServices, @NotNull MultiNodeTasks multiNodeTasks, @NotNull MultiNodeAgentCommandsListener multiNodeAgentCommandsListener, @NotNull Supplier<Long> timeSupplier)
-
-
Method Detail
-
describeAgent
public String describeAgent()
-
isLocal
public void isLocal(Action<Boolean> callback)
The following algorithm is used: - Server creates random file and writes random data into it. - Server asks Agent to read this file. - Agent responds with the file content. - If contents are equal then Agent is local.- Specified by:
isLocal
in interfaceRemoteAgentConnection
-
hasActiveSubscriptions
public boolean hasActiveSubscriptions()
-
runBuild
@NotNull public AgentBuildResult runBuild(@NotNull AgentBuild agentBuild)
Description copied from interface:RemoteAgentConnection
Run build on the Agent.- Specified by:
runBuild
in interfaceRemoteAgentConnection
-
stopBuild
public boolean stopBuild(long buildId)
Description copied from interface:RemoteAgentConnection
Send stop build command to agent.- Specified by:
stopBuild
in interfaceRemoteAgentConnection
- Returns:
- true if agent confirms build stopping.
-
upgrade
public boolean upgrade(Action<Boolean> callback)
Description copied from interface:RemoteAgentConnection
Sends upgrade command on agent- Specified by:
upgrade
in interfaceRemoteAgentConnection
- Parameters:
callback
- will be called with true if upgrade was accepted by agent.
-
getCustomHandler
public <T> T getCustomHandler(Class<T> clazz)
Description copied from interface:RemoteAgentConnection
Extension point allowing to send custom commands to agent.- Specified by:
getCustomHandler
in interfaceRemoteAgentConnection
-
getProtocolDescription
@NotNull public String getProtocolDescription()
- Specified by:
getProtocolDescription
in interfaceRemoteAgentConnection
-
getType
@NotNull public String getType()
Description copied from interface:RemoteAgentConnection
It's different fromRemoteAgentConnection.getProtocolDescription()
in a way that the returned value will not change in the future and can be used to determine type of the connection.- Specified by:
getType
in interfaceRemoteAgentConnection
-
dispose
public void dispose()
Description copied from interface:RemoteAgentConnection
Close this connection.- Specified by:
dispose
in interfaceRemoteAgentConnection
-
setListener
public void setListener(RemoteAgentConnection.Listener listener)
- Specified by:
setListener
in interfaceRemoteAgentConnection
-
updateAgentInfo
public void updateAgentInfo(int agentId, @Nullable String agentName)
Description copied from interface:RemoteAgentConnection
Updates information about the agent in the connection- Specified by:
updateAgentInfo
in interfaceRemoteAgentConnection
-
onAgentRequest
public void onAgentRequest()
Called when agent comes to the server.
-
subscribeToNextCommand
@NotNull public com.google.common.util.concurrent.ListenableFuture<PollingRemoteAgentConnection.Command> subscribeToNextCommand()
Allows to subscribe to the next command for the agent. Returned future will be released when command is available. In this caseFuture.get()
will return this command.
-
unsubscribeFromNextCommand
public void unsubscribeFromNextCommand(@NotNull com.google.common.util.concurrent.ListenableFuture<PollingRemoteAgentConnection.Command> future)
Remove listener returned bysubscribeToNextCommand()
method.
-
getNextCommand
@Nullable public PollingRemoteAgentConnection.Command getNextCommand()
-
done
public void done(String result, int commandId)
- Throws:
UnrecognizedCommandException
- when server doesn't know about this command
-
inProgress
public void inProgress(int commandId)
-
failed
public void failed(Error error, int commandId)
- Throws:
UnrecognizedCommandException
- when server doesn't know about this command
-
getAcceptableAgentInactivityMillis
public static long getAcceptableAgentInactivityMillis()
-
getLongCommandWarningMillis
public static long getLongCommandWarningMillis()
-
isMultiNodeAware
public boolean isMultiNodeAware()
- Specified by:
isMultiNodeAware
in interfaceRemoteAgentConnection
- Returns:
- true if this connection can be used on any node and false if it can be used only on the node which manages agents
-
isMultiNodeAgentConnectionEnabled
public static boolean isMultiNodeAgentConnectionEnabled()
-
-