DelayPreOpPlugin.java revision 04a13ed0142e4ee74842a64dd3d65153eaeb3d0c
/*
* 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
* 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
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. 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 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.
*/
/**
* 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}
*/
@Override()
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}
*/
@Override()
public PluginResult.PreOperation
throws CanceledOperationException {
return doPreOperationInternal(addOperation);
}
/**
* {@inheritDoc}
*/
@Override()
public PluginResult.PreOperation
{
try
{
return doPreOperationInternal(bindOperation);
}
catch(CanceledOperationException coe)
{
// Bind ops can't be canceled. Just ignore.
}
}
/**
* {@inheritDoc}
*/
@Override()
public PluginResult.PreOperation
throws CanceledOperationException {
return doPreOperationInternal(compareOperation);
}
/**
* {@inheritDoc}
*/
@Override()
public PluginResult.PreOperation
throws CanceledOperationException {
return doPreOperationInternal(deleteOperation);
}
/**
* {@inheritDoc}
*/
@Override()
public PluginResult.PreOperation
throws CanceledOperationException {
return doPreOperationInternal(extendedOperation);
}
/**
* {@inheritDoc}
*/
@Override()
public PluginResult.PreOperation
throws CanceledOperationException {
return doPreOperationInternal(modifyOperation);
}
/**
* {@inheritDoc}
*/
@Override()
public PluginResult.PreOperation
throws CanceledOperationException {
return doPreOperationInternal(modifyDNOperation);
}
/**
* {@inheritDoc}
*/
@Override()
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 {
long delayDuration = 0L;
if (requestControls != null)
{
for (Control c : requestControls)
{
{
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 Control(OID_DELAY_REQUEST, false,
}
/**
* Retrieves a list containing a delay request control with the specified
* delay.
*
* @param delay The length of time in milliseconds to sleep.
*
* @return A list containing the appropriate delay request control.
*/
{
return controlList;
}
/**
* Creates a delay request LDAP control with the specified delay.
*
* @param delay The length of time in milliseconds to sleep.
*
* @return The appropriate delay request LDAP control.
*/
{
return new LDAPControl(OID_DELAY_REQUEST, false,
}
/**
* 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;
}
}