use of org.apache.jackrabbit.core.persistence.PersistenceManager in project jackrabbit by apache.
the class RepositoryImpl method createVersionManager.
/**
* Creates the version manager.
*
* @param vConfig the versioning config
* @return the newly created version manager
* @throws RepositoryException if an error occurs
*/
protected InternalVersionManagerImpl createVersionManager(VersioningConfig vConfig, DelegatingObservationDispatcher delegatingDispatcher) throws RepositoryException {
FileSystem fs = vConfig.getFileSystem();
PersistenceManager pm = createPersistenceManager(vConfig.getHomeDir(), fs, vConfig.getPersistenceManagerConfig());
ISMLocking ismLocking = vConfig.getISMLocking();
return new InternalVersionManagerImpl(pm, fs, context.getNodeTypeRegistry(), delegatingDispatcher, SYSTEM_ROOT_NODE_ID, VERSION_STORAGE_NODE_ID, ACTIVITIES_NODE_ID, context.getItemStateCacheFactory(), ismLocking, context.getNodeIdFactory());
}
use of org.apache.jackrabbit.core.persistence.PersistenceManager in project jackrabbit by apache.
the class RepositoryImpl method createPersistenceManager.
/**
* Creates a workspace persistence manager based on the given
* configuration. The persistence manager is instantiated using
* information in the given persistence manager configuration and
* initialized with a persistence manager context containing the other
* arguments.
*
* @return the created workspace persistence manager
* @throws RepositoryException if the persistence manager could
* not be instantiated/initialized
*/
private PersistenceManager createPersistenceManager(File homeDir, FileSystem fs, PersistenceManagerConfig pmConfig) throws RepositoryException {
try {
PersistenceManager pm = pmConfig.newInstance(PersistenceManager.class);
PMContext pmContext = new PMContext(homeDir, fs, context.getRootNodeId(), context.getNamespaceRegistry(), context.getNodeTypeRegistry(), context.getDataStore(), context.getRepositoryStatistics());
pm.init(pmContext);
return pm;
} catch (Exception e) {
String msg = "Cannot instantiate persistence manager " + pmConfig.getClassName();
throw new RepositoryException(msg, e);
}
}
use of org.apache.jackrabbit.core.persistence.PersistenceManager in project jackrabbit by apache.
the class RepositoryImpl method createDataStoreGarbageCollector.
/**
* Creates a data store garbage collector for this repository.
* <p>
* Note that you should use the {@link RepositoryManager} interface
* to access this functionality. This RepositoryImpl method may be
* removed in future Jackrabbit versions.
*/
public GarbageCollector createDataStoreGarbageCollector() throws RepositoryException {
ArrayList<PersistenceManager> pmList = new ArrayList<PersistenceManager>();
InternalVersionManagerImpl vm = context.getInternalVersionManager();
PersistenceManager pm = vm.getPersistenceManager();
pmList.add(pm);
String[] wspNames = getWorkspaceNames();
SessionImpl[] sessions = new SessionImpl[wspNames.length];
for (int i = 0; i < wspNames.length; i++) {
String wspName = wspNames[i];
WorkspaceInfo wspInfo = getWorkspaceInfo(wspName);
// this will initialize the workspace if required
SessionImpl systemSession = SystemSession.create(context, wspInfo.getConfig());
// mark the workspace as 'active' so it does not get disposed by
// the workspace-janitor until the garbage collector is done
wspInfo.setActive(true);
// the workspace could be disposed, so re-initialize if required
// afterwards it will not be disposed because it was marked active
wspInfo.initialize();
sessions[i] = systemSession;
pm = wspInfo.getPersistenceManager();
pmList.add(pm);
}
IterablePersistenceManager[] ipmList = new IterablePersistenceManager[pmList.size()];
for (int i = 0; i < pmList.size(); i++) {
pm = pmList.get(i);
if (!(pm instanceof IterablePersistenceManager)) {
ipmList = null;
break;
}
ipmList[i] = (IterablePersistenceManager) pm;
}
GarbageCollector gc = new GarbageCollector(context, context.getDataStore(), ipmList, sessions);
synchronized (this) {
if (context.isGcRunning()) {
throw new RepositoryException("Cannot create GC. GC already running");
}
context.setGcRunning(true);
}
return gc;
}
use of org.apache.jackrabbit.core.persistence.PersistenceManager in project jackrabbit-oak by apache.
the class JackrabbitNodeState method createRootNodeState.
public static JackrabbitNodeState createRootNodeState(RepositoryContext context, String workspaceName, NodeState root, Map<String, String> uriToPrefix, boolean copyBinariesByReference, boolean skipOnError) throws RepositoryException {
final Map<NodeId, JackrabbitNodeState> emptyMountPoints = ImmutableMap.of();
final PersistenceManager versionPM = context.getInternalVersionManager().getPersistenceManager();
final JackrabbitNodeState versionStorage = new JackrabbitNodeState(versionPM, root, uriToPrefix, VERSION_STORAGE_NODE_ID, "/jcr:system/jcr:versionStorage", null, emptyMountPoints, copyBinariesByReference, skipOnError);
final JackrabbitNodeState activities = new JackrabbitNodeState(versionPM, root, uriToPrefix, ACTIVITIES_NODE_ID, "/jcr:system/jcr:activities", null, emptyMountPoints, copyBinariesByReference, skipOnError);
PersistenceManager pm = context.getWorkspaceInfo(workspaceName).getPersistenceManager();
final Map<NodeId, JackrabbitNodeState> mountPoints = ImmutableMap.of(VERSION_STORAGE_NODE_ID, versionStorage, ACTIVITIES_NODE_ID, activities);
return new JackrabbitNodeState(pm, root, uriToPrefix, ROOT_NODE_ID, "/", workspaceName, mountPoints, copyBinariesByReference, skipOnError);
}
use of org.apache.jackrabbit.core.persistence.PersistenceManager in project jackrabbit by apache.
the class PersistenceManagerIteratorTest method testGetAllNodeIds.
public void testGetAllNodeIds() throws Exception {
Node root = testRootNode;
Session session = root.getSession();
Repository rep = session.getRepository();
if (!(rep instanceof RepositoryImpl)) {
log("Test skipped. Required repository class: " + RepositoryImpl.class + " got: " + rep.getClass());
return;
}
RepositoryImpl r = (RepositoryImpl) rep;
RepositoryConfig conf = r.getConfig();
Collection<WorkspaceConfig> coll = conf.getWorkspaceConfigs();
String[] names = new String[coll.size()];
Iterator<WorkspaceConfig> wspIt = coll.iterator();
for (int i = 0; wspIt.hasNext(); i++) {
WorkspaceConfig wsc = wspIt.next();
names[i] = wsc.getName();
}
for (int i = 0; i < names.length && i < 1; i++) {
Session s = getHelper().getSuperuserSession(names[i]);
try {
Method m = r.getClass().getDeclaredMethod("getWorkspaceInfo", new Class[] { String.class });
m.setAccessible(true);
Object info = m.invoke(r, names[i]);
m = info.getClass().getDeclaredMethod("getPersistenceManager", new Class[0]);
m.setAccessible(true);
PersistenceManager pm = (PersistenceManager) m.invoke(info, new Object[0]);
if (!(pm instanceof AbstractBundlePersistenceManager)) {
log("PM skipped: " + pm.getClass());
continue;
}
AbstractBundlePersistenceManager apm = (AbstractBundlePersistenceManager) pm;
log("PM: " + pm.getClass().getName());
log("All nodes in one step");
NodeId after = null;
NodeId first = null;
for (NodeId id : apm.getAllNodeIds(null, 0)) {
log(" " + id);
if (first == null) {
// initialize first node id
first = id;
}
if (after != null) {
assertFalse(id.compareTo(after) == 0);
}
after = id;
}
// start with first
after = first;
log("All nodes using batches");
while (true) {
log(" bigger than: " + after);
Iterator<NodeId> it = apm.getAllNodeIds(after, 2).iterator();
if (!it.hasNext()) {
break;
}
while (it.hasNext()) {
NodeId id = it.next();
log(" " + id);
assertFalse(id.compareTo(after) == 0);
after = id;
}
}
log("Random access");
for (int j = 0; j < 50; j++) {
after = NodeId.randomId();
log(" bigger than: " + after);
for (NodeId id : apm.getAllNodeIds(after, 2)) {
log(" " + id);
assertFalse(id.compareTo(after) == 0);
after = id;
}
}
} finally {
s.logout();
}
}
}
Aggregations