Skip to content

Commit fff8e07

Browse files
committed
Merge branch 1.2 into 1.3
2 parents 3183334 + 4d2631b commit fff8e07

29 files changed

+922
-912
lines changed

driver/src/main/java/org/neo4j/driver/internal/DriverFactory.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
import org.neo4j.driver.internal.net.SocketConnector;
2929
import org.neo4j.driver.internal.net.pooling.PoolSettings;
3030
import org.neo4j.driver.internal.net.pooling.SocketConnectionPool;
31-
import org.neo4j.driver.internal.retry.ExponentialBackoff;
32-
import org.neo4j.driver.internal.retry.RetryDecision;
31+
import org.neo4j.driver.internal.retry.ExponentialBackoffRetryLogic;
3332
import org.neo4j.driver.internal.retry.RetryLogic;
3433
import org.neo4j.driver.internal.retry.RetrySettings;
3534
import org.neo4j.driver.internal.security.SecurityPlan;
@@ -57,7 +56,7 @@ public final Driver newInstance( URI uri, AuthToken authToken, RoutingSettings r
5756
BoltServerAddress address = BoltServerAddress.from( uri );
5857
SecurityPlan securityPlan = createSecurityPlan( address, config );
5958
ConnectionPool connectionPool = createConnectionPool( authToken, securityPlan, config );
60-
RetryLogic<RetryDecision> retryLogic = createRetryLogic( retrySettings );
59+
RetryLogic retryLogic = createRetryLogic( retrySettings, config.logging() );
6160

6261
try
6362
{
@@ -80,8 +79,7 @@ public final Driver newInstance( URI uri, AuthToken authToken, RoutingSettings r
8079
}
8180

8281
private Driver createDriver( BoltServerAddress address, String scheme, ConnectionPool connectionPool,
83-
Config config, RoutingSettings routingSettings, SecurityPlan securityPlan,
84-
RetryLogic<RetryDecision> retryLogic )
82+
Config config, RoutingSettings routingSettings, SecurityPlan securityPlan, RetryLogic retryLogic )
8583
{
8684
switch ( scheme.toLowerCase() )
8785
{
@@ -100,7 +98,7 @@ private Driver createDriver( BoltServerAddress address, String scheme, Connectio
10098
* <b>This method is protected only for testing</b>
10199
*/
102100
protected Driver createDirectDriver( BoltServerAddress address, ConnectionPool connectionPool, Config config,
103-
SecurityPlan securityPlan, RetryLogic<RetryDecision> retryLogic )
101+
SecurityPlan securityPlan, RetryLogic retryLogic )
104102
{
105103
ConnectionProvider connectionProvider = new DirectConnectionProvider( address, connectionPool );
106104
SessionFactory sessionFactory = createSessionFactory( connectionProvider, retryLogic, config );
@@ -113,8 +111,7 @@ protected Driver createDirectDriver( BoltServerAddress address, ConnectionPool c
113111
* <b>This method is protected only for testing</b>
114112
*/
115113
protected Driver createRoutingDriver( BoltServerAddress address, ConnectionPool connectionPool,
116-
Config config, RoutingSettings routingSettings, SecurityPlan securityPlan,
117-
RetryLogic<RetryDecision> retryLogic )
114+
Config config, RoutingSettings routingSettings, SecurityPlan securityPlan, RetryLogic retryLogic )
118115
{
119116
if ( !securityPlan.isRoutingCompatible() )
120117
{
@@ -190,19 +187,19 @@ protected Connector createConnector( ConnectionSettings connectionSettings, Secu
190187
* <b>This method is protected only for testing</b>
191188
*/
192189
protected SessionFactory createSessionFactory( ConnectionProvider connectionProvider,
193-
RetryLogic<RetryDecision> retryLogic, Config config )
190+
RetryLogic retryLogic, Config config )
194191
{
195192
return new SessionFactoryImpl( connectionProvider, retryLogic, config );
196193
}
197194

198195
/**
199-
* Creates new {@link RetryLogic<RetryDecision>}.
196+
* Creates new {@link RetryLogic >}.
200197
* <p>
201198
* <b>This method is protected only for testing</b>
202199
*/
203-
protected RetryLogic<RetryDecision> createRetryLogic( RetrySettings settings )
200+
protected RetryLogic createRetryLogic( RetrySettings settings, Logging logging )
204201
{
205-
return ExponentialBackoff.create( settings, createClock() );
202+
return new ExponentialBackoffRetryLogic( settings, createClock(), logging );
206203
}
207204

208205
private static SecurityPlan createSecurityPlan( BoltServerAddress address, Config config )
@@ -230,7 +227,7 @@ private static SecurityPlan createSecurityPlanImpl( BoltServerAddress address, C
230227

231228
if ( requiresEncryption )
232229
{
233-
Logger logger = config.logging().getLog( "session" );
230+
Logger logger = config.logging().getLog( "SecurityPlan" );
234231
switch ( config.trustStrategy().strategy() )
235232
{
236233

driver/src/main/java/org/neo4j/driver/internal/LeakLoggingNetworkSession.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.neo4j.driver.internal;
2020

21-
import org.neo4j.driver.internal.retry.RetryDecision;
2221
import org.neo4j.driver.internal.retry.RetryLogic;
2322
import org.neo4j.driver.internal.spi.ConnectionProvider;
2423
import org.neo4j.driver.v1.AccessMode;
@@ -30,8 +29,8 @@ class LeakLoggingNetworkSession extends NetworkSession
3029
{
3130
private final String stackTrace;
3231

33-
LeakLoggingNetworkSession( ConnectionProvider connectionProvider, AccessMode mode,
34-
RetryLogic<RetryDecision> retryLogic, Logging logging )
32+
LeakLoggingNetworkSession( ConnectionProvider connectionProvider, AccessMode mode, RetryLogic retryLogic,
33+
Logging logging )
3534
{
3635
super( connectionProvider, mode, retryLogic, logging );
3736
this.stackTrace = captureStackTrace();

driver/src/main/java/org/neo4j/driver/internal/NetworkSession.java

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
import java.util.Map;
2424
import java.util.concurrent.atomic.AtomicBoolean;
2525

26-
import org.neo4j.driver.internal.retry.RetryDecision;
2726
import org.neo4j.driver.internal.retry.RetryLogic;
2827
import org.neo4j.driver.internal.spi.Connection;
2928
import org.neo4j.driver.internal.spi.ConnectionProvider;
3029
import org.neo4j.driver.internal.spi.PooledConnection;
3130
import org.neo4j.driver.internal.types.InternalTypeSystem;
31+
import org.neo4j.driver.internal.util.Supplier;
3232
import org.neo4j.driver.v1.AccessMode;
3333
import org.neo4j.driver.v1.Logger;
3434
import org.neo4j.driver.v1.Logging;
@@ -49,7 +49,7 @@ public class NetworkSession implements Session, SessionResourcesHandler
4949
{
5050
private final ConnectionProvider connectionProvider;
5151
private final AccessMode mode;
52-
private final RetryLogic<RetryDecision> retryLogic;
52+
private final RetryLogic retryLogic;
5353
protected final Logger logger;
5454

5555
private String bookmark;
@@ -58,7 +58,7 @@ public class NetworkSession implements Session, SessionResourcesHandler
5858

5959
private final AtomicBoolean isOpen = new AtomicBoolean( true );
6060

61-
public NetworkSession( ConnectionProvider connectionProvider, AccessMode mode, RetryLogic<RetryDecision> retryLogic,
61+
public NetworkSession( ConnectionProvider connectionProvider, AccessMode mode, RetryLogic retryLogic,
6262
Logging logging )
6363
{
6464
this.connectionProvider = connectionProvider;
@@ -160,8 +160,7 @@ public void close()
160160
}
161161
catch ( Throwable e )
162162
{
163-
// Best-effort
164-
logger.warn( "WARNING: Failed to close tx due to error: " + e.toString() );
163+
logger.warn( "Failed to close transaction", e );
165164
}
166165
}
167166
}
@@ -252,46 +251,31 @@ public synchronized void onConnectionError( boolean recoverable )
252251
}
253252
}
254253

255-
private <T> T transaction( AccessMode mode, TransactionWork<T> work )
254+
private <T> T transaction( final AccessMode mode, final TransactionWork<T> work )
256255
{
257-
RetryDecision decision = null;
258-
List<Throwable> errors = null;
259-
260-
while ( true )
256+
return retryLogic.retry( new Supplier<T>()
261257
{
262-
try ( Transaction tx = beginTransaction( mode ) )
263-
{
264-
T result;
265-
try
266-
{
267-
result = work.execute( tx );
268-
}
269-
catch ( Throwable t )
270-
{
271-
// mark transaction for failure if the given unit of work threw exception
272-
// this will override any success marks that were made by the unit of work
273-
tx.failure();
274-
throw t;
275-
}
276-
// given unit of work completed successfully, mark transaction for commit
277-
tx.success();
278-
return result;
279-
}
280-
catch ( Throwable newError )
258+
@Override
259+
public T get()
281260
{
282-
decision = retryLogic.apply( newError, decision );
283-
284-
if ( decision.shouldRetry() )
261+
try ( Transaction tx = beginTransaction( mode ) )
285262
{
286-
errors = recordError( newError, errors );
287-
}
288-
else
289-
{
290-
addSuppressed( newError, errors );
291-
throw newError;
263+
try
264+
{
265+
T result = work.execute( tx );
266+
tx.success();
267+
return result;
268+
}
269+
catch ( Throwable t )
270+
{
271+
// mark transaction for failure if the given unit of work threw exception
272+
// this will override any success marks that were made by the unit of work
273+
tx.failure();
274+
throw t;
275+
}
292276
}
293277
}
294-
}
278+
} );
295279
}
296280

297281
private synchronized Transaction beginTransaction( AccessMode mode )

driver/src/main/java/org/neo4j/driver/internal/SessionFactoryImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.neo4j.driver.internal;
2020

21-
import org.neo4j.driver.internal.retry.RetryDecision;
2221
import org.neo4j.driver.internal.retry.RetryLogic;
2322
import org.neo4j.driver.internal.spi.ConnectionProvider;
2423
import org.neo4j.driver.v1.AccessMode;
@@ -29,11 +28,11 @@
2928
public class SessionFactoryImpl implements SessionFactory
3029
{
3130
protected final ConnectionProvider connectionProvider;
32-
protected final RetryLogic<RetryDecision> retryLogic;
31+
protected final RetryLogic retryLogic;
3332
protected final Logging logging;
3433
protected final boolean leakedSessionsLoggingEnabled;
3534

36-
SessionFactoryImpl( ConnectionProvider connectionProvider, RetryLogic<RetryDecision> retryLogic, Config config )
35+
SessionFactoryImpl( ConnectionProvider connectionProvider, RetryLogic retryLogic, Config config )
3736
{
3837
this.connectionProvider = connectionProvider;
3938
this.leakedSessionsLoggingEnabled = config.logLeakedSessions();

driver/src/main/java/org/neo4j/driver/internal/logging/DevNullLogger.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public void warn( String message, Object... params )
4343
{
4444
}
4545

46+
@Override
47+
public void warn( String message, Throwable cause )
48+
{
49+
}
50+
4651
@Override
4752
public void debug( String message, Object... params )
4853
{

driver/src/main/java/org/neo4j/driver/internal/logging/JULogger.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ public void warn( String format, Object... params )
5454
delegate.log( Level.WARNING, String.format( format, params ) );
5555
}
5656

57+
@Override
58+
public void warn( String message, Throwable cause )
59+
{
60+
delegate.log( Level.WARNING, message, cause );
61+
}
62+
5763
@Override
5864
public void debug( String format, Object... params )
5965
{

driver/src/main/java/org/neo4j/driver/internal/net/pooling/BlockingPooledConnectionQueue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,6 @@ private void disposeSafely( PooledConnection connection )
162162

163163
private static Logger createLogger( BoltServerAddress address, Logging logging )
164164
{
165-
return logging.getLog( "connectionQueue[" + address + "]" );
165+
return logging.getLog( "ConnectionQueue[" + address + "]" );
166166
}
167167
}

driver/src/main/java/org/neo4j/driver/internal/retry/ExponentialBackoffDecision.java

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)