| | |
| | | */ |
| | | private Map<Short, DbHandler> sourceDbHandlers = |
| | | new ConcurrentHashMap<Short, DbHandler>(); |
| | | private Changelog changelog; |
| | | |
| | | /** |
| | | * Creates a new ChangelogCache associated to the DN baseDn. |
| | | * |
| | | * @param baseDn The baseDn associated to the ChangelogCache. |
| | | * @param changelog the Changelog that created this changelog cache. |
| | | */ |
| | | public ChangelogCache(DN baseDn) |
| | | public ChangelogCache(DN baseDn, Changelog changelog) |
| | | { |
| | | this.baseDn = baseDn; |
| | | this.changelog = changelog; |
| | | } |
| | | |
| | | /** |
| | |
| | | { |
| | | try |
| | | { |
| | | dbHandler = new DbHandler(id, baseDn); |
| | | dbHandler = changelog.newDbHandler(id, baseDn); |
| | | } catch (DatabaseException e) |
| | | { |
| | | /* |
| | |
| | | * from at least one LDAP server. |
| | | * This changelog therefore can't do it's job properly anymore |
| | | * and needs to close all its connections and shutdown itself. |
| | | * TODO : log error |
| | | */ |
| | | int msgID = MSGID_CHANGELOG_SHUTDOWN_DATABASE_ERROR; |
| | | String message = getMessage(msgID) + stackTraceToSingleLineString(e); |
| | | logError(ErrorLogCategory.SYNCHRONIZATION, |
| | | ErrorLogSeverity.SEVERE_ERROR, |
| | | message, msgID); |
| | | Changelog.shutdown(); |
| | | changelog.shutdown(); |
| | | return; |
| | | } |
| | | sourceDbHandlers.put(id, dbHandler); |
| | |
| | | /** |
| | | * creates a new ChangelogDB with specified identifier. |
| | | * @param id the identifier of the new ChangelogDB. |
| | | * @param baseDn the baseDn of the new ChangelogDB. |
| | | * @param db the new db. |
| | | * |
| | | * @throws DatabaseException If a database error happened. |
| | | */ |
| | | public void newDb(short id, DN baseDn) throws DatabaseException |
| | | public void newDb(short id, DbHandler db) throws DatabaseException |
| | | { |
| | | synchronized (sourceDbHandlers) |
| | | { |
| | | sourceDbHandlers.put(id , new DbHandler(id, baseDn)); |
| | | sourceDbHandlers.put(id , db); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | public void ack(AckMessage message, short fromServerId) |
| | | { |
| | | /* |
| | | * there are 2 possible cases here : |
| | | * - the message that was acked comes from a server to which |
| | | * we are directly connected. |
| | | * In this case, we can find the handler from the connectedServers map |
| | | * - the message that was acked comes from a server to which we are not |
| | | * connected. |
| | | * In this case we need to find the changelog server that forwarded |
| | | * the change and send back the ack to this server. |
| | | */ |
| | | ServerHandler handler = connectedServers.get( |
| | | message.getChangeNumber().getServerId()); |
| | | if (handler != null) |
| | |
| | | { |
| | | return "ChangelogCache " + baseDn; |
| | | } |
| | | |
| | | |
| | | } |