use of org.apache.jackrabbit.commons.SimpleValueFactory in project jackrabbit-oak by apache.
the class DocumentNodeStoreService method registerNodeStore.
private void registerNodeStore() throws IOException {
String uri = PropertiesUtil.toString(prop(PROP_URI, FWK_PROP_URI), DEFAULT_URI);
String db = PropertiesUtil.toString(prop(PROP_DB, FWK_PROP_DB), DEFAULT_DB);
boolean soKeepAlive = PropertiesUtil.toBoolean(prop(PROP_SO_KEEP_ALIVE, FWK_PROP_SO_KEEP_ALIVE), DEFAULT_SO_KEEP_ALIVE);
int cacheSize = toInteger(prop(PROP_CACHE), DEFAULT_CACHE);
int nodeCachePercentage = toInteger(prop(PROP_NODE_CACHE_PERCENTAGE), DEFAULT_NODE_CACHE_PERCENTAGE);
int prevDocCachePercentage = toInteger(prop(PROP_PREV_DOC_CACHE_PERCENTAGE), DEFAULT_NODE_CACHE_PERCENTAGE);
int childrenCachePercentage = toInteger(prop(PROP_CHILDREN_CACHE_PERCENTAGE), DEFAULT_CHILDREN_CACHE_PERCENTAGE);
int diffCachePercentage = toInteger(prop(PROP_DIFF_CACHE_PERCENTAGE), DEFAULT_DIFF_CACHE_PERCENTAGE);
int blobCacheSize = toInteger(prop(PROP_BLOB_CACHE_SIZE), DEFAULT_BLOB_CACHE_SIZE);
String persistentCache = getPath(PROP_PERSISTENT_CACHE, DEFAULT_PERSISTENT_CACHE);
String journalCache = getPath(PROP_JOURNAL_CACHE, DEFAULT_JOURNAL_CACHE);
int cacheSegmentCount = toInteger(prop(PROP_CACHE_SEGMENT_COUNT), DEFAULT_CACHE_SEGMENT_COUNT);
int cacheStackMoveDistance = toInteger(prop(PROP_CACHE_STACK_MOVE_DISTANCE), DEFAULT_CACHE_STACK_MOVE_DISTANCE);
boolean bundlingDisabled = toBoolean(prop(PROP_BUNDLING_DISABLED), DEFAULT_BUNDLING_DISABLED);
boolean prefetchExternalChanges = toBoolean(prop(PROP_PREFETCH_EXTERNAL_CHANGES), false);
int updateLimit = toInteger(prop(PROP_UPDATE_LIMIT), DocumentMK.UPDATE_LIMIT);
DocumentMK.Builder mkBuilder = new DocumentMK.Builder().setStatisticsProvider(statisticsProvider).memoryCacheSize(cacheSize * MB).memoryCacheDistribution(nodeCachePercentage, prevDocCachePercentage, childrenCachePercentage, diffCachePercentage).setCacheSegmentCount(cacheSegmentCount).setCacheStackMoveDistance(cacheStackMoveDistance).setBundlingDisabled(bundlingDisabled).setJournalPropertyHandlerFactory(journalPropertyHandlerFactory).setLeaseCheck(!ClusterNodeInfo.DEFAULT_LEASE_CHECK_DISABLED).setLeaseFailureHandler(new LeaseFailureHandler() {
@Override
public void handleLeaseFailure() {
try {
// plan A: try stopping oak-core
log.error("handleLeaseFailure: stopping oak-core...");
Bundle bundle = context.getBundleContext().getBundle();
bundle.stop(Bundle.STOP_TRANSIENT);
log.error("handleLeaseFailure: stopped oak-core.");
// plan A worked, perfect!
} catch (BundleException e) {
log.error("handleLeaseFailure: exception while stopping oak-core: " + e, e);
// plan B: stop only DocumentNodeStoreService (to stop the background threads)
log.error("handleLeaseFailure: stopping DocumentNodeStoreService...");
context.disableComponent(DocumentNodeStoreService.class.getName());
log.error("handleLeaseFailure: stopped DocumentNodeStoreService");
// plan B succeeded.
}
}
}).setPrefetchExternalChanges(prefetchExternalChanges).setUpdateLimit(updateLimit);
if (!Strings.isNullOrEmpty(persistentCache)) {
mkBuilder.setPersistentCache(persistentCache);
}
if (!Strings.isNullOrEmpty(journalCache)) {
mkBuilder.setJournalCache(journalCache);
}
boolean wrappingCustomBlobStore = customBlobStore && blobStore instanceof BlobStoreWrapper;
//Set blobstore before setting the DB
if (customBlobStore && !wrappingCustomBlobStore) {
checkNotNull(blobStore, "Use of custom BlobStore enabled via [%s] but blobStore reference not " + "initialized", CUSTOM_BLOB_STORE);
mkBuilder.setBlobStore(blobStore);
}
if (documentStoreType == DocumentStoreType.RDB) {
checkNotNull(dataSource, "DataStore type set [%s] but DataSource reference not initialized", PROP_DS_TYPE);
if (!customBlobStore) {
checkNotNull(blobDataSource, "DataStore type set [%s] but BlobDataSource reference not initialized", PROP_DS_TYPE);
mkBuilder.setRDBConnection(dataSource, blobDataSource);
log.info("Connected to datasources {} {}", dataSource, blobDataSource);
} else {
if (blobDataSource != null && blobDataSource != dataSource) {
log.info("Ignoring blobDataSource {} as custom blob store takes precedence.", blobDataSource);
}
mkBuilder.setRDBConnection(dataSource);
log.info("Connected to datasource {}", dataSource);
}
} else {
MongoClientURI mongoURI = new MongoClientURI(uri);
if (log.isInfoEnabled()) {
// Take care around not logging the uri directly as it
// might contain passwords
log.info("Starting DocumentNodeStore with host={}, db={}, cache size (MB)={}, persistentCache={}, " + "journalCache={}, blobCacheSize (MB)={}, maxReplicationLagInSecs={}", mongoURI.getHosts(), db, cacheSize, persistentCache, journalCache, blobCacheSize, maxReplicationLagInSecs);
log.info("Mongo Connection details {}", MongoConnection.toString(mongoURI.getOptions()));
}
mkBuilder.setMaxReplicationLag(maxReplicationLagInSecs, TimeUnit.SECONDS);
mkBuilder.setSocketKeepAlive(soKeepAlive);
mkBuilder.setMongoDB(uri, db, blobCacheSize);
log.info("Connected to database '{}'", db);
}
if (!customBlobStore) {
defaultBlobStore = mkBuilder.getBlobStore();
log.info("Registering the BlobStore with ServiceRegistry");
blobStoreReg = context.getBundleContext().registerService(BlobStore.class.getName(), defaultBlobStore, null);
}
//Set wrapping blob store after setting the DB
if (wrappingCustomBlobStore) {
((BlobStoreWrapper) blobStore).setBlobStore(mkBuilder.getBlobStore());
mkBuilder.setBlobStore(blobStore);
}
mkBuilder.setExecutor(executor);
// attach GCMonitor
final GCMonitorTracker gcMonitor = new GCMonitorTracker();
gcMonitor.start(whiteboard);
closer.register(asCloseable(gcMonitor));
mkBuilder.setGCMonitor(gcMonitor);
nodeStore = mkBuilder.getNodeStore();
// ensure a clusterId is initialized
// and expose it as 'oak.clusterid' repository descriptor
GenericDescriptors clusterIdDesc = new GenericDescriptors();
clusterIdDesc.put(ClusterRepositoryInfo.OAK_CLUSTERID_REPOSITORY_DESCRIPTOR_KEY, new SimpleValueFactory().createValue(ClusterRepositoryInfo.getOrCreateId(nodeStore)), true, false);
whiteboard.register(Descriptors.class, clusterIdDesc, Collections.emptyMap());
// If a shared data store register the repo id in the data store
if (SharedDataStoreUtils.isShared(blobStore)) {
String repoId = null;
try {
repoId = ClusterRepositoryInfo.getOrCreateId(nodeStore);
((SharedDataStore) blobStore).addMetadataRecord(new ByteArrayInputStream(new byte[0]), SharedDataStoreUtils.SharedStoreRecordType.REPOSITORY.getNameFromId(repoId));
} catch (Exception e) {
throw new IOException("Could not register a unique repositoryId", e);
}
if (blobStore instanceof BlobTrackingStore) {
final long trackSnapshotInterval = toLong(prop(PROP_BLOB_SNAPSHOT_INTERVAL), DEFAULT_BLOB_SNAPSHOT_INTERVAL);
String root = getRepositoryHome();
BlobTrackingStore trackingStore = (BlobTrackingStore) blobStore;
if (trackingStore.getTracker() != null) {
trackingStore.getTracker().close();
}
((BlobTrackingStore) blobStore).addTracker(new BlobIdTracker(root, repoId, trackSnapshotInterval, (SharedDataStore) blobStore));
}
}
registerJMXBeans(nodeStore, mkBuilder);
registerLastRevRecoveryJob(nodeStore);
registerJournalGC(nodeStore);
if (!isNodeStoreProvider()) {
observerTracker = new ObserverTracker(nodeStore);
observerTracker.start(context.getBundleContext());
}
journalPropertyHandlerFactory.start(whiteboard);
DocumentStore ds = nodeStore.getDocumentStore();
// OAK-2682: time difference detection applied at startup with a default
// max time diff of 2000 millis (2sec)
final long maxDiff = Long.parseLong(System.getProperty("oak.documentMK.maxServerTimeDiffMillis", "2000"));
try {
if (maxDiff >= 0) {
final long timeDiff = ds.determineServerTimeDifferenceMillis();
log.info("registerNodeStore: server time difference: {}ms (max allowed: {}ms)", timeDiff, maxDiff);
if (Math.abs(timeDiff) > maxDiff) {
throw new AssertionError("Server clock seems off (" + timeDiff + "ms) by more than configured amount (" + maxDiff + "ms)");
}
}
} catch (RuntimeException e) {
// no checked exception
// in case of a RuntimeException, just log but continue
log.warn("registerNodeStore: got RuntimeException while trying to determine time difference to server: " + e, e);
}
String[] serviceClasses;
if (isNodeStoreProvider()) {
registerNodeStoreProvider(nodeStore);
serviceClasses = new String[] { DocumentNodeStore.class.getName(), Clusterable.class.getName() };
} else {
serviceClasses = new String[] { NodeStore.class.getName(), DocumentNodeStore.class.getName(), Clusterable.class.getName() };
}
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(Constants.SERVICE_PID, DocumentNodeStore.class.getName());
props.put(DESCRIPTION, getMetadata(ds));
// OAK-2844: in order to allow DocumentDiscoveryLiteService to directly
// require a service DocumentNodeStore (instead of having to do an 'instanceof')
// the registration is now done for both NodeStore and DocumentNodeStore here.
nodeStoreReg = context.getBundleContext().registerService(serviceClasses, nodeStore, props);
}
use of org.apache.jackrabbit.commons.SimpleValueFactory in project jackrabbit-oak by apache.
the class AggregatingDescriptorsTest method testInitialDescriptors.
@Test
public void testInitialDescriptors() throws Exception {
final ValueFactory valueFactory = new SimpleValueFactory();
final MyTracker<Descriptors> tracker = createTracker();
final GenericDescriptors input = new GenericDescriptors();
input.put("a", valueFactory.createValue("b"), true, false);
input.put("b", valueFactory.createValue("c"), true, true);
tracker.addService(input);
AggregatingDescriptors aggregator = new AggregatingDescriptors(tracker);
assertMatches(aggregator, 2, input);
}
use of org.apache.jackrabbit.commons.SimpleValueFactory in project jackrabbit-oak by apache.
the class AggregatingDescriptorsTest method testLaterAddedDescriptors.
@Test
public void testLaterAddedDescriptors() throws Exception {
final ValueFactory valueFactory = new SimpleValueFactory();
final MyTracker<Descriptors> tracker = createTracker();
AggregatingDescriptors aggregator = new AggregatingDescriptors(tracker);
assertMatches(aggregator, 0);
final GenericDescriptors input1 = new GenericDescriptors();
input1.put("a", valueFactory.createValue("b"), true, false);
input1.put("b", valueFactory.createValue("c"), true, true);
tracker.addService(input1);
assertMatches(aggregator, 2, input1);
final GenericDescriptors input2 = new GenericDescriptors();
input2.put("b", valueFactory.createValue("c2"), true, true);
input2.put("c", valueFactory.createValue("d"), true, true);
tracker.addService(input2);
assertMatches(aggregator, 3, input2, input1);
}
use of org.apache.jackrabbit.commons.SimpleValueFactory in project sling by apache.
the class DescriptorHelper method setDescriptor.
public static void setDescriptor(ResourceResolverFactory factory, String key, String value) throws Exception {
ResourceResolver resourceResolver = factory.getServiceResourceResolver(null);
try {
Session session = resourceResolver.adaptTo(Session.class);
if (session == null) {
return;
}
Repository repo = session.getRepository();
//<hack>
// Method setDescriptorMethod = repo.getClass().
// getDeclaredMethod("setDescriptor", String.class, String.class);
// if (setDescriptorMethod!=null) {
// setDescriptorMethod.setAccessible(true);
// setDescriptorMethod.invoke(repo, key, value);
// } else {
// fail("could not get 'setDescriptor' method");
// }
Method getDescriptorsMethod = repo.getClass().getDeclaredMethod("getDescriptors");
if (getDescriptorsMethod == null) {
fail("could not get 'getDescriptors' method");
} else {
getDescriptorsMethod.setAccessible(true);
GenericDescriptors descriptors = (GenericDescriptors) getDescriptorsMethod.invoke(repo);
SimpleValueFactory valueFactory = new SimpleValueFactory();
descriptors.put(key, valueFactory.createValue(value), true, true);
}
//</hack>
//<verify-hack>
assertEquals(value, repo.getDescriptor(key));
//</verify-hack>
} finally {
if (resourceResolver != null) {
resourceResolver.close();
}
}
}
use of org.apache.jackrabbit.commons.SimpleValueFactory in project jackrabbit-oak by apache.
the class ContentRepositoryImpl method createDescriptors.
@SuppressWarnings("deprecation")
@Nonnull
protected GenericDescriptors createDescriptors() {
final ValueFactory valueFactory = new SimpleValueFactory();
final Value trueValue = valueFactory.createValue(true);
final Value falseValue = valueFactory.createValue(false);
GenericDescriptors gd = new GenericDescriptors(baseDescriptors).put(IDENTIFIER_STABILITY, valueFactory.createValue(Repository.IDENTIFIER_STABILITY_METHOD_DURATION), true, true).put(LEVEL_1_SUPPORTED, trueValue, true, true).put(LEVEL_2_SUPPORTED, trueValue, true, true).put(OPTION_NODE_TYPE_MANAGEMENT_SUPPORTED, trueValue, true, true).put(NODE_TYPE_MANAGEMENT_AUTOCREATED_DEFINITIONS_SUPPORTED, trueValue, true, true).put(NODE_TYPE_MANAGEMENT_INHERITANCE, valueFactory.createValue(NODE_TYPE_MANAGEMENT_INHERITANCE_SINGLE), true, true).put(NODE_TYPE_MANAGEMENT_MULTIPLE_BINARY_PROPERTIES_SUPPORTED, trueValue, true, true).put(NODE_TYPE_MANAGEMENT_MULTIVALUED_PROPERTIES_SUPPORTED, trueValue, true, true).put(NODE_TYPE_MANAGEMENT_ORDERABLE_CHILD_NODES_SUPPORTED, trueValue, true, true).put(NODE_TYPE_MANAGEMENT_OVERRIDES_SUPPORTED, trueValue, true, true).put(NODE_TYPE_MANAGEMENT_PRIMARY_ITEM_NAME_SUPPORTED, trueValue, true, true).put(NODE_TYPE_MANAGEMENT_PROPERTY_TYPES, new Value[] { valueFactory.createValue(PropertyType.TYPENAME_STRING), valueFactory.createValue(PropertyType.TYPENAME_BINARY), valueFactory.createValue(PropertyType.TYPENAME_LONG), valueFactory.createValue(PropertyType.TYPENAME_LONG), valueFactory.createValue(PropertyType.TYPENAME_DOUBLE), valueFactory.createValue(PropertyType.TYPENAME_DECIMAL), valueFactory.createValue(PropertyType.TYPENAME_DATE), valueFactory.createValue(PropertyType.TYPENAME_BOOLEAN), valueFactory.createValue(PropertyType.TYPENAME_NAME), valueFactory.createValue(PropertyType.TYPENAME_PATH), valueFactory.createValue(PropertyType.TYPENAME_REFERENCE), valueFactory.createValue(PropertyType.TYPENAME_WEAKREFERENCE), valueFactory.createValue(PropertyType.TYPENAME_URI), valueFactory.createValue(PropertyType.TYPENAME_UNDEFINED) }, false, true).put(NODE_TYPE_MANAGEMENT_RESIDUAL_DEFINITIONS_SUPPORTED, trueValue, true, true).put(NODE_TYPE_MANAGEMENT_SAME_NAME_SIBLINGS_SUPPORTED, falseValue, true, true).put(NODE_TYPE_MANAGEMENT_VALUE_CONSTRAINTS_SUPPORTED, trueValue, true, true).put(NODE_TYPE_MANAGEMENT_UPDATE_IN_USE_SUPORTED, falseValue, true, true).put(OPTION_ACCESS_CONTROL_SUPPORTED, trueValue, true, true).put(OPTION_JOURNALED_OBSERVATION_SUPPORTED, falseValue, true, true).put(OPTION_LIFECYCLE_SUPPORTED, falseValue, true, true).put(OPTION_LOCKING_SUPPORTED, falseValue, true, true).put(OPTION_OBSERVATION_SUPPORTED, trueValue, true, true).put(OPTION_NODE_AND_PROPERTY_WITH_SAME_NAME_SUPPORTED, trueValue, true, true).put(OPTION_QUERY_SQL_SUPPORTED, falseValue, true, true).put(OPTION_RETENTION_SUPPORTED, falseValue, true, true).put(OPTION_SHAREABLE_NODES_SUPPORTED, falseValue, true, true).put(OPTION_SIMPLE_VERSIONING_SUPPORTED, falseValue, true, true).put(OPTION_TRANSACTIONS_SUPPORTED, falseValue, true, true).put(OPTION_UNFILED_CONTENT_SUPPORTED, falseValue, true, true).put(OPTION_UPDATE_MIXIN_NODE_TYPES_SUPPORTED, trueValue, true, true).put(OPTION_UPDATE_PRIMARY_NODE_TYPE_SUPPORTED, trueValue, true, true).put(OPTION_VERSIONING_SUPPORTED, trueValue, true, true).put(OPTION_WORKSPACE_MANAGEMENT_SUPPORTED, falseValue, true, true).put(OPTION_XML_EXPORT_SUPPORTED, falseValue, true, true).put(OPTION_XML_IMPORT_SUPPORTED, falseValue, true, true).put(OPTION_ACTIVITIES_SUPPORTED, falseValue, true, true).put(OPTION_BASELINES_SUPPORTED, falseValue, true, true).put(QUERY_FULL_TEXT_SEARCH_SUPPORTED, falseValue, true, true).put(QUERY_JOINS, valueFactory.createValue(QUERY_JOINS_NONE), true, true).put(QUERY_LANGUAGES, new Value[0], false, true).put(QUERY_STORED_QUERIES_SUPPORTED, falseValue, true, true).put(QUERY_XPATH_DOC_ORDER, falseValue, true, true).put(QUERY_XPATH_POS_INDEX, falseValue, true, true).put(REP_NAME_DESC, valueFactory.createValue("Apache Jackrabbit Oak"), true, true).put(REP_VERSION_DESC, valueFactory.createValue(OakVersion.getVersion()), true, true).put(REP_VENDOR_DESC, valueFactory.createValue("The Apache Software Foundation"), true, true).put(REP_VENDOR_URL_DESC, valueFactory.createValue("http://www.apache.org/"), true, true).put(SPEC_NAME_DESC, valueFactory.createValue("Content Repository for Java Technology API"), true, true).put(SPEC_VERSION_DESC, valueFactory.createValue("2.0"), true, true).put(WRITE_SUPPORTED, trueValue, true, true);
// jackrabbit API specific descriptors
gd.put(JackrabbitRepository.OPTION_USER_MANAGEMENT_SUPPORTED, falseValue, true, false);
gd.put(JackrabbitRepository.OPTION_PRINCIPAL_MANAGEMENT_SUPPORTED, falseValue, true, false);
gd.put(JackrabbitRepository.OPTION_PRIVILEGE_MANAGEMENT_SUPPORTED, falseValue, true, false);
for (SecurityConfiguration sc : securityProvider.getConfigurations()) {
String name = sc.getName();
if (UserConfiguration.NAME.equals(name)) {
gd.put(JackrabbitRepository.OPTION_USER_MANAGEMENT_SUPPORTED, trueValue, true, false);
} else if (PrincipalConfiguration.NAME.equals(name)) {
gd.put(JackrabbitRepository.OPTION_PRINCIPAL_MANAGEMENT_SUPPORTED, trueValue, true, false);
} else if (PrivilegeConfiguration.NAME.equals(name)) {
gd.put(JackrabbitRepository.OPTION_PRIVILEGE_MANAGEMENT_SUPPORTED, trueValue, true, false);
}
}
return gd;
}
Aggregations