private void sendStop() { Iterator<WsClientHandler> itr = clients.iterator(); if (itr.hasNext()) { WsClientHandler client = itr.next(); client.postMessage("doClose"); } else { // clientsが空 stat = Stat.READY; publish(0, failCount, true); } }
private synchronized void addWsClient() { if (stat != Stat.INC) { return; } int size = clients.size(); if ((size % 100) == 0 || size == count) { publish(size, failCount, false); } if (size >= count) { if (timerId == TimerManager.INVALID_ID) { stop(); } else { stat = Stat.KEEP; } return; } WsClientHandler wsClientHandler = WsClientHandler.create(false, config.getSelfDomain(), config.getInt(Config.SELF_PORT)); wsClientHandler.ref(); wsClientHandler.startRequest( this, wsClientHandler, 10000, "/connect", "connect", config.getAdminUrl()); clients.add(wsClientHandler); }
private synchronized void delWsClient(WsClientHandler wsClientHandler, boolean isFail) { clients.remove(wsClientHandler); wsClientHandler.unref(); int size = clients.size(); if (isFail) { failCount++; if (failCount >= maxFailCount) { publish(size, failCount, false); stop(); return; } } switch (stat) { case INC: addWsClient(); break; case DEC: if ((size % 100) == 0) { publish(size, failCount, false); } sendStop(); break; } }