本文整理匯總了Java中net.sf.freecol.common.networking.ServerListMessage類的典型用法代碼示例。如果您正苦於以下問題:Java ServerListMessage類的具體用法?Java ServerListMessage怎麽用?Java ServerListMessage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ServerListMessage類屬於net.sf.freecol.common.networking包,在下文中一共展示了ServerListMessage類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handle
import net.sf.freecol.common.networking.ServerListMessage; //導入依賴的package包/類
/**
* {@inheritDoc}
*/
public Message handle(Connection connection, Message message)
throws FreeColException {
if (message == null) return null;
final String tag = message.getType();
switch (tag) {
case DisconnectMessage.TAG:
break;
case ServerListMessage.TAG:
ServerListMessage slm = (ServerListMessage)message;
this.consumer.accept(slm.getServers());
break;
default:
logger.warning("MetaInputHandler does not handle: " + tag);
break;
}
return null;
}
示例2: getServerList
import net.sf.freecol.common.networking.ServerListMessage; //導入依賴的package包/類
/**
* Gets a list of servers from the meta server.
*
* @return A list of {@link ServerInfo} objects, or null on error.
*/
public static List<ServerInfo> getServerList() {
List<ServerInfo> lsi = new ArrayList<>();
List<ServerInfo> ret = null;
Connection mc = getMetaServerConnection(lsi);
if (mc == null) {
logger.warning("Could not connect to metaserver.");
return null;
}
try {
if (!mc.sendMessage(new ServerListMessage())) {
logger.warning("Error querying metaserver.");
return null;
}
final int MAXTRIES = 5;
final int SLEEP_TIME = 1000; // 1s
for (int n = MAXTRIES; n > 0; n--) {
if (lsi.size() != 1 || lsi.get(0) != sentinel) {
ret = new ArrayList<>(lsi);
break;
}
Thread.sleep(SLEEP_TIME);
}
if (ret == null) logger.warning("No response from metaserver.");
} catch (Exception ex) {
logger.log(Level.WARNING, "Exception getting server list", ex);
} finally {
mc.close();
}
return ret;
}
示例3: handle
import net.sf.freecol.common.networking.ServerListMessage; //導入依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public Message handle(Connection connection, Message message)
throws FreeColException {
if (message == null) return null;
Message reply = null;
final String tag = message.getType();
switch (tag) {
case DisconnectMessage.TAG:
disconnect(connection);
break;
case RegisterServerMessage.TAG:
RegisterServerMessage rsm = (RegisterServerMessage)message;
rsm.setAddress(connection.getHostAddress()); // Trust the connection
register(rsm);
break;
case RemoveServerMessage.TAG:
remove((RemoveServerMessage)message);
break;
case ServerListMessage.TAG:
reply = serverList();
break;
case UpdateServerMessage.TAG:
UpdateServerMessage usm = (UpdateServerMessage)message;
usm.setAddress(connection.getHostAddress()); // Trust the connection
update(usm);
break;
default:
logger.warning("Unknown request: " + tag);
break;
}
return reply;
}
示例4: serverList
import net.sf.freecol.common.networking.ServerListMessage; //導入依賴的package包/類
/**
* Handle a "serverList"-request.
*
* @return A {@code ServerListMessage} with attached {@code ServerInfo}
* for each current server known to the meta-register.
*/
private Message serverList() {
return new ServerListMessage().addServers(metaRegister.getServers());
}