use of org.alfresco.solr.SolrKeyResourceLoader in project SearchServices by Alfresco.
the class SolrCoreLoadRegistration method registerForCore.
/**
* Registers with the admin handler the information server and the trackers.
*/
public static void registerForCore(AlfrescoCoreAdminHandler adminHandler, CoreContainer coreContainer, SolrCore core, String coreName) {
TrackerRegistry trackerRegistry = adminHandler.getTrackerRegistry();
Properties props = new CoreDescriptorDecorator(core.getCoreDescriptor()).getProperties();
if (Boolean.parseBoolean(props.getProperty("enable.alfresco.tracking", "false"))) {
SolrTrackerScheduler scheduler = adminHandler.getScheduler();
SolrResourceLoader loader = core.getLatestSchema().getResourceLoader();
SolrKeyResourceLoader keyResourceLoader = new SolrKeyResourceLoader(loader);
if (trackerRegistry.hasTrackersForCore(coreName)) {
log.info("Trackers for " + coreName + " is already registered, shutting them down.");
shutdownTrackers(coreName, trackerRegistry.getTrackersForCore(coreName), scheduler);
trackerRegistry.removeTrackersForCore(coreName);
adminHandler.getInformationServers().remove(coreName);
}
SOLRAPIClientFactory clientFactory = new SOLRAPIClientFactory();
SOLRAPIClient repositoryClient = clientFactory.getSOLRAPIClient(props, keyResourceLoader, AlfrescoSolrDataModel.getInstance().getDictionaryService(CMISStrictDictionaryService.DEFAULT), AlfrescoSolrDataModel.getInstance().getNamespaceDAO());
// Start content store
SolrContentStore contentStore = new SolrContentStore(coreContainer.getSolrHome());
SolrInformationServer srv = new SolrInformationServer(adminHandler, core, repositoryClient, contentStore);
props.putAll(srv.getProps());
adminHandler.getInformationServers().put(coreName, srv);
log.info("Starting to track " + coreName);
ModelTracker mTracker = null;
// Prevents other threads from registering the ModelTracker at the same time
synchronized (trackerRegistry) {
mTracker = trackerRegistry.getModelTracker();
if (mTracker == null) {
log.debug("Creating ModelTracker when registering trackers for core " + coreName);
mTracker = new ModelTracker(coreContainer.getSolrHome(), props, repositoryClient, coreName, srv);
trackerRegistry.setModelTracker(mTracker);
log.info("Ensuring first model sync.");
mTracker.ensureFirstModelSync();
log.info("Done ensuring first model sync.");
// Scheduling the ModelTracker.
scheduler.schedule(mTracker, coreName, props);
}
}
List<Tracker> trackers = createTrackers(coreName, trackerRegistry, props, scheduler, repositoryClient, srv);
CommitTracker commitTracker = new CommitTracker(props, repositoryClient, coreName, srv, trackers);
trackerRegistry.register(coreName, commitTracker);
scheduler.schedule(commitTracker, coreName, props);
log.info("The Trackers are now scheduled to run");
// Add the commitTracker to the list of scheduled trackers that can be shutdown
trackers.add(commitTracker);
core.addCloseHook(new CloseHook() {
@Override
public void preClose(SolrCore core) {
log.info("Shutting down " + core.getName());
SolrCoreLoadRegistration.shutdownTrackers(core.getName(), trackers, scheduler);
}
@Override
public void postClose(SolrCore core) {
}
});
}
}
Aggregations