// security
parseSecurity(context, model, configDoc);
// Now create the repository service that manages the lifecycle of the JcrRepository instance ...
RepositoryConfiguration repositoryConfig = new RepositoryConfiguration(configDoc, repositoryName);
RepositoryService repositoryService = new RepositoryService(repositoryConfig);
// Journaling
parseJournaling(repositoryService, context, model, configDoc);
ServiceName repositoryServiceName = ModeShapeServiceNames.repositoryServiceName(repositoryName);
// Add the EngineService's dependencies ...
ServiceBuilder<JcrRepository> repositoryServiceBuilder = target.addService(repositoryServiceName, repositoryService);
// Add dependency to the ModeShape engine service ...
repositoryServiceBuilder.addDependency(ModeShapeServiceNames.ENGINE,
ModeShapeEngine.class,
repositoryService.getEngineInjector());
repositoryServiceBuilder.setInitialMode(ServiceController.Mode.ACTIVE);
// Add garbage collection information ...
if (gcThreadPool != null) {
configDoc.getOrCreateDocument(FieldName.GARBAGE_COLLECTION).setString(FieldName.THREAD_POOL, gcThreadPool);
}
if (gcInitialTime != null) {
configDoc.getOrCreateDocument(FieldName.GARBAGE_COLLECTION).setString(FieldName.INITIAL_TIME, gcInitialTime);
}
configDoc.getOrCreateDocument(FieldName.GARBAGE_COLLECTION).setNumber(FieldName.INTERVAL_IN_HOURS, gcIntervalInHours);
// Add document optimization information ...
if (optTarget != null) {
EditableDocument docOpt = configDoc.getOrCreateDocument(FieldName.STORAGE)
.getOrCreateDocument(FieldName.DOCUMENT_OPTIMIZATION);
if (optThreadPool != null) {
docOpt.setString(FieldName.THREAD_POOL, optThreadPool);
}
if (optInitialTime != null) {
docOpt.setString(FieldName.INITIAL_TIME, optInitialTime);
}
docOpt.setNumber(FieldName.INTERVAL_IN_HOURS, optIntervalInHours);
docOpt.setNumber(FieldName.OPTIMIZATION_CHILD_COUNT_TARGET, optTarget.intValue());
if (optTolerance != null) {
docOpt.setNumber(FieldName.OPTIMIZATION_CHILD_COUNT_TOLERANCE, optTolerance.intValue());
}
}
// Add dependency to the Infinispan cache container used for content ...
repositoryServiceBuilder.addDependency(ServiceName.JBOSS.append("infinispan", namedContainer),
CacheContainer.class,
repositoryService.getCacheManagerInjector());
// Add dependency, if necessary, to the workspaces cache container
String workspacesCacheContainer = attribute(context, model, ModelAttributes.WORKSPACES_CACHE_CONTAINER, null);
if (workspacesCacheContainer != null && !workspacesCacheContainer.toLowerCase().equalsIgnoreCase(namedContainer)) {
// there is a different ISPN container configured for the ws caches
repositoryServiceBuilder.addDependency(ServiceName.JBOSS.append("infinispan", workspacesCacheContainer),
CacheContainer.class,
repositoryService.getWorkspacesCacheContainerInjector());
// the name is a constant which will be resolved later by the RepositoryService
workspacesDoc.set(FieldName.WORKSPACE_CACHE_CONFIGURATION, RepositoryService.WORKSPACES_CONTAINER_NAME);
}
repositoryServiceBuilder.addDependency(Services.JBOSS_SERVICE_MODULE_LOADER,
ModuleLoader.class,
repositoryService.getModuleLoaderInjector());
// Add dependency to the binaries storage service, which captures the properties for the binaries storage
repositoryServiceBuilder.addDependency(ModeShapeServiceNames.binaryStorageDefaultServiceName(repositoryName),
BinaryStorage.class,
repositoryService.getBinaryStorageInjector());
// Set up the JNDI binder service ...
final ReferenceFactoryService<JcrRepository> referenceFactoryService = new ReferenceFactoryService<JcrRepository>();
ServiceName referenceFactoryServiceName = ModeShapeServiceNames.referenceFactoryServiceName(repositoryName);
final ServiceBuilder<?> referenceBuilder = target.addService(referenceFactoryServiceName, referenceFactoryService);
referenceBuilder.addDependency(repositoryServiceName, JcrRepository.class, referenceFactoryService.getInjector());
referenceBuilder.setInitialMode(ServiceController.Mode.ACTIVE);
ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);
BinderService binder = new BinderService(bindInfo.getBindName());
ServiceBuilder<?> binderBuilder = target.addService(bindInfo.getBinderServiceName(), binder);
if (jndiAlias != null) {
ContextNames.BindInfo aliasInfo = ContextNames.bindInfoFor(jndiAlias);
ServiceName alias = aliasInfo.getBinderServiceName();
binderBuilder.addAliases(alias);
LOG.debugv("Binding repository {0} to JNDI name {1} and {2}",
repositoryName,
bindInfo.getAbsoluteJndiName(),
aliasInfo.getAbsoluteJndiName());
} else {
LOG.debugv("Binding repository {0} to JNDI name {1}", repositoryName, bindInfo.getAbsoluteJndiName());
}
binderBuilder.addDependency(referenceFactoryServiceName, ManagedReferenceFactory.class, binder.getManagedObjectInjector());
binderBuilder.addDependency(bindInfo.getParentContextServiceName(),
ServiceBasedNamingStore.class,
binder.getNamingStoreInjector());
binderBuilder.setInitialMode(ServiceController.Mode.ACTIVE);
// Add dependency to the data directory ...
ServiceName dataDirServiceName = ModeShapeServiceNames.dataDirectoryServiceName(repositoryName);
ServiceController<String> dataDirServiceController = RelativePathService.addService(dataDirServiceName,
"modeshape/" + repositoryName,
ModeShapeExtension.JBOSS_DATA_DIR_VARIABLE,
target);
newControllers.add(dataDirServiceController);
repositoryServiceBuilder.addDependency(dataDirServiceName, String.class, repositoryService.getDataDirectoryPathInjector());
// Add the default binary storage service which will provide the binary configuration
BinaryStorageService defaultBinaryService = new BinaryStorageService(repositoryName);
ServiceBuilder<BinaryStorage> binaryStorageBuilder = target.addService(ModeShapeServiceNames.binaryStorageDefaultServiceName(repositoryName),
defaultBinaryService);