📄 abstractworkitemstore.java
字号:
/** * Delegate works to this workitem store */ public void delegate (InFlowWorkItem wi) throws StoreException { java.security.AccessController.checkPermission (StorePermission.newStorePermission(getName(), "delegate")); log.debug ("'"+getName()+"' Received delegated WI "+ wi.getLastExpressionId()); store(wi); } public void delegateToParticipant (Subject s, InFlowWorkItem wi, String participantName) throws StoreException { // // find participant ParticipantMap pMap = openwfe.org.engine.Definitions .getParticipantMap(getContext()); Participant p = pMap.get(participantName); if (p == null) { throw new StoreException ("Cannot delegate to unknown participant '"+ participantName+"'"); } // // remove from store this.remove(s, wi.getLastExpressionId()); // // tag history wi.addHistoryItem ("subject::"+BasicPrincipal.getBasicPrincipal(s).getName(), "Delegated to participant::"+participantName); // // dispatch try { p.dispatch(wi); } catch (DispatchingException de) { throw new StoreException ("Failed to delegate to participant '"+participantName+"'", de); } } 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 ? 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. Use 'getAndLock()'"); } Subject locker = lock.getLocker(); // // is the subject the locker ? if ( ! s.equals(locker)) { throw new StoreException ("WorkItem '"+expressionId+ "' is already locked by someone else."); } // // find item final InFlowWorkItem wi = get(s, expressionId); // // do it removeWorkItem(expressionId); // // remove lock this.lockMap.remove(expressionId); log.debug(getName()+" remove() removed "+expressionId); // // notify : the headers for this participant // are not up to date anymore this.cachedHeaders = null; } } public InFlowWorkItem get (final Subject s, final FlowExpressionId expressionId) throws StoreException { //log.debug(getName()+" get() for "+expressionId); //logDebugCache(); java.security.AccessController.checkPermission (StorePermission.newStorePermission(getName(), "read")); // // is workitem cached ? InFlowWorkItem wi = (InFlowWorkItem)this.cache.get(expressionId); if (wi != null) { //log.debug // (getName()+" get() was cached : "+wi.getLastExpressionId()); return wi; } // // no, load it wi = retrieveWorkItem(s, expressionId); //log.debug // (getName()+" get() had to retrieve : "+wi.getLastExpressionId()); // // cache it this.cache.put(expressionId, wi); //log.debug // (getName()+" get() caching \n"+expressionId+ // "\n ---> \n"+wi.getLastExpressionId()); // // return it return wi; } /** * fetches and lock a workitem from the store : ticket... */ public InFlowWorkItem getAndLock (final Subject s, final FlowExpressionId expressionId) throws StoreException { log.debug(getName()+" getAndLock() for "+expressionId); //openwfe.org.Utils.debugMap(log, this.lockMap); // DEBUG java.security.AccessController.checkPermission (StorePermission.newStorePermission(getName(), "write")); synchronized (this) // check impact on perf { // // get item final InFlowWorkItem wi = get(s, expressionId); //log.debug // (getName()+" getAndLock() found "+wi.getLastExpressionId()); // (caching is handled by getWorkItem) // // lock it this.lockMap.put(expressionId, new Lock(s, this.lockTimeout)); //log.debug(getName()+" getAndLock() locked "+expressionId); // // 'uncache' headers this.cachedHeaders = null; // // return it return wi; } } public void release (final Subject s, final FlowExpressionId workItemId) throws StoreException { java.security.AccessController.checkPermission (StorePermission.newStorePermission(getName(), "write")); //FlowExpressionId id = wi.getLastExpressionId(); synchronized (this) { // // find lock //Lock lock = (Lock)this.lockMap.get(id); final Lock lock = getLock(workItemId); if (lock == null) { throw new StoreException ("WorkItem is not locked. No need to release it."); } Subject locker = lock.getLocker(); if (locker == null) return; // success by default if ( ! s.equals(locker)) { throw new StoreException ("WorkItem is locked by someone else."); } // // remove lock this.lockMap.remove(workItemId); log.debug(getName()+" release() released "+workItemId); // // notify : the headers for this participant // are not up to date anymore this.cachedHeaders = null; } } /** * Returns the workitem belonging to a certain 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 = 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 headers of workitem. Younger workitems first. */ public java.util.List getHeaders (final Subject s, final int limit) throws StoreException { return getHeaders(s, limit, null); } /** * Returns headers of workitem. * You can specify the comparator first. */ public java.util.List getHeaders (final Subject s, final int limit, java.util.Comparator comparator) throws StoreException { java.security.AccessController.checkPermission (StorePermission.newStorePermission(getName(), "browse")); if (comparator == null) comparator = LastModifiedHeaderComparator.YOUNGER_FIRST; if (shouldReloadHeaders(limit, comparator)) { log.debug ("getHeaders() reloading headers"); loadHeaders(s, limit, comparator); } return this.cachedHeaders.getHeaders(); } /** * Implementing classes may override this method to have a * different headers reload rythm */ protected boolean shouldReloadHeaders (int limit, java.util.Comparator comparator) { return (this.cachedHeaders == null || //this.cachedHeaders.getLimit() < limit || ! this.cachedHeaders.getComparator().equals(comparator)); } public int countWorkItems (Subject s) throws StoreException { java.security.AccessController.checkPermission (StorePermission.newStorePermission(getName(), "browse")); return doCountWorkItems(s); } public boolean acceptsWorkItemsFor (String participantName) { log.debug ("acceptsWorkItemsFor() (store '"+getName()+ "') ? >"+participantName+"<"); for (int i=0; i<this.acceptedParticipants.length; i++) { log.debug ("acceptsWorkItemsFor() does '"+participantName+ "' matches '"+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; } 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 public void stop () throws ServiceException { super.stop(); this.unlockDaemon.cancel(); log.info("UnlockDaemon stopped."); log.info("Service '"+getName()+"' stopped."); } // // ABSTRACT METHODS protected abstract void storeWorkItem (InFlowWorkItem wi) throws StoreException; protected abstract void removeWorkItem (FlowExpressionId fei) throws StoreException; protected abstract InFlowWorkItem retrieveWorkItem (Subject s, FlowExpressionId fei) throws StoreException; protected abstract int doCountWorkItems (Subject s) throws StoreException; protected abstract java.util.List listWorkItems (Subject s, int limit) throws StoreException; // // LOCAL METHODS // // 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 + -