📄 simpleworkitemstore.java
字号:
wi.addHistoryItem ("subject::"+BasicPrincipal.getBasicPrincipal(s).getName(), "Delegated to participant::"+participantName); // // dispatch try { p.dispatch(wi); } catch (final DispatchingException de) { throw new StoreException ("Failed to delegate to participant '"+participantName+"'", de); } } /** * Updates a workitem in the store */ public void save (final Subject s, final InFlowWorkItem wi) throws StoreException { java.security.AccessController.checkPermission (StorePermission.newStorePermission(getName(), "write")); synchronized (this) // check impact on perf { final FlowExpressionId id = wi.getLastExpressionId(); // // is the item locked ? final Lock lock = (Lock)this.lockMap.get(id); if (lock != null) { Subject locker = lock.getLocker(); // // is the subject the locker ? if ( ! s.equals(locker)) { throw new StoreException ("WorkItem '"+id+ "' is already locked by someone else."); } } else { //log.debug("Saving a workitem that was not locked before..."); throw new StoreException ("Cannot save workitem : you have no lock on it."); } // // proceed wi.touch(); // update wi.lastModified this.putStrategy.put(wi); lock.touch(); // leave lock untouched ??? } } /** * Removes a workitem from the store */ public void remove (final Subject s, final FlowExpressionId expressionId) throws StoreException { //openwfe.org.Utils.debugMap(log, this.lockMap); // DEBUG java.security.AccessController.checkPermission (StorePermission.newStorePermission(getName(), "write")); synchronized (this) // check impact on perf { // // is the item locked ? final Lock lock = (Lock)this.lockMap.get(expressionId); if (lock == null) { throw new StoreException ("You cannot remove a workitem when there "+ "is no lock on it."); } final Subject locker = lock.getLocker(); // // is the subject the locker ? if ( ! s.equals(locker)) { throw new StoreException ("WorkItem '"+expressionId+ "' is already locked by someone else."); } // // do it this.putStrategy.remove(expressionId); // // remove lock unlock(expressionId); log.debug(getName()+" remove() removed "+expressionId); } } /** * Fetches a workitem from the store. */ public InFlowWorkItem get (final Subject s, final FlowExpressionId fei) throws StoreException { java.security.AccessController.checkPermission (StorePermission.newStorePermission(getName(), "read")); return this.getStrategy.retrieveWorkItem(s, fei); } /** * Fetches a workitem, the store will tag it as locked. */ public InFlowWorkItem getAndLock (final Subject s, final FlowExpressionId expressionId) throws StoreException { log.debug("getAndLock() from '"+getName()+"' for "+expressionId); java.security.AccessController.checkPermission (StorePermission.newStorePermission(getName(), "write")); //debugLockMap(); if (isLockedBySomeoneElse(s, expressionId)) { throw new StoreException ("WorkItem already locked by someone else"); } synchronized (this) { // // get item final InFlowWorkItem wi = get(s, expressionId); // // lock it lockWorkItem(s, expressionId); return wi; } } private void debugLockMap () { final StringBuffer sb = new StringBuffer(); synchronized (this.lockMap) { final java.util.Iterator it = this.lockMap.keySet().iterator(); while (it.hasNext()) { final FlowExpressionId id = (FlowExpressionId)it.next(); final Lock lock = (Lock)this.lockMap.get(id); sb.append(" - "); sb.append(id); sb.append(" <-- "); sb.append(openwfe.org.auth.BasicPrincipal .getBasicPrincipal(lock.getLocker()).getName()); if (it.hasNext()) sb.append("\n"); } } log.debug("debugLockMap() :\n"+sb.toString()); } /** * Releases the lock on a workitem */ public void release (final Subject s, final FlowExpressionId workItemId) throws StoreException { java.security.AccessController.checkPermission (StorePermission.newStorePermission(getName(), "write")); synchronized (this) { // // find lock final Lock lock = (Lock)this.lockMap.get(workItemId); if (lock == null) { throw new StoreException ("WorkItem is not locked. No need to release it."); } final Subject locker = lock.getLocker(); //log.debug("release() locker is "+locker); //if (locker == null) return; // success by default //if ( ! s.equals(locker)) if (isNotTheSameLocker(s, locker)) { throw new StoreException ("WorkItem is locked by someone else."); } // // remove lock unlock(workItemId); log.debug(getName()+" release() released "+workItemId); } } private boolean isNotTheSameLocker (final Subject unlocker, final Subject locker) { if (locker == null) return false; return ! locker.equals(unlocker); } /** * Returns the count of workitems found in this store. */ public int countWorkItems (final Subject s) throws StoreException { java.security.AccessController.checkPermission (StorePermission.newStorePermission(getName(), "browse")); return this.getStrategy.countWorkItems(s); } /** * Returns true if this store has been parameterized as 'default'. */ public boolean isDefaultStore () { return MapUtils.getAsBoolean(getParams(), P_DEFAULT, false); } /** * Returns the flowExpressionId instances of the workitems belonging * to the given workflow instance. */ public java.util.List findFlowInstance (final Subject s, final String workflowInstanceId) throws StoreException { log.debug("findFlowInstance()"); final int limit = 1500; final java.util.List result = new java.util.ArrayList(10); final java.util.Iterator it = this.getStrategy.listWorkItems(s, limit).iterator(); while (it.hasNext()) { final InFlowWorkItem item = (InFlowWorkItem)it.next(); final FlowExpressionId fei = item.getLastExpressionId(); if (fei.getWorkflowInstanceId().equals(workflowInstanceId)) result.add(item.getLastExpressionId()); } return result; } /** * Returns a list of headers for this store. * A header is a 'summary' of a workitem, it's built by a HeaderFactory. * For each store, a different header factory may be used, giving a * specific view on the workitems contained in the store. */ public java.util.List getHeaders (final Subject s, final int limit) throws StoreException { return getHeaders(s, limit, null); } /** * Returns a list of headers for this store, a comparator passed as * argument takes care of sorting the headers found. * A header is a 'summary' of a workitem, it's built by a HeaderFactory. * For each store, a different header factory may be used, giving a * specific view on the workitems contained in the store. */ public java.util.List getHeaders (final Subject s, final int limit, java.util.Comparator headerComparator) throws StoreException { java.security.AccessController.checkPermission (StorePermission.newStorePermission(getName(), "browse")); if (headerComparator == null) headerComparator = LastModifiedHeaderComparator.YOUNGER_FIRST; final long startTime = System.currentTimeMillis(); int capacity = limit; if (capacity < 0) capacity = 100; final java.util.List result = new java.util.ArrayList(capacity); final java.util.List items = this.getStrategy.listWorkItems(s, limit); log.debug ("getHeaders() '"+getName()+"' found "+items.size()+" workitems"); final java.util.Iterator it = items.iterator(); while (it.hasNext()) { final InFlowWorkItem wi = (InFlowWorkItem)it.next(); //log.debug("loadHeaders() Building header..."); try { final Header header = getHeaderFactory() //.buildHeader(wi, isLocked(wi.getLastExpressionId())); .buildHeader(wi, getLockerName(wi.getLastExpressionId())); result.add(header); } catch (final WorkListException wle) { throw new StoreException ("Failed to loadHeaders from store '"+getName()+"'", wle); } } //log.debug("loadHeaders() Built headers"); ((java.util.ArrayList)result).trimToSize(); // less bandwidth required java.util.Collections.sort(result, headerComparator); log.debug ("getHeaders() '"+getName()+"' took "+ (System.currentTimeMillis()-startTime)+" ms"); return result; } /** * Will return true if the given subject has a lock on the workitem * designated by its lastExpressionId. */ public boolean hasLockOn (Subject s, FlowExpressionId expressionId) { log.debug(getName()+" hasLockOn() "+expressionId); final Lock lock = (Lock)this.lockMap.get(expressionId); log.debug(getName()+" hasLockOn() found lock "+lock); if (lock == null) return false; //log.debug("hasLockOn() subject >"+s+"<"); //log.debug("hasLockOn() locker >"+lock.getLocker()+"<"); if ( ! s.equals(lock.getLocker())) return false; lock.touch(); // ensure that the dispatching (that happens next) will be ok return true; } /** * Returns true if the store accepts workitems for the given * participant. */ public boolean acceptsWorkItemsFor (final String participantName) { log.debug ("acceptsWorkItemsFor() (store '"+getName()+ "') ? >"+participantName+"<"); for (int i=0; i<this.acceptedParticipants.length; i++) { log.debug ("acceptsWorkItemsFor() does '"+participantName+ "' match '"+this.acceptedParticipants[i]+"' ?"); if (participantName.matches(this.acceptedParticipants[i])) { log.debug("acceptsWorkItemsFor() true."); return true; } log.debug("acceptsWorkItemsFor() false"); } log.debug("acceptsWorkItemsFor() no success : returning false."); return false; } /** * This method will return true if the current user/codebase has the * right to perform the given action on this store. */ public boolean checkPermission (final String action) { log.debug ("checkPermission() checking '"+getName()+ "' for permission '"+action+"'"); try { java.security.AccessController.checkPermission (StorePermission.newStorePermission(getName(), action)); } catch (final java.security.AccessControlException ace) { log.debug("checkPermission() returning false : permission denied"); //log.debug("checkPermission() returning false", ace); return false; } log.debug("checkPermission() returning true"); return true; } // // METHODS from Service /** * Stops this store (takes especially care of stopping the unlock daemon). */ public void stop () throws ServiceException { super.stop(); this.unlockDaemon.cancel(); log.info("stop() UnlockDaemon stopped."); log.info("stop() Service '"+getName()+"' stopped."); } // // STATIC METHODS // // copied from openwfe.org.worklist.impl.AbstractWorkItemStore : // // Tue Oct 29 09:01:21 CET 2002 // je suis dans un wagon restaurant 'Blaise Cendrars'. Est-ce // l'unique wagon-restaurant d閐i
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -