001 /*
002 * Copyright 2014-2015 UnboundID Corp.
003 * All Rights Reserved.
004 */
005 /*
006 * Copyright (C) 2015 UnboundID Corp.
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU General Public License (GPLv2 only)
010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011 * as published by the Free Software Foundation.
012 *
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program; if not, see <http://www.gnu.org/licenses>.
020 */
021 package com.unboundid.ldap.sdk.unboundidds.extensions;
022
023
024
025 import com.unboundid.asn1.ASN1Element;
026 import com.unboundid.asn1.ASN1OctetString;
027 import com.unboundid.asn1.ASN1Sequence;
028 import com.unboundid.ldap.sdk.Control;
029 import com.unboundid.ldap.sdk.ExtendedRequest;
030 import com.unboundid.ldap.sdk.LDAPException;
031 import com.unboundid.ldap.sdk.ResultCode;
032 import com.unboundid.util.Debug;
033 import com.unboundid.util.NotMutable;
034 import com.unboundid.util.StaticUtils;
035 import com.unboundid.util.ThreadSafety;
036 import com.unboundid.util.ThreadSafetyLevel;
037 import com.unboundid.util.Validator;
038
039 import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*;
040
041
042
043 /**
044 * <BLOCKQUOTE>
045 * <B>NOTE:</B> This class is part of the Commercial Edition of the UnboundID
046 * LDAP SDK for Java. It is not available for use in applications that
047 * include only the Standard Edition of the LDAP SDK, and is not supported for
048 * use in conjunction with non-UnboundID products.
049 * </BLOCKQUOTE>
050 * This class provides an extended request that may be used to clear a server
051 * alarm condition about missed change notifications. The request has an OID of
052 * 1.3.6.1.4.1.30221.2.6.42 and a value with the following encoding:
053 * <BR><BR>
054 * <PRE>
055 * ClearMissedNotificationChangesAlarmRequest ::= SEQUENCE {
056 * notificationManagerID OCTET STRING,
057 * notificationDestinationID OCTET STRING }
058 * </PRE>
059 */
060 @NotMutable()
061 @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
062 public final class ClearMissedNotificationChangesAlarmExtendedRequest
063 extends ExtendedRequest
064 {
065 /**
066 * The OID (1.3.6.1.4.1.30221.2.6.42) for the clear missed notification
067 * changes alarm extended request.
068 */
069 public static final String
070 CLEAR_MISSED_NOTIFICATION_CHANGES_ALARM_REQUEST_OID =
071 "1.3.6.1.4.1.30221.2.6.42";
072
073
074
075 /**
076 * The serial version UID for this serializable class.
077 */
078 private static final long serialVersionUID = -5245417833641929585L;
079
080
081
082 // The notification destination ID.
083 private final String destinationID;
084
085 // The notification manager ID.
086 private final String managerID;
087
088
089
090 /**
091 * Creates a new clear missed notification changes alarm extended request with
092 * the provided information.
093 *
094 * @param managerID The notification manager ID. It must not be
095 * {@code null}.
096 * @param destinationID The notification destination ID. It must not be
097 * {@code null}.
098 * @param controls The set of controls to include in the request.
099 * It may be {@code null} or empty if no controls
100 * are needed.
101 */
102 public ClearMissedNotificationChangesAlarmExtendedRequest(
103 final String managerID, final String destinationID,
104 final Control... controls)
105 {
106 super(CLEAR_MISSED_NOTIFICATION_CHANGES_ALARM_REQUEST_OID,
107 encodeValue(managerID, destinationID), controls);
108
109 this.managerID = managerID;
110 this.destinationID = destinationID;
111 }
112
113
114
115 /**
116 * Creates a new clear missed notification changes alarm extended request from
117 * the provided generic extended request.
118 *
119 * @param extendedRequest The generic extended request to use to create this
120 * clear missed notification changes alarm extended
121 * request.
122 *
123 * @throws LDAPException If a problem occurs while decoding the request.
124 */
125 public ClearMissedNotificationChangesAlarmExtendedRequest(
126 final ExtendedRequest extendedRequest)
127 throws LDAPException
128 {
129 super(extendedRequest);
130
131 final ASN1OctetString value = extendedRequest.getValue();
132 if (value == null)
133 {
134 throw new LDAPException(ResultCode.DECODING_ERROR,
135 ERR_CLEAR_MISSED_NOTIFICATION_CHANGES_ALARM_REQ_DECODE_NO_VALUE.
136 get());
137 }
138
139 try
140 {
141 final ASN1Element[] elements =
142 ASN1Sequence.decodeAsSequence(value.getValue()).elements();
143 managerID =
144 ASN1OctetString.decodeAsOctetString(elements[0]).stringValue();
145 destinationID =
146 ASN1OctetString.decodeAsOctetString(elements[1]).stringValue();
147 }
148 catch (final Exception e)
149 {
150 Debug.debugException(e);
151 throw new LDAPException(ResultCode.DECODING_ERROR,
152 ERR_CLEAR_MISSED_NOTIFICATION_CHANGES_ALARM_REQ_ERROR_DECODING_VALUE.
153 get(StaticUtils.getExceptionMessage(e)),
154 e);
155 }
156 }
157
158
159
160 /**
161 * Encodes the provided information into an ASN.1 octet string suitable for
162 * use as the value of this extended request.
163 *
164 * @param managerID The notification manager ID. It must not be
165 * {@code null}.
166 * @param destinationID The notification destination ID. It must not be
167 * {@code null}.
168 *
169 * @return The ASN.1 octet string containing the encoded value.
170 */
171 private static ASN1OctetString encodeValue(final String managerID,
172 final String destinationID)
173 {
174 Validator.ensureNotNull(managerID);
175 Validator.ensureNotNull(destinationID);
176
177 final ASN1Sequence valueSequence = new ASN1Sequence(
178 new ASN1OctetString(managerID),
179 new ASN1OctetString(destinationID));
180 return new ASN1OctetString(valueSequence.encode());
181 }
182
183
184
185 /**
186 * Retrieves the notification manager ID.
187 *
188 * @return The notification manager ID.
189 */
190 public String getManagerID()
191 {
192 return managerID;
193 }
194
195
196
197 /**
198 * Retrieves the notification destination ID.
199 *
200 * @return The notification destination ID.
201 */
202 public String getDestinationID()
203 {
204 return destinationID;
205 }
206
207
208
209 /**
210 * {@inheritDoc}
211 */
212 @Override()
213 public ClearMissedNotificationChangesAlarmExtendedRequest duplicate()
214 {
215 return duplicate(getControls());
216 }
217
218
219
220 /**
221 * {@inheritDoc}
222 */
223 @Override()
224 public ClearMissedNotificationChangesAlarmExtendedRequest
225 duplicate(final Control[] controls)
226 {
227 final ClearMissedNotificationChangesAlarmExtendedRequest r =
228 new ClearMissedNotificationChangesAlarmExtendedRequest(managerID,
229 destinationID, controls);
230 r.setResponseTimeoutMillis(getResponseTimeoutMillis(null));
231 return r;
232 }
233
234
235
236 /**
237 * {@inheritDoc}
238 */
239 @Override()
240 public String getExtendedRequestName()
241 {
242 return INFO_EXTENDED_REQUEST_NAME_CLEAR_MISSED_NOTIFICATION_CHANGES_ALARM.
243 get();
244 }
245
246
247
248 /**
249 * {@inheritDoc}
250 */
251 @Override()
252 public void toString(final StringBuilder buffer)
253 {
254 buffer.append("ClearMissedNotificationChangesAlarmExtendedRequest(" +
255 "managerID='");
256 buffer.append(managerID);
257 buffer.append("', destinationID='");
258 buffer.append(destinationID);
259 buffer.append('\'');
260
261 final Control[] controls = getControls();
262 if (controls.length > 0)
263 {
264 buffer.append(", controls={");
265 for (int i=0; i < controls.length; i++)
266 {
267 if (i > 0)
268 {
269 buffer.append(", ");
270 }
271
272 buffer.append(controls[i]);
273 }
274 buffer.append('}');
275 }
276
277 buffer.append(')');
278 }
279 }