@Override
  void requestFinished(Object result, DIRRequest rq) {

    configurationSetResponse response =
        configurationSetResponse.newBuilder().setNewVersion((Long) result).build();
    rq.sendSuccess(response);
  }
  @Override
  public void startRequest(DIRRequest rq) {

    final Configuration conf = (Configuration) rq.getRequestMessage();

    String uuid = null;

    if (conf.getParameterCount() == 0) {
      rq.sendError(
          ErrorType.ERRNO, POSIXErrno.POSIX_ERROR_EINVAL, "empty configuration set not allowed");
      return;
    }

    uuid = conf.getUuid();

    assert (uuid != null);
    assert (database != null);

    final String UUID = uuid;

    database
        .lookup(DIRRequestDispatcher.INDEX_ID_CONFIGURATIONS, uuid.getBytes(), rq)
        .registerListener(
            new DBRequestListener<byte[], Long>(false) {
              @Override
              Long execute(byte[] result, DIRRequest rq) throws Exception {

                long currentVersion = 0;
                if (result != null) {
                  ReusableBuffer buf = ReusableBuffer.wrap(result);
                  ConfigurationRecord dbData = new ConfigurationRecord(buf);
                  currentVersion = dbData.getVersion();
                }

                if (conf.getVersion() != currentVersion) {
                  throw new ConcurrentModificationException();
                }

                final long version = ++currentVersion;

                ConfigurationRecord newRec = new ConfigurationRecord(conf);
                newRec.setVersion(version);

                final int size = newRec.getSize();
                byte[] newBytes = new byte[size];
                ReusableBuffer buf = ReusableBuffer.wrap(newBytes);
                newRec.serialize(buf);

                database
                    .singleInsert(
                        DIRRequestDispatcher.INDEX_ID_CONFIGURATIONS, UUID.getBytes(), newBytes, rq)
                    .registerListener(
                        new DBRequestListener<Object, Long>(true) {

                          @Override
                          Long execute(Object result, DIRRequest rq) throws Exception {
                            return version;
                          }
                        });

                return null;
              }
            });

    //
    // database.lookup(DIRRequestDispatcher.INDEX_ID_CONFIGURATIONS,
    // uuid.getBytes(), rq).registerListener(
    // new DBRequestListener<byte[], Configuration>(true) {
    //
    // @Override
    // Configuration execute(byte[] result, DIRRequest rq) throws Exception
    // {
    //
    // if (result == null) {
    // return Configuration.getDefaultInstance();
    // } else
    // return new
    // ConfigurationRecord(ReusableBuffer.wrap(result)).getConfiguration();
    // }
    // });

  }