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