Skip to content

Commit

Permalink
CR feedback 1
Browse files Browse the repository at this point in the history
  • Loading branch information
campersau committed Feb 10, 2022
1 parent 65dfaa8 commit 78ec3b8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 65 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,16 @@ class SomeFunctionResult
string connectionString = "AppServerHost=MY_SERVER_HOST; SystemNumber=00; User=MY_SAP_USER; Password=SECRET; Client=100; Language=EN; PoolSize=5; Trace=8";

var connectionPool = new SapConnectionPool(connectionString);
var pooledConnection = new SapPooledConnection(connectionPool);

SapServer.InstallGenericServerFunctionHandler(
(string functionName, SapAttributes attributes) =>
{
return pooledConnection.GetFunctionMetadata(functionName);
using var connection = connectionPool.GetConnection();
return connection.GetFunctionMetadata(functionName);
},
(ISapServerConnection connection, ISapServerFunction function) =>
{
SapAttributes attributes = connection.GetAttributes();
var attributes = connection.GetAttributes();

switch (function.GetName())
{
Expand Down
16 changes: 0 additions & 16 deletions src/SapNwRfc/Pooling/ISapPooledConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,6 @@ namespace SapNwRfc.Pooling
/// </summary>
public interface ISapPooledConnection : IDisposable
{
/// <summary>
/// Gets the metadata for the specified type name.
/// </summary>
/// <param name="typeName">The type name.</param>
/// <param name="cancellationToken">The cancellation token for cancelling the underlying operation.</param>
/// <returns>The metadata for the type name.</returns>
ISapTypeMetadata GetTypeMetadata(string typeName, CancellationToken cancellationToken = default);

/// <summary>
/// Gets the metadata for the specified function name.
/// </summary>
/// <param name="functionName">The function name.</param>
/// <param name="cancellationToken">The cancellation token for cancelling the underlying operation.</param>
/// <returns>The matadata for the function name.</returns>
ISapFunctionMetadata GetFunctionMetadata(string functionName, CancellationToken cancellationToken = default);

/// <summary>
/// Invokes the remote function.
/// </summary>
Expand Down
49 changes: 3 additions & 46 deletions src/SapNwRfc/Pooling/SapPooledConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,46 +48,6 @@ public void Dispose()
_disposed = true;
}

/// <inheritdoc cref="ISapPooledConnection"/>
public ISapTypeMetadata GetTypeMetadata(string typeName, CancellationToken cancellationToken = default)
{
_connection = _connection ?? _pool.GetConnection(cancellationToken);

try
{
return _connection.GetTypeMetadata(typeName);
}
catch (SapCommunicationFailedException)
{
// Let the pool collect the dead connection
_pool.ForgetConnection(_connection);

// Retry invocation with new connection from the pool
_connection = _pool.GetConnection(cancellationToken);
return _connection.GetTypeMetadata(typeName);
}
}

/// <inheritdoc cref="ISapPooledConnection"/>
public ISapFunctionMetadata GetFunctionMetadata(string functionName, CancellationToken cancellationToken = default)
{
_connection = _connection ?? _pool.GetConnection(cancellationToken);

try
{
return _connection.GetFunctionMetadata(functionName);
}
catch (SapCommunicationFailedException)
{
// Let the pool collect the dead connection
_pool.ForgetConnection(_connection);

// Retry invocation with new connection from the pool
_connection = _pool.GetConnection(cancellationToken);
return _connection.GetFunctionMetadata(functionName);
}
}

/// <inheritdoc cref="ISapPooledConnection"/>
public void InvokeFunction(string name, CancellationToken cancellationToken = default)
{
Expand All @@ -113,10 +73,9 @@ public void InvokeFunction(string name, CancellationToken cancellationToken = de
/// <inheritdoc cref="ISapPooledConnection"/>
public void InvokeFunction(string name, object input, CancellationToken cancellationToken = default)
{
_connection = _connection ?? _pool.GetConnection(cancellationToken);

try
{
_connection = _connection ?? _pool.GetConnection(cancellationToken);
using (ISapFunction function = _connection.CreateFunction(name))
function.Invoke(input);
}
Expand All @@ -135,10 +94,9 @@ public void InvokeFunction(string name, object input, CancellationToken cancella
/// <inheritdoc cref="ISapPooledConnection"/>
public TOutput InvokeFunction<TOutput>(string name, CancellationToken cancellationToken = default)
{
_connection = _connection ?? _pool.GetConnection(cancellationToken);

try
{
_connection = _connection ?? _pool.GetConnection(cancellationToken);
using (ISapFunction function = _connection.CreateFunction(name))
return function.Invoke<TOutput>();
}
Expand All @@ -157,10 +115,9 @@ public TOutput InvokeFunction<TOutput>(string name, CancellationToken cancellati
/// <inheritdoc cref="ISapPooledConnection"/>
public TOutput InvokeFunction<TOutput>(string name, object input, CancellationToken cancellationToken = default)
{
_connection = _connection ?? _pool.GetConnection(cancellationToken);

try
{
_connection = _connection ?? _pool.GetConnection(cancellationToken);
using (ISapFunction function = _connection.CreateFunction(name))
return function.Invoke<TOutput>(input);
}
Expand Down

0 comments on commit 78ec3b8

Please sign in to comment.