summaryrefslogtreecommitdiffstats
path: root/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java
diff options
context:
space:
mode:
authorAde Lee <alee@redhat.com>2012-01-11 12:57:53 -0500
committerAde Lee <alee@redhat.com>2012-01-11 13:49:04 -0500
commit10cfe7756e967ac91c66d33b392aeab9cf3780fb (patch)
treed5ac9b58442265d2ce5ef60e31f041ddacba1b4f /pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java
parentedcb24f65cc3700e75d0a1d14dc2483f210b0ee4 (diff)
downloadpki-10cfe7756e967ac91c66d33b392aeab9cf3780fb.tar.gz
pki-10cfe7756e967ac91c66d33b392aeab9cf3780fb.tar.xz
pki-10cfe7756e967ac91c66d33b392aeab9cf3780fb.zip
Formatting (no line wrap in comments or code)
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.java199
1 files changed, 105 insertions, 94 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 b748f23bb..b1b4fb04f 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,12 @@ 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 {
+ extends ARequestQueue
+ implements IRequestMod {
// ARequestQueue.newRequestId
protected RequestId newRequestId()
- throws EBaseException {
+ throws EBaseException {
// get the next request Id
BigInteger next = mRepository.getNextSerialNumber();
@@ -63,7 +61,7 @@ public class RequestQueue
// String name = Schema.LDAP_ATTR_REQUEST_ID + "=" +
String name = "cn" + "=" +
- id + "," + mBaseDN;
+ id + "," + mBaseDN;
Object obj = null;
IDBSSession dbs = null;
@@ -71,19 +69,21 @@ 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;
@@ -107,20 +107,21 @@ public class RequestQueue
// compute the name of the object
// String name = Schema.LDAP_ATTR_REQUEST_ID + "=" +
String name = "cn" + "=" +
- record.mRequestId + "," + mBaseDN;
+ 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) {
}
@@ -170,19 +171,20 @@ public class RequestQueue
// String name = Schema.LDAP_ATTR_REQUEST_ID + "=" +
String name = "cn" + "=" +
- r.getRequestId() + "," + mBaseDN;
+ 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 +220,30 @@ 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)
- {
+ 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)
- {
+ 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");
+ ListEnumeration recList = (ListEnumeration) getPagedRequestsByFilter(fromId, filter, 5 * -1, "requestId");
int size = recList.getSize();
@@ -272,33 +270,29 @@ 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"));
@@ -311,12 +305,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 +320,7 @@ public class RequestQueue
/**
* Implements IRequestQueue.findRequestsBySourceId
* <p>
+ *
* @see com.netscape.certsrv.request.IRequestQueue#findRequestsBySourceId
*/
public IRequestList findRequestsBySourceId(String id) {
@@ -343,13 +340,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 +362,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 +390,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 +414,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,14 +423,16 @@ 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);
}
@@ -446,13 +451,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 +480,20 @@ public class RequestQueue
dbs = mDB.createSession();
results = dbs.search(mBaseDN, f1);
- } catch (EBaseException e) {
+ } 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);
}
@@ -500,19 +509,19 @@ public class RequestQueue
* Implements IRequestQueue.getPagedRequestsByFilter
*/
public IRequestVirtualList
- getPagedRequestsByFilter(String filter, int pageSize, String sortKey) {
+ 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);
+ 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) {
+ getPagedRequestsByFilter(RequestId from, boolean jumpToEnd, String filter, int pageSize,
+ String sortKey) {
IDBVirtualList results = null;
IDBSSession dbs = null;
@@ -525,24 +534,24 @@ public class RequestQueue
try {
if (from == null) {
- results = dbs.createVirtualList(mBaseDN, filter, (String[]) null,
+ 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,
+ results = dbs.createVirtualList(mBaseDN, filter, (String[]) null,
internalRequestId, sortKey, pageSize);
}
} catch (EBaseException e) {
@@ -565,14 +574,14 @@ public class RequestQueue
}
public RequestQueue(String name, int increment, IPolicy p, IService s, INotify n,
- INotify pendingNotify)
- throws EBaseException {
+ 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);
}
@@ -592,7 +601,7 @@ public class RequestQueue
/*
* return request repository
- */
+ */
public IRepository getRequestRepository() {
return (IRepository) mRepository;
}
@@ -610,15 +619,15 @@ public class RequestQueue
protected RequestRepository mRepository;
}
-
class SearchEnumeration
- implements IRequestList {
+ 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 +656,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 +665,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 +675,13 @@ class SearchEnumeration
protected RequestQueue mQueue;
}
-
class ListEnumeration
- implements IRequestVirtualList {
+ 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 +703,7 @@ class ListEnumeration
return mList.getSizeAfterJumpTo();
}
+
ListEnumeration(RequestQueue queue, IDBVirtualList list) {
mQueue = queue;
mList = list;