-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
Configurator.java
840 lines (770 loc) · 25.5 KB
/
Configurator.java
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
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
/*
* Copyright 2012 Martin Winandy
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package org.pmw.tinylog;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.regex.Pattern;
import org.pmw.tinylog.writers.ConsoleWriter;
import org.pmw.tinylog.writers.Writer;
/**
* Configurator to configure {@link org.pmw.tinylog.Logger Logger}.
*/
public final class Configurator {
private static final String DEFAULT_PROPERTIES_FILE = "tinylog.properties";
private static final String DEFAULT_THREAD_TO_OBSERVE_BY_WRITING_THREAD = "main";
private static final int DEFAULT_PRIORITY_FOR_WRITING_THREAD = (Thread.MIN_PRIORITY + Thread.NORM_PRIORITY) / 2;
private static final Pattern URL_DETECTION_PATTERN = Pattern.compile("^[a-zA-Z]{2,}:/.*");
private static WritingThread activeWritingThread = null;
private static final Object lock = new Object();
private Level level;
private final Map<String, Level> customLevels;
private String formatPattern;
private Locale locale;
private final List<WriterDefinition> writers;
private WritingThreadData writingThreadData;
private Integer maxStackTraceElements;
/**
* @param level
* Severity level
* @param customLevels
* Custom severity levels for specific packages and classes
* @param formatPattern
* Format pattern for log entries
* @param locale
* Locale for format pattern
* @param writers
* Writer definitions (can be <code>empty</code> to disable any output)
* @param writingThreadData
* Data for writing thread (can be <code>null</code> to write log entries synchronously)
* @param maxStackTraceElements
* Limit of stack traces for exceptions
*/
Configurator(final Level level, final Map<String, Level> customLevels, final String formatPattern, final Locale locale,
final List<WriterDefinition> writers, final WritingThreadData writingThreadData, final Integer maxStackTraceElements) {
this.level = level;
this.customLevels = new HashMap<String, Level>(customLevels);
this.formatPattern = formatPattern;
this.locale = locale;
this.writers = new ArrayList<WriterDefinition>(writers);
this.writingThreadData = writingThreadData;
this.maxStackTraceElements = maxStackTraceElements;
}
/**
* Create a new configurator, based on the default configuration.
*
* @return A new configurator
*/
public static Configurator defaultConfig() {
return new Configurator(null, Collections.<String, Level> emptyMap(), null, Locale.getDefault(),
Collections.<WriterDefinition> singletonList(new WriterDefinition(new ConsoleWriter())), null, null);
}
/**
* Create a new configurator, based on the current configuration.
*
* @return A new configurator
*/
public static Configurator currentConfig() {
return Logger.getConfiguration();
}
/**
* Load a properties file from classpath.
*
* @param file
* Path to file to load
* @return A new configurator
* @throws IOException
* Failed to load and read file
*/
public static Configurator fromResource(final String file) throws IOException {
Properties properties = new Properties();
InputStream stream = Configurator.class.getClassLoader().getResourceAsStream(file);
if (stream == null) {
throw new FileNotFoundException(file);
} else {
try {
shutdownWritingThread(true);
properties.load(stream);
} finally {
stream.close();
}
}
return PropertiesLoader.readProperties(properties);
}
/**
* Load a properties file from file system.
*
* @param file
* File to load
* @return A new configurator
* @throws IOException
* Failed to load and read file
*/
public static Configurator fromFile(final File file) throws IOException {
Properties properties = new Properties();
InputStream stream = null;
try {
stream = new FileInputStream(file);
shutdownWritingThread(true);
properties.load(stream);
} finally {
if (stream != null) {
stream.close();
}
}
return PropertiesLoader.readProperties(properties);
}
/**
* Load a properties file from an input stream.
*
* @param stream
* Properties file
* @return A new configurator
* @throws IOException
* Failed to read from stream
*/
public static Configurator fromStream(final InputStream stream) throws IOException {
if (stream == null) {
throw new FileNotFoundException();
} else {
Properties properties = new Properties();
properties.load(stream);
return PropertiesLoader.readProperties(properties);
}
}
/**
* Load a properties file from a URL.
*
* @param url
* Properties file
* @return A new configurator
* @throws IOException
* Failed to read from URL
*/
public static Configurator fromURL(final URL url) throws IOException {
Properties properties = new Properties();
InputStream stream = url.openStream();
if (stream == null) {
throw new FileNotFoundException();
} else {
try {
properties.load(stream);
} finally {
stream.close();
}
}
return PropertiesLoader.readProperties(properties);
}
/**
* Load properties from a {@link Map}.
*
* @param map
* Map with configuration
* @return A new configurator
*/
public static Configurator fromMap(final Map<String, ?> map) {
Properties properties = new Properties();
for (Entry<String, ?> entry : map.entrySet()) {
Object value = entry.getValue();
if (value != null) {
properties.put(entry.getKey(), value.toString());
}
}
return PropertiesLoader.readProperties(properties);
}
/**
* Change the severity level. The logger creates and outputs only log entries for the current severity level and
* higher.
*
* @param level
* New severity level
* @return The current configurator
*/
public Configurator level(final Level level) {
this.level = level;
return this;
}
/**
* Set a custom severity level for a package.
*
* This will override the default severity level for this package.
*
* @param packageObject
* Package
* @param level
* The severity level (or <code>null</code> to reset it to the default severity level)
* @return The current configurator
*/
public Configurator level(final Package packageObject, final Level level) {
return level(packageObject.getName(), level);
}
/**
* Set a custom severity level for a class.
*
* This will override the default severity level for this class.
*
* @param classObject
* Class
* @param level
* The severity level (or <code>null</code> to reset it to the default severity level)
* @return The current configurator
*/
public Configurator level(final Class<?> classObject, final Level level) {
return level(classObject.getName(), level);
}
/**
* Set a custom severity level for a package or class.
*
* This will override the default severity level for this package respectively class.
*
* @param packageOrClass
* Name of a package or class
* @param level
* The severity level (or <code>null</code> to reset it to the default severity level)
* @return The current configurator
*/
public Configurator level(final String packageOrClass, final Level level) {
if (level == null) {
customLevels.remove(packageOrClass);
} else {
customLevels.put(packageOrClass, level);
}
return this;
}
/**
* Reset all custom severity levels (to use the default severity level again).
*
* @return The current configurator
*/
public Configurator resetCustomLevels() {
customLevels.clear();
return this;
}
/**
* Set the format pattern for log entries.
* <code>"{date:yyyy-MM-dd HH:mm:ss} [{thread}] {class}.{method}()\n{level}: {message}"</code> is the default format
* pattern. The date format pattern is compatible with {@link SimpleDateFormat}.
*
* @param formatPattern
* Format pattern for log entries (or <code>null</code> to reset to default)
* @return The current configurator
*
* @see SimpleDateFormat
*/
public Configurator formatPattern(final String formatPattern) {
this.formatPattern = formatPattern;
return this;
}
/**
* Set the locale that is used to render format patterns for log entries.
*
* It will be used e. g. to format numbers and dates.
*
* @param locale
* Locale for format patterns
* @return The current configurator
*/
public Configurator locale(final Locale locale) {
if (locale == null) {
this.locale = Locale.getDefault();
} else {
this.locale = locale;
}
return this;
}
/**
* Set a writer to output created log entries. All existing writers will be replaced.
*
* @param writer
* Writer to set (can be <code>null</code> to disable any output)
* @return The current configurator
*/
public Configurator writer(final Writer writer) {
writers.clear();
if (writer != null) {
writers.add(new WriterDefinition(writer));
}
return this;
}
/**
* Set a writer to output created log entries. All existing writers will be replaced.
*
* @param writer
* Writer to set (can be <code>null</code> to disable any output)
* @param level
* Writer will output entries with the same or higher severity level
* @return The current configurator
*/
public Configurator writer(final Writer writer, final Level level) {
if (writer == null) {
throw new NullPointerException("writer is null");
}
if (level == null) {
throw new NullPointerException("level is null");
}
writers.clear();
writers.add(new WriterDefinition(writer, level));
return this;
}
/**
* Set a writer to output created log entries. All existing writers will be replaced.
*
* @param writer
* Writer to set (can be <code>null</code> to disable any output)
* @param formatPattern
* Format pattern to use instead of the global format pattern to render log entries
* @return The current configurator
*/
public Configurator writer(final Writer writer, final String formatPattern) {
if (writer == null) {
throw new NullPointerException("writer is null");
}
if (formatPattern == null) {
throw new NullPointerException("format pattern is null");
}
writers.clear();
writers.add(new WriterDefinition(writer, formatPattern));
return this;
}
/**
* Set a writer to output created log entries. All existing writers will be replaced.
*
* @param writer
* Writer to set (can be <code>null</code> to disable any output)
* @param level
* Writer will output entries with the same or higher severity level
* @param formatPattern
* Format pattern to use instead of the global format pattern to render log entries
* @return The current configurator
*/
public Configurator writer(final Writer writer, final Level level, final String formatPattern) {
if (writer == null) {
throw new NullPointerException("writer is null");
}
if (level == null) {
throw new NullPointerException("level is null");
}
if (formatPattern == null) {
throw new NullPointerException("format pattern is null");
}
writers.clear();
writers.add(new WriterDefinition(writer, level, formatPattern));
return this;
}
/**
* Add an additional writer for outputting the created log entries.
*
* @param writer
* Writer to add
* @return The current configurator
*/
public Configurator addWriter(final Writer writer) {
if (writer == null) {
throw new NullPointerException("writer is null");
}
writers.add(new WriterDefinition(writer));
return this;
}
/**
* Add an additional writer for outputting the created log entries.
*
* @param writer
* Writer to add
* @param level
* Writer will output entries with the same or higher severity level
* @return The current configurator
*/
public Configurator addWriter(final Writer writer, final Level level) {
if (writer == null) {
throw new NullPointerException("writer is null");
}
if (level == null) {
throw new NullPointerException("level is null");
}
writers.add(new WriterDefinition(writer, level));
return this;
}
/**
* Add an additional writer for outputting the created log entries.
*
* @param writer
* Writer to add
* @param formatPattern
* Format pattern to use instead of the global format pattern to render log entries
* @return The current configurator
*/
public Configurator addWriter(final Writer writer, final String formatPattern) {
if (writer == null) {
throw new NullPointerException("writer is null");
}
if (formatPattern == null) {
throw new NullPointerException("format pattern is null");
}
writers.add(new WriterDefinition(writer, formatPattern));
return this;
}
/**
* Add an additional writer for outputting the created log entries.
*
* @param writer
* Writer to set (can be <code>null</code> to disable any output)
* @param level
* Writer will output entries with the same or higher severity level
* @param formatPattern
* Format pattern to use instead of the global format pattern to render log entries
* @return The current configurator
*/
public Configurator addWriter(final Writer writer, final Level level, final String formatPattern) {
if (writer == null) {
throw new NullPointerException("writer is null");
}
if (level == null) {
throw new NullPointerException("level is null");
}
if (formatPattern == null) {
throw new NullPointerException("format pattern is null");
}
writers.add(new WriterDefinition(writer, level, formatPattern));
return this;
}
/**
* Remove a writer.
*
* @param writer
* Writer to remove
* @return The current configurator
*/
public Configurator removeWriter(final Writer writer) {
Iterator<WriterDefinition> iterator = writers.iterator();
while (iterator.hasNext()) {
if (iterator.next().getWriter() == writer) {
iterator.remove();
}
}
return this;
}
/**
* Remove all writers.
*
* @return The current configurator
*/
public Configurator removeAllWriters() {
writers.clear();
return this;
}
/**
* The writing thread can writes log entries asynchronously. This thread will automatically shutdown, if the main
* thread is dead.
*
* @param enable
* <code>true</code> to enable the writing thread, <code>false</code> to disable it
* @return The current configurator
*/
public Configurator writingThread(final boolean enable) {
if (enable) {
return writingThread(DEFAULT_THREAD_TO_OBSERVE_BY_WRITING_THREAD, DEFAULT_PRIORITY_FOR_WRITING_THREAD);
} else {
this.writingThreadData = null;
return this;
}
}
/**
* The writing thread can writes log entries asynchronously. This thread will automatically shutdown, if the main
* thread is dead.
*
* @param priority
* Priority of the writing thread (must be between {@link Thread#MIN_PRIORITY} and
* {@link Thread#MAX_PRIORITY})
* @return The current configurator
*/
public Configurator writingThread(final int priority) {
return writingThread(DEFAULT_THREAD_TO_OBSERVE_BY_WRITING_THREAD, priority);
}
/**
* The writing thread can writes log entries asynchronously. This thread will automatically shutdown, if the
* observed thread is dead.
*
* @param threadToObserve
* Name of the tread to observe (e.g. "main" for the main thread) or <code>null</code> to disable
* automatic shutdown
* @return The current configurator
*/
public Configurator writingThread(final String threadToObserve) {
return writingThread(threadToObserve, DEFAULT_PRIORITY_FOR_WRITING_THREAD);
}
/**
* The writing thread can writes log entries asynchronously. This thread will automatically shutdown, if the
* observed thread is dead.
*
* @param threadToObserve
* Name of the tread to observe (e.g. "main" for the main thread) or <code>null</code> to disable
* automatic shutdown
* @param priority
* Priority of the writing thread (must be between {@link Thread#MIN_PRIORITY} and
* {@link Thread#MAX_PRIORITY})
* @return The current configurator
*/
public Configurator writingThread(final String threadToObserve, final int priority) {
this.writingThreadData = new WritingThreadData(threadToObserve, priority);
return this;
}
/**
* Set the limit of stack traces for exceptions (default is 40). Can be set to "-1" for no limitation and to "0" to
* disable any stack traces.
*
* @param maxStackTraceElements
* Limit of stack traces
* @return The current configurator
*/
public Configurator maxStackTraceElements(final int maxStackTraceElements) {
if (maxStackTraceElements < 0) {
this.maxStackTraceElements = Integer.MAX_VALUE;
} else {
this.maxStackTraceElements = maxStackTraceElements;
}
return this;
}
/**
* Activate the configuration.
*
* @return <code>true</code> if the configuration has been successfully activated, <code>false</code> if the
* activation failed
*/
public boolean activate() {
synchronized (lock) {
if (activeWritingThread != null && (writingThreadData == null || !writingThreadData.covers(activeWritingThread))) {
activeWritingThread.shutdown();
activeWritingThread = null;
}
Configuration configuration = create();
try {
Logger.setConfiguration(configuration);
} catch (Exception ex) {
InternalLogger.error(ex, "Failed to activate configuration");
return false;
}
if (activeWritingThread == null && configuration.getWritingThread() != null) {
activeWritingThread = configuration.getWritingThread();
activeWritingThread.start();
}
return true;
}
}
/**
* Manually shutdown of writing thread.
*
* @param wait
* <code>true</code> to wait for the successful shutdown, <code>false</code> for an asynchronous shutdown
*/
public static void shutdownWritingThread(final boolean wait) {
synchronized (lock) {
if (activeWritingThread != null) {
activeWritingThread.shutdown();
if (wait) {
boolean finished;
do {
try {
activeWritingThread.join();
finished = true;
} catch (InterruptedException ex) {
finished = false;
}
} while (!finished);
}
activeWritingThread = null;
}
}
}
/**
* Manually shutdown of configuration observer.
*
* @param wait
* <code>true</code> to wait for the successful shutdown, <code>false</code> for an asynchronous shutdown
*/
public static void shutdownConfigurationObserver(final boolean wait) {
ConfigurationObserver observer = ConfigurationObserver.getActiveObserver();
if (observer != null) {
observer.shutdown();
if (wait) {
while (true) {
try {
observer.join();
break;
} catch (InterruptedException ex) {
continue;
}
}
}
}
}
/**
* Load properties from environment variables (also know as "-D" parameter) and from the default properties file
* "tinylog.properties", which must be placed in the default package.
*
* @return A new configurator
*/
static Configurator init() {
Properties properties = new Properties();
String file = System.getProperty("tinylog.configuration", DEFAULT_PROPERTIES_FILE);
URL url = null;
InputStream stream = null;
boolean isResource = false;
boolean isFile = false;
boolean isURL = false;
if (URL_DETECTION_PATTERN.matcher(file).matches()) {
try {
url = new URL(file);
stream = url.openStream();
isURL = true;
} catch (MalformedURLException ex) {
InternalLogger.error(ex, "Invalid URL: \"{}\"", file);
} catch (IOException ex) {
InternalLogger.error(ex, "Cannot connect to \"{}\"", file);
}
} else {
stream = Configurator.class.getClassLoader().getResourceAsStream(file);
if (stream == null) {
try {
stream = new FileInputStream(file);
isFile = true;
} catch (FileNotFoundException ex) {
if (file != DEFAULT_PROPERTIES_FILE) {
InternalLogger.error(ex, "Cannot find \"{}\"", file);
}
}
} else {
isResource = true;
}
}
if (stream != null) {
try {
try {
properties.load(stream);
} finally {
stream.close();
}
} catch (IOException ex) {
InternalLogger.error(ex, "Failed to read properties file \"{}\"", file);
}
}
Properties systemProperties = System.getProperties();
for (Object key : systemProperties.keySet()) {
String name = (String) key;
if (name.startsWith("tinylog.")) {
properties.put(name, systemProperties.getProperty(name));
}
}
if (properties.isEmpty()) {
return Configurator.defaultConfig();
} else {
if ("true".equalsIgnoreCase(properties.getProperty("tinylog.configuration.observe"))) {
shutdownWritingThread(true);
Configurator configurator = PropertiesLoader.readProperties(properties);
if (isResource) {
ConfigurationObserver.createResourceConfigurationObserver(configurator, properties, file).start();
} else if (isFile) {
ConfigurationObserver.createFileConfigurationObserver(configurator, properties, file).start();
} else if (isURL) {
ConfigurationObserver.createURLConfigurationObserver(configurator, properties, url).start();
}
return configurator;
} else {
shutdownWritingThread(true);
return PropertiesLoader.readProperties(properties);
}
}
}
/**
* Copy the configurator.
*
* @return A new configurator with the same configuration
*/
Configurator copy() {
WritingThreadData writingThreadDataCopy = writingThreadData == null ? null
: new WritingThreadData(writingThreadData.threadToObserve, writingThreadData.priority);
return new Configurator(level, customLevels, formatPattern, locale, writers, writingThreadDataCopy, maxStackTraceElements);
}
/**
* Create the configuration.
*
* @return The created configuration
*/
Configuration create() {
Configurator configurator = copy();
WritingThread writingThread;
if (configurator.writingThreadData == null) {
writingThread = null;
} else {
writingThread = new WritingThread(configurator.writingThreadData.threadToObserve, configurator.writingThreadData.priority);
if (configurator.writingThreadData.threadToObserve != null && writingThread.getThreadToObserve() == null) {
InternalLogger.warn("Thread \"{}\" could not be found, writing thread will not be used", configurator.writingThreadData.threadToObserve);
writingThread = null;
}
}
return new Configuration(configurator, configurator.level, configurator.customLevels, configurator.formatPattern, configurator.locale,
configurator.writers, writingThread, configurator.maxStackTraceElements);
}
/**
* Data for {@link org.pmw.tinylog.WritingThread}.
*/
static final class WritingThreadData {
private final String threadToObserve;
private final int priority;
/**
* @param threadToObserve
* Name of the tread to observe (e.g. "main" for the main thread) or <code>null</code> to disable
* automatic shutdown
* @param priority
* Priority of the writing thread (must be between {@link Thread#MIN_PRIORITY} and
* {@link Thread#MAX_PRIORITY})
*/
WritingThreadData(final String threadToObserve, final int priority) {
this.threadToObserve = threadToObserve;
this.priority = priority;
}
/**
* Test if this writing thread has the same parameters as another writing thread.
*
* @param writingThread
* Writing thread to compare
* @return <code>true</code> if both writing threads have the same parameters, <code>false</code> if not
*/
boolean covers(final WritingThread writingThread) {
if (writingThread == null) {
return false;
}
if (threadToObserve == null) {
if (writingThread.getNameOfThreadToObserve() != null) {
return false;
}
} else if (!threadToObserve.equals(writingThread.getNameOfThreadToObserve())) {
return false;
}
return priority == writingThread.getPriority();
}
}
}