2020import static org .neo4j .driver .internal .logging .DevNullLogging .DEV_NULL_LOGGING ;
2121import static org .neo4j .driver .internal .util .DriverInfoUtil .driverVersion ;
2222
23+ import io .netty .channel .EventLoop ;
2324import java .io .File ;
2425import java .io .Serial ;
2526import java .io .Serializable ;
2829import java .util .Collections ;
2930import java .util .List ;
3031import java .util .Objects ;
32+ import java .util .Optional ;
33+ import java .util .Set ;
3134import java .util .concurrent .TimeUnit ;
3235import java .util .logging .Level ;
36+ import java .util .stream .Collectors ;
37+ import org .neo4j .driver .async .AsyncSession ;
3338import org .neo4j .driver .exceptions .UnsupportedFeatureException ;
39+ import org .neo4j .driver .internal .InternalNotificationConfig ;
3440import org .neo4j .driver .internal .SecuritySettings ;
3541import org .neo4j .driver .internal .async .pool .PoolSettings ;
3642import org .neo4j .driver .internal .cluster .RoutingSettings ;
3945import org .neo4j .driver .net .ServerAddressResolver ;
4046import org .neo4j .driver .util .Experimental ;
4147import org .neo4j .driver .util .Immutable ;
48+ import org .neo4j .driver .util .Resource ;
4249
4350/**
4451 * A configuration class to config driver properties.
@@ -140,6 +147,7 @@ public final class Config implements Serializable {
140147 /**
141148 * The notification config.
142149 */
150+ @ SuppressWarnings ("deprecation" )
143151 private final NotificationConfig notificationConfig ;
144152 /**
145153 * The {@link MetricsAdapter}.
@@ -223,6 +231,7 @@ public int connectionTimeoutMillis() {
223231
224232 /**
225233 * Returns the maximum connection pool size.
234+ *
226235 * @return the maximum size
227236 */
228237 public int maxConnectionPoolSize () {
@@ -231,6 +240,7 @@ public int maxConnectionPoolSize() {
231240
232241 /**
233242 * Returns the connection acquisition timeout in milliseconds.
243+ *
234244 * @return the acquisition timeout
235245 */
236246 public long connectionAcquisitionTimeoutMillis () {
@@ -296,6 +306,7 @@ public long maxTransactionRetryTimeMillis() {
296306
297307 /**
298308 * Returns the fetch size.
309+ *
299310 * @return the fetch size
300311 */
301312 public long fetchSize () {
@@ -304,15 +315,45 @@ public long fetchSize() {
304315
305316 /**
306317 * Returns notification config.
318+ *
307319 * @return the notification config
308320 * @since 5.7
321+ * @deprecated superseded by {@link #minimumNotificationSeverity()} and
322+ * {@link #disabledNotificationClassifications()}
309323 */
324+ @ Deprecated
310325 public NotificationConfig notificationConfig () {
311326 return notificationConfig ;
312327 }
313328
314329 /**
315- * Returns the number of {@link io.netty.channel.EventLoop} threads.
330+ * Returns a minimum notification severity.
331+ *
332+ * @return an {@link Optional} of minimum {@link NotificationSeverity} or an empty {@link Optional} if it is not set
333+ * @since 5.22.0
334+ */
335+ public Optional <NotificationSeverity > minimumNotificationSeverity () {
336+ return Optional .ofNullable (((InternalNotificationConfig ) notificationConfig ).minimumSeverity ());
337+ }
338+
339+ /**
340+ * Returns a set of disabled notification classifications.
341+ * @return the {@link Set} of disabled {@link NotificationClassification}
342+ * @since 5.22.0
343+ */
344+ public Set <NotificationClassification > disabledNotificationClassifications () {
345+ var disabledCategories = ((InternalNotificationConfig ) notificationConfig ).disabledCategories ();
346+ return disabledCategories != null
347+ ? ((InternalNotificationConfig ) notificationConfig )
348+ .disabledCategories ().stream ()
349+ .map (NotificationClassification .class ::cast )
350+ .collect (Collectors .toUnmodifiableSet ())
351+ : Collections .emptySet ();
352+ }
353+
354+ /**
355+ * Returns the number of {@link EventLoop} threads.
356+ *
316357 * @return the number of threads
317358 */
318359 public int eventLoopThreads () {
@@ -328,6 +369,7 @@ public boolean isMetricsEnabled() {
328369
329370 /**
330371 * Returns the {@link MetricsAdapter}.
372+ *
331373 * @return the metrics adapter
332374 */
333375 public MetricsAdapter metricsAdapter () {
@@ -373,6 +415,8 @@ public static final class ConfigBuilder {
373415 private MetricsAdapter metricsAdapter = MetricsAdapter .DEV_NULL ;
374416 private long fetchSize = FetchSizeUtil .DEFAULT_FETCH_SIZE ;
375417 private int eventLoopThreads = 0 ;
418+
419+ @ SuppressWarnings ("deprecation" )
376420 private NotificationConfig notificationConfig = NotificationConfig .defaultConfig ();
377421
378422 private boolean telemetryDisabled = false ;
@@ -399,7 +443,7 @@ public ConfigBuilder withLogging(Logging logging) {
399443 * Enable logging of leaked sessions.
400444 * <p>
401445 * Each {@link Session session} is associated with a network connection and thus is a
402- * {@link org.neo4j.driver.util. Resource resource} that needs to be explicitly closed.
446+ * {@link Resource resource} that needs to be explicitly closed.
403447 * Unclosed sessions will result in socket leaks and could cause {@link OutOfMemoryError}s.
404448 * <p>
405449 * Session is considered to be leaked when it is finalized via {@link Object#finalize()} while not being
@@ -579,8 +623,8 @@ public ConfigBuilder withTrustStrategy(TrustStrategy trustStrategy) {
579623 public ConfigBuilder withRoutingTablePurgeDelay (long delay , TimeUnit unit ) {
580624 var routingTablePurgeDelayMillis = unit .toMillis (delay );
581625 if (routingTablePurgeDelayMillis < 0 ) {
582- throw new IllegalArgumentException (String . format (
583- "The routing table purge delay may not be smaller than 0, but was %d %s." , delay , unit ));
626+ throw new IllegalArgumentException (
627+ format ( "The routing table purge delay may not be smaller than 0, but was %d %s." , delay , unit ));
584628 }
585629 this .routingTablePurgeDelayMillis = routingTablePurgeDelayMillis ;
586630 return this ;
@@ -591,11 +635,11 @@ public ConfigBuilder withRoutingTablePurgeDelay(long delay, TimeUnit unit) {
591635 * This config is only valid when the driver is used with servers that support Bolt V4 (Server version 4.0 and later).
592636 * <p>
593637 * Bolt V4 enables pulling records in batches to allow client to take control of data population and apply back pressure to server.
594- * This config specifies the default fetch size for all query runs using {@link Session} and {@link org.neo4j.driver.async. AsyncSession}.
638+ * This config specifies the default fetch size for all query runs using {@link Session} and {@link AsyncSession}.
595639 * By default, the value is set to {@code 1000}.
596640 * Use {@code -1} to disables back pressure and config client to pull all records at once after each run.
597641 * <p>
598- * This config only applies to run results obtained via {@link Session} and {@link org.neo4j.driver.async. AsyncSession}.
642+ * This config only applies to run results obtained via {@link Session} and {@link AsyncSession}.
599643 * As with the reactive sessions the batch size is managed by the subscription requests instead.
600644 *
601645 * @param size the default record fetch size when pulling records in batches using Bolt V4.
@@ -627,11 +671,11 @@ public ConfigBuilder withConnectionTimeout(long value, TimeUnit unit) {
627671 var connectionTimeoutMillis = unit .toMillis (value );
628672 if (connectionTimeoutMillis < 0 ) {
629673 throw new IllegalArgumentException (
630- String . format ("The connection timeout may not be smaller than 0, but was %d %s." , value , unit ));
674+ format ("The connection timeout may not be smaller than 0, but was %d %s." , value , unit ));
631675 }
632676 var connectionTimeoutMillisInt = (int ) connectionTimeoutMillis ;
633677 if (connectionTimeoutMillisInt != connectionTimeoutMillis ) {
634- throw new IllegalArgumentException (String . format (
678+ throw new IllegalArgumentException (format (
635679 "The connection timeout must represent int value when converted to milliseconds %d." ,
636680 connectionTimeoutMillis ));
637681 }
@@ -655,7 +699,7 @@ public ConfigBuilder withMaxTransactionRetryTime(long value, TimeUnit unit) {
655699 var maxRetryTimeMs = unit .toMillis (value );
656700 if (maxRetryTimeMs < 0 ) {
657701 throw new IllegalArgumentException (
658- String . format ("The max retry time may not be smaller than 0, but was %d %s." , value , unit ));
702+ format ("The max retry time may not be smaller than 0, but was %d %s." , value , unit ));
659703 }
660704 this .maxTransactionRetryTimeMillis = maxRetryTimeMs ;
661705 return this ;
@@ -732,7 +776,7 @@ public ConfigBuilder withMetricsAdapter(MetricsAdapter metricsAdapter) {
732776 public ConfigBuilder withEventLoopThreads (int size ) {
733777 if (size < 1 ) {
734778 throw new IllegalArgumentException (
735- String . format ("The event loop thread may not be smaller than 1, but was %d." , size ));
779+ format ("The event loop thread may not be smaller than 1, but was %d." , size ));
736780 }
737781 this .eventLoopThreads = size ;
738782 return this ;
@@ -762,12 +806,51 @@ public ConfigBuilder withUserAgent(String userAgent) {
762806 * @param notificationConfig the notification config
763807 * @return this builder
764808 * @since 5.7
809+ * @deprecated superseded by {@link #withMinimumNotificationSeverity(NotificationSeverity)} and {@link #withDisabledNotificationClassifications(Set)}
765810 */
811+ @ Deprecated
812+ @ SuppressWarnings ("DeprecatedIsStillUsed" )
766813 public ConfigBuilder withNotificationConfig (NotificationConfig notificationConfig ) {
767814 this .notificationConfig = Objects .requireNonNull (notificationConfig , "notificationConfig must not be null" );
768815 return this ;
769816 }
770817
818+ /**
819+ * Sets a minimum severity for notifications produced by the server.
820+ *
821+ * @param minimumNotificationSeverity the minimum notification severity
822+ * @return this builder
823+ * @since 5.22.0
824+ */
825+ @ SuppressWarnings ("deprecation" )
826+ public ConfigBuilder withMinimumNotificationSeverity (NotificationSeverity minimumNotificationSeverity ) {
827+ if (minimumNotificationSeverity == null ) {
828+ notificationConfig = NotificationConfig .disableAllConfig ();
829+ } else {
830+ notificationConfig = notificationConfig .enableMinimumSeverity (minimumNotificationSeverity );
831+ }
832+ return this ;
833+ }
834+
835+ /**
836+ * Sets a set of disabled classifications for notifications produced by the server.
837+ *
838+ * @param disabledNotificationClassifications the set of disabled notification classifications
839+ * @return this builder
840+ * @since 5.22.0
841+ */
842+ @ SuppressWarnings ("deprecation" )
843+ public ConfigBuilder withDisabledNotificationClassifications (
844+ Set <NotificationClassification > disabledNotificationClassifications ) {
845+ var disabledCategories = disabledNotificationClassifications == null
846+ ? Collections .<NotificationCategory >emptySet ()
847+ : disabledNotificationClassifications .stream ()
848+ .map (NotificationCategory .class ::cast )
849+ .collect (Collectors .toSet ());
850+ notificationConfig = notificationConfig .disableCategories (disabledCategories );
851+ return this ;
852+ }
853+
771854 /**
772855 * Sets if telemetry is disabled on the driver side.
773856 * <p>
0 commit comments