| | |
| | | private boolean shutdown = false; |
| | | private boolean done = false; |
| | | private DirectoryThread thread = null; |
| | | private Object flushLock = new Object(); |
| | | |
| | | /** |
| | | * Creates a New dbHandler associated to a given LDAP server. |
| | |
| | | public ChangelogIterator generateIterator(ChangeNumber changeNumber) |
| | | throws DatabaseException, Exception |
| | | { |
| | | /* |
| | | * make sure to flush some changes in the database so that |
| | | * we don't create the iterator on an empty database when the |
| | | * dbHandler has just been started. |
| | | */ |
| | | flush(); |
| | | return new ChangelogIterator(serverId, db, changeNumber); |
| | | } |
| | | |
| | |
| | | while ((size < 5000 ) && (!finished)) |
| | | { |
| | | ChangeNumber changeNumber = cursor.nextChangeNumber(); |
| | | if ((changeNumber != null) && (!changeNumber.equals(lastChange)) |
| | | && (changeNumber.older(trimDate))) |
| | | if (changeNumber != null) |
| | | { |
| | | size++; |
| | | cursor.delete(); |
| | | if ((!changeNumber.equals(lastChange)) |
| | | && (changeNumber.older(trimDate))) |
| | | { |
| | | size++; |
| | | cursor.delete(); |
| | | } |
| | | else |
| | | { |
| | | firstChange = changeNumber; |
| | | finished = true; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | firstChange = changeNumber; |
| | | finished = true; |
| | | } |
| | | } |
| | | |
| | | cursor.close(); |
| | |
| | | |
| | | do |
| | | { |
| | | // get N messages to save in the DB |
| | | List<UpdateMessage> changes = getChanges(500); |
| | | synchronized(flushLock) |
| | | { |
| | | // get N messages to save in the DB |
| | | List<UpdateMessage> changes = getChanges(500); |
| | | |
| | | // if no more changes to save exit immediately. |
| | | if ((changes == null) || ((size = changes.size()) == 0)) |
| | | return; |
| | | // if no more changes to save exit immediately. |
| | | if ((changes == null) || ((size = changes.size()) == 0)) |
| | | return; |
| | | |
| | | // save the change to the stable storage. |
| | | db.addEntries(changes); |
| | | // save the change to the stable storage. |
| | | db.addEntries(changes); |
| | | |
| | | // remove the changes from the list of changes to be saved. |
| | | clear(changes.size()); |
| | | |
| | | // remove the changes from the list of changes to be saved. |
| | | clear(changes.size()); |
| | | } |
| | | } while (size >=500); |
| | | } |
| | | |
| | |
| | | attributes.add(new Attribute("changelog-database", |
| | | String.valueOf(serverId))); |
| | | attributes.add(new Attribute("base-dn", baseDn.toString())); |
| | | ChangeNumber first = getFirstChange(); |
| | | ChangeNumber last = getLastChange(); |
| | | if (first != null) |
| | | if (firstChange != null) |
| | | { |
| | | Date firstTime = new Date(first.getTime()); |
| | | Date firstTime = new Date(firstChange.getTime()); |
| | | attributes.add(new Attribute("first-change", |
| | | first.toString() + " " + firstTime.toString())); |
| | | firstChange.toString() + " " + firstTime.toString())); |
| | | } |
| | | if (last != null) |
| | | if (lastChange != null) |
| | | { |
| | | Date lastTime = new Date(last.getTime()); |
| | | Date lastTime = new Date(lastChange.getTime()); |
| | | attributes.add(new Attribute("last-change", |
| | | last.toString() + " " + lastTime.toString())); |
| | | lastChange.toString() + " " + lastTime.toString())); |
| | | } |
| | | |
| | | return attributes; |