Skip to content

Commit 0f74b0b

Browse files
authored
Merge pull request #629 from zhenlineo/1.7-conn-timeout
Changing default conneciton timeout to be 30s
2 parents d56154a + 1b14464 commit 0f74b0b

File tree

86 files changed

+890
-950
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+890
-950
lines changed

driver/src/main/java/org/neo4j/driver/internal/messaging/request/BeginMessage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public BeginMessage( Bookmarks bookmarks, TransactionConfig config, AccessMode m
3838

3939
public BeginMessage( Bookmarks bookmarks, Duration txTimeout, Map<String,Value> txMetadata, AccessMode mode )
4040
{
41-
super( bookmarks, txTimeout, txMetadata, mode );
41+
super( buildMetadata( bookmarks, txTimeout, txMetadata, mode ) );
4242
}
4343

4444
@Override

driver/src/main/java/org/neo4j/driver/internal/messaging/request/RunWithMetadataMessage.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,41 @@
2424

2525
import org.neo4j.driver.internal.Bookmarks;
2626
import org.neo4j.driver.v1.AccessMode;
27+
import org.neo4j.driver.v1.Statement;
2728
import org.neo4j.driver.v1.TransactionConfig;
2829
import org.neo4j.driver.v1.Value;
2930

31+
import static java.util.Collections.emptyMap;
32+
import static org.neo4j.driver.v1.Values.ofValue;
33+
3034
public class RunWithMetadataMessage extends TransactionStartingMessage
3135
{
3236
public final static byte SIGNATURE = 0x10;
3337

3438
private final String statement;
3539
private final Map<String,Value> parameters;
3640

37-
public RunWithMetadataMessage( String statement, Map<String,Value> parameters, Bookmarks bookmarks, TransactionConfig config, AccessMode mode )
41+
public static RunWithMetadataMessage autoCommitTxRunMessage( Statement statement, TransactionConfig config, AccessMode mode,
42+
Bookmarks bookmark )
43+
{
44+
return autoCommitTxRunMessage( statement.text(), statement.parameters().asMap( ofValue() ), config.timeout(), config.metadata(), mode, bookmark );
45+
}
46+
47+
public static RunWithMetadataMessage autoCommitTxRunMessage( String statement, Map<String,Value> parameters, Duration txTimeout, Map<String,Value> txMetadata, AccessMode mode,
48+
Bookmarks bookmark )
49+
{
50+
Map<String,Value> metadata = buildMetadata( bookmark, txTimeout, txMetadata, mode );
51+
return new RunWithMetadataMessage( statement, parameters, metadata );
52+
}
53+
54+
public static RunWithMetadataMessage explicitTxRunMessage( Statement statement )
3855
{
39-
this( statement, parameters, bookmarks, config.timeout(), config.metadata(), mode );
56+
return new RunWithMetadataMessage( statement.text(), statement.parameters().asMap( ofValue() ), emptyMap() );
4057
}
4158

42-
public RunWithMetadataMessage( String statement, Map<String,Value> parameters, Bookmarks bookmarks, Duration txTimeout, Map<String,Value> txMetadata,
43-
AccessMode mode )
59+
public RunWithMetadataMessage( String statement, Map<String,Value> parameters, Map<String,Value> metadata )
4460
{
45-
super( bookmarks, txTimeout, txMetadata, mode );
61+
super( metadata );
4662
this.statement = statement;
4763
this.parameters = parameters;
4864
}

driver/src/main/java/org/neo4j/driver/internal/messaging/request/TransactionStartingMessage.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.neo4j.driver.v1.Value;
2929

3030
import static java.util.Collections.emptyMap;
31+
import static java.util.Objects.requireNonNull;
3132
import static org.neo4j.driver.v1.Values.value;
3233

3334
abstract class TransactionStartingMessage implements Message
@@ -40,17 +41,17 @@ abstract class TransactionStartingMessage implements Message
4041

4142
final Map<String,Value> metadata;
4243

43-
TransactionStartingMessage( Bookmarks bookmarks, Duration txTimeout, Map<String,Value> txMetadata, AccessMode mode )
44+
TransactionStartingMessage( Map<String,Value> metadata )
4445
{
45-
this.metadata = buildMetadata( bookmarks, txTimeout, txMetadata, mode );
46+
this.metadata = requireNonNull( metadata );
4647
}
4748

4849
public final Map<String,Value> metadata()
4950
{
5051
return metadata;
5152
}
5253

53-
private static Map<String,Value> buildMetadata( Bookmarks bookmarks, Duration txTimeout, Map<String,Value> txMetadata, AccessMode mode )
54+
static Map<String,Value> buildMetadata( Bookmarks bookmarks, Duration txTimeout, Map<String,Value> txMetadata, AccessMode mode )
5455
{
5556
boolean bookmarksPresent = bookmarks != null && !bookmarks.isEmpty();
5657
boolean txTimeoutPresent = txTimeout != null;

driver/src/main/java/org/neo4j/driver/internal/messaging/v3/BoltProtocolV3.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import org.neo4j.driver.internal.messaging.request.BeginMessage;
4545
import org.neo4j.driver.internal.messaging.request.GoodbyeMessage;
4646
import org.neo4j.driver.internal.messaging.request.HelloMessage;
47-
import org.neo4j.driver.internal.messaging.request.RunWithMetadataMessage;
4847
import org.neo4j.driver.internal.spi.Connection;
4948
import org.neo4j.driver.internal.util.Futures;
5049
import org.neo4j.driver.internal.util.MetadataExtractor;
@@ -57,6 +56,8 @@
5756
import static org.neo4j.driver.internal.messaging.request.CommitMessage.COMMIT;
5857
import static org.neo4j.driver.internal.messaging.request.PullAllMessage.PULL_ALL;
5958
import static org.neo4j.driver.internal.messaging.request.RollbackMessage.ROLLBACK;
59+
import static org.neo4j.driver.internal.messaging.request.RunWithMetadataMessage.autoCommitTxRunMessage;
60+
import static org.neo4j.driver.internal.messaging.request.RunWithMetadataMessage.explicitTxRunMessage;
6061
import static org.neo4j.driver.v1.Values.ofValue;
6162

6263
public class BoltProtocolV3 implements BoltProtocol
@@ -131,24 +132,25 @@ public CompletionStage<Void> rollbackTransaction( Connection connection )
131132
public CompletionStage<InternalStatementResultCursor> runInAutoCommitTransaction( Connection connection, Statement statement,
132133
BookmarksHolder bookmarksHolder, TransactionConfig config, boolean waitForRunResponse )
133134
{
134-
return runStatement( connection, statement, bookmarksHolder, null, config, waitForRunResponse );
135+
Message runMessage = autoCommitTxRunMessage( statement, config, connection.mode(), bookmarksHolder.getBookmarks() );
136+
return runStatement( connection, statement, bookmarksHolder, null, waitForRunResponse, runMessage );
135137
}
136138

137139
@Override
138140
public CompletionStage<InternalStatementResultCursor> runInExplicitTransaction( Connection connection, Statement statement, ExplicitTransaction tx,
139141
boolean waitForRunResponse )
140142
{
141-
return runStatement( connection, statement, BookmarksHolder.NO_OP, tx, TransactionConfig.empty(), waitForRunResponse );
143+
Message runMessage = explicitTxRunMessage( statement );
144+
return runStatement( connection, statement, BookmarksHolder.NO_OP, tx, waitForRunResponse, runMessage );
142145
}
143146

144-
private static CompletionStage<InternalStatementResultCursor> runStatement( Connection connection, Statement statement,
145-
BookmarksHolder bookmarksHolder, ExplicitTransaction tx, TransactionConfig config, boolean waitForRunResponse )
147+
private static CompletionStage<InternalStatementResultCursor> runStatement( Connection connection, Statement statement, BookmarksHolder bookmarksHolder,
148+
ExplicitTransaction tx, boolean waitForRunResponse, Message runMessage )
146149
{
147150
String query = statement.text();
148151
Map<String,Value> params = statement.parameters().asMap( ofValue() );
149152

150153
CompletableFuture<Void> runCompletedFuture = new CompletableFuture<>();
151-
Message runMessage = new RunWithMetadataMessage( query, params, bookmarksHolder.getBookmarks(), config, connection.mode() );
152154
RunResponseHandler runHandler = new RunResponseHandler( runCompletedFuture, METADATA_EXTRACTOR );
153155
PullAllResponseHandler pullAllHandler = newPullAllHandler( statement, runHandler, connection, bookmarksHolder, tx );
154156

driver/src/main/java/org/neo4j/driver/v1/Config.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public static class ConfigBuilder
297297
private LoadBalancingStrategy loadBalancingStrategy = LoadBalancingStrategy.LEAST_CONNECTED;
298298
private int routingFailureLimit = RoutingSettings.DEFAULT.maxRoutingFailures();
299299
private long routingRetryDelayMillis = RoutingSettings.DEFAULT.retryTimeoutDelay();
300-
private int connectionTimeoutMillis = (int) TimeUnit.SECONDS.toMillis( 5 );
300+
private int connectionTimeoutMillis = (int) TimeUnit.SECONDS.toMillis( 30 );
301301
private RetrySettings retrySettings = RetrySettings.DEFAULT;
302302
private ServerAddressResolver resolver;
303303

@@ -687,7 +687,7 @@ public ConfigBuilder withRoutingRetryDelay( long delay, TimeUnit unit )
687687
* Timeout value should be greater or equal to zero and represent a valid {@code int} value when converted to
688688
* {@link TimeUnit#MILLISECONDS milliseconds}.
689689
* <p>
690-
* The default value of this parameter is {@code 5 SECONDS}.
690+
* The default value of this parameter is {@code 30 SECONDS}.
691691
*
692692
* @param value the timeout duration
693693
* @param unit the unit in which duration is given

driver/src/main/java/org/neo4j/driver/v1/Driver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
* The <a href="https://tools.ietf.org/html/rfc3986">URI</a> passed to
3838
* this method determines the type of Driver created.
3939
* <br>
40-
* <table border="1" cellpadding="4" style="border-collapse: collapse" summary="Available schemes and drivers">
40+
* <table border="1" style="border-collapse: collapse">
41+
* <caption>Available schemes and drivers</caption>
4142
* <thead>
4243
* <tr><th>URI Scheme</th><th>Driver</th></tr>
4344
* </thead>

driver/src/main/java/org/neo4j/driver/v1/Logging.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
* <p>
4646
* Driver logging API defines the following log levels: ERROR, INFO, WARN, DEBUG and TRACE. They are similar to levels defined by SLF4J but different from
4747
* log levels defined for {@link java.util.logging}. The following mapping takes place:
48-
* <table border="1" cellpadding="4" summary="Driver and JUL log levels">
48+
* <table border="1" style="border-collapse: collapse">
49+
* <caption>Driver and JUL log levels</caption>
4950
* <tr>
5051
* <th>Driver</th>
5152
* <th>java.util.logging</th>

driver/src/main/java/org/neo4j/driver/v1/Value.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public interface Value extends MapAccessor, MapAccessorWithDefaultValue
117117
/**
118118
* If this value represents a list or map, test if the collection is empty.
119119
*
120-
* @return <tt>true</tt> if size() is 0, otherwise <tt>false</tt>
120+
* @return {@code true} if size() is 0, otherwise {@code false}
121121
*/
122122
boolean isEmpty();
123123

@@ -154,17 +154,17 @@ public interface Value extends MapAccessor, MapAccessorWithDefaultValue
154154
boolean hasType( Type type );
155155

156156
/**
157-
* @return <tt>true</tt> if the value is a Boolean value and has the value True.
157+
* @return {@code true} if the value is a Boolean value and has the value True.
158158
*/
159159
boolean isTrue();
160160

161161
/**
162-
* @return <tt>true</tt> if the value is a Boolean value and has the value False.
162+
* @return {@code true} if the value is a Boolean value and has the value False.
163163
*/
164164
boolean isFalse();
165165

166166
/**
167-
* @return <tt>true</tt> if the value is a Null, otherwise <tt>false</tt>
167+
* @return {@code true} if the value is a Null, otherwise {@code false}
168168
*/
169169
boolean isNull();
170170

driver/src/main/java/org/neo4j/driver/v1/Values.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ public static Function<Value,List<Object>> ofList()
679679
}
680680

681681
/**
682-
* Converts values to {@link List} of <tt>T</tt>.
682+
* Converts values to {@link List} of {@code T}.
683683
*
684684
* @param innerMap converter for the values inside the list
685685
* @param <T> the type of values inside the list

driver/src/main/java/org/neo4j/driver/v1/types/MapAccessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public interface MapAccessor
4646
* Check if the list of keys contains the given key
4747
*
4848
* @param key the key
49-
* @return <tt>true</tt> if this map keys contains the given key otherwise <tt>false</tt>
49+
* @return {@code true} if this map keys contains the given key otherwise {@code false}
5050
*/
5151
boolean containsKey( String key );
5252

0 commit comments

Comments
 (0)