當前位置: 首頁>>代碼示例>>Java>>正文


Java ServerListMessage類代碼示例

本文整理匯總了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;
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:21,代碼來源:MetaServerUtils.java

示例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;
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:36,代碼來源:MetaServerUtils.java

示例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;
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:36,代碼來源:MetaServerHandler.java

示例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());
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:10,代碼來源:MetaServerHandler.java


注:本文中的net.sf.freecol.common.networking.ServerListMessage類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。