Hi,
So the automatic prefetching tool that I’ve been working on has soon been migrated to 5.3.0.Final. There is a problem still though, and it has to do with the custom service that the tool relies on. For some reason it does not get instantiated, causing an UnknownServiceException in my test suite. We are injecting the service with a ServiceContributor, which should, in theory, take care of all the instantiation of the service. However, this does not occur. When I debug the contributor, the breakpoint is never triggered. Is there something I need to do in order to make this happen? I checked in the Integrations guide and it seems like this should be the way to automatically inject a service.
This is the code of the service, contributor, etc:
@SuppressWarnings("unused")
@AutoService(ServiceContributor.class)
public class AutofetchServiceContributor implements ServiceContributor {
@Override
public void contribute(StandardServiceRegistryBuilder serviceRegistryBuilder) {
serviceRegistryBuilder.addInitiator( AutofetchServiceInitiator.INSTANCE );
}
}
public interface AutofetchService extends Service, Serializable {
ExtentManager getExtentManager();
}
final class AutofetchServiceImpl implements AutofetchService {
private final ExtentManager extentManager;
AutofetchServiceImpl() {
this.extentManager = new ExtentManager();
}
@Override
public ExtentManager getExtentManager() {
return extentManager;
}
}
final class AutofetchServiceInitiator implements StandardServiceInitiator<AutofetchService> {
static final AutofetchServiceInitiator INSTANCE = new AutofetchServiceInitiator();
@Override
public AutofetchService initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
return new AutofetchServiceImpl();
}
@Override
public Class<AutofetchService> getServiceInitiated() {
return AutofetchService.class;
}
}
@SuppressWarnings("unused")
@AutoService(Integrator.class)
public class AutofetchIntegrator implements Integrator {
@Override
public void integrate(
Metadata metadata,
SessionFactoryImplementor sessionFactory,
SessionFactoryServiceRegistry serviceRegistry) {
BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
integrateEventListeners( serviceRegistry );
}
@Override
public void disintegrate(
SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
}
private static void integrateEventListeners(ServiceRegistry serviceRegistry) {
final ExtentManager extentManager = serviceRegistry.getService( AutofetchService.class ).getExtentManager(); //fails here
EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
eventListenerRegistry.setListeners( EventType.LOAD, new AutofetchLoadListener( extentManager ) );
eventListenerRegistry.setListeners(
EventType.INIT_COLLECTION,
new AutofetchInitializeCollectionListener( extentManager )
);
}
}
Any ideas what might be the problem? Why is my Contributor never used?