Skip to content

Commit

Permalink
Expose connection.liveness.check.timeout driver property to fix conne…
Browse files Browse the repository at this point in the history
…ction problems with firewalls.

See #358
  • Loading branch information
nmervaillie committed May 10, 2017
1 parent 0801eec commit 383d8f9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
2.0.7-SNAPSHOT
--------------
o Fixes issue where session.loadAll would sort by ids instead of by the sort order specified. Fixes #302.
o Expose connection.liveness.check.timeout driver property to fix connection problems with firewalls. See #358.


2.0.6
Expand Down
19 changes: 16 additions & 3 deletions api/src/main/java/org/neo4j/ogm/config/DriverConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002-2016 "Neo Technology,"
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This product is licensed to you under the Apache License, Version 2.0 (the "License").
Expand All @@ -13,11 +13,11 @@

package org.neo4j.ogm.config;

import java.net.URI;

import org.neo4j.ogm.authentication.Credentials;
import org.neo4j.ogm.authentication.UsernamePasswordCredentials;

import java.net.URI;

/**
*
* A wrapper class for a generic {@link Configuration} that exposes the configuration for a Driver via
Expand All @@ -34,6 +34,7 @@ public class DriverConfiguration {
public static final String[] PASSWORD = {"neo4j.ogm.password", "spring.data.neo4j.password", "password"};

public static final String[] CONNECTION_POOL_SIZE = {"connection.pool.size"};
public static final String[] CONNECTION_LIVENESS_CHECK_TIMEOUT = {"connection.liveness.check.timeout"};
public static final String[] ENCRYPTION_LEVEL = {"encryption.level"};
public static final String[] TRUST_STRATEGY = {"trust.strategy"};
public static final String[] TRUST_CERT_FILE = {"trust.certificate.file"};
Expand Down Expand Up @@ -85,6 +86,11 @@ public DriverConfiguration setConnectionPoolSize(Integer sessionPoolSize) {
return this;
}

public DriverConfiguration setConnectionLivenessCheckTimeout(Integer timeoutInMs) {
configuration.set(CONNECTION_LIVENESS_CHECK_TIMEOUT[0], timeoutInMs.toString());
return this;
}

public DriverConfiguration setEncryptionLevel(String encryptionLevel) {
configuration.set(ENCRYPTION_LEVEL[0], encryptionLevel);
return this;
Expand Down Expand Up @@ -140,6 +146,13 @@ public Integer getConnectionPoolSize() {
return CONNECTION_POOL_SIZE_DEFAULT;
}

public Integer getConnectionLivenessCheckTimeout() {
if (configuration.get(CONNECTION_LIVENESS_CHECK_TIMEOUT) != null) {
return Integer.valueOf((String)configuration.get(CONNECTION_LIVENESS_CHECK_TIMEOUT));
}
return null;
}

public String getEncryptionLevel() {
if (configuration.get(ENCRYPTION_LEVEL) != null) {
return (String)configuration.get(ENCRYPTION_LEVEL);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002-2016 "Neo Technology,"
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This product is licensed to you under the Apache License, Version 2.0 (the "License").
Expand All @@ -13,6 +13,9 @@

package org.neo4j.ogm.drivers.bolt.driver;

import java.io.File;
import java.net.URI;

import org.neo4j.driver.v1.*;
import org.neo4j.driver.v1.exceptions.ClientException;
import org.neo4j.ogm.authentication.UsernamePasswordCredentials;
Expand All @@ -26,9 +29,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.net.URI;

/**
* @author vince
* @author Luanne Misquitta
Expand Down Expand Up @@ -150,6 +150,10 @@ private BoltConfig getBoltConfiguration(DriverConfiguration driverConfiguration)
boltConfig.trustCertFile = driverConfiguration.getTrustCertFile();
}

if (driverConfiguration.getConnectionLivenessCheckTimeout() != null) {
boltConfig.connectionLivenessCheckTimeout = driverConfiguration.getConnectionLivenessCheckTimeout();
}

return boltConfig;
}

Expand All @@ -159,6 +163,10 @@ private Config buildDriverConfig(DriverConfiguration driverConfig) {
Config.ConfigBuilder configBuilder = Config.build();
configBuilder.withMaxSessions(boltConfig.sessionPoolSize);
configBuilder.withEncryptionLevel(boltConfig.encryptionLevel);
if (boltConfig.connectionLivenessCheckTimeout != null) {
// deprecated in driver 1.1 +, replaced by ConnectionLivenessCheckTimeout
configBuilder.withSessionLivenessCheckTimeout(boltConfig.connectionLivenessCheckTimeout);
}
if (boltConfig.trustStrategy != null) {
if (boltConfig.trustCertFile == null) {
throw new IllegalArgumentException("Missing configuration value for trust.certificate.file");
Expand All @@ -184,5 +192,6 @@ class BoltConfig {
int sessionPoolSize = DEFAULT_SESSION_POOL_SIZE;
Config.TrustStrategy.Strategy trustStrategy;
String trustCertFile;
Integer connectionLivenessCheckTimeout;
}
}
5 changes: 4 additions & 1 deletion core/src/test/resources/ogm-bolt.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2002-2016 "Neo Technology,"
# Copyright (c) 2002-2017 "Neo Technology,"
# Network Engine for Objects in Lund AB [http://neotechnology.com]
#
# This product is licensed to you under the Apache License, Version 2.0 (the "License").
Expand All @@ -18,3 +18,6 @@ URI=bolt://localhost
#Do not set the pool size to < 150 otherwise tests that spawn 100 concurrent requests will fail
connection.pool.size=150
encryption.level=NONE
# stale connections test interval in milliseconds
# please see official driver documentation before activating this
#connection.liveness.check.timeout=100
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
~ Copyright (c) 2002-2016 "Neo Technology,"
~ Copyright (c) 2002-2017 "Neo Technology,"
~ Network Engine for Objects in Lund AB [http://neotechnology.com]
~
~ This product is licensed to you under the Apache License, Version 2.0 (the "License").
Expand Down

0 comments on commit 383d8f9

Please sign in to comment.