001/*
002 * Copyright 2020-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2020-2024 Ping Identity Corporation
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020/*
021 * Copyright (C) 2020-2024 Ping Identity Corporation
022 *
023 * This program is free software; you can redistribute it and/or modify
024 * it under the terms of the GNU General Public License (GPLv2 only)
025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
026 * as published by the Free Software Foundation.
027 *
028 * This program is distributed in the hope that it will be useful,
029 * but WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
031 * GNU General Public License for more details.
032 *
033 * You should have received a copy of the GNU General Public License
034 * along with this program; if not, see <http://www.gnu.org/licenses>.
035 */
036package com.unboundid.ldap.sdk.unboundidds.extensions;
037
038
039
040import com.unboundid.asn1.ASN1Element;
041import com.unboundid.asn1.ASN1Long;
042import com.unboundid.ldap.sdk.LDAPException;
043import com.unboundid.ldap.sdk.ResultCode;
044import com.unboundid.util.Debug;
045import com.unboundid.util.NotMutable;
046import com.unboundid.util.NotNull;
047import com.unboundid.util.StaticUtils;
048import com.unboundid.util.ThreadSafety;
049import com.unboundid.util.ThreadSafetyLevel;
050import com.unboundid.util.Validator;
051
052import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*;
053
054
055
056/**
057 * This class provides a collect support data log capture window implementation
058 * that indicates that the tool should capture information for a specified
059 * length of time up to the time the {@link CollectSupportDataExtendedRequest}
060 * was received.
061 * <BR>
062 * <BLOCKQUOTE>
063 *   <B>NOTE:</B>  This class, and other classes within the
064 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
065 *   supported for use against Ping Identity, UnboundID, and
066 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
067 *   for proprietary functionality or for external specifications that are not
068 *   considered stable or mature enough to be guaranteed to work in an
069 *   interoperable way with other types of LDAP servers.
070 * </BLOCKQUOTE>
071 *
072 * @see  CollectSupportDataExtendedRequest
073 */
074@NotMutable()
075@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
076public final class DurationCollectSupportDataLogCaptureWindow
077       extends CollectSupportDataLogCaptureWindow
078{
079  /**
080   * The serial version UID for this serializable class.
081   */
082  private static final long serialVersionUID = -6685577889240682295L;
083
084
085
086  // An ASN.1 element that provides an encoded representation of this duration
087  // collect support data log capture window.
088  @NotNull private final ASN1Element encodedWindow;
089
090  // The log duration, in milliseconds.
091  private final long durationMillis;
092
093
094
095  /**
096   * Creates a new instance of this collect support data log capture window
097   * object that will capture log content for the specified duration.
098   *
099   * @param  durationMillis  The duration of log content to capture, in
100   *                         milliseconds.  It must be greater than or equal to
101   *                         zero.
102   */
103  public DurationCollectSupportDataLogCaptureWindow(final long durationMillis)
104  {
105    Validator.ensureTrue((durationMillis >= 0L),
106         "DurationCollectSupportDataLogCaptureWindow.durationMillis must be " +
107              "greater than or equal to zero.");
108
109    this.durationMillis = durationMillis;
110
111    encodedWindow = new ASN1Long(TYPE_DURATION, durationMillis);
112  }
113
114
115
116  /**
117   * Retrieves the duration, in milliseconds, of log content that should be
118   * included in the support data archive.
119   *
120   * @return  The duration, in milliseconds, of log content that should be
121   *          included in the support data archive.
122   */
123  public long getDurationMillis()
124  {
125    return durationMillis;
126  }
127
128
129
130  /**
131   * Decodes the provided ASN.1 element as a duration collect support data log
132   * capture window object.
133   *
134   * @param  e  The ASN.1 element to be decoded.  It must not be {@code null}.
135   *
136   * @return  The duration collect support data log capture window object that
137   *          was decoded.
138   *
139   * @throws  LDAPException  If the provided ASN.1 element cannot be decoded as
140   *                         a valid duration collect support data log capture
141   *                         window object.
142   */
143  @NotNull()
144  static DurationCollectSupportDataLogCaptureWindow decodeInternal(
145              @NotNull final ASN1Element e)
146         throws LDAPException
147  {
148    try
149    {
150      final long durationMillis = ASN1Long.decodeAsLong(e).longValue();
151      return new DurationCollectSupportDataLogCaptureWindow(durationMillis);
152    }
153    catch (final Exception ex)
154    {
155      Debug.debugException(ex);
156      throw new LDAPException(ResultCode.DECODING_ERROR,
157           ERR_DURATION_CSD_LOG_WINDOW_CANNOT_DECODE.get(
158                StaticUtils.getExceptionMessage(ex)),
159           ex);
160    }
161  }
162
163
164
165  /**
166   * {@inheritDoc}
167   */
168  @Override()
169  @NotNull()
170  public ASN1Element encode()
171  {
172    return encodedWindow;
173  }
174
175
176
177  /**
178   * {@inheritDoc}
179   */
180  @Override()
181  public void toString(@NotNull final StringBuilder buffer)
182  {
183    buffer.append("DurationCollectSupportDataLogCaptureWindow(durationMillis=");
184    buffer.append(durationMillis);
185    buffer.append(')');
186  }
187}