Exemplo n.º 1
0
 public void remove(String type) {
   synchronized (mutex) {
     DocumentMapper docMapper = mappers.get(type);
     if (docMapper == null) {
       return;
     }
     docMapper.close();
     mappers = newMapBuilder(mappers).remove(type).map();
     removeObjectAndFieldMappers(docMapper);
   }
 }
Exemplo n.º 2
0
  // never expose this to the outside world, we need to reparse the doc mapper so we get fresh
  // instances of field mappers to properly remove existing doc mapper
  private void add(DocumentMapper mapper) {
    synchronized (mutex) {
      if (mapper.type().length() == 0) {
        throw new InvalidTypeNameException("mapping type name is empty");
      }
      if (mapper.type().charAt(0) == '_') {
        throw new InvalidTypeNameException(
            "mapping type name [" + mapper.type() + "] can't start with '_'");
      }
      if (mapper.type().contains("#")) {
        throw new InvalidTypeNameException(
            "mapping type name [" + mapper.type() + "] should not include '#' in it");
      }
      if (mapper.type().contains(",")) {
        throw new InvalidTypeNameException(
            "mapping type name [" + mapper.type() + "] should not include ',' in it");
      }
      if (mapper.type().contains(".")) {
        logger.warn(
            "Type [{}] contains a '.', it is recommended not to include it within a type name",
            mapper.type());
      }
      // we can add new field/object mappers while the old ones are there
      // since we get new instances of those, and when we remove, we remove
      // by instance equality
      DocumentMapper oldMapper = mappers.get(mapper.type());

      FieldMapperListener.Aggregator fieldMappersAgg = new FieldMapperListener.Aggregator();
      mapper.traverse(fieldMappersAgg);
      addFieldMappers(
          fieldMappersAgg.fieldMappers.toArray(
              new FieldMapper[fieldMappersAgg.fieldMappers.size()]));
      mapper.addFieldMapperListener(fieldMapperListener, false);

      ObjectMapperListener.Aggregator objectMappersAgg = new ObjectMapperListener.Aggregator();
      mapper.traverse(objectMappersAgg);
      addObjectMappers(
          objectMappersAgg.objectMappers.toArray(
              new ObjectMapper[objectMappersAgg.objectMappers.size()]));
      mapper.addObjectMapperListener(objectMapperListener, false);

      mappers = newMapBuilder(mappers).put(mapper.type(), mapper).map();
      if (oldMapper != null) {
        removeObjectAndFieldMappers(oldMapper);
        oldMapper.close();
      }
    }
  }