/** * triggered when an admin client connects * * @param data * @param connection */ public void onNewAdminClient(Client data, NetworkServiceClient connection) { // also trigger the normal client handling onNewClient(data, connection); ServerClient newAdminClient = new ServerClient(data, connection); synchronized (m_adminClients) { m_adminClients.put(data, newAdminClient); } // tell him about all the server configs + send him list of all clients List<ServerClient> all = null; synchronized (m_clients) { // copy the entries to be reistent to modifications while sending List<ServerClient> targets = m_clients.getAllClients(); all = new ArrayList<ServerClient>(targets); } String msg = ""; // tell him about all the clients that are connected for (ServerClient sc : all) { msg = AdminServerProtocolAbstractor.createClientMessage( sc.getClientInfo().m_id, sc.getClientInfo().m_address, true); sendToClient(newAdminClient, msg); } // tell him about all server configs: // TODO maybe add more configs! String pollTimeKey = Definitions.PREFIX_SERVER_DEFAULT_POLLING; String pollTimeValue = m_prefs.getValue(pollTimeKey); msg = AdminServerProtocolAbstractor.createConfigMessage( new Configuration( "default polling time: ", pollTimeKey, SettingType.number, pollTimeValue)); sendToClient(newAdminClient, msg); // send all invisible sensors as sensor-config items // + send all polling sensors as polling frequency objects List<Sensor> allSensors = Server.getSensorStorage().getAllSensors(); for (Sensor sensor : allSensors) { msg = createSensorVisiblityConf(sensor); sendToClient(newAdminClient, msg); if (sensor.isPolling) { msg = createSensorPollTimeConf(sensor); sendToClient(newAdminClient, msg); } } }
protected void broadcastToAllClients(String msg) { // TODO: implement broadcasting, consider the following: // don't block the caller, because this could take some time // are clients where we lose the connection already handled? // XXX this dummy implementation BLOCKS THE WHOLE TIME!!! List<ServerClient> all = null; synchronized (m_clients) { // copy the entries to be reistent to modifications while sending List<ServerClient> targets = m_clients.getAllClients(); all = new ArrayList<ServerClient>(targets); } if (log.isTraceEnabled()) { log.trace("sending to all " + all.size() + "clients"); } for (ServerClient sc : all) { sendToClient(sc, msg); } }
/** * get the number of connected clients, for status tracking * * @return */ public int getClientCount() { return m_clients.getAllClients().size(); }