/**
  * creates a config item for the sensors polling time
  *
  * @param sensor
  * @return
  */
 private String createSensorPollTimeConf(Sensor sensor) {
   String sensorsPollTimeKey = POLLTIME + sensor.ident;
   String value = m_prefs.getValue(sensorsPollTimeKey);
   Configuration config =
       new Configuration(
           "polling time of sensor " + sensor.description,
           sensorsPollTimeKey,
           SettingType.number,
           value);
   return AdminServerProtocolAbstractor.createSensorConfigMessage(sensor.ident, config);
 }
 /**
  * this creates a config item for the admin clients which allows them to toggle the visibility of
  * a sensor
  *
  * @param sensor the sensor
  */
 private String createSensorVisiblityConf(Sensor sensor) {
   String sensorsVisibilityKey = VISIBILITY + sensor.ident;
   String value = m_prefs.getValue(sensorsVisibilityKey);
   Configuration config =
       new Configuration(
           "visibility of sensor " + sensor.description,
           sensorsVisibilityKey,
           SettingType.bool,
           value);
   return AdminServerProtocolAbstractor.createSensorConfigMessage(sensor.ident, config);
 }
 /** {@inheritDoc} */
 @Override
 public void onAdminSensorConfigCommand(Client c, String sensorId, String conf, String data) {
   log.info(
       "admin client set sensor configuration: "
           + conf
           + " for sensor: "
           + sensorId
           + " to: "
           + data);
   // we generate the confIds in a way that they are dedicated to one
   // sensor anyway, so we don't really need the sensorId here
   m_prefs.updatePreference(conf, data);
 }
  /**
   * 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);
      }
    }
  }
  /** {@inheritDoc} */
  @Override
  public void onNewClient(Client data, NetworkServiceClient connection) {
    ServerClient sc = new ServerClient(data, connection);
    m_clients.addClient(sc);

    List<Sensor> allSensors = Server.getSensorStorage().getAllSensors();

    for (Sensor sensor : allSensors) {
      String value = m_prefs.getValue(VISIBILITY + sensor.ident);
      if ("true".equals(value)) {
        String msg =
            ServerProtocolAbstractor.createSensorVisibilityMessage(
                sensor.ident, sensor.description, sensor.dataType, true);
        sendToClient(sc, msg);
      }
    }
  }
 /** {@inheritDoc} */
 @Override
 public void onAdminConfigCommand(Client c, String conf, String data) {
   log.info("admin client set configuration: " + conf + " to: " + data);
   m_prefs.updatePreference(conf, data);
 }