本文整理汇总了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());
}