/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2008 Sun Microsystems, Inc.
*/
/**
* This class provides some common tools to all entry cache implementations.
*/
public class EntryCacheCommon
{
/**
* Configuration phases. Each value identifies a configuration step:
* - PHASE_INIT when invoking method initializeEntryCache()
* - PHASE_ACCEPTABLE when invoking method isConfigurationChangeAcceptable()
* - PHASE_APPLY when invoking method applyConfigurationChange()
*/
public static enum ConfigPhase
{
/**
* Indicates that entry cache is in initialization check phase.
*/
/**
* Indicates that entry cache is in configuration check phase.
*/
/**
* Indicates that entry cache is applying its configuration.
*/
}
/**
* Error handler used by local methods to report configuration error.
* The error handler simplifies the code of initializeEntryCache(),
* isConfigurationChangeAcceptable() and applyConfigurationChanges() methods.
*/
public class ConfigErrorHandler
{
// Configuration phase.
// Unacceptable reasons. Used when _configPhase is PHASE_ACCEPTABLE.
// Error messages. Used when _configPhase is PHASE_APPLY.
// Result code. Used when _configPhase is PHASE_APPLY.
// Acceptable Configuration ? Used when _configPhase is PHASE_ACCEPTABLE
// or PHASE_APPLY.
private boolean _isAcceptable;
// Indicates whether administrative action is required or not. Used when
// _configPhase is PHASE_APPLY.
private boolean _isAdminActionRequired;
/**
* Create an error handler.
*
* @param configPhase the configuration phase for which the
* error handler is used
* @param unacceptableReasons the reasons why the configuration cannot
* be applied (during PHASE_ACCEPTABLE phase)
* @param errorMessages the errors found when applying a new
* configuration (during PHASE_APPLY phase)
*/
public ConfigErrorHandler (
)
{
_isAcceptable = true;
_isAdminActionRequired = false;
}
/**
* Report an error.
*
* @param error the error to report
* @param isAcceptable <code>true</code> if the configuration is acceptable
* @param resultCode the change result for the current configuration
*/
public void reportError(
boolean isAcceptable,
)
{
switch (_configPhase)
{
case PHASE_INIT:
{
break;
}
case PHASE_ACCEPTABLE:
{
break;
}
case PHASE_APPLY:
{
{
}
break;
}
}
}
/**
* Report an error.
*
* @param error the error to report
* @param isAcceptable <code>true</code> if the configuration is acceptable
* @param resultCode the change result for the current configuration
* @param isAdminActionRequired <code>true</code> if administrative action
* is required or <code>false</code> otherwise
*/
public void reportError(
boolean isAcceptable,
boolean isAdminActionRequired
)
{
switch (_configPhase)
{
case PHASE_INIT:
{
break;
}
case PHASE_ACCEPTABLE:
{
break;
}
case PHASE_APPLY:
{
{
}
break;
}
}
}
/**
* Get the current result code that was elaborated right after a
* configuration has been applied.
*
* @return the current result code
*/
{
return _resultCode;
}
/**
* Get the current isAcceptable flag. The isAcceptable flag is elaborated
* right after the configuration was checked.
*
* @return the isAcceptable flag
*/
public boolean getIsAcceptable()
{
return _isAcceptable;
}
/**
* Get the current unacceptable reasons. The unacceptable reasons are
* elaborated when the configuration is checked.
*
* @return the list of unacceptable reasons
*/
{
return _unacceptableReasons;
}
/**
* Get the current error messages. The error messages are elaborated
* when the configuration is applied.
*
* @return the list of error messages
*/
{
return _errorMessages;
}
/**
* Get the current configuration phase. The configuration phase indicates
* whether the entry cache is in initialization step, or in configuration
* checking step or in configuration being applied step.
*
* @return the current configuration phase.
*/
{
return _configPhase;
}
/**
* Get the current isAdminActionRequired flag as determined after apply
* action has been taken on a given configuration.
*
* @return the isAdminActionRequired flag
*/
public boolean getIsAdminActionRequired()
{
return _isAdminActionRequired;
}
} // ConfigErrorHandler
/**
* Reads a list of string filters and convert it to a list of search
* filters.
*
* @param filters the list of string filter to convert to search filters
* @param decodeErrorMsg the error message ID to use in case of error
* @param errorHandler error handler to report filter decoding errors on
* @param configEntryDN the entry cache configuration DN
*
* @return the set of search filters
*/
)
{
// Returned value
// Convert the string filters to search filters.
{
{
try
{
}
catch (DirectoryException de)
{
// We couldn't decode this filter. Report an error and continue.
}
}
}
// done
return searchFilters;
}
/**
* Create a new error handler.
*
* @param configPhase the configuration phase for which the
* error handler is used
* @param unacceptableReasons the reasons why the configuration cannot
* be applied (during PHASE_ACCEPTABLE phase)
* @param errorMessages the errors found when applying a new
* configuration (during PHASE_APPLY phase)
*
* @return a new configuration error handler
*/
)
{
);
return errorHandler;
}
/**
* Constructs a set of generic attributes containing entry cache
* monitor data. Note that <code>null</code> can be passed in
* place of any argument to denote the argument is omitted, such
* is when no state data of a given kind is available or can be
* provided.
*
* @param cacheHits number of cache hits.
* @param cacheMisses number of cache misses.
* @param cacheSize size of the current cache, in bytes.
* @param maxCacheSize maximum allowed cache size, in bytes.
* @param cacheCount number of entries stored in the cache.
* @param maxCacheCount maximum number of cache entries allowed.
*
* @return A set of generic attributes containing monitor data.
*/
{
{
// Cache misses is required to get cache tries and hit ratio.
if (cacheMisses != null)
{
.toString()));
}
}
{
.toString()));
}
if (maxCacheSize != null)
{
.toString()));
}
if (cacheCount != null)
{
.toString()));
}
if (maxCacheCount != null)
{
.toString()));
}
return attrs;
}
}