DelayPreOpPlugin.java revision a89f7014aeb71dba5c94404dfea7eb89e7eeee74
/*
* 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.
* Portions Copyright 2014-2015 ForgeRock AS
*/
/**
* This class defines a very simple pre-operation plugin that sleeps for up to
* five seconds for add, compare, delete, extended, modify, modify DN, and
* search operations (and therefore not for abandon, bind, and unbind
* operations, since those operations cannot be cancelled). While it is
* sleeping, it also checks for a request to cancel the associated operation and
* will respond to it accordingly.
*/
public class DelayPreOpPlugin
extends DirectoryServerPlugin<PluginCfg>
{
/**
* The OID for the delay request control, which is used to flag operations
* that should be delayed.
*/
/**
* The control used by this plugin.
*/
public static class DelayRequestControl extends Control
{
/**
* ControlDecoder implementation to decode this control from a ByteString.
*/
private static final class Decoder
implements ControlDecoder<DelayRequestControl>
{
/** {@inheritDoc} */
throws DirectoryException
{
try
{
}
catch (Exception e)
{
// TODO: Need a better message
}
}
{
return OID_DELAY_REQUEST;
}
}
/**
* The Control Decoder that can be used to decode this control.
*/
new Decoder();
private long delayDuration;
/**
* Constructs a new control of this class.
*
* @param isCritical
* Indicates whether support for this control should be considered
* a critical part of the server processing.
* @param delayDuration
* The requested delay duration.
*/
{
super(OID_DELAY_REQUEST, isCritical);
this.delayDuration = delayDuration;
}
/**
* Writes this control's value to an ASN.1 writer. The value (if any)
* must be written as an ASN1OctetString.
*
* @param writer The ASN.1 writer to use.
* @throws IOException If a problem occurs while writing to the stream.
*/
}
/**
* Retrieves the delay duration.
*
* @return The delay duration.
*/
public long getDelayDuration()
{
return delayDuration;
}
}
/**
* Creates a new instance of this Directory Server plugin. Every
* plugin must implement a default constructor (it is the only one
* that will be used to create plugins defined in the
* configuration), and every plugin constructor must call
* <CODE>super()</CODE> as its first element.
*/
public DelayPreOpPlugin()
{
super();
}
/** {@inheritDoc} */
throws ConfigException
{
// This plugin may only be used as a pre-operation plugin.
for (PluginType t : pluginTypes)
{
switch (t)
{
case PRE_OPERATION_ADD:
case PRE_OPERATION_BIND:
case PRE_OPERATION_COMPARE:
case PRE_OPERATION_DELETE:
case PRE_OPERATION_EXTENDED:
case PRE_OPERATION_MODIFY:
case PRE_OPERATION_MODIFY_DN:
case PRE_OPERATION_SEARCH:
// This is fine.
break;
default:
" for delay pre-op plugin."));
}
}
}
/** {@inheritDoc} */
public PluginResult.PreOperation
throws CanceledOperationException {
return doPreOperationInternal(addOperation);
}
/** {@inheritDoc} */
public PluginResult.PreOperation
{
try
{
return doPreOperationInternal(bindOperation);
}
catch(CanceledOperationException coe)
{
// Bind ops can't be canceled. Just ignore.
}
}
/** {@inheritDoc} */
public PluginResult.PreOperation
throws CanceledOperationException {
return doPreOperationInternal(compareOperation);
}
/** {@inheritDoc} */
public PluginResult.PreOperation
throws CanceledOperationException {
return doPreOperationInternal(deleteOperation);
}
/** {@inheritDoc} */
public PluginResult.PreOperation
throws CanceledOperationException {
return doPreOperationInternal(extendedOperation);
}
/** {@inheritDoc} */
public PluginResult.PreOperation
throws CanceledOperationException {
return doPreOperationInternal(modifyOperation);
}
/** {@inheritDoc} */
public PluginResult.PreOperation
throws CanceledOperationException {
return doPreOperationInternal(modifyDNOperation);
}
/** {@inheritDoc} */
public PluginResult.PreOperation
throws CanceledOperationException {
return doPreOperationInternal(searchOperation);
}
/**
* Looks for a delay request control in the operation, and if one is found
* then sleep in 10 millisecond increments up to the length of time specified
* in the control value. If the operation receives a cancel request during
* this time, then the control will stop sleeping immediately.
*
* @param operation The operation to be processed.
*
* @return The result of the plugin processing.
*/
private PluginResult.PreOperation
throws CanceledOperationException
{
try
{
}
catch (Exception e)
{
e));
}
{
if (delayDuration <= 0)
{
}
{
operation.checkIfCanceled(false);
try
{
} catch (Exception e) {}
}
}
}
/**
* Creates a delay request control with the specified delay.
*
* @param delay The length of time in milliseconds to sleep.
*
* @return The appropriate delay request control.
*/
{
return new DelayRequestControl(false, delay);
}
/**
* Retrieves a list containing a delay request LDAP control with the specified
* delay.
*
* @param delay The length of time in milliseconds to sleep.
*
* @return A list containing the appropriate delay request LDAP control.
*/
{
return controlList;
}
}