repositoryimpl.java
来自「jsr170接口的java实现。是个apache的开源项目。」· Java 代码 · 共 1,761 行 · 第 1/5 页
JAVA
1,761 行
// create the workspace configuration WorkspaceConfig config = repConfig.createWorkspaceConfig(workspaceName); WorkspaceInfo info = createWorkspaceInfo(config); wspInfos.put(workspaceName, info); } } /** * Creates a workspace with the given name and given workspace configuration * template. * * @param workspaceName name of the new workspace * @param configTemplate the workspace configuration template of the new * workspace * @throws RepositoryException if a workspace with the given name already * exists or if another error occurs * @see SessionImpl#createWorkspace(String,InputSource) */ protected void createWorkspace(String workspaceName, InputSource configTemplate) throws RepositoryException { synchronized (wspInfos) { if (wspInfos.containsKey(workspaceName)) { throw new RepositoryException("workspace '" + workspaceName + "' already exists."); } // create the workspace configuration WorkspaceConfig config = repConfig.createWorkspaceConfig(workspaceName, configTemplate); WorkspaceInfo info = createWorkspaceInfo(config); wspInfos.put(workspaceName, info); } } SharedItemStateManager getWorkspaceStateManager(String workspaceName) throws NoSuchWorkspaceException, RepositoryException { // check sanity of this instance sanityCheck(); return getWorkspaceInfo(workspaceName).getItemStateProvider(); } ObservationDispatcher getObservationDispatcher(String workspaceName) throws NoSuchWorkspaceException { // check sanity of this instance sanityCheck(); return getWorkspaceInfo(workspaceName).getObservationDispatcher(); } /** * Returns the {@link SearchManager} for the workspace with name * <code>workspaceName</code>. * * @param workspaceName the name of the workspace. * @return the <code>SearchManager</code> for the workspace, or * <code>null</code> if the workspace does not have a * <code>SearchManager</code> configured. * @throws NoSuchWorkspaceException if there is no workspace with name * <code>workspaceName</code>. * @throws RepositoryException if an error occurs while opening the * search index. */ SearchManager getSearchManager(String workspaceName) throws NoSuchWorkspaceException, RepositoryException { // check sanity of this instance sanityCheck(); return getWorkspaceInfo(workspaceName).getSearchManager(); } /** * Returns the {@link LockManager} for the workspace with name * <code>workspaceName</code> * * @param workspaceName workspace name * @return <code>LockManager</code> for the workspace * @throws NoSuchWorkspaceException if such a workspace does not exist * @throws RepositoryException if some other error occurs */ LockManager getLockManager(String workspaceName) throws NoSuchWorkspaceException, RepositoryException { // check sanity of this instance sanityCheck(); return getWorkspaceInfo(workspaceName).getLockManager(); } /** * Returns the {@link SystemSession} for the workspace with name * <code>workspaceName</code> * * @param workspaceName workspace name * @return system session of the specified workspace * @throws NoSuchWorkspaceException if such a workspace does not exist * @throws RepositoryException if some other error occurs */ SystemSession getSystemSession(String workspaceName) throws NoSuchWorkspaceException, RepositoryException { // check sanity of this instance sanityCheck(); return getWorkspaceInfo(workspaceName).getSystemSession(); } /** * Creates a new repository session on the specified workspace for the * <b><i>authenticated</i></b> subject of the given login context and * adds it to the <i>active</i> sessions. * <p/> * Calls {@link #createSessionInstance(AuthContext, WorkspaceConfig)} to * create the actual <code>SessionImpl</code> instance. * * @param loginContext login context with authenticated subject * @param workspaceName workspace name * @return a new session * @throws NoSuchWorkspaceException if the specified workspace does not exist * @throws AccessDeniedException if the subject of the given login context * is not granted access to the specified * workspace * @throws RepositoryException if another error occurs */ protected final SessionImpl createSession(AuthContext loginContext, String workspaceName) throws NoSuchWorkspaceException, AccessDeniedException, RepositoryException { WorkspaceInfo wspInfo = getWorkspaceInfo(workspaceName); SessionImpl ses = createSessionInstance(loginContext, wspInfo.getConfig()); onSessionCreated(ses); // reset idle timestamp wspInfo.setIdleTimestamp(0); return ses; } /** * Creates a new repository session on the specified workspace for the given * <b><i>authenticated</i></b> subject and adds it to the <i>active</i> * sessions. * <p/> * Calls {@link #createSessionInstance(Subject, WorkspaceConfig)} to * create the actual <code>SessionImpl</code> instance. * * @param subject authenticated subject * @param workspaceName workspace name * @return a new session * @throws NoSuchWorkspaceException if the specified workspace does not exist * @throws AccessDeniedException if the subject of the given login context * is not granted access to the specified * workspace * @throws RepositoryException if another error occurs */ protected final SessionImpl createSession(Subject subject, String workspaceName) throws NoSuchWorkspaceException, AccessDeniedException, RepositoryException { WorkspaceInfo wspInfo = getWorkspaceInfo(workspaceName); SessionImpl ses = createSessionInstance(subject, wspInfo.getConfig()); onSessionCreated(ses); // reset idle timestamp wspInfo.setIdleTimestamp(0); return ses; } /** * Adds the given session to the list of active sessions and registers this * repository as listener. * * @param session the session to register */ protected void onSessionCreated(SessionImpl session) { synchronized (activeSessions) { session.addListener(this); activeSessions.put(session, session); } } //-------------------------------------------------< JackrabbitRepository > /** * Shuts down this repository. The shutdown is guarded by a shutdown lock * that prevents any new sessions from being started simultaneously. */ public void shutdown() { try { shutdownLock.writeLock().acquire(); } catch (InterruptedException e) { // TODO: Should this be a checked exception? throw new RuntimeException("Shutdown lock could not be acquired", e); } try { // check status of this instance if (!disposed) { doShutdown(); } } finally { shutdownLock.writeLock().release(); } } /** * Private method that performs the actual shutdown after the shutdown * lock has been acquired by the {@link #shutdown()} method. */ private synchronized void doShutdown() { log.info("Shutting down repository..."); // stop optional cluster node if (clusterNode != null) { clusterNode.stop(); } // close active user sessions // (copy sessions to array to avoid ConcurrentModificationException; // manually copy entries rather than calling ReferenceMap#toArray() in // order to work around http://issues.apache.org/bugzilla/show_bug.cgi?id=25551) SessionImpl[] sa; synchronized (activeSessions) { int cnt = 0; sa = new SessionImpl[activeSessions.size()]; for (Iterator it = activeSessions.values().iterator(); it.hasNext(); cnt++) { sa[cnt] = (SessionImpl) it.next(); } } for (int i = 0; i < sa.length; i++) { if (sa[i] != null) { sa[i].logout(); } } // shutdown system search manager if there is one if (systemSearchMgr != null) { systemSearchMgr.close(); } // shut down workspaces synchronized (wspInfos) { for (Iterator it = wspInfos.values().iterator(); it.hasNext();) { WorkspaceInfo wspInfo = (WorkspaceInfo) it.next(); wspInfo.dispose(); } } try { vMgr.close(); } catch (Exception e) { log.error("Error while closing Version Manager.", e); } // persist repository properties try { storeRepProps(repProps); } catch (RepositoryException e) { log.error("failed to persist repository properties", e); } try { // close repository file system repStore.close(); } catch (FileSystemException e) { log.error("error while closing repository file system", e); } // make sure this instance is not used anymore disposed = true; // wake up threads waiting on this instance's monitor (e.g. workspace janitor) notifyAll(); // finally release repository lock repLock.release(); log.info("Repository has been shutdown"); } /** * Returns the configuration of this repository. * @return repository configuration */ public RepositoryConfig getConfig() { return repConfig; } /** * Returns the repository file system. * @return repository file system */ protected FileSystem getFileSystem() { return repStore; } /** * Sets the default properties of the repository. * <p/> * This method loads the <code>Properties</code> from the * <code>org/apache/jackrabbit/core/repository.properties</code> resource * found in the class path and (re)sets the statistics properties, if not * present. * * @param props the properties object to load * * @throws RepositoryException if the properties can not be loaded */ protected void setDefaultRepositoryProperties(Properties props) throws RepositoryException { InputStream in = RepositoryImpl.class.getResourceAsStream("repository.properties"); try { props.load(in); in.close(); // set counts if (!props.containsKey(STATS_NODE_COUNT_PROPERTY)) { props.setProperty(STATS_NODE_COUNT_PROPERTY, Long.toString(nodesCount)); } if (!props.containsKey(STATS_PROP_COUNT_PROPERTY)) { props.setProperty(STATS_PROP_COUNT_PROPERTY, Long.toString(propsCount)); } } catch (IOException e) { String msg = "Failed to load repository properties: " + e.toString(); log.error(msg); throw new RepositoryException(msg, e); } } /** * Loads the repository properties by executing the following steps: * <ul> * <li> if the {@link #PROPERTIES_RESOURCE} exists in the meta data store, * the properties are loaded from that resource.</li> * <li> {@link #setDefaultRepositoryProperties(Properties)} is called * afterwards in order to initialize/update the repository properties * since some default properties might have changed and need updating.</li> * <li> finally {@link #storeRepProps(Properties)} is called in order to * persist the newly generated properties.</li> * </ul> * * @return the newly loaded/initialized repository properties * * @throws RepositoryException */ protected Properties loadRepProps() throws RepositoryException { FileSystemResource propFile = new FileSystemResource(metaDataStore, PROPERTIES_RESOURCE); try { Properties props = new Properties(); if (propFile.exists()) { InputStream in = propFile.getInputStream(); try { props.load(in); } finally { in.close(); } } // now set the default props
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?