001/* 002 * Copyright 2020 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2020 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 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.StaticUtils; 047import com.unboundid.util.ThreadSafety; 048import com.unboundid.util.ThreadSafetyLevel; 049import com.unboundid.util.Validator; 050 051import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*; 052 053 054 055/** 056 * This class provides a collect support data log capture window implementation 057 * that indicates that the tool should capture information for a specified 058 * length of time up to the time the {@link CollectSupportDataExtendedRequest} 059 * was received. 060 * <BR> 061 * <BLOCKQUOTE> 062 * <B>NOTE:</B> This class, and other classes within the 063 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 064 * supported for use against Ping Identity, UnboundID, and 065 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 066 * for proprietary functionality or for external specifications that are not 067 * considered stable or mature enough to be guaranteed to work in an 068 * interoperable way with other types of LDAP servers. 069 * </BLOCKQUOTE> 070 * 071 * @see CollectSupportDataExtendedRequest 072 */ 073@NotMutable() 074@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 075public final class DurationCollectSupportDataLogCaptureWindow 076 extends CollectSupportDataLogCaptureWindow 077{ 078 /** 079 * The serial version UID for this serializable class. 080 */ 081 private static final long serialVersionUID = -6685577889240682295L; 082 083 084 085 // An ASN.1 element that provides an encoded representation of this duration 086 // collect support data log capture window. 087 private final ASN1Element encodedWindow; 088 089 // The log duration, in milliseconds. 090 private final long durationMillis; 091 092 093 094 /** 095 * Creates a new instance of this collect support data log capture window 096 * object that will capture log content for the specified duration. 097 * 098 * @param durationMillis The duration of log content to capture, in 099 * milliseconds. It must be greater than or equal to 100 * zero. 101 */ 102 public DurationCollectSupportDataLogCaptureWindow(final long durationMillis) 103 { 104 Validator.ensureTrue((durationMillis >= 0L), 105 "DurationCollectSupportDataLogCaptureWindow.durationMillis must be " + 106 "greater than or equal to zero."); 107 108 this.durationMillis = durationMillis; 109 110 encodedWindow = new ASN1Long(TYPE_DURATION, durationMillis); 111 } 112 113 114 115 /** 116 * Retrieves the duration, in milliseconds, of log content that should be 117 * included in the support data archive. 118 * 119 * @return The duration, in milliseconds, of log content that should be 120 * included in the support data archive. 121 */ 122 public long getDurationMillis() 123 { 124 return durationMillis; 125 } 126 127 128 129 /** 130 * Decodes the provided ASN.1 element as a tool-default collect support data 131 * log capture window object. 132 * 133 * @param e The ASN.1 element to be decoded. It must not be {@code null}. 134 * 135 * @return The tool-default collect support data log capture window object 136 * that was decoded. 137 * 138 * @throws LDAPException If the provided ASN.1 element cannot be decoded as 139 * a valid tool-default collect support data log 140 * capture window object. 141 */ 142 static DurationCollectSupportDataLogCaptureWindow 143 decodeInternal(final ASN1Element e) 144 throws LDAPException 145 { 146 try 147 { 148 final long durationMillis = ASN1Long.decodeAsLong(e).longValue(); 149 return new DurationCollectSupportDataLogCaptureWindow(durationMillis); 150 } 151 catch (final Exception ex) 152 { 153 Debug.debugException(ex); 154 throw new LDAPException(ResultCode.DECODING_ERROR, 155 ERR_DURATION_CSD_LOG_WINDOW_CANNOT_DECODE.get( 156 StaticUtils.getExceptionMessage(ex)), 157 ex); 158 } 159 } 160 161 162 163 /** 164 * {@inheritDoc} 165 */ 166 @Override() 167 public ASN1Element encode() 168 { 169 return encodedWindow; 170 } 171 172 173 174 /** 175 * {@inheritDoc} 176 */ 177 @Override() 178 public void toString(final StringBuilder buffer) 179 { 180 buffer.append("DurationCollectSupportDataLogCaptureWindow(durationMillis="); 181 buffer.append(durationMillis); 182 buffer.append(')'); 183 } 184}