Skip to content

Commit 5ea44cb

Browse files
author
Zhen Li
authored
Merge pull request #204 from nigelsmall/1.1-cluster-prep
Prep for clustering functionality
2 parents ad04a53 + b5f8cc0 commit 5ea44cb

File tree

84 files changed

+1034
-918
lines changed

Some content is hidden

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

84 files changed

+1034
-918
lines changed

driver/src/main/java/org/neo4j/driver/internal/util/AddressUtil.java renamed to driver/src/main/java/org/neo4j/driver/internal/BaseDriver.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,29 @@
1717
* limitations under the License.
1818
*/
1919

20-
package org.neo4j.driver.internal.util;
20+
package org.neo4j.driver.internal;
2121

22-
import java.net.InetAddress;
23-
import java.net.UnknownHostException;
22+
import org.neo4j.driver.internal.security.SecurityPlan;
23+
import org.neo4j.driver.v1.Driver;
24+
import org.neo4j.driver.v1.Logger;
25+
import org.neo4j.driver.v1.Logging;
26+
import org.neo4j.driver.v1.Session;
2427

25-
public class AddressUtil
28+
abstract class BaseDriver implements Driver
2629
{
27-
/**
28-
* Return true if the host provided matches "localhost" or "127.x.x.x".
29-
*
30-
* @param host the host name to test
31-
* @return true if localhost, false otherwise
32-
*/
33-
public static boolean isLocalHost( String host )
30+
private final SecurityPlan securityPlan;
31+
protected final Logger log;
32+
33+
BaseDriver( SecurityPlan securityPlan, Logging logging )
34+
{
35+
this.securityPlan = securityPlan;
36+
this.log = logging.getLog( Session.LOG_NAME );
37+
}
38+
39+
@Override
40+
public boolean isEncrypted()
3441
{
35-
try
36-
{
37-
// confirmed to work as desired with both "localhost" and "127.x.x.x"
38-
return InetAddress.getByName( host ).isLoopbackAddress();
39-
}
40-
catch ( UnknownHostException e )
41-
{
42-
// if it's unknown, it's not local so we can safely return false
43-
return false;
44-
}
42+
return securityPlan.requiresEncryption();
4543
}
4644

4745
}

driver/src/main/java/org/neo4j/driver/internal/Version.java renamed to driver/src/main/java/org/neo4j/driver/internal/ConnectionSettings.java

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,32 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19+
1920
package org.neo4j.driver.internal;
2021

22+
import org.neo4j.driver.v1.AuthToken;
2123
import org.neo4j.driver.v1.Session;
2224

23-
public class Version
25+
import static java.lang.String.format;
26+
27+
/**
28+
* The connection settings are used whenever a new connection is
29+
* established to a server, specifically as part of the INIT request.
30+
*/
31+
public class ConnectionSettings
2432
{
33+
public static final String DEFAULT_USER_AGENT = format( "neo4j-java/%s", driverVersion() );
34+
2535
/**
2636
* Extracts the driver version from the driver jar MANIFEST.MF file.
2737
*/
28-
public static String driverVersion()
38+
private static String driverVersion()
2939
{
3040
// "Session" is arbitrary - the only thing that matters is that the class we use here is in the
3141
// 'org.neo4j.driver' package, because that is where the jar manifest specifies the version.
3242
// This is done as part of the build, adding a MANIFEST.MF file to the generated jarfile.
3343
Package pkg = Session.class.getPackage();
34-
if(pkg != null && pkg.getImplementationVersion() != null)
44+
if ( pkg != null && pkg.getImplementationVersion() != null )
3545
{
3646
return pkg.getImplementationVersion();
3747
}
@@ -40,4 +50,29 @@ public static String driverVersion()
4050
// This should only happen during development, so call the version 'dev'.
4151
return "dev";
4252
}
53+
54+
private final AuthToken authToken;
55+
private final String userAgent;
56+
57+
public ConnectionSettings( AuthToken authToken, String userAgent )
58+
{
59+
this.authToken = authToken;
60+
this.userAgent = userAgent;
61+
}
62+
63+
public ConnectionSettings( AuthToken authToken )
64+
{
65+
this( authToken, DEFAULT_USER_AGENT );
66+
}
67+
68+
public AuthToken authToken()
69+
{
70+
return authToken;
71+
}
72+
73+
public String userAgent()
74+
{
75+
return userAgent;
76+
}
77+
4378
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Copyright (c) 2002-2016 "Neo Technology,"
3+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
package org.neo4j.driver.internal;
21+
22+
import org.neo4j.driver.internal.net.BoltServerAddress;
23+
import org.neo4j.driver.internal.net.pooling.PoolSettings;
24+
import org.neo4j.driver.internal.net.pooling.SocketConnectionPool;
25+
import org.neo4j.driver.internal.security.SecurityPlan;
26+
import org.neo4j.driver.internal.spi.ConnectionPool;
27+
import org.neo4j.driver.v1.Logging;
28+
import org.neo4j.driver.v1.Session;
29+
30+
import static java.lang.String.format;
31+
32+
public class DirectDriver extends BaseDriver
33+
{
34+
private final BoltServerAddress address;
35+
private final ConnectionPool connections;
36+
37+
public DirectDriver( BoltServerAddress address, ConnectionSettings connectionSettings, SecurityPlan securityPlan,
38+
PoolSettings poolSettings, Logging logging )
39+
{
40+
super( securityPlan, logging );
41+
this.address = address;
42+
this.connections = new SocketConnectionPool( connectionSettings, securityPlan, poolSettings, logging );
43+
}
44+
45+
@Override
46+
public Session session()
47+
{
48+
return new InternalSession( connections.acquire( address ), log );
49+
}
50+
51+
@Override
52+
public void close()
53+
{
54+
try
55+
{
56+
connections.close();
57+
}
58+
catch ( Exception ex )
59+
{
60+
log.error( format( "~~ [ERROR] %s", ex.getMessage() ), ex );
61+
}
62+
}
63+
64+
}

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

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

driver/src/main/java/org/neo4j/driver/internal/connector/socket/SSLContextFactory.java

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

0 commit comments

Comments
 (0)