| | |
| | | */ |
| | | package org.opends.server.loggers; |
| | | |
| | | import static org.opends.server.loggers.CommonAudit.*; |
| | | import static org.opends.messages.ConfigMessages.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | |
| | | private final Arg3<Object, Object, Object> |
| | | invalidLoggerClassErrorMessage; |
| | | |
| | | ServerContext serverContext; |
| | | private ServerContext serverContext; |
| | | |
| | | /** |
| | | * The constructor for this class. |
| | |
| | | { |
| | | config.addChangeListener((ConfigurationChangeListener) this); |
| | | |
| | | if(config.isEnabled()) |
| | | if (config.isEnabled()) |
| | | { |
| | | addLogPublisher(getLogPublisher(config)); |
| | | final P logPublisher = isCommonAuditConfig(config) ? |
| | | getLogPublisherForCommonAudit(config) : getLogPublisher(config); |
| | | addLogPublisher(logPublisher); |
| | | } |
| | | } |
| | | } |
| | | |
| | | ServerContext getServerContext() |
| | | { |
| | | return serverContext; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isConfigurationAddAcceptable(C config, |
| | |
| | | { |
| | | try |
| | | { |
| | | addLogPublisher(getLogPublisher(config)); |
| | | final P logPublisher = isCommonAuditConfig(config) ? |
| | | getLogPublisherForCommonAudit(config) : getLogPublisher(config); |
| | | addLogPublisher(logPublisher); |
| | | } |
| | | catch(ConfigException e) |
| | | { |
| | |
| | | catch (Exception e) |
| | | { |
| | | LocalizedLogger.getLoggerForThisClass().traceException(e); |
| | | ccr.addMessage(ERR_CONFIG_LOGGER_CANNOT_CREATE_LOGGER.get( |
| | | config.dn(), stackTraceToSingleLineString(e))); |
| | | ccr.addMessage(ERR_CONFIG_LOGGER_CANNOT_CREATE_LOGGER.get(config.dn(), stackTraceToSingleLineString(e))); |
| | | ccr.setResultCode(DirectoryServer.getServerErrorResultCode()); |
| | | } |
| | | } |
| | |
| | | final ConfigChangeResult ccr = new ConfigChangeResult(); |
| | | |
| | | P logPublisher = findLogPublisher(config.dn()); |
| | | if(logPublisher == null) |
| | | if (logPublisher == null) |
| | | { |
| | | if(config.isEnabled()) |
| | | if (config.isEnabled()) |
| | | { |
| | | // Needs to be added and enabled. |
| | | return applyConfigurationAdd(config); |
| | |
| | | } |
| | | else |
| | | { |
| | | if(config.isEnabled()) |
| | | if (config.isEnabled()) |
| | | { |
| | | // The publisher is currently active, so we don't need to do anything. |
| | | // Changes to the class name cannot be |
| | | // applied dynamically, so if the class name did change then |
| | | // indicate that administrative action is required for that |
| | | // change to take effect. |
| | | String className = config.getJavaClass(); |
| | | if(!className.equals(logPublisher.getClass().getName())) |
| | | if (!className.equals(logPublisher.getClass().getName())) |
| | | { |
| | | ccr.setAdminActionRequired(true); |
| | | } |
| | | try |
| | | { |
| | | if (isCommonAuditConfig(config)) |
| | | { |
| | | serverContext.getCommonAudit().addOrUpdatePublisher(config); |
| | | } // else the publisher is currently active, so we don't need to do |
| | | // anything. |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | LocalizedLogger.getLoggerForThisClass().traceException(e); |
| | | ccr.addMessage(ERR_CONFIG_LOGGER_CANNOT_UPDATE_LOGGER.get(config.dn(), stackTraceToSingleLineString(e))); |
| | | ccr.setResultCode(DirectoryServer.getServerErrorResultCode()); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | // The publisher is being disabled so shut down and remove. |
| | | removeLogPublisher(logPublisher); |
| | | return applyConfigurationDelete(config); |
| | | } |
| | | } |
| | | |
| | | return ccr; |
| | | } |
| | | |
| | |
| | | return findLogPublisher(config.dn()) != null; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public ConfigChangeResult applyConfigurationDelete(C config) |
| | | { |
| | |
| | | if(logPublisher != null) |
| | | { |
| | | removeLogPublisher(logPublisher); |
| | | try |
| | | { |
| | | if (isCommonAuditConfig(config)) |
| | | { |
| | | serverContext.getCommonAudit().removePublisher(config); |
| | | } |
| | | } |
| | | catch (ConfigException e) |
| | | { |
| | | LocalizedLogger.getLoggerForThisClass().traceException(e); |
| | | ccr.addMessage(ERR_CONFIG_LOGGER_CANNOT_DELETE_LOGGER.get(config.dn(), stackTraceToSingleLineString(e))); |
| | | ccr.setResultCode(DirectoryServer.getServerErrorResultCode()); |
| | | } |
| | | } |
| | | else |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | private P getLogPublisherForCommonAudit(C config) throws InitializationException, ConfigException |
| | | { |
| | | CommonAudit commonAudit = serverContext.getCommonAudit(); |
| | | commonAudit.addOrUpdatePublisher(config); |
| | | P logPublisher = getLogPublisher(config); |
| | | CommonAuditLogPublisher publisher = (CommonAuditLogPublisher) logPublisher; |
| | | publisher.setRequestHandler(commonAudit.getRequestHandler(config)); |
| | | return logPublisher; |
| | | } |
| | | |
| | | } |