Skip to content
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

Add async support for routing driver #203

Merged
merged 3 commits into from
Aug 3, 2017

Conversation

zhenlineo
Copy link
Contributor

@zhenlineo zhenlineo commented Jul 25, 2017

Improved statistic collector to be able to pull data from multiple statistic provider and remove statistic provider once it is no longer valid.

if (_statistics != null)
{
_statistics.Dispose();
_statisticsCollector?.Unregister(_statistics);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though it does not make any difference specifically with this usage scenerio, these two lines should be swapped for avoiding access to a disposed object.

@@ -81,6 +94,7 @@ public void Dispose()
_pool = null;
}

public static ConnectionPoolStatistics Read(IDictionary<string, object> dict) => new ConnectionPoolStatistics(dict);
public static ConnectionPoolStatistics Read(string name, IDictionary<string, object> dict)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to have it named as From or FromDictionary?

@@ -49,7 +49,7 @@ public static T GetValue<T>(this IDictionary<string, object> dict, string key, T

public static string ToContentString<K, V>(this IDictionary<K, V> dict)
{
var output = dict.Select(item => $"{{{item.Key}, {item.Value}}}");
var output = dict.Select(item => $"{{{item.Key}, {item.Value.ValueToString()}}}");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an improvement, I think we should develop more readable display format (may be indented?) for statistics as it becomes hard to decompose & understand especially when output is large.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Statistics will be reported in a dictionary. It depends on how the end user would like to print.

The real way of consuming statistics in my mind was that we will give the dictionary to a graphic server and show us all statistics in real time (every a few sec). I would suggest to not bother too much of how we internally print them out now. We are not really relying on console printout in our tests anyway.

@@ -79,6 +80,18 @@ public IConnection Acquire(Uri uri)
return pool.Acquire(ignored);
}

public async Task<IConnection> AcquireAsync(Uri uri)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

async and await keywords could be avoided in this method.

try
{
var result = await session.RunAsync(DiscoveryProcedure).ConfigureAwait(false);
await result.ReadAsync().ConfigureAwait(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to standardize this usage as

if (await result.ReadAsync().ConfigureAwait(false)) {

} else {
   throw ....
}

or negation of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this place

await result.ReadAsync().ConfigureAwait(false);
var record = result.Current();

What we really want is

await result.SingleAsync().ConfigureAwait(false);

So I added an extension class to impl this SingleAsync now :D

@@ -130,7 +179,17 @@ public IConnection Acquire(AccessMode mode)

public Task<IConnection> AcquireAsync(AccessMode mode)
{
throw new NotImplementedException();
var task = new TaskCompletionSource<IConnection>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified as

return Task.FromResult(Acquire(mode));


public async Task CloseAsync()
{
if (_connection != null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

async & await keywords could be avoided in this method, like

if (_connection != null) {
   return _connection.CloseAsync();
}

return Task.CompletedTask;

Added extension method SingleAsync on IStatementREsultReader
@ali-ince ali-ince merged commit 5d260cd into neo4j:1.5 Aug 3, 2017
@zhenlineo zhenlineo deleted the 1.5-async-routing-driver branch August 3, 2017 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants