| | |
| | | |
| | | |
| | | |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.CopyOnWriteArrayList; |
| | | import java.util.List; |
| | | import java.util.ArrayList; |
| | | import java.lang.reflect.Method; |
| | |
| | | |
| | | // The set of error loggers that have been registered with the server. It |
| | | // will initially be empty. |
| | | private static ConcurrentHashMap<DN, ErrorLogPublisher> errorPublishers = |
| | | new ConcurrentHashMap<DN, ErrorLogPublisher>(); |
| | | private static CopyOnWriteArrayList<ErrorLogPublisher> errorPublishers = |
| | | new CopyOnWriteArrayList<ErrorLogPublisher>(); |
| | | |
| | | // The singleton instance of this class for configuration purposes. |
| | | private static final ErrorLogger instance = new ErrorLogger(); |
| | |
| | | /** |
| | | * Add an error log publisher to the error logger. |
| | | * |
| | | * @param dn The DN of the configuration entry for the publisher. |
| | | * @param publisher The error log publisher to add. |
| | | */ |
| | | public synchronized static void addErrorLogPublisher(DN dn, |
| | | ErrorLogPublisher publisher) |
| | | public synchronized static void addErrorLogPublisher( |
| | | ErrorLogPublisher publisher) |
| | | { |
| | | errorPublishers.put(dn, publisher); |
| | | errorPublishers.add(publisher); |
| | | } |
| | | |
| | | /** |
| | | * Remove an error log publisher from the error logger. |
| | | * |
| | | * @param dn The DN of the publisher to remove. |
| | | * @return The publisher that was removed or null if it was not found. |
| | | * @param publisher The error log publisher to remove. |
| | | * @return True if the error log publisher is removed or false otherwise. |
| | | */ |
| | | public synchronized static ErrorLogPublisher removeErrorLogPublisher(DN dn) |
| | | public synchronized static boolean removeErrorLogPublisher( |
| | | ErrorLogPublisher publisher) |
| | | { |
| | | ErrorLogPublisher errorLogPublisher = errorPublishers.remove(dn); |
| | | if(errorLogPublisher != null) |
| | | boolean removed = errorPublishers.remove(publisher); |
| | | |
| | | if(removed) |
| | | { |
| | | errorLogPublisher.close(); |
| | | publisher.close(); |
| | | } |
| | | |
| | | return errorLogPublisher; |
| | | return removed; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public synchronized static void removeAllErrorLogPublishers() |
| | | { |
| | | for(ErrorLogPublisher publisher : errorPublishers.values()) |
| | | for(ErrorLogPublisher publisher : errorPublishers) |
| | | { |
| | | publisher.close(); |
| | | } |
| | |
| | | { |
| | | ErrorLogPublisher errorLogPublisher = getErrorPublisher(config); |
| | | |
| | | addErrorLogPublisher(config.dn(), errorLogPublisher); |
| | | addErrorLogPublisher(errorLogPublisher); |
| | | } |
| | | } |
| | | } |
| | |
| | | { |
| | | ErrorLogPublisher errorLogPublisher = getErrorPublisher(config); |
| | | |
| | | addErrorLogPublisher(config.dn(), errorLogPublisher); |
| | | addErrorLogPublisher(errorLogPublisher); |
| | | } |
| | | catch(ConfigException e) |
| | | { |
| | |
| | | ArrayList<String> messages = new ArrayList<String>(); |
| | | |
| | | DN dn = config.dn(); |
| | | ErrorLogPublisher errorLogPublisher = errorPublishers.get(dn); |
| | | |
| | | ErrorLogPublisher errorLogPublisher = null; |
| | | for(ErrorLogPublisher publisher : errorPublishers) |
| | | { |
| | | if(publisher.getDN().equals(dn)) |
| | | { |
| | | errorLogPublisher = publisher; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if(errorLogPublisher == null) |
| | | { |
| | |
| | | else |
| | | { |
| | | // The publisher is being disabled so shut down and remove. |
| | | removeErrorLogPublisher(config.dn()); |
| | | removeErrorLogPublisher(errorLogPublisher); |
| | | } |
| | | } |
| | | |
| | |
| | | List<String> unacceptableReasons) |
| | | { |
| | | DN dn = config.dn(); |
| | | ErrorLogPublisher errorLogPublisher = errorPublishers.get(dn); |
| | | return errorLogPublisher != null; |
| | | |
| | | ErrorLogPublisher errorLogPublisher = null; |
| | | for(ErrorLogPublisher publisher : errorPublishers) |
| | | { |
| | | if(publisher.getDN().equals(dn)) |
| | | { |
| | | errorLogPublisher = publisher; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | return errorLogPublisher != null; |
| | | } |
| | | |
| | | /** |
| | |
| | | ResultCode resultCode = ResultCode.SUCCESS; |
| | | boolean adminActionRequired = false; |
| | | |
| | | removeErrorLogPublisher(config.dn()); |
| | | ErrorLogPublisher errorLogPublisher = null; |
| | | for(ErrorLogPublisher publisher : errorPublishers) |
| | | { |
| | | if(publisher.getDN().equals(config.dn())) |
| | | { |
| | | errorLogPublisher = publisher; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if(errorLogPublisher != null) |
| | | { |
| | | removeErrorLogPublisher(errorLogPublisher); |
| | | } |
| | | else |
| | | { |
| | | resultCode = ResultCode.NO_SUCH_OBJECT; |
| | | } |
| | | |
| | | return new ConfigChangeResult(resultCode, adminActionRequired); |
| | | } |
| | |
| | | { |
| | | String message = MessageHandler.getMessage(errorID); |
| | | |
| | | for (ErrorLogPublisher publisher : errorPublishers.values()) |
| | | for (ErrorLogPublisher publisher : errorPublishers) |
| | | { |
| | | publisher.logError(category, severity, message, errorID); |
| | | } |
| | |
| | | { |
| | | String message = MessageHandler.getMessage(errorID, args); |
| | | |
| | | for (ErrorLogPublisher publisher : errorPublishers.values()) |
| | | for (ErrorLogPublisher publisher : errorPublishers) |
| | | { |
| | | publisher.logError(category, severity, message, errorID); |
| | | } |
| | |
| | | ErrorLogSeverity severity, String message, |
| | | int errorID) |
| | | { |
| | | for (ErrorLogPublisher publisher : errorPublishers.values()) |
| | | for (ErrorLogPublisher publisher : errorPublishers) |
| | | { |
| | | publisher.logError(category, severity, message, errorID); |
| | | } |