javaapache-cayenne

How do I register a class/object as listener for object life-cycle events after the ServerRuntime has been built?


The Cayenne docs shows how to use ServerRuntimeBuilder to register as a listener for object life-cycle events with something like this:

ServerRuntime.builder()
             .addConfig("cayenne-model.xml")
             .addModule(binder -> ServerModule.contributeDomainListeners(binder)
                                              .add(MyListener.class))
             .build();

How do I register for those events later, when the ServerRuntime has already been created?


Solution

  • After startup a listener can be added to the DataDomain directly:

    ServerRuntime rt = ..
    rt.getDataDomain().addListener(new MyListener());