diff options
Diffstat (limited to 'pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java')
-rw-r--r-- | pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java | 285 |
1 files changed, 147 insertions, 138 deletions
diff --git a/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java b/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java index b748f23b..82b90636 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java +++ b/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java @@ -17,7 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.request; - import java.math.BigInteger; import java.util.Date; import java.util.Enumeration; @@ -43,13 +42,9 @@ import com.netscape.certsrv.request.ldap.IRequestMod; import com.netscape.cmscore.dbs.DBSubsystem; import com.netscape.cmscore.util.Debug; - -public class RequestQueue - extends ARequestQueue - implements IRequestMod { +public class RequestQueue extends ARequestQueue implements IRequestMod { // ARequestQueue.newRequestId - protected RequestId newRequestId() - throws EBaseException { + protected RequestId newRequestId() throws EBaseException { // get the next request Id BigInteger next = mRepository.getNextSerialNumber(); @@ -62,8 +57,7 @@ public class RequestQueue RequestRecord record; // String name = Schema.LDAP_ATTR_REQUEST_ID + "=" + - String name = "cn" + "=" + - id + "," + mBaseDN; + String name = "cn" + "=" + id + "," + mBaseDN; Object obj = null; IDBSSession dbs = null; @@ -71,29 +65,29 @@ public class RequestQueue try { dbs = mDB.createSession(); obj = dbs.read(name); - } catch (EBaseException e) { - Debug.trace("Error: " + e); + } catch (EBaseException e) { + Debug.trace("Error: " + e); Debug.printStackTrace(e); } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } } // TODO Errors!!! - if (obj == null || !(obj instanceof RequestRecord)) return null; + if (obj == null || !(obj instanceof RequestRecord)) + return null; record = (RequestRecord) obj; /* - setRequestStatus(r, record.mRequestState); - r.setSourceId(record.mSourceId); - r.setRequestOwner(record.mOwner); - record.storeAttrs(r, record.mRequestAttrs); - setModificationTime(r, record.mModifyTime); - setCreationTime(r, record.mCreateTime); + * setRequestStatus(r, record.mRequestState); + * r.setSourceId(record.mSourceId); r.setRequestOwner(record.mOwner); + * record.storeAttrs(r, record.mRequestAttrs); setModificationTime(r, + * record.mModifyTime); setCreationTime(r, record.mCreateTime); */ return makeRequest(record); } @@ -106,21 +100,21 @@ public class RequestQueue // compute the name of the object // String name = Schema.LDAP_ATTR_REQUEST_ID + "=" + - String name = "cn" + "=" + - record.mRequestId + "," + mBaseDN; + String name = "cn" + "=" + record.mRequestId + "," + mBaseDN; IDBSSession dbs = null; try { dbs = mDB.createSession(); dbs.add(name, record); - } catch (EBaseException e) { - Debug.trace("Error: " + e); + } catch (EBaseException e) { + Debug.trace("Error: " + e); Debug.printStackTrace(e); throw e; } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } @@ -150,39 +144,38 @@ public class RequestQueue } /* - // - mods.add(IRequestRecord.ATTR_REQUEST_STATE, - Modification.MOD_REPLACE, r.getRequestStatus()); - - mods.add(IRequestRecord.ATTR_SOURCE_ID, - Modification.MOD_REPLACE, r.getSourceId()); - - mods.add(IRequestRecord.ATTR_REQUEST_OWNER, - Modification.MOD_REPLACE, r.getRequestOwner()); - - mods.add(IRequestRecord.ATTR_MODIFY_TIME, - Modification.MOD_REPLACE, r.getModificationTime()); - - java.util.Hashtable ht = RequestRecord.loadAttrs(r); - mods.add(RequestRecord.ATTR_REQUEST_ATTRS, - Modification.MOD_REPLACE, ht); + * // mods.add(IRequestRecord.ATTR_REQUEST_STATE, + * Modification.MOD_REPLACE, r.getRequestStatus()); + * + * mods.add(IRequestRecord.ATTR_SOURCE_ID, Modification.MOD_REPLACE, + * r.getSourceId()); + * + * mods.add(IRequestRecord.ATTR_REQUEST_OWNER, Modification.MOD_REPLACE, + * r.getRequestOwner()); + * + * mods.add(IRequestRecord.ATTR_MODIFY_TIME, Modification.MOD_REPLACE, + * r.getModificationTime()); + * + * java.util.Hashtable ht = RequestRecord.loadAttrs(r); + * mods.add(RequestRecord.ATTR_REQUEST_ATTRS, Modification.MOD_REPLACE, + * ht); */ // String name = Schema.LDAP_ATTR_REQUEST_ID + "=" + - String name = "cn" + "=" + - r.getRequestId() + "," + mBaseDN; + String name = "cn" + "=" + r.getRequestId() + "," + mBaseDN; IDBSSession dbs = null; try { dbs = mDB.createSession(); dbs.modify(name, mods); - } catch (EBaseException e) { - Debug.trace("Error: " + e); + } catch (EBaseException e) { + Debug.trace("Error: " + e); Debug.printStackTrace(e); } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } @@ -218,34 +211,35 @@ public class RequestQueue /** * Resets serial number. */ - public void resetSerialNumber(BigInteger serial) throws EBaseException - { + public void resetSerialNumber(BigInteger serial) throws EBaseException { mRepository.resetSerialNumber(serial); } - + /** * Removes all objects with this repository. */ - public void removeAllObjects() throws EBaseException - { + public void removeAllObjects() throws EBaseException { mRepository.removeAllObjects(); } - public BigInteger getLastRequestIdInRange(BigInteger reqId_low_bound, BigInteger reqId_upper_bound) - { - CMS.debug("RequestQueue: getLastRequestId: low " + reqId_low_bound + " high " + reqId_upper_bound); - if(reqId_low_bound == null || reqId_upper_bound == null || reqId_low_bound.compareTo(reqId_upper_bound) >= 0) - { + public BigInteger getLastRequestIdInRange(BigInteger reqId_low_bound, + BigInteger reqId_upper_bound) { + CMS.debug("RequestQueue: getLastRequestId: low " + reqId_low_bound + + " high " + reqId_upper_bound); + if (reqId_low_bound == null || reqId_upper_bound == null + || reqId_low_bound.compareTo(reqId_upper_bound) >= 0) { CMS.debug("RequestQueue: getLastRequestId: bad upper and lower bound range."); return null; } - String filter = "(" + "requeststate" + "=*" + ")"; + String filter = "(" + "requeststate" + "=*" + ")"; RequestId fromId = new RequestId(reqId_upper_bound.toString(10)); - CMS.debug("RequestQueue: getLastRequestId: filter " + filter + " fromId " + fromId); - ListEnumeration recList = (ListEnumeration) getPagedRequestsByFilter(fromId,filter,5 * -1,"requestId"); + CMS.debug("RequestQueue: getLastRequestId: filter " + filter + + " fromId " + fromId); + ListEnumeration recList = (ListEnumeration) getPagedRequestsByFilter( + fromId, filter, 5 * -1, "requestId"); int size = recList.getSize(); @@ -262,7 +256,8 @@ public class RequestQueue ret = ret.add(new BigInteger("-1")); - CMS.debug("CertificateRepository:getLastCertRecordSerialNo: returning " + ret); + CMS.debug("CertificateRepository:getLastCertRecordSerialNo: returning " + + ret); return ret; } @@ -272,38 +267,38 @@ public class RequestQueue String reqId = null; - for(int i = 0; i < 5; i++) - { - curRec = recList.getElementAt(i); - - if(curRec != null) { + for (int i = 0; i < 5; i++) { + curRec = recList.getElementAt(i); - curId = curRec.getRequestId(); + if (curRec != null) { - reqId = curId.toString(); + curId = curRec.getRequestId(); - CMS.debug("RequestQueue: curReqId: " + reqId); + reqId = curId.toString(); - BigInteger curIdInt = new BigInteger(reqId); + CMS.debug("RequestQueue: curReqId: " + reqId); + BigInteger curIdInt = new BigInteger(reqId); - if( ((curIdInt.compareTo(reqId_low_bound) == 0) || (curIdInt.compareTo(reqId_low_bound) == 1) ) && - ((curIdInt.compareTo(reqId_upper_bound) == 0) || (curIdInt.compareTo(reqId_upper_bound) == -1) )) - { - CMS.debug("RequestQueue: getLastRequestId : returning value " + curIdInt); - return curIdInt; - } + if (((curIdInt.compareTo(reqId_low_bound) == 0) || (curIdInt + .compareTo(reqId_low_bound) == 1)) + && ((curIdInt.compareTo(reqId_upper_bound) == 0) || (curIdInt + .compareTo(reqId_upper_bound) == -1))) { + CMS.debug("RequestQueue: getLastRequestId : returning value " + + curIdInt); + return curIdInt; + } - } + } } - BigInteger ret = new BigInteger(reqId_low_bound.toString(10)); ret = ret.add(new BigInteger("-1")); - CMS.debug("CertificateRepository:getLastCertRecordSerialNo: returning " + ret); + CMS.debug("CertificateRepository:getLastCertRecordSerialNo: returning " + + ret); return ret; } @@ -311,12 +306,14 @@ public class RequestQueue /** * Implements IRequestQueue.findRequestBySourceId * <p> + * * @see com.netscape.certsrv.request.IRequestQueue#findRequestBySourceId */ public RequestId findRequestBySourceId(String id) { IRequestList irl = findRequestsBySourceId(id); - if (irl == null) return null; + if (irl == null) + return null; return irl.nextRequestId(); } @@ -324,6 +321,7 @@ public class RequestQueue /** * Implements IRequestQueue.findRequestsBySourceId * <p> + * * @see com.netscape.certsrv.request.IRequestQueue#findRequestsBySourceId */ public IRequestList findRequestsBySourceId(String id) { @@ -343,13 +341,15 @@ public class RequestQueue Debug.printStackTrace(e); } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } } - if (results == null || !results.hasMoreElements()) return null; + if (results == null || !results.hasMoreElements()) + return null; return new SearchEnumeration(this, results); @@ -363,18 +363,20 @@ public class RequestQueue try { dbs = mDB.createSession(); results = dbs.search(mBaseDN, "(requestId=*)"); - } catch (EBaseException e) { - Debug.trace("Error: " + e); + } catch (EBaseException e) { + Debug.trace("Error: " + e); Debug.printStackTrace(e); } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } } - if (results == null) return null; + if (results == null) + return null; return new SearchEnumeration(this, results); } @@ -389,18 +391,20 @@ public class RequestQueue try { dbs = mDB.createSession(); results = dbs.search(mBaseDN, f); - } catch (EBaseException e) { - Debug.trace("Error: " + e); + } catch (EBaseException e) { + Debug.trace("Error: " + e); Debug.printStackTrace(e); } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } } - if (results == null) return null; + if (results == null) + return null; return new SearchEnumeration(this, results); } @@ -411,7 +415,7 @@ public class RequestQueue IDBSearchResults results = null; IDBSSession dbs = null; String attrs[] = { IRequestRecord.ATTR_REQUEST_ID }; - + try { dbs = mDB.createSession(); results = dbs.search(mBaseDN, f, maxSize); @@ -420,20 +424,23 @@ public class RequestQueue Debug.printStackTrace(e); } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } } - - if (results == null) return null; - + + if (results == null) + return null; + return new SearchEnumeration(this, results); } /** */ - public IRequestList listRequestsByFilter(String f, int maxSize, int timeLimit) { + public IRequestList listRequestsByFilter(String f, int maxSize, + int timeLimit) { IDBSearchResults results = null; IDBSSession dbs = null; String attrs[] = { IRequestRecord.ATTR_REQUEST_ID }; @@ -446,13 +453,15 @@ public class RequestQueue Debug.printStackTrace(e); } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } } - if (results == null) return null; + if (results == null) + return null; return new SearchEnumeration(this, results); } @@ -473,18 +482,20 @@ public class RequestQueue dbs = mDB.createSession(); results = dbs.search(mBaseDN, f1); - } catch (EBaseException e) { - //System.err.println("Error: "+e); - //e.printStackTrace(); + } catch (EBaseException e) { + // System.err.println("Error: "+e); + // e.printStackTrace(); } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } } - if (results == null) return null; + if (results == null) + return null; return new SearchEnumeration(this, results); } @@ -499,20 +510,18 @@ public class RequestQueue /* * Implements IRequestQueue.getPagedRequestsByFilter */ - public IRequestVirtualList - getPagedRequestsByFilter(String filter, int pageSize, String sortKey) { + public IRequestVirtualList getPagedRequestsByFilter(String filter, + int pageSize, String sortKey) { return getPagedRequestsByFilter(null, filter, pageSize, sortKey); } - public IRequestVirtualList - getPagedRequestsByFilter(RequestId from, String filter, int pageSize, - String sortKey) { - return getPagedRequestsByFilter(from, false, filter, pageSize, sortKey); + public IRequestVirtualList getPagedRequestsByFilter(RequestId from, + String filter, int pageSize, String sortKey) { + return getPagedRequestsByFilter(from, false, filter, pageSize, sortKey); } - public IRequestVirtualList - getPagedRequestsByFilter(RequestId from, boolean jumpToEnd, String filter, int pageSize, - String sortKey) { + public IRequestVirtualList getPagedRequestsByFilter(RequestId from, + boolean jumpToEnd, String filter, int pageSize, String sortKey) { IDBVirtualList results = null; IDBSSession dbs = null; @@ -525,25 +534,26 @@ public class RequestQueue try { if (from == null) { - results = dbs.createVirtualList(mBaseDN, filter, (String[]) null, - sortKey, pageSize); + results = dbs.createVirtualList(mBaseDN, filter, + (String[]) null, sortKey, pageSize); } else { int len = from.toString().length(); String internalRequestId = null; if (jumpToEnd) { - internalRequestId ="99"; - } else { - if (len > 9) { - internalRequestId = Integer.toString(len) + from.toString(); + internalRequestId = "99"; } else { - internalRequestId = "0" + Integer.toString(len) + - from.toString(); + if (len > 9) { + internalRequestId = Integer.toString(len) + + from.toString(); + } else { + internalRequestId = "0" + Integer.toString(len) + + from.toString(); + } } - } - results = dbs.createVirtualList(mBaseDN, filter, (String[]) null, - internalRequestId, sortKey, pageSize); + results = dbs.createVirtualList(mBaseDN, filter, + (String[]) null, internalRequestId, sortKey, pageSize); } } catch (EBaseException e) { return null; @@ -556,7 +566,7 @@ public class RequestQueue try { results.setSortKey(sortKey); - } catch (EBaseException e) {//XXX + } catch (EBaseException e) {// XXX System.out.println(e.toString()); return null; } @@ -564,15 +574,14 @@ public class RequestQueue return new ListEnumeration(this, results); } - public RequestQueue(String name, int increment, IPolicy p, IService s, INotify n, - INotify pendingNotify) - throws EBaseException { + public RequestQueue(String name, int increment, IPolicy p, IService s, + INotify n, INotify pendingNotify) throws EBaseException { super(p, s, n, pendingNotify); mDB = DBSubsystem.getInstance(); mBaseDN = "ou=" + name + ",ou=requests," + mDB.getBaseDN(); - mRepository = new RequestRepository(name, increment, mDB,this); + mRepository = new RequestRepository(name, increment, mDB, this); } @@ -591,8 +600,8 @@ public class RequestQueue } /* - * return request repository - */ + * return request repository + */ public IRepository getRequestRepository() { return (IRepository) mRepository; } @@ -610,15 +619,14 @@ public class RequestQueue protected RequestRepository mRepository; } - -class SearchEnumeration - implements IRequestList { +class SearchEnumeration implements IRequestList { public RequestId nextRequestId() { Object obj; obj = mResults.nextElement(); - if (obj == null || !(obj instanceof RequestRecord)) return null; + if (obj == null || !(obj instanceof RequestRecord)) + return null; RequestRecord r = (RequestRecord) obj; @@ -647,7 +655,8 @@ class SearchEnumeration obj = mResults.nextElement(); - if (obj == null || !(obj instanceof RequestRecord)) return null; + if (obj == null || !(obj instanceof RequestRecord)) + return null; RequestRecord r = (RequestRecord) obj; @@ -655,7 +664,7 @@ class SearchEnumeration } public IRequest nextRequestObject() { - RequestRecord record = (RequestRecord)nextRequest(); + RequestRecord record = (RequestRecord) nextRequest(); if (record != null) return mQueue.makeRequest(record); return null; @@ -665,13 +674,12 @@ class SearchEnumeration protected RequestQueue mQueue; } - -class ListEnumeration - implements IRequestVirtualList { +class ListEnumeration implements IRequestVirtualList { public IRequest getElementAt(int i) { RequestRecord record = (RequestRecord) mList.getElementAt(i); - if (record == null) return null; + if (record == null) + return null; return mQueue.makeRequest(record); } @@ -693,6 +701,7 @@ class ListEnumeration return mList.getSizeAfterJumpTo(); } + ListEnumeration(RequestQueue queue, IDBVirtualList list) { mQueue = queue; mList = list; |