diff options
Diffstat (limited to 'pki/base/common/src/com/netscape/cmscore/request/ARequestQueue.java')
-rw-r--r-- | pki/base/common/src/com/netscape/cmscore/request/ARequestQueue.java | 271 |
1 files changed, 135 insertions, 136 deletions
diff --git a/pki/base/common/src/com/netscape/cmscore/request/ARequestQueue.java b/pki/base/common/src/com/netscape/cmscore/request/ARequestQueue.java index e7bc05f64..016e368c6 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/ARequestQueue.java +++ b/pki/base/common/src/com/netscape/cmscore/request/ARequestQueue.java @@ -17,7 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.request; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -62,31 +61,25 @@ import com.netscape.certsrv.request.PolicyResult; import com.netscape.certsrv.request.RequestId; import com.netscape.certsrv.request.RequestStatus; - /** * The ARequestQueue class is an abstract class that implements - * most portions of the IRequestQueue interface. This includes + * most portions of the IRequestQueue interface. This includes * the state engine as defined for processing IRequest objects. * <p> * !Put state machine description here! * <p> - * This class defines several abstract protected functions that - * need to be defined by the concrete implementation. In - * particular, this class does not implement the operations - * for storing requests persistantly. + * This class defines several abstract protected functions that need to be defined by the concrete implementation. In particular, this class does not implement the operations for storing requests persistantly. * <p> - * This class also provides several accessor functions for setting - * fields in the IRequest object. These functions are provided - * as an aid to saving and restoring the state in the database. + * This class also provides several accessor functions for setting fields in the IRequest object. These functions are provided as an aid to saving and restoring the state in the database. * <p> - * This class also implements the locking operations specified by - * the IRequestQueue interface. + * This class also implements the locking operations specified by the IRequestQueue interface. * <p> + * * @author thayes * @version $Revision$ $Date$ */ public abstract class ARequestQueue - implements IRequestQueue { + implements IRequestQueue { /** * global request version for tracking request changes. @@ -96,37 +89,33 @@ public abstract class ARequestQueue /** * Create a new (unique) RequestId. (abstract) * <p> - * This method must be implemented by the specialized class to - * generate a new id from data in the persistant store. This id - * is used to create a new request object. + * This method must be implemented by the specialized class to generate a new id from data in the persistant store. This id is used to create a new request object. * <p> + * * @return - * a new RequestId object. + * a new RequestId object. * @exception EBaseException - * indicates that creation of the new id could not be completed. + * indicates that creation of the new id could not be completed. * @see RequestId */ protected abstract RequestId newRequestId() - throws EBaseException; + throws EBaseException; /** * Read a request from the persistant store. (abstract) * <p> - * This function is called to create the in-memory version of - * a request object. + * This function is called to create the in-memory version of a request object. * <p> - * The implementation of this object can use the createRequest - * member function to create a new instance of an IRequest, and - * use the setRequestStatus, setCreationTime and setModificationTime - * functions to set those values. + * The implementation of this object can use the createRequest member function to create a new instance of an IRequest, and use the setRequestStatus, setCreationTime and setModificationTime functions to set those values. * <p> + * * @param id - * the id of the request to read. + * the id of the request to read. * @return - * a new IRequest object. null is returned if the object cannot - * be located. + * a new IRequest object. null is returned if the object cannot + * be located. * @exception EBaseException - * TODO: this is not implemented yet + * TODO: this is not implemented yet * @see #createRequest * @see #setRequestStatus * @see #setModificationTime @@ -137,28 +126,27 @@ public abstract class ARequestQueue /** * Add the request to the store. (abstract) * <p> - * This function is called when a new request immediately after - * creating a new request. + * This function is called when a new request immediately after creating a new request. * <p> + * * @param request - * the request to add. + * the request to add. * @exception EBaseException - * TODO: this is not implemented yet + * TODO: this is not implemented yet */ protected abstract void addRequest(IRequest request) throws EBaseException; /** * Modify the request in the store. (abstract) * <p> - * Update the persistant copy of this request with the - * current values in the object. + * Update the persistant copy of this request with the current values in the object. * <p> - * Currently there are no hints for what has changed, so - * the entire request should be updated. + * Currently there are no hints for what has changed, so the entire request should be updated. * <p> + * * @param request * @exception EBaseException - * TODO: this is not implemented yet + * TODO: this is not implemented yet */ protected abstract void modifyRequest(IRequest request); @@ -166,27 +154,24 @@ public abstract class ARequestQueue * Get complete list of RequestId values found i this * queue. * <p> - * This method can form the basis for creating other types - * of search/list operations (although there are probably more - * efficient ways of doing this. ARequestQueue implements - * default versions of some of the searching by using this - * method as a basis. + * This method can form the basis for creating other types of search/list operations (although there are probably more efficient ways of doing this. ARequestQueue implements default versions of some of the searching by using this method as a basis. * <p> - * TODO: return IRequestList -or- just use listRequests as - * the basic engine. + * TODO: return IRequestList -or- just use listRequests as the basic engine. * <p> + * * @return - * an Enumeration that generates RequestId objects. + * an Enumeration that generates RequestId objects. */ abstract protected Enumeration getRawList(); /** * protected access for setting the current state of a request. * <p> + * * @param request - * The request to be modified. + * The request to be modified. * @param status - * The new value for the request status. + * The new value for the request status. */ protected final void setRequestStatus(IRequest request, RequestStatus status) { Request r = (Request) request; @@ -197,10 +182,11 @@ public abstract class ARequestQueue /** * protected access for setting the modification time of a request. * <p> + * * @param request - * The request to be modified. + * The request to be modified. * @param date - * The new value for the time. + * The new value for the time. */ protected final void setModificationTime(IRequest request, Date date) { Request r = (Request) request; @@ -211,10 +197,11 @@ public abstract class ARequestQueue /** * protected access for setting the creation time of a request. * <p> + * * @param request - * The request to be modified. + * The request to be modified. * @param date - * The new value for the time. + * The new value for the time. */ protected final void setCreationTime(IRequest request, Date date) { Request r = (Request) request; @@ -225,11 +212,12 @@ public abstract class ARequestQueue /** * protected access for creating a new Request object * <p> + * * @param id - * The identifier for the new request + * The identifier for the new request * @return - * A new request object. The caller should fill in other data - * values from the datastore. + * A new request object. The caller should fill in other data + * values from the datastore. */ protected final IRequest createRequest(RequestId id, String requestType) { Request r; @@ -250,12 +238,13 @@ public abstract class ARequestQueue } /** - * Implements IRequestQueue.newRequest + * Implements IRequestQueue.newRequest * <p> + * * @see IRequestQueue#newRequest */ public IRequest newRequest(String requestType) - throws EBaseException { + throws EBaseException { if (requestType == null) { throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_REQUEST_TYPE", "null")); } @@ -287,16 +276,18 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.cloneRequest * <p> + * * @see IRequestQueue#cloneRequest */ - public IRequest cloneRequest(IRequest r) - throws EBaseException { + public IRequest cloneRequest(IRequest r) + throws EBaseException { // 1. check for valid state. (Are any invalid ?) RequestStatus rs = r.getRequestStatus(); - if (rs == RequestStatus.BEGIN) throw new EBaseException("Invalid Status"); + if (rs == RequestStatus.BEGIN) + throw new EBaseException("Invalid Status"); - // 2. create new request + // 2. create new request String reqType = r.getRequestType(); IRequest clone = newRequest(reqType); @@ -316,10 +307,11 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.findRequest * <p> + * * @see IRequestQueue#findRequest */ public IRequest findRequest(RequestId id) - throws EBaseException { + throws EBaseException { IRequest r; // mTable.lock(id); @@ -327,12 +319,12 @@ public abstract class ARequestQueue r = readRequest(id); // if (r == null) mTable.unlock(id); - + return r; } private IRequestScheduler mRequestScheduler = null; - + public void setRequestScheduler(IRequestScheduler scheduler) { mRequestScheduler = scheduler; } @@ -344,10 +336,11 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.processRequest * <p> + * * @see IRequestQueue#processRequest */ public final void processRequest(IRequest r) - throws EBaseException { + throws EBaseException { // #610553 Thread Scheduler IRequestScheduler scheduler = getRequestScheduler(); @@ -360,7 +353,8 @@ public abstract class ARequestQueue // 1. Check for valid state RequestStatus rs = r.getRequestStatus(); - if (rs != RequestStatus.BEGIN) throw new EBaseException("Invalid Status"); + if (rs != RequestStatus.BEGIN) + throw new EBaseException("Invalid Status"); stateEngine(r); } finally { @@ -373,19 +367,21 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.markRequestPending * <p> + * * @see IRequestQueue#markRequestPending */ public final void markRequestPending(IRequest r) - throws EBaseException { + throws EBaseException { // 1. Check for valid state RequestStatus rs = r.getRequestStatus(); - if (rs != RequestStatus.BEGIN) throw new EBaseException("Invalid Status"); + if (rs != RequestStatus.BEGIN) + throw new EBaseException("Invalid Status"); - // 2. Change the request state. This method of making - // a request PENDING does NOT invoke the PENDING notifiers. - // To change this, just call stateEngine at the completion of this - // routine. + // 2. Change the request state. This method of making + // a request PENDING does NOT invoke the PENDING notifiers. + // To change this, just call stateEngine at the completion of this + // routine. setRequestStatus(r, RequestStatus.PENDING); updateRequest(r); @@ -395,10 +391,11 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.cloneAndMarkPending * <p> + * * @see IRequestQueue#cloneAndMarkPending */ - public IRequest cloneAndMarkPending(IRequest r) - throws EBaseException { + public IRequest cloneAndMarkPending(IRequest r) + throws EBaseException { IRequest clone = cloneRequest(r); markRequestPending(clone); @@ -408,14 +405,16 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.approveRequest * <p> + * * @see IRequestQueue#approveRequest */ public final void approveRequest(IRequest r) - throws EBaseException { + throws EBaseException { // 1. Check for valid state RequestStatus rs = r.getRequestStatus(); - if (rs != RequestStatus.PENDING) throw new EBaseException("Invalid Status"); + if (rs != RequestStatus.PENDING) + throw new EBaseException("Invalid Status"); AgentApprovals aas = AgentApprovals.fromStringVector( r.getExtDataInStringVector(AgentApprovals.class.getName())); @@ -426,7 +425,8 @@ public abstract class ARequestQueue // Record agent who did this String agentName = getUserIdentity(); - if (agentName == null) throw new EBaseException("Missing agent information"); + if (agentName == null) + throw new EBaseException("Missing agent information"); aas.addApproval(agentName); r.setExtData(AgentApprovals.class.getName(), aas.toStringVector()); @@ -436,7 +436,7 @@ public abstract class ARequestQueue if (pr == PolicyResult.ACCEPTED) { setRequestStatus(r, RequestStatus.APPROVED); } else if (pr == PolicyResult.DEFERRED || - pr == PolicyResult.REJECTED) { + pr == PolicyResult.REJECTED) { } // Always update. The policy code may have made changes to the @@ -449,16 +449,18 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.rejectRequest * <p> + * * @see IRequestQueue#rejectRequest */ public final void rejectRequest(IRequest r) - throws EBaseException { + throws EBaseException { // 1. Check for valid state RequestStatus rs = r.getRequestStatus(); - if (rs != RequestStatus.PENDING) throw new EBaseException("Invalid Status"); + if (rs != RequestStatus.PENDING) + throw new EBaseException("Invalid Status"); - // 2. Change state + // 2. Change state setRequestStatus(r, RequestStatus.REJECTED); updateRequest(r); @@ -469,10 +471,11 @@ public abstract class ARequestQueue /** * Implments IRequestQueue.cancelRequest * <p> + * * @see IRequestQueue#cancelRequest */ public final void cancelRequest(IRequest r) - throws EBaseException { + throws EBaseException { setRequestStatus(r, RequestStatus.CANCELED); updateRequest(r); @@ -488,7 +491,8 @@ public abstract class ARequestQueue setRequestStatus(r, RequestStatus.COMPLETE); updateRequest(r); - if (mNotify != null) mNotify.notify(r); + if (mNotify != null) + mNotify.notify(r); return; } @@ -496,10 +500,9 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.listRequests * <p> - * Should be overridden by the specialized class if - * a more efficient method is available for implementing - * this operation. + * Should be overridden by the specialized class if a more efficient method is available for implementing this operation. * <P> + * * @see IRequestQueue#listRequests */ public IRequestList listRequests() { @@ -509,10 +512,9 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.listRequestsByStatus * <p> - * Should be overridden by the specialized class if - * a more efficient method is available for implementing - * this operation. + * Should be overridden by the specialized class if a more efficient method is available for implementing this operation. * <P> + * * @see IRequestQueue#listRequestsByStatus */ public IRequestList listRequestsByStatus(RequestStatus s) { @@ -522,6 +524,7 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.releaseRequest * <p> + * * @see IRequestQueue#releaseRequest */ public final void releaseRequest(IRequest request) { @@ -533,17 +536,18 @@ public abstract class ARequestQueue String name = getUserIdentity(); - if (name != null) r.setExtData(IRequest.UPDATED_BY, name); + if (name != null) + r.setExtData(IRequest.UPDATED_BY, name); - // TODO: use a state flag to determine whether to call - // addRequest or modifyRequest (see newRequest as well) + // TODO: use a state flag to determine whether to call + // addRequest or modifyRequest (see newRequest as well) modifyRequest(r); } // PRIVATE functions private final void stateEngine(IRequest r) - throws EBaseException { + throws EBaseException { boolean complete = false; while (!complete) { @@ -643,14 +647,14 @@ public abstract class ARequestQueue */ public void recover() { if (CMS.isRunningMode()) { - RecoverThread t = new RecoverThread(this); + RecoverThread t = new RecoverThread(this); - t.start(); + t.start(); } } /** - * recover from a crash. Resends all requests that are in + * recover from a crash. Resends all requests that are in * the APPROVED state. */ public void recoverWillBlock() { @@ -684,7 +688,7 @@ public abstract class ARequestQueue // Constructor protected ARequestQueue(IPolicy policy, IService service, INotify notify, - INotify pendingNotify) { + INotify pendingNotify) { mPolicy = policy; mService = service; mNotify = notify; @@ -704,7 +708,6 @@ public abstract class ARequestQueue protected ILogger mLogger; } - // // Table of RequestId values that are currently in use by some thread. // The fact that the request is in this table constitutes a lock @@ -735,13 +738,12 @@ public abstract class ARequestQueue } */ - // // Request - implementation of the IRequest interface. This // version is returned by ARequestQueue (and its derivatives) // class Request - implements IRequest { + implements IRequest { // IRequest.getRequestId public RequestId getRequestId() { return mRequestId; @@ -834,8 +836,8 @@ class Request while (e.hasMoreElements()) { String key = (String) e.nextElement(); if (!key.equals(IRequest.ISSUED_CERTS) && - !key.equals(IRequest.ERRORS) && - !key.equals(IRequest.REMOTE_REQID)) { + !key.equals(IRequest.ERRORS) && + !key.equals(IRequest.REMOTE_REQID)) { if (req.isSimpleExtDataValue(key)) { setExtData(key, req.getExtDataInString(key)); } else { @@ -847,15 +849,15 @@ class Request /** * This function used to check that the keys obeyed LDAP attribute name - * syntax rules. Keys are being encoded now, so it is changed to just + * syntax rules. Keys are being encoded now, so it is changed to just * filter out null and empty string keys. - * - * @param key The key to check - * @return false if invalid + * + * @param key The key to check + * @return false if invalid */ protected boolean isValidExtDataKey(String key) { return key != null && - (! key.equals("")); + (!key.equals("")); } protected boolean isValidExtDataHashtableValue(Hashtable<String, String> hash) { @@ -865,13 +867,12 @@ class Request Enumeration<String> keys = hash.keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); - if (! ((key instanceof String) && - isValidExtDataKey((String)key)) ) { + if (!((key instanceof String) && isValidExtDataKey((String) key))) { return false; } Object value = hash.get(key); - if (! (value instanceof String)) { + if (!(value instanceof String)) { return false; } } @@ -880,7 +881,7 @@ class Request } public boolean setExtData(String key, String value) { - if (! isValidExtDataKey(key)) { + if (!isValidExtDataKey(key)) { return false; } if (value == null) { @@ -892,7 +893,7 @@ class Request } public boolean setExtData(String key, Hashtable value) { - if ( !(isValidExtDataKey(key) && isValidExtDataHashtableValue(value)) ) { + if (!(isValidExtDataKey(key) && isValidExtDataHashtableValue(value))) { return false; } @@ -909,10 +910,10 @@ class Request if (value == null) { return null; } - if (! (value instanceof String)) { + if (!(value instanceof String)) { return null; } - return (String)value; + return (String) value; } public Hashtable getExtDataInHashtable(String key) { @@ -920,10 +921,10 @@ class Request if (value == null) { return null; } - if (! (value instanceof Hashtable)) { + if (!(value instanceof Hashtable)) { return null; } - return new ExtDataHashtable((Hashtable)value); + return new ExtDataHashtable((Hashtable) value); } public Enumeration getExtDataKeys() { @@ -935,7 +936,7 @@ class Request } public boolean setExtData(String key, String subkey, String value) { - if (! (isValidExtDataKey(key) && isValidExtDataKey(subkey)) ) { + if (!(isValidExtDataKey(key) && isValidExtDataKey(subkey))) { return false; } if (isSimpleExtDataValue(key)) { @@ -945,7 +946,7 @@ class Request return false; } - Hashtable existingValue = (Hashtable)mExtData.get(key); + Hashtable existingValue = (Hashtable) mExtData.get(key); if (existingValue == null) { existingValue = new ExtDataHashtable(); mExtData.put(key, existingValue); @@ -959,7 +960,7 @@ class Request if (value == null) { return null; } - return (String)value.get(subkey); + return (String) value.get(subkey); } public boolean setExtData(String key, Integer value) { @@ -1223,7 +1224,7 @@ class Request return false; } try { - stringArray = (String[])stringVector.toArray(new String[0]); + stringArray = (String[]) stringVector.toArray(new String[0]); } catch (ArrayStoreException e) { return false; } @@ -1374,7 +1375,7 @@ class Request Set arrayKeys = hashValue.keySet(); Vector listValue = new Vector(arrayKeys.size()); for (Iterator iter = arrayKeys.iterator(); iter.hasNext();) { - String arrayKey = (String)iter.next(); + String arrayKey = (String) iter.next(); try { index = Integer.parseInt(arrayKey); } catch (NumberFormatException e) { @@ -1386,7 +1387,7 @@ class Request listValue.set(index, hashValue.get(arrayKey)); } - return (String[])listValue.toArray(new String[0]); + return (String[]) listValue.toArray(new String[0]); } public IAttrSet asIAttrSet() { @@ -1425,7 +1426,7 @@ class RequestIAttrSetWrapper implements IAttrSet { public void set(String name, Object obj) throws EBaseException { try { - mRequest.setExtData(name, (String)obj); + mRequest.setExtData(name, (String) obj); } catch (ClassCastException e) { throw new EBaseException(e.toString()); } @@ -1444,21 +1445,19 @@ class RequestIAttrSetWrapper implements IAttrSet { } } - /** * Example of a specialized request class. */ class EnrollmentRequest - extends Request - implements IEnrollmentRequest { + extends Request + implements IEnrollmentRequest { EnrollmentRequest(RequestId id) { super(id); } } - class RequestListByStatus - implements IRequestList { + implements IRequestList { public boolean hasMoreElements() { return (mNext != null); } @@ -1501,14 +1500,16 @@ class RequestListByStatus mNext = null; while (mNext == null) { - if (!mEnumeration.hasMoreElements()) break; - + if (!mEnumeration.hasMoreElements()) + break; + rId = (RequestId) mEnumeration.nextElement(); try { IRequest r = mQueue.findRequest(rId); - if (r.getRequestStatus() == mStatus) mNext = rId; + if (r.getRequestStatus() == mStatus) + mNext = rId; mQueue.releaseRequest(r); } catch (Exception e) { @@ -1518,13 +1519,12 @@ class RequestListByStatus protected RequestStatus mStatus; protected IRequestQueue mQueue; - protected Enumeration mEnumeration; + protected Enumeration mEnumeration; protected RequestId mNext; } - class RequestList - implements IRequestList { + implements IRequestList { public boolean hasMoreElements() { return mEnumeration.hasMoreElements(); } @@ -1549,10 +1549,9 @@ class RequestList mEnumeration = e; } - protected Enumeration mEnumeration; + protected Enumeration mEnumeration; } - class RecoverThread extends Thread { private ARequestQueue mQ = null; |