001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2006-2010 Sun Microsystems, Inc.
025 *      Portions Copyright 2012-2015 ForgeRock AS
026 */
027package org.opends.server.protocols.ldap;
028
029import static org.opends.messages.ProtocolMessages.*;
030import static org.opends.server.protocols.ldap.LDAPConstants.*;
031import static org.opends.server.util.ServerConstants.*;
032
033import java.util.ArrayList;
034import java.util.List;
035import java.util.concurrent.atomic.AtomicLong;
036
037import org.forgerock.i18n.LocalizableMessage;
038import org.opends.server.admin.std.server.MonitorProviderCfg;
039import org.opends.server.api.MonitorProvider;
040import org.forgerock.opendj.config.server.ConfigException;
041import org.opends.server.core.DirectoryServer;
042import org.opends.server.types.*;
043
044/**
045 * This class defines a data structure that will be used to keep track
046 * of various metrics related to LDAP communication that the server has
047 * conducted. The statistics that will be tracked include:
048 * <UL>
049 * <LI>The total number of LDAP client connections accepted by the
050 * server.</LI>
051 * <LI>The total number of LDAP client connections that have been
052 * closed.</LI>
053 * <LI>The total number of LDAP messages read, both overall and broken
054 * down by message type.</LI>
055 * <LI>The total number of LDAP messages written, both overall and
056 * broken down by message type.</LI>
057 * <LI>The total number of bytes read from LDAP clients.</LI>
058 * <LI>The total number of bytes written to LDAP clients.</LI>
059 * </UL>
060 * <BR>
061 * <BR>
062 * This class may also be used in a hierarchical form if it is desirable
063 * to get specific and general statistics at the same time (e.g.,
064 * information about the interaction with a specific client or
065 * aggregated for all clients).
066 */
067public class LDAPStatistics extends MonitorProvider<MonitorProviderCfg>
068{
069
070  // The statistics maintained by this class.
071  private AtomicLong abandonRequests = new AtomicLong(0);
072  private AtomicLong addRequests = new AtomicLong(0);
073  private AtomicLong bindRequests = new AtomicLong(0);
074  private AtomicLong addResponses = new AtomicLong(0);
075  private AtomicLong bindResponses = new AtomicLong(0);
076  private AtomicLong bytesRead = new AtomicLong(0);
077  private AtomicLong bytesWritten = new AtomicLong(0);
078  private AtomicLong compareRequests = new AtomicLong(0);
079  private AtomicLong compareResponses = new AtomicLong(0);
080  private AtomicLong connectionsClosed = new AtomicLong(0);
081  private AtomicLong connectionsEstablished = new AtomicLong(0);
082  private AtomicLong deleteRequests = new AtomicLong(0);
083  private AtomicLong deleteResponses = new AtomicLong(0);
084  private AtomicLong extendedRequests = new AtomicLong(0);
085  private AtomicLong extendedResponses = new AtomicLong(0);
086  private AtomicLong messagesRead = new AtomicLong(0);
087  private AtomicLong messagesWritten = new AtomicLong(0);
088  private AtomicLong modifyRequests = new AtomicLong(0);
089  private AtomicLong modifyResponses = new AtomicLong(0);
090  private AtomicLong modifyDNRequests = new AtomicLong(0);
091  private AtomicLong modifyDNResponses = new AtomicLong(0);
092  private AtomicLong operationsAbandoned = new AtomicLong(0);
093  private AtomicLong operationsCompleted = new AtomicLong(0);
094  private AtomicLong operationsInitiated = new AtomicLong(0);
095  private AtomicLong searchRequests = new AtomicLong(0);
096  private AtomicLong searchOneRequests = new AtomicLong(0);
097  private AtomicLong searchSubRequests = new AtomicLong(0);
098  private AtomicLong searchResultEntries = new AtomicLong(0);
099  private AtomicLong searchResultReferences = new AtomicLong(0);
100  private AtomicLong searchResultsDone = new AtomicLong(0);
101  private AtomicLong unbindRequests = new AtomicLong(0);
102
103
104  /** The instance name for this monitor provider instance. */
105  private final String instanceName;
106
107  // Monitor Objects : for Operations (count and time)
108  private AtomicLong addOperationCount = new AtomicLong(0);
109  private AtomicLong addOperationTime = new AtomicLong(0);
110  private AtomicLong searchOperationCount = new AtomicLong(0);
111  private AtomicLong searchOperationTime = new AtomicLong(0);
112  private AtomicLong delOperationCount = new AtomicLong(0);
113  private AtomicLong delOperationTime = new AtomicLong(0);
114  private AtomicLong bindOperationCount = new AtomicLong(0);
115  private AtomicLong bindOperationTime = new AtomicLong(0);
116  private AtomicLong unbindOperationCount = new AtomicLong(0);
117  private AtomicLong unbindOperationTime = new AtomicLong(0);
118  private AtomicLong compOperationCount = new AtomicLong(0);
119  private AtomicLong compOperationTime = new AtomicLong(0);
120  private AtomicLong modOperationCount = new AtomicLong(0);
121  private AtomicLong modOperationTime = new AtomicLong(0);
122  private AtomicLong moddnOperationCount = new AtomicLong(0);
123  private AtomicLong moddnOperationTime = new AtomicLong(0);
124  private AtomicLong abandonOperationCount = new AtomicLong(0);
125  private AtomicLong abandonOperationTime = new AtomicLong(0);
126  private AtomicLong extOperationCount = new AtomicLong(0);
127  private AtomicLong extOperationTime = new AtomicLong(0);
128
129
130  /**
131   * Creates a new instance of this class with the specified parent.
132   *
133   * @param instanceName
134   *          The name for this monitor provider instance.
135   */
136  public LDAPStatistics(String instanceName)
137  {
138    this.instanceName = instanceName;
139  }
140
141
142
143  /** {@inheritDoc} */
144  @Override
145  public void initializeMonitorProvider(MonitorProviderCfg configuration)
146      throws ConfigException
147  {
148    // Throw an exception, because this monitor is not intended to be
149    // dynamically loaded from the configuration. Rather, it should be
150    // explicitly created and registered by the LDAP connection handler
151    // or an LDAP client connection.
152    LocalizableMessage message =
153        ERR_LDAP_STATS_INVALID_MONITOR_INITIALIZATION.get(configuration.dn());
154    throw new ConfigException(message);
155  }
156
157
158
159  /**
160   * Retrieves the name of this monitor provider. It should be unique
161   * among all monitor providers, including all instances of the same
162   * monitor provider.
163   *
164   * @return The name of this monitor provider.
165   */
166  @Override
167  public String getMonitorInstanceName()
168  {
169    return instanceName;
170  }
171
172
173  /** {@inheritDoc} */
174  @Override
175  public ObjectClass getMonitorObjectClass()
176  {
177      return DirectoryConfig.getObjectClass(OC_MONITOR_CONNHANDLERSTATS, true);
178  }
179
180
181  /**
182   * Retrieves a set of attributes containing monitor data that should
183   * be returned to the client if the corresponding monitor entry is
184   * requested.
185   *
186   * @return A set of attributes containing monitor data that should be
187   *         returned to the client if the corresponding monitor entry
188   *         is requested.
189   */
190  @Override
191  public List<Attribute> getMonitorData()
192  {
193      List<Attribute> attrs = new ArrayList<>();
194
195      long tmpAbandonRequests = abandonRequests.get();
196      long tmpAddRequests = addRequests.get();
197      long tmpAddResponses = addResponses.get();
198      long tmpBindRequests = bindRequests.get();
199      long tmpBindResponses = bindResponses.get();
200      long tmpBytesRead = bytesRead.get();
201      long tmpBytesWritten = bytesWritten.get();
202      long tmpCompareRequests = compareRequests.get();
203      long tmpCompareResponses = compareResponses.get();
204      long tmpConnectionsClosed = connectionsClosed.get();
205      long tmpConnectionsEstablished = connectionsEstablished.get();
206      long tmpDeleteRequests = deleteRequests.get();
207      long tmpDeleteResponses = deleteResponses.get();
208      long tmpExtendedRequests = extendedRequests.get();
209      long tmpExtendedResponses = extendedResponses.get();
210      long tmpMessagesRead = messagesRead.get();
211      long tmpMessagesWritten = messagesWritten.get();
212      long tmpModifyRequests = modifyRequests.get();
213      long tmpModifyResponses = modifyResponses.get();
214      long tmpModifyDNRequests = modifyDNRequests.get();
215      long tmpModifyDNResponses = modifyDNResponses.get();
216      long tmpOperationsAbandoned = operationsAbandoned.get();
217      long tmpOperationsCompleted = operationsCompleted.get();
218      long tmpOperationsInitiated = operationsInitiated.get();
219      long tmpSearchRequests = searchRequests.get();
220      long tmpSearchOneRequests = searchOneRequests.get();
221      long tmpSearchSubRequests = searchSubRequests.get();
222      long tmpSearchEntries = searchResultEntries.get();
223      long tmpSearchReferences = searchResultReferences.get();
224      long tmpSearchResultsDone = searchResultsDone.get();
225      long tmpUnbindRequests = unbindRequests.get();
226      long tmpAddOperationCount = addOperationCount.get();
227      long tmpAddOperationTime = addOperationTime.get();
228      long tmpSearchOperationCount = searchOperationCount.get();
229      long tmpSearchOperationTime = searchOperationTime.get();
230      long tmpDelOperationCount = delOperationCount.get();
231      long tmpDelOperationTime = delOperationTime.get();
232      long tmpBindOperationCount = bindOperationCount.get();
233      long tmpBindOperationTime = bindOperationTime.get();
234      long tmpUnbindOperationCount = unbindOperationCount.get();
235      long tmpUnbindOperationTime = unbindOperationTime.get();
236      long tmpCompOperationCount = compOperationCount.get();
237      long tmpCompOperationTime = compOperationTime.get();
238      long tmpModOperationCount = modOperationCount.get();
239      long tmpModOperationTime = modOperationTime.get();
240      long tmpModdnOperationCount = moddnOperationCount.get();
241      long tmpModdnOperationTime = moddnOperationTime.get();
242      long tmpAbandonOperationCount = abandonOperationCount.get();
243      long tmpAbandonOperationTime = abandonOperationTime.get();
244      long tmpExtOperationCount = extOperationCount.get();
245      long tmpExtOperationTime = extOperationTime.get();
246
247
248    // Construct the list of attributes to return.
249    /* TODO : the attribute names should be constant (in ServerConstants.java
250     *        and associated with their objectclass
251     *        OC_MONITOR_CONNHANDLERSTATS
252     */
253    attrs.add(createAttribute("connectionsEstablished", String
254        .valueOf(tmpConnectionsEstablished)));
255    attrs.add(createAttribute("connectionsClosed", String
256        .valueOf(tmpConnectionsClosed)));
257    attrs.add(createAttribute("bytesRead", String
258        .valueOf(tmpBytesRead)));
259    attrs.add(createAttribute("bytesWritten", String
260        .valueOf(tmpBytesWritten)));
261    attrs.add(createAttribute("ldapMessagesRead", String
262        .valueOf(tmpMessagesRead)));
263    attrs.add(createAttribute("ldapMessagesWritten", String
264        .valueOf(tmpMessagesWritten)));
265    attrs.add(createAttribute("operationsAbandoned", String
266        .valueOf(tmpOperationsAbandoned)));
267    attrs.add(createAttribute("operationsInitiated", String
268        .valueOf(tmpOperationsInitiated)));
269    attrs.add(createAttribute("operationsCompleted", String
270        .valueOf(tmpOperationsCompleted)));
271    attrs.add(createAttribute("abandonRequests", String
272        .valueOf(tmpAbandonRequests)));
273    attrs.add(createAttribute("addRequests", String
274        .valueOf(tmpAddRequests)));
275    attrs.add(createAttribute("addResponses", String
276        .valueOf(tmpAddResponses)));
277    attrs.add(createAttribute("bindRequests", String
278        .valueOf(tmpBindRequests)));
279    attrs.add(createAttribute("bindResponses", String
280        .valueOf(tmpBindResponses)));
281    attrs.add(createAttribute("compareRequests", String
282        .valueOf(tmpCompareRequests)));
283    attrs.add(createAttribute("compareResponses", String
284        .valueOf(tmpCompareResponses)));
285    attrs.add(createAttribute("deleteRequests", String
286        .valueOf(tmpDeleteRequests)));
287    attrs.add(createAttribute("deleteResponses", String
288        .valueOf(tmpDeleteResponses)));
289    attrs.add(createAttribute("extendedRequests", String
290        .valueOf(tmpExtendedRequests)));
291    attrs.add(createAttribute("extendedResponses", String
292        .valueOf(tmpExtendedResponses)));
293    attrs.add(createAttribute("modifyRequests", String
294        .valueOf(tmpModifyRequests)));
295    attrs.add(createAttribute("modifyResponses", String
296        .valueOf(tmpModifyResponses)));
297    attrs.add(createAttribute("modifyDNRequests", String
298        .valueOf(tmpModifyDNRequests)));
299    attrs.add(createAttribute("modifyDNResponses", String
300        .valueOf(tmpModifyDNResponses)));
301    attrs.add(createAttribute("searchRequests", String
302        .valueOf(tmpSearchRequests)));
303    attrs.add(createAttribute("searchOneRequests", String
304        .valueOf(tmpSearchOneRequests)));
305    attrs.add(createAttribute("searchSubRequests", String
306        .valueOf(tmpSearchSubRequests)));
307    attrs.add(createAttribute("searchResultEntries", String
308        .valueOf(tmpSearchEntries)));
309    attrs.add(createAttribute("searchResultReferences", String
310        .valueOf(tmpSearchReferences)));
311    attrs.add(createAttribute("searchResultsDone", String
312        .valueOf(tmpSearchResultsDone)));
313    attrs.add(createAttribute("unbindRequests", String
314        .valueOf(tmpUnbindRequests)));
315
316    // adds
317    attrs.add(createAttribute("ds-mon-add-operations-total-count",
318        String.valueOf(tmpAddOperationCount)));
319
320    attrs.add(createAttribute(
321        "ds-mon-resident-time-add-operations-total-time", String
322            .valueOf(tmpAddOperationTime)));
323
324    // search
325    attrs.add(createAttribute("ds-mon-search-operations-total-count",
326        String.valueOf(tmpSearchOperationCount)));
327    attrs.add(createAttribute(
328        "ds-mon-resident-time-search-operations-total-time", String
329            .valueOf(tmpSearchOperationTime)));
330
331    // bind
332    attrs.add(createAttribute("ds-mon-bind-operations-total-count",
333        String.valueOf(tmpBindOperationCount)));
334    attrs.add(createAttribute(
335        "ds-mon-resident-time-bind-operations-total-time", String
336            .valueOf(tmpBindOperationTime)));
337
338    // unbind
339    attrs.add(createAttribute("ds-mon-unbind-operations-total-count",
340        String.valueOf(tmpUnbindOperationCount)));
341    attrs.add(createAttribute(
342        "ds-mon-resident-time-unbind-operations-total-time", String
343            .valueOf(tmpUnbindOperationTime)));
344
345    // compare
346    attrs
347        .add(createAttribute("ds-mon-compare-operations-total-count",
348            String.valueOf(tmpCompOperationCount)));
349    attrs.add(createAttribute(
350        "ds-mon-resident-time-compare-operations-total-time", String
351            .valueOf(tmpCompOperationTime)));
352    // del
353    attrs.add(createAttribute("ds-mon-delete-operations-total-count",
354        String.valueOf(tmpDelOperationCount)));
355    attrs.add(createAttribute(
356        "ds-mon-resident-time-delete-operations-total-time", String
357            .valueOf(tmpDelOperationTime)));
358
359    // mod
360    attrs.add(createAttribute("ds-mon-mod-operations-total-count",
361        String.valueOf(tmpModOperationCount)));
362    attrs.add(createAttribute(
363        "ds-mon-resident-time-mod-operations-total-time", String
364            .valueOf(tmpModOperationTime)));
365
366    // moddn
367    attrs.add(createAttribute("ds-mon-moddn-operations-total-count",
368        String.valueOf(tmpModdnOperationCount)));
369    attrs.add(createAttribute(
370        "ds-mon-resident-time-moddn-operations-total-time", String
371            .valueOf(tmpModdnOperationTime)));
372
373    // abandon
374    attrs
375        .add(createAttribute("ds-mon-abandon-operations-total-count",
376            String.valueOf(tmpAbandonOperationCount)));
377    attrs.add(createAttribute(
378        "ds-mon-resident-time-abandon-operations-total-time", String
379            .valueOf(tmpAbandonOperationTime)));
380
381    // extended
382    attrs
383        .add(createAttribute("ds-mon-extended-operations-total-count",
384            String.valueOf(tmpExtOperationCount)));
385    attrs.add(createAttribute(
386        "ds-mon-resident-time-extended-operations-total-time", String
387            .valueOf(tmpExtOperationTime)));
388
389    return attrs;
390  }
391
392
393  /**
394   * Clears any statistical information collected to this point.
395   */
396  public void clearStatistics()
397  {
398      abandonRequests.set(0);
399      addRequests.set(0);
400      addResponses.set(0);
401      bindRequests.set(0);
402      bindResponses.set(0);
403      bytesRead.set(0);
404      bytesWritten.set(0);
405      compareRequests.set(0);
406      compareResponses.set(0);
407      connectionsClosed.set(0);
408      connectionsEstablished.set(0);
409      deleteRequests.set(0);
410      deleteResponses.set(0);
411      extendedRequests.set(0);
412      extendedResponses.set(0);
413      messagesRead.set(0);
414      messagesWritten.set(0);
415      modifyRequests.set(0);
416      modifyResponses.set(0);
417      modifyDNRequests.set(0);
418      modifyDNResponses.set(0);
419      operationsAbandoned.set(0);
420      operationsCompleted.set(0);
421      operationsInitiated.set(0);
422      searchRequests.set(0);
423      searchOneRequests.set(0);
424      searchSubRequests.set(0);
425      searchResultEntries.set(0);
426      searchResultReferences.set(0);
427      searchResultsDone.set(0);
428      unbindRequests.set(0);
429
430      addOperationCount.set(0);
431      addOperationTime.set(0);
432      searchOperationCount.set(0);
433      searchOperationTime.set(0);
434      delOperationCount.set(0);
435      delOperationTime.set(0);
436      bindOperationCount.set(0);
437      bindOperationTime.set(0);
438      unbindOperationCount.set(0);
439      unbindOperationTime.set(0);
440      compOperationCount.set(0);
441      compOperationTime.set(0);
442      modOperationCount.set(0);
443      modOperationTime.set(0);
444      moddnOperationCount.set(0);
445      moddnOperationTime.set(0);
446      abandonOperationCount.set(0);
447      abandonOperationTime.set(0);
448      extOperationCount.set(0);
449      extOperationTime.set(0);
450  }
451
452
453
454
455  /**
456   * Updates the appropriate set of counters to indicate that a new
457   * connection has been established.
458   */
459  public void updateConnect()
460  {
461    connectionsEstablished.getAndIncrement();
462  }
463
464
465
466  /**
467   * Updates the appropriate set of counters to indicate that a
468   * connection has been closed.
469   */
470  public void updateDisconnect()
471  {
472      connectionsClosed.getAndIncrement();
473  }
474
475
476
477  /**
478   * Updates the appropriate set of counters to indicate that the
479   * specified number of bytes have been read by the client.
480   *
481   * @param bytesRead
482   *          The number of bytes read by the client.
483   */
484  public void updateBytesRead(int bytesRead)
485  {
486     this.bytesRead.getAndAdd(bytesRead);
487  }
488
489
490
491  /**
492   * Updates the appropriate set of counters to indicate that the
493   * specified number of bytes have been written to the client.
494   *
495   * @param bytesWritten
496   *          The number of bytes written to the client.
497   */
498  public void updateBytesWritten(int bytesWritten)
499  {
500     this.bytesWritten.getAndAdd(bytesWritten);
501  }
502
503
504
505  /**
506   * Updates the appropriate set of counters based on the provided
507   * message that has been read from the client.
508   *
509   * @param message
510   *          The message that was read from the client.
511   */
512  public void updateMessageRead(LDAPMessage message)
513  {
514      messagesRead.getAndIncrement();
515      operationsInitiated.getAndIncrement();
516
517      switch (message.getProtocolOp().getType())
518      {
519      case OP_TYPE_ABANDON_REQUEST:
520        abandonRequests.getAndIncrement();
521        break;
522      case OP_TYPE_ADD_REQUEST:
523        addRequests.getAndIncrement();
524        break;
525      case OP_TYPE_BIND_REQUEST:
526        bindRequests.getAndIncrement();
527        break;
528      case OP_TYPE_COMPARE_REQUEST:
529        compareRequests.getAndIncrement();
530        break;
531      case OP_TYPE_DELETE_REQUEST:
532        deleteRequests.getAndIncrement();
533        break;
534      case OP_TYPE_EXTENDED_REQUEST:
535        extendedRequests.getAndIncrement();
536        break;
537      case OP_TYPE_MODIFY_REQUEST:
538        modifyRequests.getAndIncrement();
539        break;
540      case OP_TYPE_MODIFY_DN_REQUEST:
541        modifyDNRequests.getAndIncrement();
542        break;
543      case OP_TYPE_SEARCH_REQUEST:
544        searchRequests.getAndIncrement();
545        SearchRequestProtocolOp s = (SearchRequestProtocolOp)message
546            .getProtocolOp();
547        switch (s.getScope().asEnum())
548        {
549        case BASE_OBJECT:
550            // we don't count base object searches as
551            // this value can be derived from the others
552            break;
553        case SINGLE_LEVEL:
554            searchOneRequests.getAndIncrement();
555            break;
556        case WHOLE_SUBTREE:
557            searchSubRequests.getAndIncrement();
558            break;
559        default:
560            break;
561        }
562        break;
563      case OP_TYPE_UNBIND_REQUEST:
564        unbindRequests.getAndIncrement();
565        break;
566      }
567  }
568
569
570
571  /**
572   * Updates the appropriate set of counters based on the provided
573   * message that has been written to the client.
574   *
575   * @param message
576   *          The message that was written to the client.
577   */
578  public void updateMessageWritten(LDAPMessage message)
579  {
580      messagesWritten.getAndIncrement();
581
582      switch (message.getProtocolOp().getType())
583      {
584      case OP_TYPE_ADD_RESPONSE:
585        addResponses.getAndIncrement();
586        operationsCompleted.getAndIncrement();
587        break;
588      case OP_TYPE_BIND_RESPONSE:
589        bindResponses.getAndIncrement();
590        operationsCompleted.getAndIncrement();
591        break;
592      case OP_TYPE_COMPARE_RESPONSE:
593        compareResponses.getAndIncrement();
594        operationsCompleted.getAndIncrement();
595        break;
596      case OP_TYPE_DELETE_RESPONSE:
597        deleteResponses.getAndIncrement();
598        operationsCompleted.getAndIncrement();
599        break;
600      case OP_TYPE_EXTENDED_RESPONSE:
601        extendedResponses.getAndIncrement();
602
603        // We don't want to include unsolicited notifications as
604        // "completed" operations.
605        if (message.getMessageID() > 0)
606        {
607          operationsCompleted.getAndIncrement();
608        }
609        break;
610      case OP_TYPE_MODIFY_RESPONSE:
611        modifyResponses.getAndIncrement();
612        operationsCompleted.getAndIncrement();
613        break;
614      case OP_TYPE_MODIFY_DN_RESPONSE:
615        modifyDNResponses.getAndIncrement();
616        operationsCompleted.getAndIncrement();
617        break;
618      case OP_TYPE_SEARCH_RESULT_ENTRY:
619        searchResultEntries.getAndIncrement();
620        break;
621      case OP_TYPE_SEARCH_RESULT_REFERENCE:
622        searchResultReferences.getAndIncrement();
623        break;
624      case OP_TYPE_SEARCH_RESULT_DONE:
625        searchResultsDone.getAndIncrement();
626        operationsCompleted.getAndIncrement();
627        break;
628      }
629  }
630
631
632
633  /**
634   * Updates the appropriate set of counters to indicate that an
635   * operation was abandoned without sending a response to the client.
636   */
637  public void updateAbandonedOperation()
638  {
639      operationsAbandoned.getAndIncrement();
640  }
641
642
643
644  /**
645   * Constructs an attribute using the provided information. It will
646   * use the server's schema definitions.
647   *
648   * @param name
649   *          The name to use for the attribute.
650   * @param value
651   *          The value to use for the attribute.
652   * @return the constructed attribute.
653   */
654  protected Attribute createAttribute(String name, String value)
655  {
656    AttributeType attrType =
657      DirectoryServer.getAttributeType(name.toLowerCase());
658    return Attributes.create(attrType, value);
659  }
660
661
662
663  /**
664   * Retrieves the number of client connections that have been
665   * established.
666   *
667   * @return The number of client connections that have been
668   *         established.
669   */
670  public long getConnectionsEstablished()
671  {
672   return connectionsEstablished.get();
673  }
674
675
676
677  /**
678   * Retrieves the number of client connections that have been closed.
679   *
680   * @return The number of client connections that have been closed.
681   */
682  public long getConnectionsClosed()
683  {
684      return connectionsClosed.get();
685
686  }
687
688
689
690  /**
691   * Retrieves the number of bytes that have been received from clients.
692   *
693   * @return The number of bytes that have been received from clients.
694   */
695  public long getBytesRead()
696  {
697      return bytesRead.get();
698  }
699
700
701
702  /**
703   * Retrieves the number of bytes that have been written to clients.
704   *
705   * @return The number of bytes that have been written to clients.
706   */
707  public long getBytesWritten()
708  {
709      return bytesWritten.get();
710  }
711
712
713
714  /**
715   * Retrieves the number of LDAP messages that have been received from
716   * clients.
717   *
718   * @return The number of LDAP messages that have been received from
719   *         clients.
720   */
721  public long getMessagesRead()
722  {
723    return messagesRead.get();
724  }
725
726
727
728  /**
729   * Retrieves the number of LDAP messages that have been written to
730   * clients.
731   *
732   * @return The number of LDAP messages that have been written to
733   *         clients.
734   */
735  public long getMessagesWritten()
736  {
737   return messagesWritten.get();
738  }
739
740
741
742  /**
743   * Retrieves the number of operations that have been initiated by
744   * clients.
745   *
746   * @return The number of operations that have been initiated by
747   *         clients.
748   */
749  public long getOperationsInitiated()
750  {
751    return operationsInitiated.get();
752  }
753
754
755
756  /**
757   * Retrieves the number of operations for which the server has
758   * completed processing.
759   *
760   * @return The number of operations for which the server has completed
761   *         processing.
762   */
763  public long getOperationsCompleted()
764  {
765      return operationsCompleted.get();
766  }
767
768
769
770  /**
771   * Retrieves the number of operations that have been abandoned by
772   * clients.
773   *
774   * @return The number of operations that have been abandoned by
775   *         clients.
776   */
777  public long getOperationsAbandoned()
778  {
779      return operationsAbandoned.get();
780  }
781
782
783
784  /**
785   * Retrieves the number of abandon requests that have been received.
786   *
787   * @return The number of abandon requests that have been received.
788   */
789  public long getAbandonRequests()
790  {
791      return abandonRequests.get();
792  }
793
794
795
796  /**
797   * Retrieves the number of add requests that have been received.
798   *
799   * @return The number of add requests that have been received.
800   */
801  public long getAddRequests()
802  {
803      return addRequests.get();
804  }
805
806
807
808  /**
809   * Retrieves the number of add responses that have been sent.
810   *
811   * @return The number of add responses that have been sent.
812   */
813  public long getAddResponses()
814  {
815      return addResponses.get();
816  }
817
818
819
820  /**
821   * Retrieves the number of bind requests that have been received.
822   *
823   * @return The number of bind requests that have been received.
824   */
825  public long getBindRequests()
826  {
827      return bindRequests.get();
828  }
829
830
831
832  /**
833   * Retrieves the number of bind responses that have been sent.
834   *
835   * @return The number of bind responses that have been sent.
836   */
837  public long getBindResponses()
838  {
839      return bindResponses.get();
840  }
841
842
843
844  /**
845   * Retrieves the number of compare requests that have been received.
846   *
847   * @return The number of compare requests that have been received.
848   */
849  public long getCompareRequests()
850  {
851      return compareRequests.get();
852  }
853
854
855
856  /**
857   * Retrieves the number of compare responses that have been sent.
858   *
859   * @return The number of compare responses that have been sent.
860   */
861  public long getCompareResponses()
862  {
863      return compareResponses.get();
864  }
865
866
867
868  /**
869   * Retrieves the number of delete requests that have been received.
870   *
871   * @return The number of delete requests that have been received.
872   */
873  public long getDeleteRequests()
874  {
875      return deleteRequests.get();
876  }
877
878
879
880  /**
881   * Retrieves the number of delete responses that have been sent.
882   *
883   * @return The number of delete responses that have been sent.
884   */
885  public long getDeleteResponses()
886  {
887      return deleteResponses.get();
888  }
889
890
891
892  /**
893   * Retrieves the number of extended requests that have been received.
894   *
895   * @return The number of extended requests that have been received.
896   */
897  public long getExtendedRequests()
898  {
899      return extendedRequests.get();
900  }
901
902
903
904  /**
905   * Retrieves the number of extended responses that have been sent.
906   *
907   * @return The number of extended responses that have been sent.
908   */
909  public long getExtendedResponses()
910  {
911      return extendedResponses.get();
912  }
913
914
915
916  /**
917   * Retrieves the number of modify requests that have been received.
918   *
919   * @return The number of modify requests that have been received.
920   */
921  public long getModifyRequests()
922  {
923      return modifyRequests.get();
924  }
925
926
927
928  /**
929   * Retrieves the number of modify responses that have been sent.
930   *
931   * @return The number of modify responses that have been sent.
932   */
933  public long getModifyResponses()
934  {
935      return modifyResponses.get();
936  }
937
938
939
940  /**
941   * Retrieves the number of modify DN requests that have been received.
942   *
943   * @return The number of modify DN requests that have been received.
944   */
945  public long getModifyDNRequests()
946  {
947      return modifyDNRequests.get();
948  }
949
950
951
952  /**
953   * Retrieves the number of modify DN responses that have been sent.
954   *
955   * @return The number of modify DN responses that have been sent.
956   */
957  public long getModifyDNResponses()
958  {
959      return modifyDNResponses.get();
960  }
961
962
963
964  /**
965   * Retrieves the number of search requests that have been received.
966   *
967   * @return The number of search requests that have been received.
968   */
969  public long getSearchRequests()
970  {
971      return searchRequests.get();
972  }
973
974
975
976  /**
977   * Retrieves the number of one-level search requests that have been received.
978   *
979   * @return The number of one-level search requests that have been received.
980   */
981  public long getSearchOneRequests()
982  {
983      return searchOneRequests.get();
984  }
985
986
987
988  /**
989   * Retrieves the number of subtree search requests that have been received.
990   *
991   * @return The number of subtree search requests that have been received.
992   */
993  public long getSearchSubRequests()
994  {
995      return searchSubRequests.get();
996  }
997
998
999
1000  /**
1001   * Retrieves the number of search result entries that have been sent.
1002   *
1003   * @return The number of search result entries that have been sent.
1004   */
1005  public long getSearchResultEntries()
1006  {
1007      return searchResultEntries.get();
1008  }
1009
1010
1011
1012  /**
1013   * Retrieves the number of search result references that have been
1014   * sent.
1015   *
1016   * @return The number of search result references that have been sent.
1017   */
1018  public long getSearchResultReferences()
1019  {
1020      return searchResultReferences.get();
1021  }
1022
1023
1024
1025  /**
1026   * Retrieves the number of search result done messages that have been
1027   * sent.
1028   *
1029   * @return The number of search result done messages that have been
1030   *         sent.
1031   */
1032  public long getSearchResultsDone()
1033  {
1034      return searchResultsDone.get();
1035  }
1036
1037
1038
1039  /**
1040   * Retrieves the number of unbind requests that have been received.
1041   *
1042   * @return The number of unbind requests that have been received.
1043   */
1044  public long getUnbindRequests()
1045  {
1046      return unbindRequests.get();
1047  }
1048
1049  /**
1050   * Update the operation counters and times depending on the OperationType.
1051   * @param type of the operation.
1052   * @param time of the operation execution.
1053   */
1054
1055  public void updateOperationMonitoringData(OperationType type, long time) {
1056      if (type.equals(OperationType.ADD)) {
1057          addOperationCount.getAndIncrement();
1058          addOperationTime.getAndAdd(time);
1059      }
1060      else if (type.equals(OperationType.SEARCH)) {
1061          searchOperationCount.getAndIncrement();
1062          searchOperationTime.getAndAdd(time);
1063      }
1064      else if (type.equals(OperationType.ABANDON)) {
1065          abandonOperationCount.getAndIncrement();
1066          abandonOperationTime.getAndAdd(time);
1067      }
1068      else if (type.equals(OperationType.BIND)) {
1069          bindOperationCount.getAndIncrement();
1070          bindOperationTime.getAndAdd(time);
1071      }
1072      else if (type.equals(OperationType.UNBIND)) {
1073          unbindOperationCount.getAndIncrement();
1074          unbindOperationTime.getAndAdd(time);
1075      }
1076      else if (type.equals(OperationType.COMPARE)) {
1077          compOperationCount.getAndIncrement();
1078          compOperationTime.getAndAdd(time);
1079      }
1080      else if (type.equals(OperationType.DELETE)) {
1081          delOperationCount.getAndIncrement();
1082          delOperationTime.getAndAdd(time);
1083      }
1084      else if (type.equals(OperationType.EXTENDED)) {
1085          extOperationCount.getAndIncrement();
1086          extOperationTime.getAndAdd(time);
1087      }
1088      else if (type.equals(OperationType.MODIFY)) {
1089          modOperationCount.getAndIncrement();
1090          modOperationTime.getAndAdd(time);
1091      }
1092      else if (type.equals(OperationType.MODIFY_DN)) {
1093          moddnOperationCount.getAndIncrement();
1094          moddnOperationTime.getAndAdd(time);
1095      }
1096  }
1097
1098}