d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * CDDL HEADER START
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * The contents of this file are subject to the terms of the
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * Common Development and Distribution License, Version 1.0 only
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * (the "License"). You may not use this file except in compliance
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * with the License.
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignac * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignac * or http://forgerock.org/license/CDDLv1.0.html.
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * See the License for the specific language governing permissions
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * and limitations under the License.
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * When distributing Covered Code, include this CDDL HEADER in each
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignac * file and include the License file at legal-notices/CDDLv1_0.txt.
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignac * If applicable, add the following below this CDDL HEADER, with the
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignac * fields enclosed by brackets "[]" replaced with your own identifying
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignac * information:
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * Portions Copyright [yyyy] [name of copyright owner]
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * CDDL HEADER END
05b42f00b813c3dc70cbb80d62089f9cc0f6f549ludovicp * Copyright 2006-2008 Sun Microsystems, Inc.
bb8874d71cdd8e5288297b9727703437c6dfcfedmatthew_swiftimport org.opends.server.admin.std.server.PluginCfg;
d1759377955a57f4c7362308bc78565694a87680neil_a_wilsonimport org.opends.server.api.plugin.DirectoryServerPlugin;
d1759377955a57f4c7362308bc78565694a87680neil_a_wilsonimport org.opends.server.config.ConfigException;
80f9ce2386be52767bcbb60953ab2fcfd4395ea4JnRouvignacimport org.opends.server.controls.ControlDecoder;
80f9ce2386be52767bcbb60953ab2fcfd4395ea4JnRouvignacimport org.opends.server.protocols.asn1.ASN1Reader;
80f9ce2386be52767bcbb60953ab2fcfd4395ea4JnRouvignacimport org.opends.server.protocols.asn1.ASN1Writer;
80f9ce2386be52767bcbb60953ab2fcfd4395ea4JnRouvignacimport static org.opends.server.protocols.asn1.ASN1Constants.*;
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * This class defines a very simple pre-operation plugin that sleeps for up to
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * five seconds for add, compare, delete, extended, modify, modify DN, and
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * search operations (and therefore not for abandon, bind, and unbind
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * operations, since those operations cannot be cancelled). While it is
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * sleeping, it also checks for a request to cancel the associated operation and
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * will respond to it accordingly.
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * The OID for the delay request control, which is used to flag operations
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * that should be delayed.
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson public static final String OID_DELAY_REQUEST = "1.3.6.1.4.1.26027.1.999.1";
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift * The control used by this plugin.
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift public static class DelayRequestControl extends Control
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift * ControlDecoder implentation to decode this control from a ByteString.
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift implements ControlDecoder<DelayRequestControl>
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift * {@inheritDoc}
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift public DelayRequestControl decode(boolean isCritical, ByteString value)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift return new DelayRequestControl(isCritical, delay);
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift // TODO: Need a better message
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift throw new DirectoryException(ResultCode.PROTOCOL_ERROR, null, e);
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift * The Control Decoder that can be used to decode this control.
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift public static final ControlDecoder<DelayRequestControl> DECODER =
80f9ce2386be52767bcbb60953ab2fcfd4395ea4JnRouvignac * Constructs a new control of this class.
80f9ce2386be52767bcbb60953ab2fcfd4395ea4JnRouvignac * @param isCritical
80f9ce2386be52767bcbb60953ab2fcfd4395ea4JnRouvignac * Indicates whether support for this control should be considered
80f9ce2386be52767bcbb60953ab2fcfd4395ea4JnRouvignac * a critical part of the server processing.
80f9ce2386be52767bcbb60953ab2fcfd4395ea4JnRouvignac * @param delayDuration
80f9ce2386be52767bcbb60953ab2fcfd4395ea4JnRouvignac * The requested delay duration.
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift public DelayRequestControl(boolean isCritical, long delayDuration)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift * Writes this control's value to an ASN.1 writer. The value (if any)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift * must be written as an ASN1OctetString.
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift * @param writer The ASN.1 writer to use.
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift * @throws IOException If a problem occurs while writing to the stream.
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift protected void writeValue(ASN1Writer writer) throws IOException {
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift writer.writeStartSequence(UNIVERSAL_OCTET_STRING_TYPE);
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift * Retrieves the delay duration.
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift * @return The delay duration.
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * Creates a new instance of this Directory Server plugin. Every
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * plugin must implement a default constructor (it is the only one
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * that will be used to create plugins defined in the
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * configuration), and every plugin constructor must call
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * <CODE>super()</CODE> as its first element.
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * {@inheritDoc}
54e2384a2c22191e7df5a2bbf25778dcbcf64368neil_a_wilson public void initializePlugin(Set<PluginType> pluginTypes,
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson // This plugin may only be used as a pre-operation plugin.
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson // This is fine.
53247d28ba99538f841a13ea2cde01c3faa3ef36kenneth_suter throw new ConfigException(Message.raw("Invalid plugin type " + t +
53247d28ba99538f841a13ea2cde01c3faa3ef36kenneth_suter " for delay pre-op plugin."));
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * {@inheritDoc}
b4851fc75ef4634840dcbadec085d586d36b434dneil_a_wilson doPreOperation(PreOperationAddOperation addOperation)
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * {@inheritDoc}
04a13ed0142e4ee74842a64dd3d65153eaeb3d0cboli doPreOperation(PreOperationBindOperation bindOperation)
04a13ed0142e4ee74842a64dd3d65153eaeb3d0cboli // Bind ops can't be canceled. Just ignore.
04a13ed0142e4ee74842a64dd3d65153eaeb3d0cboli return PluginResult.PreOperation.continueOperationProcessing();
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * {@inheritDoc}
04a13ed0142e4ee74842a64dd3d65153eaeb3d0cboli doPreOperation(PreOperationCompareOperation compareOperation)
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson return doPreOperationInternal(compareOperation);
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * {@inheritDoc}
b4851fc75ef4634840dcbadec085d586d36b434dneil_a_wilson doPreOperation(PreOperationDeleteOperation deleteOperation)
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson return doPreOperationInternal(deleteOperation);
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * {@inheritDoc}
b4851fc75ef4634840dcbadec085d586d36b434dneil_a_wilson doPreOperation(PreOperationExtendedOperation extendedOperation)
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson return doPreOperationInternal(extendedOperation);
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * {@inheritDoc}
b4851fc75ef4634840dcbadec085d586d36b434dneil_a_wilson doPreOperation(PreOperationModifyOperation modifyOperation)
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson return doPreOperationInternal(modifyOperation);
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * {@inheritDoc}
b4851fc75ef4634840dcbadec085d586d36b434dneil_a_wilson doPreOperation(PreOperationModifyDNOperation modifyDNOperation)
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson return doPreOperationInternal(modifyDNOperation);
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * {@inheritDoc}
b4851fc75ef4634840dcbadec085d586d36b434dneil_a_wilson doPreOperation(PreOperationSearchOperation searchOperation)
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson return doPreOperationInternal(searchOperation);
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * Looks for a delay request control in the operation, and if one is found
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * then sleep in 10 millisecond increments up to the length of time specified
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * in the control value. If the operation receives a cancel request during
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * this time, then the control will stop sleeping immediately.
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * @param operation The operation to be processed.
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * @return The result of the plugin processing.
b4851fc75ef4634840dcbadec085d586d36b434dneil_a_wilson doPreOperationInternal(PreOperationOperation operation)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift control = operation.getRequestControl(DelayRequestControl.DECODER);
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift return PluginResult.PreOperation.stopProcessing(
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift Message.raw("Unable to decode the delay request control: " +
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift long delayDuration = control.getDelayDuration();
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift return PluginResult.PreOperation.continueOperationProcessing();
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift long stopSleepTime = System.currentTimeMillis() + delayDuration;
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift while (System.currentTimeMillis() < stopSleepTime)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift } catch (Exception e) {}
04a13ed0142e4ee74842a64dd3d65153eaeb3d0cboli return PluginResult.PreOperation.continueOperationProcessing();
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * Creates a delay request control with the specified delay.
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * @param delay The length of time in milliseconds to sleep.
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * @return The appropriate delay request control.
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson public static Control createDelayControl(long delay)
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * Retrieves a list containing a delay request LDAP control with the specified
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * @param delay The length of time in milliseconds to sleep.
d1759377955a57f4c7362308bc78565694a87680neil_a_wilson * @return A list containing the appropriate delay request LDAP control.
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift public static List<Control> createDelayControlList(long delay)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift ArrayList<Control> controlList = new ArrayList<Control>(1);