Package net.sf.freecol.metaserver
Class MetaRegister
- java.lang.Object
-
- net.sf.freecol.metaserver.MetaRegister
-
public final class MetaRegister extends java.lang.ObjectTheMetaRegisterstores information about running servers. Each server has it's ownServerInfoobject.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<ServerInfo>itemsThe current list of servers.private static java.util.logging.Loggerloggerprivate static intREMOVE_DEAD_SERVERS_INTERVALCleanup interval.private static intREMOVE_OLDER_THANRemoval interval.
-
Constructor Summary
Constructors Constructor Description MetaRegister()Create a new MetaRegister.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddServer(ServerInfo newSi)Adds a new server with the given attributes.private booleancanConnectToServer(ServerInfo serverInfo)private ServerInfogetServer(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 intindexOf(java.lang.String address, int port)Gets the index of the server entry with the diven address and port.voidremoveDeadServers()Removes servers that have not sent an update for some time.voidremoveServer(java.lang.String address, int port)Removes a server from the register.private voidstartCleanupTimer()Start a timer to periodically clean up dead servers.voidupdateServer(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
nullif 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
-1if 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 newServerInfoto 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.
-
-