repositoryimpl.java
来自「jsr170接口的java实现。是个apache的开源项目。」· Java 代码 · 共 1,761 行 · 第 1/5 页
JAVA
1,761 行
private final Mutex xaLock = new Mutex(); /** * Update event channel, used in clustered environment. */ private UpdateEventChannel updateChannel; /** * Lock event channel, used in clustered environment. */ private LockEventChannel lockChannel; /** * Creates a new <code>WorkspaceInfo</code> based on the given * <code>config</code>. * * @param config workspace configuration */ protected WorkspaceInfo(WorkspaceConfig config) { this.config = config; idleTimestamp = 0; initialized = false; } /** * Returns the workspace name. * * @return the workspace name */ protected String getName() { return config.getName(); } /** * Returns the workspace configuration. * * @return the workspace configuration */ public WorkspaceConfig getConfig() { return config; } /** * Returns the timestamp when the workspace has become idle or zero * if the workspace is currently not idle. * * @return the timestamp when the workspace has become idle or zero if * the workspace is not idle. */ long getIdleTimestamp() { return idleTimestamp; } /** * Sets the timestamp when the workspace has become idle. if * <code>ts == 0</code> the workspace is marked as being currently * active. * * @param ts timestamp when workspace has become idle. */ void setIdleTimestamp(long ts) { idleTimestamp = ts; } /** * Returns <code>true</code> if this workspace info is initialized, * otherwise returns <code>false</code>. * * @return <code>true</code> if this workspace info is initialized. */ protected boolean isInitialized() { try { if (!initLock.readLock().attempt(0)) { return false; } } catch (InterruptedException e) { return false; } // can't use 'finally' pattern here boolean ret = initialized; initLock.readLock().release(); return ret; } /** * Returns the workspace file system. * * @return the workspace file system */ FileSystem getFileSystem() { if (!isInitialized()) { throw new IllegalStateException("workspace '" + getName() + "' not initialized"); } return fs; } /** * Returns the workspace persistence manager. * * @return the workspace persistence manager * @throws RepositoryException if the persistence manager could not be * instantiated/initialized */ PersistenceManager getPersistenceManager() throws RepositoryException { if (!isInitialized()) { throw new IllegalStateException("workspace '" + getName() + "' not initialized"); } return persistMgr; } /** * Returns the workspace item state provider * * @return the workspace item state provider * @throws RepositoryException if the workspace item state provider * could not be created */ SharedItemStateManager getItemStateProvider() throws RepositoryException { if (!isInitialized()) { throw new IllegalStateException("workspace '" + getName() + "' not initialized"); } return itemStateMgr; } /** * Returns the observation dispatcher for this workspace * * @return the observation dispatcher for this workspace */ ObservationDispatcher getObservationDispatcher() { if (!isInitialized()) { throw new IllegalStateException("workspace '" + getName() + "' not initialized"); } return dispatcher; } /** * Returns the search manager for this workspace. * * @return the search manager for this workspace, or <code>null</code> * if no <code>SearchManager</code> * @throws RepositoryException if the search manager could not be created */ SearchManager getSearchManager() throws RepositoryException { if (!isInitialized()) { throw new IllegalStateException("workspace '" + getName() + "' not initialized"); } synchronized (this) { if (searchMgr == null) { if (config.getSearchConfig() == null) { // no search index configured return null; } // search manager is lazily instantiated in order to avoid // 'chicken & egg' bootstrap problems searchMgr = new SearchManager(config.getSearchConfig(), nsReg, ntReg, itemStateMgr, rootNodeId, getSystemSearchManager(getName()), SYSTEM_ROOT_NODE_ID); } return searchMgr; } } /** * Returns the lock manager for this workspace. * * @return the lock manager for this workspace * @throws RepositoryException if the lock manager could not be created */ LockManager getLockManager() throws RepositoryException { if (!isInitialized()) { throw new IllegalStateException("workspace '" + getName() + "' not initialized"); } synchronized (this) { // lock manager is lazily instantiated in order to avoid // 'chicken & egg' bootstrap problems if (lockMgr == null) { lockMgr = new LockManagerImpl(getSystemSession(), fs); if (clusterNode != null && config.isClustered()) { lockChannel = clusterNode.createLockChannel(getName()); lockMgr.setEventChannel(lockChannel); } } return lockMgr; } } /** * Returns the system session for this workspace. * * @return the system session for this workspace * @throws RepositoryException if the system session could not be created */ protected SystemSession getSystemSession() throws RepositoryException { if (!isInitialized()) { throw new IllegalStateException("workspace '" + getName() + "' not initialized"); } synchronized (this) { // system session is lazily instantiated in order to avoid // 'chicken & egg' bootstrap problems if (systemSession == null) { systemSession = SystemSession.create(RepositoryImpl.this, config); } return systemSession; } } /** * Initializes this workspace info. The following components are * initialized immediately: * <ul> * <li>file system</li> * <li>persistence manager</li> * <li>shared item state manager</li> * <li>observation manager factory</li> * </ul> * The following components are initialized lazily (i.e. on demand) * in order to save resources and to avoid 'chicken & egg' bootstrap * problems: * <ul> * <li>system session</li> * <li>lock manager</li> * <li>search manager</li> * </ul> * @return <code>true</code> if this instance has been successfully * initialized, <code>false</code> if it is already initialized. * @throws RepositoryException if an error occured during the initialization */ boolean initialize() throws RepositoryException { // check initialize status try { initLock.readLock().acquire(); } catch (InterruptedException e) { throw new RepositoryException("Unable to aquire read lock.", e); } try { if (initialized) { // already initialized, we're done return false; } } finally { initLock.readLock().release(); } // workspace info was not initialized, now check again with write lock try { initLock.writeLock().acquire(); } catch (InterruptedException e) { throw new RepositoryException("Unable to aquire write lock.", e); } try { if (initialized) { // already initialized, some other thread was quicker, we're done return false; } log.info("initializing workspace '" + getName() + "'..."); FileSystemConfig fsConfig = config.getFileSystemConfig(); fs = fsConfig.createFileSystem(); persistMgr = createPersistenceManager(new File(config.getHomeDir()), fs, config.getPersistenceManagerConfig(), rootNodeId, nsReg, ntReg); // create item state manager try { itemStateMgr = createItemStateManager(persistMgr, rootNodeId, ntReg, true, cacheFactory); try { itemStateMgr.addVirtualItemStateProvider( vMgr.getVirtualItemStateProvider()); itemStateMgr.addVirtualItemStateProvider( virtNTMgr.getVirtualItemStateProvider()); } catch (Exception e) { log.error("Unable to add vmgr: " + e.toString(), e); } if (clusterNode != null && config.isClustered()) { updateChannel = clusterNode.createUpdateChannel(getName()); itemStateMgr.setEventChannel(updateChannel); updateChannel.setListener(this); } } catch (ItemStateException ise) { String msg = "failed to instantiate shared item state manager"; log.debug(msg); throw new RepositoryException(msg, ise); } dispatcher = new ObservationDispatcher(); // register the observation factory of that workspace delegatingDispatcher.addDispatcher(dispatcher); initialized = true; log.info("workspace '" + getName() + "' initialized"); return true; } finally { initLock.writeLock().release(); } } /** * Disposes this <code>WorkspaceInfo</code> if it has been idle for more * than <code>maxIdleTime</code> milliseconds. * * @param maxIdleTime amount of time in mmilliseconds before an idle * workspace is automatically shutdown. */ void disposeIfIdle(long maxIdleTime) { try { initLock.readLock().acquire(); } catch (InterruptedException e) { return; } try { if (!initialized) { return; } long currentTS = System.currentTimeMillis(); if (idleTimestamp == 0) { // set idle timestamp idleTimestamp = currentTS; } else { if ((currentTS - idleTimestamp) > maxIdleTime) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?