Skip to content

Commit

Permalink
Move server info into result summary
Browse files Browse the repository at this point in the history
Replaced session.server with resultSummary.server.version
Replaced session.address with resultSummary.server.address
  • Loading branch information
Zhen committed Nov 15, 2016
1 parent 3649855 commit efdf8bd
Show file tree
Hide file tree
Showing 27 changed files with 355 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import java.util.List;
import java.util.Queue;

import org.neo4j.driver.internal.spi.Connection;
import org.neo4j.driver.internal.spi.Collector;
import org.neo4j.driver.internal.spi.Connection;
import org.neo4j.driver.internal.summary.SummaryBuilder;
import org.neo4j.driver.v1.Record;
import org.neo4j.driver.v1.Statement;
Expand All @@ -37,6 +37,7 @@
import org.neo4j.driver.v1.summary.Plan;
import org.neo4j.driver.v1.summary.ProfiledPlan;
import org.neo4j.driver.v1.summary.ResultSummary;
import org.neo4j.driver.v1.summary.ServerInfo;
import org.neo4j.driver.v1.summary.StatementType;
import org.neo4j.driver.v1.summary.SummaryCounters;
import org.neo4j.driver.v1.util.Function;
Expand All @@ -61,7 +62,7 @@ public class InternalStatementResult implements StatementResult
{
this.connection = connection;
this.runResponseCollector = newRunResponseCollector();
this.pullAllResponseCollector = newStreamResponseCollector( transaction, statement );
this.pullAllResponseCollector = newStreamResponseCollector( transaction, statement, connection.server() );
}

private Collector newRunResponseCollector()
Expand Down Expand Up @@ -91,9 +92,10 @@ public void resultAvailableAfter( long l )
};
}

private Collector newStreamResponseCollector( final ExplicitTransaction transaction, final Statement statement )
private Collector newStreamResponseCollector( final ExplicitTransaction transaction, final Statement statement,
final ServerInfo serverInfo )
{
final SummaryBuilder summaryBuilder = new SummaryBuilder( statement );
final SummaryBuilder summaryBuilder = new SummaryBuilder( statement, serverInfo );

return new Collector.NoOperationCollector()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,6 @@ private void closeConnection()
connection.close();
}

@Override
public String server()
{
return connection.server();
}

@Override
public Transaction beginTransaction()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.neo4j.driver.internal.spi.ConnectionPool;
import org.neo4j.driver.internal.util.Clock;
import org.neo4j.driver.v1.AccessMode;
import org.neo4j.driver.v1.Config;
import org.neo4j.driver.v1.Logging;
import org.neo4j.driver.v1.Session;
import org.neo4j.driver.v1.exceptions.ClientException;
Expand Down Expand Up @@ -70,7 +69,7 @@ public Session session()
public Session session( final AccessMode mode )
{
Connection connection = acquireConnection( mode );
return new RoutingNetworkSession( new NetworkSession( connection ), mode, connection.address(), loadBalancer );
return new RoutingNetworkSession( new NetworkSession( connection ), mode, connection.boltServerAddress(), loadBalancer );
}

private Connection acquireConnection( AccessMode role )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,6 @@ public void close()
}
}

@Override
public String server()
{
return delegate.server();
}

public BoltServerAddress address()
{
return address;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.neo4j.driver.v1.Logger;
import org.neo4j.driver.v1.Value;
import org.neo4j.driver.v1.exceptions.ClientException;
import org.neo4j.driver.v1.summary.ServerInfo;

/**
* This class ensures there can only ever be one thread using a connection at
Expand Down Expand Up @@ -231,15 +232,15 @@ private void markAsInUse()
}

@Override
public String server()
public ServerInfo server()
{
return delegate.server();
}

@Override
public BoltServerAddress address()
public BoltServerAddress boltServerAddress()
{
return delegate.address();
return delegate.boltServerAddress();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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() )
{
Expand All @@ -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() );
}

@Override
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,24 @@ public void handleFailureMessage( String code, String message )
public void handleSuccessMessage( Map<String,Value> meta )
{
Collector collector = collectors.remove();
collectServer( collector, meta.get( "server" ));
collectServerVersion( collector, meta.get( "server" ) );
collectFields( collector, meta.get( "fields" ) );
collectType( collector, meta.get( "type" ) );
collectStatistics( collector, meta.get( "stats" ) );
collectPlan( collector, meta.get( "plan" ) );
collectProfile( collector, meta.get( "profile" ) );
collectNotifications( collector, meta.get( "notifications" ) );
collectResultAvailableAfter( collector, meta.get("result_available_after"));
collectResultConsumedAfter( collector, meta.get("result_consumed_after"));
collectResultAvailableAfter( collector, meta.get("result_available_after") );
collectResultConsumedAfter( collector, meta.get("result_consumed_after") );
collectBookmark( collector, meta.get( "bookmark" ) );
collector.doneSuccess();
}

private void collectServer( Collector collector, Value server )
private void collectServerVersion( Collector collector, Value serverVersion )
{
if (server != null)
if ( serverVersion != null )
{
collector.server( server.asString() );
collector.serverVersion( serverVersion.asString() );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.neo4j.driver.v1.Logger;
import org.neo4j.driver.v1.Value;
import org.neo4j.driver.v1.exceptions.Neo4jException;
import org.neo4j.driver.v1.summary.ServerInfo;

/**
* The state of a pooledConnection from a pool point of view could be one of the following:
* Created,
Expand Down Expand Up @@ -233,15 +235,15 @@ public boolean isAckFailureMuted()
}

@Override
public String server()
public ServerInfo server()
{
return delegate.server();
}

@Override
public BoltServerAddress address()
public BoltServerAddress boltServerAddress()
{
return delegate.address();
return delegate.boltServerAddress();
}

@Override
Expand All @@ -257,7 +259,7 @@ public void dispose()

/**
* If something goes wrong with the delegate, we want to figure out if this "wrong" is something that means
* the connection is screwed (and thus should be evicted from the pool), or if it's something that we can
* the connection cannot be reused (and thus should be evicted from the pool), or if it's something that we can
* safely recover from.
* @param e the exception the delegate threw
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Boolean apply( PooledConnection pooledConnection )
{
// once the pooledConn has marked to have unrecoverable errors, there is no way to remove the error
// and we should close the conn without bothering to reset the conn at all
return pool.hasAddress( pooledConnection.address() ) &&
return pool.hasAddress( pooledConnection.boltServerAddress() ) &&
!pooledConnection.hasUnrecoverableErrors() &&
reset( pooledConnection ) &&
(pooledConnection.idleTime() <= poolSettings.idleTimeBeforeConnectionTest() ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void doneIgnored()
}

@Override
public void server( String server )
public void serverVersion( String server )
{
this.server = server;
}
Expand Down Expand Up @@ -160,7 +160,7 @@ public void resultAvailableAfter( long l ) {}
public void resultConsumedAfter( long l ) {}

@Override
public void server( String server ){}
public void serverVersion( String server ){}
}

// TODO: This should be modified to simply have head/record/tail methods
Expand Down Expand Up @@ -193,6 +193,6 @@ public void server( String server ){}

void resultConsumedAfter( long l );

void server( String server );
void serverVersion( String server );
}

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.neo4j.driver.internal.net.BoltServerAddress;
import org.neo4j.driver.v1.Logger;
import org.neo4j.driver.v1.Value;
import org.neo4j.driver.v1.summary.ServerInfo;

/**
* A connection is an abstraction provided by an underlying transport implementation,
Expand Down Expand Up @@ -121,15 +122,15 @@ public interface Connection extends AutoCloseable
boolean isAckFailureMuted();

/**
* Returns the version of the server connected to.
* @return The version of the server connected to.
* Returns the basic information of the server connected to.
* @return The basic information of the server connected to.
*/
String server();
ServerInfo server();

/**
* Returns the BoltServerAddress connected to
*/
BoltServerAddress address();
BoltServerAddress boltServerAddress();

/**
* Returns the logger of this connection
Expand Down
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;
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;
}
}
Loading

0 comments on commit efdf8bd

Please sign in to comment.