2

I have a problem with Orika 1.4.5 and PermGen Space.

Indeed, i'm using a a ConfigurableMapper this way :

 public class SoapSearchPrdvFreeSlotsMapper extends ConfigurableMapper {
@Override
public void configure(MapperFactory mapperFactory) {
    mapperFactory.registerClassMap(mapperFactory.classMap(PrdvFreeSlot.class, PrdvWsListerDispoTelV2Filter.class)
                .field("typeRdv", "wsldtTypeRdv")
                .field("motifId", "wsldtMotifId")
                .byDefault().toClassMap());
    }
    mapperFactory.registerClassMap(mapperFactory.classMap(PrdvFreeSlot.class, PrdvWsListerDispoTelV2.class)
                .field("typeRdv", "wsldtTypeRdv")
                .field("motifId", "wsldtMotifId")
                .field("quantum", "wsldtActiviteIdActivQuantum")
                .field("activiteJours", "wsldtActiviteIdActivJours")
                .field("activiteHeureFerme", "wsldtActiviteIdActivHeureFerme")
                .field("activiteHeureOuvert", "wsldtActiviteIdActivHeureOuvert")
                .field("startDate", "disDate")
                .field("disCapacity", "disCapacite")
                .field("disReserve", "disReserve")
                .field("reserveCC", "wsldtReserveCC")
                .byDefault().toClassMap());
    }
}

@Override
public void configureFactoryBuilder(DefaultMapperFactory.Builder builder) {
    builder.build().getConverterFactory().registerConverter(new DateXmlDateConverter());
}

}

But each time i call this mapper, i have autogenerated class mappers which are stored in the PermGen.

I try to use the "existsRegisteredMapper" of the MapperFactory to prevent class mappers auto-generation but it doesn't work:

public static <T, U> boolean existsRegisteredMapperInFactory(MapperFactory mapperFactory, Class<T> classSrc, Class<U> classDest) {
    return mapperFactory.existsRegisteredMapper(TypeFactory.valueOf(classSrc), TypeFactory.valueOf(classDest), true);
}

and the modified first code block:

if (!existsRegisteredMapperInFactory(mapperFactory, PrdvWsListerDispoTelV2Filter.class, PrdvFreeSlot.class)) {
        mapperFactory.registerClassMap(mapperFactory.classMap(PrdvFreeSlot.class, PrdvWsListerDispoTelV2Filter.class)
                .field("typeRdv", "wsldtTypeRdv")
                .field("motifId", "wsldtMotifId")
                .byDefault().toClassMap());
    }

Please, Is there a way to prevent class mappers autogeneration without rewriting all the mappers i have ?

Thanks for your help.

Psychose
  • 23
  • 4

1 Answers1

2

Please make sure that the mapper is a singleton. You don't need to instantiate it everytime.

You don't need to verify if the the mapper has been registered or not. It will be generated only once (per MapperFactory instance).

So just make sure that SoapSearchPrdvFreeSlotsMapper is a singleton (only one instance, ConfigurableMapper is thread-safe)

Sidi
  • 1,739
  • 14
  • 16
  • Thanks for your answer... i hope there was another way to prevent this problem 'cause i have a lot of singleton to implement... – Psychose Feb 12 '16 at 08:46
  • It's important that the mapper is singleton because if not, Orika will not be performant cause it need to collect metadata and generate new mappers every instance ... which is not efficient – Sidi Feb 12 '16 at 13:28
  • I implement singleton for all the mappers in my project but it doesn't work as i want... i still have mappers named xxx_Attributes_Attributes_Mapper_yyy Don't know what to do to eliminate those multiple mappers in the permgen. – Psychose Feb 13 '16 at 17:51
  • There is some suffices in the names to avoid name collision but there is only one instance per ClassMap. You should be aware also that if you have multiple SoapSearchPrdvFreeSlotsMapper you will have several MapperFactory and then each one will have its own copy. If you don't have want that, you can have only ConfigurableMapper instance within your project. Please refer to this article it cover the main concepts used by Orika to have a better idea on the Design. Hope this can help you ! – Sidi Feb 13 '16 at 21:04
  • We had a similar problem. When we did the singleton thing, it cleared all problems up. – markthegrea Feb 24 '17 at 19:59