Package net.sf.freecol.metaserver
Class MetaRegister
- java.lang.Object
-
- net.sf.freecol.metaserver.MetaRegister
-
public final class MetaRegister extends java.lang.Object
TheMetaRegister
stores information about running servers. Each server has it's ownServerInfo
object.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<ServerInfo>
items
The current list of servers.private static java.util.logging.Logger
logger
private static int
REMOVE_DEAD_SERVERS_INTERVAL
Cleanup interval.private static int
REMOVE_OLDER_THAN
Removal interval.
-
Constructor Summary
Constructors Constructor Description MetaRegister()
Create a new MetaRegister.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addServer(ServerInfo newSi)
Adds a new server with the given attributes.private boolean
canConnectToServer(ServerInfo serverInfo)
private ServerInfo
getServer(java.lang.String address, int port)
Gets the server entry with the diven address and port.java.util.List<ServerInfo>
getServers()
Get the list of servers.private int
indexOf(java.lang.String address, int port)
Gets the index of the server entry with the diven address and port.void
removeDeadServers()
Removes servers that have not sent an update for some time.void
removeServer(java.lang.String address, int port)
Removes a server from the register.private void
startCleanupTimer()
Start a timer to periodically clean up dead servers.void
updateServer(ServerInfo newSi)
Updates a server with the given attributes.
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
REMOVE_DEAD_SERVERS_INTERVAL
private static final int REMOVE_DEAD_SERVERS_INTERVAL
Cleanup interval.- See Also:
- Constant Field Values
-
REMOVE_OLDER_THAN
private static final int REMOVE_OLDER_THAN
Removal interval. @see MetaRegister#removeServer- See Also:
- Constant Field Values
-
items
private final java.util.List<ServerInfo> items
The current list of servers.
-
-
Method Detail
-
getServer
private ServerInfo getServer(java.lang.String address, int port)
Gets the server entry with the diven address and port.- Parameters:
address
- The IP-address of the server.port
- The port number of the server.- Returns:
- The server entry or
null
if the given entry could not be found.
-
indexOf
private int indexOf(java.lang.String address, int port)
Gets the index of the server entry with the diven address and port.- Parameters:
address
- The IP-address of the server.port
- The port number of the server.- Returns:
- The index or
-1
if the given entry could not be found.
-
startCleanupTimer
private void startCleanupTimer()
Start a timer to periodically clean up dead servers.
-
addServer
public boolean addServer(ServerInfo newSi)
Adds a new server with the given attributes.- Parameters:
newSi
- The newServerInfo
to add.- Returns:
- true if the server was added.
-
canConnectToServer
private boolean canConnectToServer(ServerInfo serverInfo)
-
getServers
public java.util.List<ServerInfo> getServers()
Get the list of servers.- Returns:
- The list of servers.
-
removeDeadServers
public void removeDeadServers()
Removes servers that have not sent an update for some time.
-
removeServer
public void removeServer(java.lang.String address, int port)
Removes a server from the register.- Parameters:
address
- The IP-address of the server to remove.port
- The port number of the server to remove.
-
updateServer
public void updateServer(ServerInfo newSi)
Updates a server with the given attributes.- Parameters:
newSi
- The newServerInfo
.
-
-