Skip to content

Commit

Permalink
Bolt refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
injectives committed Oct 17, 2024
1 parent bb3e535 commit 8a5dfc4
Show file tree
Hide file tree
Showing 602 changed files with 29,384 additions and 31,494 deletions.
6 changes: 5 additions & 1 deletion driver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<rootDir>${project.basedir}/..</rootDir>
<api.classes.directory>${basedir}/target/classes-without-jpms</api.classes.directory>
<maven.compiler.xlint.extras>,-try</maven.compiler.xlint.extras>
<surefire.jpms.args>--add-opens org.neo4j.driver/org.neo4j.driver.internal.util.messaging=ALL-UNNAMED</surefire.jpms.args>
<surefire.jpms.args>--add-opens org.neo4j.driver/org.neo4j.driver.internal.bolt.basicimpl.util.messaging=ALL-UNNAMED</surefire.jpms.args>
<failsafe.parallelizable.jpms.args>--add-opens org.neo4j.driver/org.neo4j.driver.internal.util=ALL-UNNAMED --add-opens org.neo4j.driver/org.neo4j.driver.internal.async=ALL-UNNAMED</failsafe.parallelizable.jpms.args>
<blockhound.tag>blockHoundTest</blockhound.tag>
<maven.deploy.skip>false</maven.deploy.skip>
Expand Down Expand Up @@ -118,6 +118,10 @@
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
20 changes: 11 additions & 9 deletions driver/src/main/java/org/neo4j/driver/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@
import org.neo4j.driver.async.AsyncSession;
import org.neo4j.driver.exceptions.UnsupportedFeatureException;
import org.neo4j.driver.internal.InternalNotificationConfig;
import org.neo4j.driver.internal.RoutingSettings;
import org.neo4j.driver.internal.SecuritySettings;
import org.neo4j.driver.internal.async.pool.PoolSettings;
import org.neo4j.driver.internal.cluster.RoutingSettings;
import org.neo4j.driver.internal.handlers.pulln.FetchSizeUtil;
import org.neo4j.driver.internal.retry.ExponentialBackoffRetryLogic;
import org.neo4j.driver.net.ServerAddressResolver;
import org.neo4j.driver.util.Experimental;
Expand Down Expand Up @@ -400,10 +398,10 @@ public boolean isTelemetryDisabled() {
public static final class ConfigBuilder {
private Logging logging = DEV_NULL_LOGGING;
private boolean logLeakedSessions;
private int maxConnectionPoolSize = PoolSettings.DEFAULT_MAX_CONNECTION_POOL_SIZE;
private long idleTimeBeforeConnectionTest = PoolSettings.DEFAULT_IDLE_TIME_BEFORE_CONNECTION_TEST;
private long maxConnectionLifetimeMillis = PoolSettings.DEFAULT_MAX_CONNECTION_LIFETIME;
private long connectionAcquisitionTimeoutMillis = PoolSettings.DEFAULT_CONNECTION_ACQUISITION_TIMEOUT;
private int maxConnectionPoolSize = 100;
private long idleTimeBeforeConnectionTest = -1;
private long maxConnectionLifetimeMillis = TimeUnit.HOURS.toMillis(1);
private long connectionAcquisitionTimeoutMillis = TimeUnit.SECONDS.toMillis(60);
private String userAgent = format("neo4j-java/%s", driverVersion());
private final SecuritySettings.SecuritySettingsBuilder securitySettingsBuilder =
new SecuritySettings.SecuritySettingsBuilder();
Expand All @@ -412,7 +410,7 @@ public static final class ConfigBuilder {
private long maxTransactionRetryTimeMillis = ExponentialBackoffRetryLogic.DEFAULT_MAX_RETRY_TIME_MS;
private ServerAddressResolver resolver;
private MetricsAdapter metricsAdapter = MetricsAdapter.DEV_NULL;
private long fetchSize = FetchSizeUtil.DEFAULT_FETCH_SIZE;
private long fetchSize = 1000;
private int eventLoopThreads = 0;

private NotificationConfig notificationConfig = NotificationConfig.defaultConfig();
Expand Down Expand Up @@ -644,7 +642,11 @@ public ConfigBuilder withRoutingTablePurgeDelay(long delay, TimeUnit unit) {
* @return this builder
*/
public ConfigBuilder withFetchSize(long size) {
this.fetchSize = FetchSizeUtil.assertValidFetchSize(size);
if (size <= 0 && size != -1) {
throw new IllegalArgumentException(String.format(
"The record fetch size may not be 0 or negative. Illegal record fetch size: %s.", size));
}
this.fetchSize = size;
return this;
}

Expand Down
1 change: 1 addition & 0 deletions driver/src/main/java/org/neo4j/driver/GraphDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* @since 1.0
*/
public final class GraphDatabase {

private GraphDatabase() {}

/**
Expand Down
7 changes: 5 additions & 2 deletions driver/src/main/java/org/neo4j/driver/SessionConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.neo4j.driver;

import static java.util.Objects.requireNonNull;
import static org.neo4j.driver.internal.handlers.pulln.FetchSizeUtil.assertValidFetchSize;

import java.io.Serial;
import java.io.Serializable;
Expand Down Expand Up @@ -374,7 +373,11 @@ public Builder withDatabase(String database) {
* @return this builder
*/
public Builder withFetchSize(long size) {
this.fetchSize = assertValidFetchSize(size);
if (size <= 0 && size != -1) {
throw new IllegalArgumentException(String.format(
"The record fetch size may not be 0 or negative. Illegal record fetch size: %s.", size));
}
this.fetchSize = size;
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion driver/src/main/java/org/neo4j/driver/Values.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
import java.util.stream.Stream;
import org.neo4j.driver.exceptions.ClientException;
import org.neo4j.driver.internal.AsValue;
import org.neo4j.driver.internal.GqlStatusError;
import org.neo4j.driver.internal.InternalIsoDuration;
import org.neo4j.driver.internal.InternalPoint2D;
import org.neo4j.driver.internal.InternalPoint3D;
import org.neo4j.driver.internal.bolt.api.GqlStatusError;
import org.neo4j.driver.internal.value.BooleanValue;
import org.neo4j.driver.internal.value.BytesValue;
import org.neo4j.driver.internal.value.DateTimeValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.io.Serial;
import org.neo4j.driver.AuthTokenManager;
import org.neo4j.driver.internal.GqlStatusError;
import org.neo4j.driver.internal.bolt.api.GqlStatusError;

/**
* The {@link org.neo4j.driver.AuthTokenManager} execution has lead to an unexpected result.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.io.Serial;
import java.util.Map;
import org.neo4j.driver.Value;
import org.neo4j.driver.internal.GqlStatusError;
import org.neo4j.driver.internal.bolt.api.GqlStatusError;
import org.neo4j.driver.util.Preview;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.io.Serial;
import java.util.Map;
import org.neo4j.driver.Value;
import org.neo4j.driver.internal.GqlStatusError;
import org.neo4j.driver.internal.bolt.api.GqlStatusError;
import org.neo4j.driver.util.Preview;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.io.Serial;
import java.util.Map;
import org.neo4j.driver.Value;
import org.neo4j.driver.internal.GqlStatusError;
import org.neo4j.driver.internal.bolt.api.GqlStatusError;
import org.neo4j.driver.util.Preview;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class ConnectionReadTimeoutException extends ServiceUnavailableException
* @deprecated superseded by the {@link ConnectionReadTimeoutException#INSTANCE} value
*/
@Deprecated
@SuppressWarnings("DeprecatedIsStillUsed")
public ConnectionReadTimeoutException(String message) {
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.io.Serial;
import java.util.Map;
import org.neo4j.driver.Value;
import org.neo4j.driver.internal.GqlStatusError;
import org.neo4j.driver.internal.bolt.api.GqlStatusError;
import org.neo4j.driver.util.Preview;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.neo4j.driver.exceptions;

import java.io.Serial;
import org.neo4j.driver.internal.GqlStatusError;
import org.neo4j.driver.internal.bolt.api.GqlStatusError;

/**
* An error has happened while getting routing table with a remote server.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.io.Serial;
import java.util.Map;
import org.neo4j.driver.Value;
import org.neo4j.driver.internal.GqlStatusError;
import org.neo4j.driver.internal.bolt.api.GqlStatusError;
import org.neo4j.driver.util.Preview;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.Objects;
import java.util.Optional;
import org.neo4j.driver.Value;
import org.neo4j.driver.internal.GqlStatusError;
import org.neo4j.driver.internal.bolt.api.GqlStatusError;
import org.neo4j.driver.types.TypeSystem;
import org.neo4j.driver.util.Preview;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.neo4j.driver.exceptions;

import java.io.Serial;
import org.neo4j.driver.internal.GqlStatusError;
import org.neo4j.driver.internal.bolt.api.GqlStatusError;

/**
* A signal that the contract for client-server communication has broken down.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.io.Serial;
import org.neo4j.driver.QueryRunner;
import org.neo4j.driver.internal.GqlStatusError;
import org.neo4j.driver.internal.bolt.api.GqlStatusError;

/**
* A user is trying to access resources that are no longer valid due to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.io.Serial;
import java.util.Map;
import org.neo4j.driver.Value;
import org.neo4j.driver.internal.GqlStatusError;
import org.neo4j.driver.internal.bolt.api.GqlStatusError;
import org.neo4j.driver.util.Preview;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.neo4j.driver.exceptions;

import java.io.Serial;
import org.neo4j.driver.internal.GqlStatusError;
import org.neo4j.driver.internal.bolt.api.GqlStatusError;

/**
* An <em>ServiceUnavailableException</em> indicates that the driver cannot communicate with the cluster.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.neo4j.driver.exceptions;

import java.io.Serial;
import org.neo4j.driver.internal.GqlStatusError;
import org.neo4j.driver.internal.bolt.api.GqlStatusError;

/**
* A <em>SessionExpiredException</em> indicates that the session can no longer satisfy the criteria under which it was acquired, e.g. a server no longer accepts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.io.Serial;
import java.util.Map;
import org.neo4j.driver.Value;
import org.neo4j.driver.internal.GqlStatusError;
import org.neo4j.driver.internal.bolt.api.GqlStatusError;
import org.neo4j.driver.util.Preview;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.neo4j.driver.exceptions;

import java.io.Serial;
import org.neo4j.driver.internal.GqlStatusError;
import org.neo4j.driver.internal.bolt.api.GqlStatusError;

/**
* This exception indicates a user is nesting new transaction with an on-going transaction (unmanaged and/or auto-commit).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.io.Serial;
import java.util.Map;
import org.neo4j.driver.Value;
import org.neo4j.driver.internal.GqlStatusError;
import org.neo4j.driver.internal.bolt.api.GqlStatusError;
import org.neo4j.driver.util.Preview;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.io.Serial;
import java.util.Map;
import org.neo4j.driver.Value;
import org.neo4j.driver.internal.GqlStatusError;
import org.neo4j.driver.internal.bolt.api.GqlStatusError;
import org.neo4j.driver.util.Preview;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.neo4j.driver.exceptions;

import java.io.Serial;
import org.neo4j.driver.internal.GqlStatusError;
import org.neo4j.driver.internal.bolt.api.GqlStatusError;

/**
* A feature is not supported in a given setup.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.io.Serial;
import org.neo4j.driver.exceptions.ClientException;
import org.neo4j.driver.internal.GqlStatusError;
import org.neo4j.driver.internal.bolt.api.GqlStatusError;

/**
* A <em>ValueException</em> indicates that the client has carried out an operation on values incorrectly.
Expand Down
67 changes: 67 additions & 0 deletions driver/src/main/java/org/neo4j/driver/internal/BoltLogger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [https://neo4j.com]
*
* 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.neo4j.driver.internal;

import java.util.ResourceBundle;
import org.neo4j.driver.Logger;

public class BoltLogger implements System.Logger {
private final Logger logger;

public BoltLogger(Logger logger) {
this.logger = logger;
}

@Override
public String getName() {
throw new RuntimeException(new UnsupportedOperationException("getName() not supported"));
}

@Override
public boolean isLoggable(Level level) {
return switch (level) {
case ALL -> logger.isTraceEnabled() && logger.isDebugEnabled();
case TRACE -> logger.isTraceEnabled();
case DEBUG -> logger.isDebugEnabled();
case INFO, WARNING, ERROR -> true;
case OFF -> false;
};
}

@Override
public void log(Level level, ResourceBundle bundle, String msg, Throwable thrown) {
switch (level) {
case ALL, OFF -> {}
case TRACE -> logger.trace(msg, thrown);
case DEBUG -> logger.debug(msg, thrown);
case INFO -> logger.info(msg, thrown);
case WARNING -> logger.warn(msg, thrown);
case ERROR -> logger.error(msg, thrown);
}
}

@Override
public void log(Level level, ResourceBundle bundle, String format, Object... params) {
switch (level) {
case TRACE -> logger.trace(format, params);
case DEBUG -> logger.debug(format, params);
case INFO -> logger.info(format, params);
case WARNING -> logger.warn(format, params);
case ALL, OFF, ERROR -> {}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [https://neo4j.com]
*
* 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.neo4j.driver.internal;

import org.neo4j.driver.Logging;
import org.neo4j.driver.internal.bolt.api.LoggingProvider;

public class BoltLoggingProvider implements LoggingProvider {
private final Logging logging;

public BoltLoggingProvider(Logging logging) {
this.logging = logging;
}

@Override
public System.Logger getLog(Class<?> cls) {
return new BoltLogger(logging.getLog(cls));
}

@Override
public System.Logger getLog(String name) {
return new BoltLogger(logging.getLog(name));
}
}
Loading

0 comments on commit 8a5dfc4

Please sign in to comment.