-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move server info into result summary #272
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,11 +32,13 @@ | |
import org.neo4j.driver.internal.security.SecurityPlan; | ||
import org.neo4j.driver.internal.spi.Collector; | ||
import org.neo4j.driver.internal.spi.Connection; | ||
import org.neo4j.driver.internal.summary.InternalServerInfo; | ||
import org.neo4j.driver.v1.Logger; | ||
import org.neo4j.driver.v1.Logging; | ||
import org.neo4j.driver.v1.Value; | ||
import org.neo4j.driver.v1.exceptions.ClientException; | ||
import org.neo4j.driver.v1.exceptions.Neo4jException; | ||
import org.neo4j.driver.v1.summary.ServerInfo; | ||
|
||
import static java.lang.String.format; | ||
import static org.neo4j.driver.internal.messaging.AckFailureMessage.ACK_FAILURE; | ||
|
@@ -50,7 +52,7 @@ public class SocketConnection implements Connection | |
private final SocketResponseHandler responseHandler; | ||
private AtomicBoolean isInterrupted = new AtomicBoolean( false ); | ||
private AtomicBoolean isAckFailureMuted = new AtomicBoolean( false ); | ||
private final Collector.InitCollector initCollector = new Collector.InitCollector(); | ||
private InternalServerInfo serverInfo; | ||
|
||
private final SocketClient socket; | ||
|
||
|
@@ -59,6 +61,7 @@ public class SocketConnection implements Connection | |
public SocketConnection( BoltServerAddress address, SecurityPlan securityPlan, Logging logging ) | ||
{ | ||
this.logger = logging.getLog( format( "conn-%s", UUID.randomUUID().toString() ) ); | ||
this.socket = new SocketClient( address, securityPlan, logger ); | ||
|
||
if( logger.isDebugEnabled() ) | ||
{ | ||
|
@@ -69,15 +72,34 @@ public SocketConnection( BoltServerAddress address, SecurityPlan securityPlan, L | |
this.responseHandler = new SocketResponseHandler(); | ||
} | ||
|
||
this.socket = new SocketClient( address, securityPlan, logger ); | ||
socket.start(); | ||
this.socket.start(); | ||
} | ||
|
||
// for mocked socket testing | ||
SocketConnection( SocketClient socket, Logger logger ) | ||
{ | ||
this.socket = socket; | ||
this.logger = logger; | ||
|
||
if( logger.isDebugEnabled() ) | ||
{ | ||
this.responseHandler = new LoggingResponseHandler( logger ); | ||
} | ||
else | ||
{ | ||
this.responseHandler = new SocketResponseHandler(); | ||
} | ||
|
||
this.socket.start(); | ||
} | ||
|
||
@Override | ||
public void init( String clientName, Map<String,Value> authToken ) | ||
{ | ||
Collector.InitCollector initCollector = new Collector.InitCollector(); | ||
queueMessage( new InitMessage( clientName, authToken ), initCollector ); | ||
sync(); | ||
this.serverInfo = new InternalServerInfo( socket.address(), initCollector.server() ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
@Override | ||
|
@@ -267,15 +289,15 @@ public boolean isAckFailureMuted() | |
} | ||
|
||
@Override | ||
public String server() | ||
public ServerInfo server() | ||
{ | ||
return initCollector.server( ); | ||
return this.serverInfo; | ||
} | ||
|
||
@Override | ||
public BoltServerAddress address() | ||
public BoltServerAddress boltServerAddress() | ||
{ | ||
return this.socket.address(); | ||
return this.serverInfo.boltServerAddress(); | ||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright (c) 2002-2016 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* 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.summary; | ||
|
||
import org.neo4j.driver.internal.net.BoltServerAddress; | ||
import org.neo4j.driver.v1.summary.ServerInfo; | ||
|
||
public class InternalServerInfo implements ServerInfo | ||
{ | ||
private BoltServerAddress address; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fields can be final |
||
private String version; | ||
|
||
public InternalServerInfo(BoltServerAddress address, String version) | ||
{ | ||
this.address = address; | ||
this.version = version; | ||
} | ||
|
||
public BoltServerAddress boltServerAddress() | ||
{ | ||
return this.address; | ||
} | ||
|
||
@Override | ||
public String address() | ||
{ | ||
return this.address.toString(); | ||
} | ||
|
||
@Override | ||
public String version() | ||
{ | ||
return version; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe extract this
if-else
in a method likecreateResponseHandler(Logger)
, otherwise it is duplicated in both constructors.