mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Nicolas Capponi
30.14.2016 40c232bb1ea09338ddbc93f2be3db6b340575fba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
/*
 * The contents of this file are subject to the terms of the Common Development and
 * Distribution License (the License). You may not use this file except in compliance with the
 * License.
 *
 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
 * specific language governing permission and limitations under the License.
 *
 * When distributing Covered Software, include this CDDL Header Notice in each file and include
 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
 * Header, with the fields enclosed by brackets [] replaced by your own identifying
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2008-2010 Sun Microsystems, Inc.
 * Portions Copyright 2014-2016 ForgeRock AS.
 */
package org.opends.guitools.controlpanel.datamodel;
 
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
 
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.responses.SearchResultEntry;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.forgerock.opendj.ldap.schema.ObjectClass;
import org.opends.guitools.controlpanel.util.ConfigFromDirContext;
import org.opends.quicksetup.UserData;
import org.opends.server.tools.tasks.TaskEntry;
import org.opends.server.types.Schema;
 
import com.forgerock.opendj.util.OperatingSystem;
 
import static org.opends.guitools.controlpanel.datamodel.BasicMonitoringAttributes.*;
import static org.opends.server.schema.ServerSchemaElement.*;
 
/**
 * This is just a class used to provide a data model describing what the
 * StatusPanelDialog will show to the user.
 */
public class ServerDescriptor
{
  private static String localHostName = UserData.getDefaultHostName();
 
  private ServerStatus status;
  private int openConnections;
  private Set<BackendDescriptor> backends = new HashSet<>();
  private Set<ConnectionHandlerDescriptor> listeners = new HashSet<>();
  private ConnectionHandlerDescriptor adminConnector;
  private Set<DN> administrativeUsers = new HashSet<>();
  private String installPath;
  private String instancePath;
  private String openDSVersion;
  private String javaVersion;
  private ArrayList<Exception> exceptions = new ArrayList<>();
  private boolean isWindowsServiceEnabled;
  private boolean isSchemaEnabled;
  private Schema schema;
 
  private SearchResultEntry rootMonitor;
  private SearchResultEntry jvmMemoryUsage;
  private SearchResultEntry systemInformation;
  private SearchResultEntry entryCaches;
  private SearchResultEntry workQueue;
 
  private Set<TaskEntry> taskEntries = new HashSet<>();
 
  private long runningTime = -1;
  private boolean isAuthenticated;
  private String hostName = localHostName;
  private boolean isLocal = true;
 
  /** Enumeration indicating the status of the server. */
  public enum ServerStatus
  {
    /** Server Started. */
    STARTED,
    /** Server Stopped. */
    STOPPED,
    /** Server Starting. */
    STARTING,
    /** Server Stopping. */
    STOPPING,
    /** Not connected to remote. */
    NOT_CONNECTED_TO_REMOTE,
    /** Status Unknown. */
    UNKNOWN
  }
 
  /** Default constructor. */
  public ServerDescriptor()
  {
  }
 
  /**
   * Return the administrative users.
   * @return the administrative users.
   */
  public Set<DN> getAdministrativeUsers()
  {
    return administrativeUsers;
  }
 
  /**
   * Set the administrative users.
   * @param administrativeUsers the administrative users to set
   */
  public void setAdministrativeUsers(Set<DN> administrativeUsers)
  {
    this.administrativeUsers = Collections.unmodifiableSet(administrativeUsers);
  }
 
  /**
   * Returns whether the schema is enabled or not.
   * @return <CODE>true</CODE> if the schema is enabled and <CODE>false</CODE>
   * otherwise.
   */
  public boolean isSchemaEnabled()
  {
    return isSchemaEnabled;
  }
 
  /**
   * Sets whether the schema is enabled or not.
   * @param isSchemaEnabled <CODE>true</CODE> if the schema is enabled and
   * <CODE>false</CODE> otherwise.
   */
  public void setSchemaEnabled(boolean isSchemaEnabled)
  {
    this.isSchemaEnabled = isSchemaEnabled;
  }
 
  /**
   * Return the instance path where the server databases and configuration is
   * located.
   * @return the instance path where the server databases and configuration is
   * located
   */
  public String getInstancePath()
  {
    return instancePath;
  }
 
  /**
   * Sets the instance path where the server databases and configuration is
   * located.
   * @param instancePath the instance path where the server databases and
   * configuration is located.
   */
  public void setInstancePath(String instancePath)
  {
    this.instancePath = instancePath;
  }
 
  /**
   * Return the install path where the server is installed.
   * @return the install path where the server is installed.
   */
  public String getInstallPath()
  {
    return installPath;
  }
 
  /**
   * Sets the install path where the server is installed.
   * @param installPath the install path where the server is installed.
   */
  public void setInstallPath(String installPath)
  {
    this.installPath = installPath;
  }
 
  /**
   * Returns whether the install and the instance are on the same server
   * or not.
   * @return whether the install and the instance are on the same server
   * or not.
   */
  public boolean sameInstallAndInstance()
  {
    boolean sameInstallAndInstance;
    String instance = getInstancePath();
    String install = getInstallPath();
    try
    {
      if (instance != null)
      {
        sameInstallAndInstance = instance.equals(install);
        if (!sameInstallAndInstance &&
            (isLocal() || OperatingSystem.isWindows()))
        {
          File f1 = new File(instance);
          File f2 = new File(install);
          sameInstallAndInstance =
            f1.getCanonicalFile().equals(f2.getCanonicalFile());
        }
      }
      else
      {
        sameInstallAndInstance = install == null;
      }
    }
    catch (IOException ioe)
    {
      sameInstallAndInstance = false;
    }
    return sameInstallAndInstance;
  }
 
  /**
   * Return the java version used to run the server.
   * @return the java version used to run the server.
   */
  public String getJavaVersion()
  {
    return javaVersion;
  }
 
  /**
   * Set the java version used to run the server.
   * @param javaVersion the java version used to run the server.
   */
  public void setJavaVersion(String javaVersion)
  {
    this.javaVersion = javaVersion;
  }
 
  /**
   * Returns the number of open connection in the server.
   * @return the number of open connection in the server.
   */
  public int getOpenConnections()
  {
    return openConnections;
  }
 
  /**
   * Set the number of open connections.
   * @param openConnections the number of open connections.
   */
  public void setOpenConnections(int openConnections)
  {
    this.openConnections = openConnections;
  }
 
  /**
   * Returns the version of the server.
   * @return the version of the server.
   */
  public String getOpenDSVersion()
  {
    return openDSVersion;
  }
 
  /**
   * Sets the version of the server.
   * @param openDSVersion the version of the server.
   */
  public void setOpenDSVersion(String openDSVersion)
  {
    this.openDSVersion = openDSVersion;
  }
 
  /**
   * Returns the status of the server.
   * @return the status of the server.
   */
  public ServerStatus getStatus()
  {
    return status;
  }
 
  /**
   * Sets the status of the server.
   * @param status the status of the server.
   */
  public void setStatus(ServerStatus status)
  {
    this.status = status;
  }
 
  /**
   * Returns the task entries.
   * @return the task entries.
   */
  public Set<TaskEntry> getTaskEntries()
  {
    return taskEntries;
  }
 
  /**
   * Sets the the task entries.
   * @param taskEntries the task entries.
   */
  public void setTaskEntries(Set<TaskEntry> taskEntries)
  {
    this.taskEntries = Collections.unmodifiableSet(taskEntries);
  }
 
  @Override
  public boolean equals(Object o)
  {
    if (this == o)
    {
      return true;
    }
    if (!(o instanceof ServerDescriptor))
    {
      return false;
    }
 
    ServerDescriptor desc = (ServerDescriptor) o;
    return desc.getStatus() == getStatus()
        && desc.isLocal() == isLocal()
        && desc.isAuthenticated() == isAuthenticated()
        && desc.getOpenConnections() == getOpenConnections()
        && areEqual(getInstallPath(), desc.getInstallPath())
        && areEqual(getInstancePath(), desc.getInstancePath())
        && areEqual(getJavaVersion(), desc.getJavaVersion())
        && areEqual(getOpenDSVersion(), desc.getOpenDSVersion())
        && areEqual(desc.getAdministrativeUsers(), getAdministrativeUsers())
        && areEqual(desc.getConnectionHandlers(), getConnectionHandlers())
        && areEqual(desc.getBackends(), getBackends())
        && areEqual(desc.getExceptions(), getExceptions())
        && desc.isSchemaEnabled() == isSchemaEnabled()
        && areSchemasEqual(getSchema(), desc.getSchema())
        && (!OperatingSystem.isWindows() || desc.isWindowsServiceEnabled() == isWindowsServiceEnabled())
        && desc.getTaskEntries().equals(getTaskEntries());
  }
 
  @Override
  public int hashCode()
  {
    String s = installPath + openDSVersion + javaVersion + isAuthenticated;
    return status.hashCode() + openConnections + s.hashCode();
  }
 
  /**
   * Return whether we were authenticated when retrieving the information of
   * this ServerStatusDescriptor.
   * @return <CODE>true</CODE> if we were authenticated when retrieving the
   * information of this ServerStatusDescriptor and <CODE>false</CODE>
   * otherwise.
   */
  public boolean isAuthenticated()
  {
    return isAuthenticated;
  }
 
  /**
   * Sets whether we were authenticated when retrieving the information of
   * this ServerStatusDescriptor.
   * @param isAuthenticated whether we were authenticated when retrieving the
   * information of this ServerStatusDescriptor.
   */
  public void setAuthenticated(boolean isAuthenticated)
  {
    this.isAuthenticated = isAuthenticated;
  }
 
  /**
   * Returns the backend descriptors of the server.
   * @return the backend descriptors of the server.
   */
  public Set<BackendDescriptor> getBackends()
  {
    return backends;
  }
 
  /**
   * Sets the backend descriptors of the server.
   * @param backends the database descriptors to set.
   */
  public void setBackends(Set<BackendDescriptor> backends)
  {
    this.backends = Collections.unmodifiableSet(backends);
  }
 
  /**
   * Returns the listener descriptors of the server.
   * @return the listener descriptors of the server.
   */
  public Set<ConnectionHandlerDescriptor> getConnectionHandlers()
  {
    return listeners;
  }
 
  /**
   * Sets the listener descriptors of the server.
   * @param listeners the listener descriptors to set.
   */
  public void setConnectionHandlers(Set<ConnectionHandlerDescriptor> listeners)
  {
    this.listeners = Collections.unmodifiableSet(listeners);
  }
 
  /**
   * Sets the schema of the server.
   * @param schema the schema of the server.
   */
  public void setSchema(Schema schema)
  {
    this.schema = schema;
  }
 
  /**
   * Returns the schema of the server.
   * @return the schema of the server.
   */
  public Schema getSchema()
  {
    return schema;
  }
 
  /**
   * Returns the host name of the server.
   * @return the host name of the server.
   */
  public String getHostname()
  {
    return hostName;
  }
 
  /**
   * Sets the host name of the server.
   * @param hostName the host name of the server.
   */
  public void setHostname(String hostName)
  {
    this.hostName = hostName;
  }
 
  /**
   * Returns <CODE>true</CODE> if we are trying to manage the local host and
   * <CODE>false</CODE> otherwise.
   * @return <CODE>true</CODE> if we are trying to manage the local host and
   * <CODE>false</CODE> otherwise.
   */
  public boolean isLocal()
  {
    return isLocal;
  }
 
  /**
   * Sets whether this server represents the local instance or a remote server.
   * @param isLocal whether this server represents the local instance or a
   * remote server (in another machine or in another installation on the same
   * machine).
   */
  public void setIsLocal(boolean isLocal)
  {
    this.isLocal = isLocal;
  }
 
  /**
   * Returns the exceptions that occurred while reading the configuration.
   * @return the exceptions that occurred while reading the configuration.
   */
  public List<Exception> getExceptions()
  {
    return Collections.unmodifiableList(exceptions);
  }
 
  /**
   * Sets the exceptions that occurred while reading the configuration.
   * @param exceptions exceptions that occurred while reading the
   * configuration.
   */
  public void setExceptions(Collection<Exception> exceptions)
  {
    this.exceptions.clear();
    this.exceptions.addAll(exceptions);
  }
 
  /**
   * Tells whether the windows service is enabled or not.
   * @return <CODE>true</CODE> if the windows service is enabled and
   * <CODE>false</CODE> otherwise.
   */
  public boolean isWindowsServiceEnabled()
  {
    return isWindowsServiceEnabled;
  }
 
  /**
   * Sets whether the windows service is enabled or not.
   * @param isWindowsServiceEnabled <CODE>true</CODE> if the windows service is
   * enabled and <CODE>false</CODE> otherwise.
   */
  public void setWindowsServiceEnabled(boolean isWindowsServiceEnabled)
  {
    this.isWindowsServiceEnabled = isWindowsServiceEnabled;
  }
 
  /**
   * Returns whether the server is running under a windows system or not.
   * @return whether the server is running under a windows system or not.
   */
  public boolean isWindows()
  {
    if (isLocal())
    {
      return OperatingSystem.isWindows();
    }
    SearchResultEntry sr = getSystemInformationMonitor();
    if (sr == null)
    {
      return false;
    }
    String os = sr.getAttribute("operatingSystem").firstValueAsString();
    return os != null && OperatingSystem.WINDOWS.equals(OperatingSystem.forName(os));
  }
 
  /**
   * Method used to compare schemas.
   * Returns <CODE>true</CODE> if the two schemas are equal and
   * <CODE>false</CODE> otherwise.
   * @param schema1 the first schema.
   * @param schema2 the second schema.
   * @return <CODE>true</CODE> if the two schemas are equal and
   * <CODE>false</CODE> otherwise.
   */
  public static boolean areSchemasEqual(Schema schema1, Schema schema2)
  {
    if (schema1 == schema2)
    {
      return true;
    }
    else if (schema2 == null)
    {
      return schema1 != null;
    }
    else if (schema1 == null)
    {
      return false;
    }
 
    return areAttributeTypesEqual(schema1, schema2)
        && areObjectClassesEqual(schema1, schema2)
        && areEqual(schema1.getMatchingRules(), schema2.getMatchingRules())
        && areEqual(schema1.getSyntaxes(), schema2.getSyntaxes());
  }
 
  private static boolean areAttributeTypesEqual(Schema schema1, Schema schema2)
  {
    final List<AttributeType> attrs1 = new ArrayList<>(schema1.getAttributeTypes());
    final List<AttributeType> attrs2 = new ArrayList<>(schema2.getAttributeTypes());
    if (attrs1.size() != attrs2.size())
    {
      return false;
    }
    Collections.sort(attrs1);
    Collections.sort(attrs2);
    for (int i = 0; i < attrs1.size(); i++)
    {
      AttributeType attr1 = attrs1.get(i);
      AttributeType attr2 = attrs2.get(i);
      if (attr2 == null || !areAttributesEqual(attr1, attr2))
      {
        return false;
      }
    }
    return true;
  }
 
  private static boolean areObjectClassesEqual(Schema schema1, Schema schema2)
  {
    final Collection<ObjectClass> ocs1 = schema1.getObjectClasses();
    final Collection<ObjectClass> ocs2 = schema2.getObjectClasses();
    if (ocs1.size() != ocs2.size())
    {
      return false;
    }
    for (ObjectClass oc1 : ocs1)
    {
      ObjectClass oc2 = schema2.getObjectClass(oc1.getNameOrOID());
      if (oc2.isPlaceHolder() || !areObjectClassesEqual(oc1, oc2))
      {
        return false;
      }
    }
    return true;
  }
 
  /**
   * Method used to compare attributes defined in the schema.
   * Returns <CODE>true</CODE> if the two schema attributes are equal and
   * <CODE>false</CODE> otherwise.
   * @param schema1 the first schema attribute.
   * @param schema2 the second schema attribute.
   * @return <CODE>true</CODE> if the two schema attributes are equal and
   * <CODE>false</CODE> otherwise.
   */
  private static boolean areAttributesEqual(AttributeType attr1, AttributeType attr2)
  {
    return attr1.getOID().equals(attr2.getOID())
        && attr1.isCollective() == attr2.isCollective()
        && attr1.isNoUserModification() == attr2.isNoUserModification()
        && attr1.isObjectClass() == attr2.isObjectClass()
        && attr1.isObsolete() == attr2.isObsolete()
        && attr1.isOperational() == attr2.isOperational()
        && attr1.isSingleValue() == attr2.isSingleValue()
        && areEqual(attr1.getApproximateMatchingRule(), attr2.getApproximateMatchingRule())
        && areEqual(getDefinitionWithFileName(attr1), getDefinitionWithFileName(attr2))
        && areEqual(attr1.getDescription(), attr2.getDescription())
        && areEqual(attr1.getEqualityMatchingRule(), attr2.getEqualityMatchingRule())
        && areEqual(attr1.getOrderingMatchingRule(), attr2.getOrderingMatchingRule())
        && areEqual(attr1.getSubstringMatchingRule(), attr2.getSubstringMatchingRule())
        && areEqual(attr1.getSuperiorType(), attr2.getSuperiorType())
        && areEqual(attr1.getSyntax(), attr2.getSyntax())
        && areEqual(attr1.getSyntax().getOID(), attr2.getSyntax().getOID())
        && areEqual(attr1.getExtraProperties().keySet(), attr2.getExtraProperties().keySet())
        && areEqual(toSet(attr1.getNames()), toSet(attr2.getNames()));
  }
 
  /**
   * Method used to compare objectclasses defined in the schema.
   * Returns <CODE>true</CODE> if the two schema objectclasses are equal and
   * <CODE>false</CODE> otherwise.
   * @param schema1 the first schema objectclass.
   * @param schema2 the second schema objectclass.
   * @return <CODE>true</CODE> if the two schema objectclasses are equal and
   * <CODE>false</CODE> otherwise.
   */
  private static boolean areObjectClassesEqual(ObjectClass oc1, ObjectClass oc2)
  {
    return oc1.getOID().equals(oc2.getOID())
        && areEqual(getDefinitionWithFileName(oc1), getDefinitionWithFileName(oc2))
        && areEqual(oc1.getDescription(), oc2.getDescription())
        && areEqual(oc1.getObjectClassType(), oc2.getObjectClassType())
        && areEqual(oc1.getDeclaredOptionalAttributes(), oc2.getDeclaredOptionalAttributes())
        && areEqual(oc1.getDeclaredRequiredAttributes(), oc2.getDeclaredRequiredAttributes())
        && areEqual(oc1.getSuperiorClasses(), oc2.getSuperiorClasses())
        && areEqual(oc1.getExtraProperties().keySet(), oc2.getExtraProperties().keySet())
        && areEqual(toSet(oc1.getNames()), toSet(oc2.getNames()));
  }
 
  private static Set<Object> toSet(Iterable<?> iterable)
  {
    Set<Object> s = new HashSet<>();
    for (Object o : iterable)
    {
      s.add(o);
    }
    return s;
  }
 
  /**
   * Commodity method used to compare two objects that might be
   * <CODE>null</CODE>.
   * @param o1 the first object.
   * @param o2 the second object.
   * @return if both objects are <CODE>null</CODE> returns true.  If not returns
   * <CODE>true</CODE> if both objects are equal according to the Object.equal
   * method and <CODE>false</CODE> otherwise.
   */
  private static boolean areEqual(Object o1, Object o2)
  {
    if (o1 != null)
    {
      return o1.equals(o2);
    }
    return o2 == null;
  }
 
  /**
   * Returns the admin connector.
   * @return the admin connector.
   */
  public ConnectionHandlerDescriptor getAdminConnector()
  {
    return adminConnector;
  }
 
  /**
   * Sets the admin connector.
   * @param adminConnector the admin connector.
   */
  public void setAdminConnector(ConnectionHandlerDescriptor adminConnector)
  {
    this.adminConnector = adminConnector;
  }
 
  /**
   * Sets the monitoring entry for the entry caches.
   * @param entryCaches the monitoring entry for the entry caches.
   */
  public void setEntryCachesMonitor(SearchResultEntry entryCaches)
  {
    this.entryCaches = entryCaches;
  }
 
  /**
   * Sets the monitoring entry for the JVM memory usage.
   * @param jvmMemoryUsage the monitoring entry for the JVM memory usage.
   */
  public void setJvmMemoryUsageMonitor(SearchResultEntry jvmMemoryUsage)
  {
    this.jvmMemoryUsage = jvmMemoryUsage;
  }
 
  /**
   * Sets the root entry of the monitoring tree.
   * @param rootMonitor the root entry of the monitoring tree.
   */
  public void setRootMonitor(SearchResultEntry rootMonitor)
  {
    this.rootMonitor = rootMonitor;
    runningTime = computeRunningTime(rootMonitor);
  }
 
  private long computeRunningTime(SearchResultEntry rootMonitor)
  {
    if (rootMonitor != null)
    {
      try
      {
        String start = rootMonitor.getAttribute(START_DATE.getAttributeName()).firstValueAsString();
        String current = rootMonitor.getAttribute(CURRENT_DATE.getAttributeName()).firstValueAsString();
        Date startTime = ConfigFromDirContext.utcParser.parse(start);
        Date currentTime = ConfigFromDirContext.utcParser.parse(current);
        return currentTime.getTime() - startTime.getTime();
      }
      catch (Throwable t)
      {
        return -1;
      }
    }
    return -1;
  }
 
  /**
   * Returns the running time of the server in milliseconds.  Returns -1 if
   * no running time could be found.
   * @return the running time of the server in milliseconds.
   */
  public long getRunningTime()
  {
    return runningTime;
  }
 
  /**
   * Sets the monitoring entry for the system information.
   * @param systemInformation entry for the system information.
   */
  public void setSystemInformationMonitor(SearchResultEntry systemInformation)
  {
    this.systemInformation = systemInformation;
  }
 
  /**
   * Sets the monitoring entry of the work queue.
   * @param workQueue entry of the work queue.
   */
  public void setWorkQueueMonitor(SearchResultEntry workQueue)
  {
    this.workQueue = workQueue;
  }
 
  /**
   * Returns the monitoring entry for the entry caches.
   * @return the monitoring entry for the entry caches.
   */
  public SearchResultEntry getEntryCachesMonitor()
  {
    return entryCaches;
  }
 
  /**
   * Returns the monitoring entry for the JVM memory usage.
   * @return the monitoring entry for the JVM memory usage.
   */
  public SearchResultEntry getJvmMemoryUsageMonitor()
  {
    return jvmMemoryUsage;
  }
 
  /**
   * Returns the root entry of the monitoring tree.
   * @return the root entry of the monitoring tree.
   */
  public SearchResultEntry getRootMonitor()
  {
    return rootMonitor;
  }
 
  /**
   * Returns the monitoring entry for the system information.
   * @return the monitoring entry for the system information.
   */
  public SearchResultEntry getSystemInformationMonitor()
  {
    return systemInformation;
  }
 
  /**
   * Returns the monitoring entry for the work queue.
   * @return the monitoring entry for the work queue.
   */
  public SearchResultEntry getWorkQueueMonitor()
  {
    return workQueue;
  }
}