versionmanagerimpl.java
来自「jsr170接口的java实现。是个apache的开源项目。」· Java 代码 · 共 575 行 · 第 1/2 页
JAVA
575 行
return checkin((InternalVersionHistoryImpl) getVersionHistory(NodeId.valueOf(histUUID)), node); } }); return (VersionImpl) ((SessionImpl) node.getSession()).getNodeById(version.getId()); } /** * {@inheritDoc} * <p/> * This method must not be synchronized since it could cause deadlocks with * item-reading listeners in the observation thread. */ public void removeVersion(VersionHistory history, final QName name) throws VersionException, RepositoryException { final VersionHistoryImpl historyImpl = (VersionHistoryImpl) history; if (!historyImpl.hasNode(name)) { throw new VersionException("Version with name " + name.toString() + " does not exist in this VersionHistory"); } escFactory.doSourced((SessionImpl) history.getSession(), new SourcedTarget(){ public Object run() throws RepositoryException { InternalVersionHistoryImpl vh = (InternalVersionHistoryImpl) historyImpl.getInternalVersionHistory(); removeVersion(vh, name); return null; } }); } /** * {@inheritDoc} * <p/> * This method must not be synchronized since it could cause deadlocks with * item-reading listeners in the observation thread. */ public Version setVersionLabel(final VersionHistory history, final QName version, final QName label, final boolean move) throws RepositoryException { InternalVersion v = (InternalVersion) escFactory.doSourced((SessionImpl) history.getSession(), new SourcedTarget(){ public Object run() throws RepositoryException { InternalVersionHistoryImpl vh = (InternalVersionHistoryImpl) ((VersionHistoryImpl) history).getInternalVersionHistory(); return setVersionLabel(vh, version, label, move); } }); if (v == null) { return null; } else { return (Version) ((SessionImpl) history.getSession()).getNodeByUUID(v.getId().getUUID()); } } /** * Invoked by some external source to indicate that some items in the * versions tree were updated. Version histories are reloaded if possible. * Matching items are removed from the cache. * * @param items items updated */ public void itemsUpdated(Collection items) { acquireReadLock(); try { synchronized (versionItems) { Iterator iter = items.iterator(); while (iter.hasNext()) { InternalVersionItem item = (InternalVersionItem) iter.next(); InternalVersionItem cached = (InternalVersionItem) versionItems.remove(item.getId()); if (cached != null) { if (cached instanceof InternalVersionHistoryImpl) { InternalVersionHistoryImpl vh = (InternalVersionHistoryImpl) cached; try { vh.reload(); versionItems.put(vh.getId(), vh); } catch (RepositoryException e) { log.warn("Unable to update version history: " + e.toString()); } } } } } } finally { releaseReadLock(); } } /** * Set an event channel to inform about updates. * * @param eventChannel event channel */ public void setEventChannel(UpdateEventChannel eventChannel) { sharedStateMgr.setEventChannel(eventChannel); eventChannel.setListener(this); } /** * {@inheritDoc} */ protected void itemDiscarded(InternalVersionItem item) { // evict removed item from cache acquireReadLock(); try { versionItems.remove(item.getId()); } finally { releaseReadLock(); } } /** * {@inheritDoc} */ protected List getItemReferences(InternalVersionItem item) { try { NodeReferences refs = stateMgr.getNodeReferences( new NodeReferencesId(item.getId())); return refs.getReferences(); } catch (ItemStateException e) { return Collections.EMPTY_LIST; } } /** * returns the id of the version history root node * * @return the id of the version history root node */ NodeId getHistoryRootId() { return historyRoot.getState().getNodeId(); } /** * Return the shared item state manager. */ protected SharedItemStateManager getSharedStateMgr() { return sharedStateMgr; } /** * Creates a <code>VersionItemStateManager</code> or derivative. * * @param pMgr persistence manager * @param rootId root node id * @param ntReg node type registry * @param cacheFactory cache factory * @return item state manager * @throws ItemStateException if an error occurs */ protected VersionItemStateManager createItemStateManager(PersistenceManager pMgr, NodeId rootId, NodeTypeRegistry ntReg, ItemStateCacheFactory cacheFactory) throws ItemStateException { return new VersionItemStateManager(pMgr, rootId, ntReg, cacheFactory); } /** * {@inheritDoc} * <p/> * Not used. */ public void stateCreated(ItemState created) {} /** * {@inheritDoc} * <p/> * Not used. */ public void stateModified(ItemState modified) {} /** * {@inheritDoc} * <p/> * Remove item from cache on removal. */ public void stateDestroyed(ItemState destroyed) { // evict removed item from cache acquireReadLock(); try { versionItems.remove(destroyed.getId()); } finally { releaseReadLock(); } } /** * {@inheritDoc} * <p/> * Not used. */ public void stateDiscarded(ItemState discarded) {} //--------------------------------------------------< UpdateEventListener > /** * {@inheritDoc} */ public void externalUpdate(ChangeLog changes, List events) throws RepositoryException { EventStateCollection esc = getEscFactory().createEventStateCollection(null); esc.addAll(events); sharedStateMgr.externalUpdate(changes, esc); } //--------------------------------------------------------< inner classes > public static final class DynamicESCFactory implements EventStateCollectionFactory { /** * the observation manager */ private DelegatingObservationDispatcher obsMgr; /** * the current event source */ private SessionImpl source; /** * Creates a new event state collection factory * @param obsMgr */ public DynamicESCFactory(DelegatingObservationDispatcher obsMgr) { this.obsMgr = obsMgr; } /** * {@inheritDoc} * <p/> * This object uses one instance of a <code>LocalItemStateManager</code> * to update data on behalf of many sessions. In order to maintain the * association between update operation and session who actually invoked * the update, an internal event source is used. */ public synchronized EventStateCollection createEventStateCollection() throws RepositoryException { if (source == null) { throw new RepositoryException("Unknown event source."); } return createEventStateCollection(source); } /** * {@inheritDoc} * <p/> * This object uses one instance of a <code>LocalItemStateManager</code> * to update data on behalf of many sessions. In order to maintain the * association between update operation and session who actually invoked * the update, an internal event source is used. */ public EventStateCollection createEventStateCollection(SessionImpl source) { return obsMgr.createEventStateCollection(source, VERSION_STORAGE_PATH); } /** * Executes the given runnable using the given event source. * * @param eventSource * @param runnable * @throws RepositoryException */ public synchronized Object doSourced(SessionImpl eventSource, SourcedTarget runnable) throws RepositoryException { this.source = eventSource; try { return runnable.run(); } finally { this.source = null; } } } private abstract class SourcedTarget { public abstract Object run() throws RepositoryException; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?