Skip to content

Commit

Permalink
Pool class refinements (#5117)
Browse files Browse the repository at this point in the history
* Some updates to the new Pool class:

 + fixed a race with pending reservations
 + use a pending counter
 + Reservation API to simplify Entry API
 + removed public methods on Entry API

* Some updates to the new Pool class:

 + fixed a race with pending reservations
 + use a pending counter
 + Reservation API to simplify Entry API
 + removed public methods on Entry API

* Updates from review

* Updates from review
Tests for cache size and acquire with creator

* Method no longer required with Reservation

* update from the feedback on the feedback of the feedback from the review.

Moved enable to Entry, removed Reservation class and clarified usage in javadoc

* Issue #5095 XmlConfiguration locking  Use pool instead of static shared instance

fixed javadoc

* Issue #5095 XmlConfiguration locking  Use pool instead of static shared instance

fixed javadoc

* Issue #5095 XmlConfiguration locking  Use pool instead of static shared instance

fixed javadoc

* Issue #5095 XmlConfiguration locking  Use pool instead of static shared instance

updates from review
  • Loading branch information
gregw authored Aug 12, 2020
1 parent bc185e3 commit 25e3f1c
Show file tree
Hide file tree
Showing 4 changed files with 459 additions and 208 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ protected void setMaxUsageCount(int maxUsageCount)
@ManagedAttribute(value = "The number of active connections", readonly = true)
public int getActiveConnectionCount()
{
return pool.getInUseConnectionCount();
return pool.getInUseCount();
}

@ManagedAttribute(value = "The number of idle connections", readonly = true)
public int getIdleConnectionCount()
{
return pool.getIdleConnectionCount();
return pool.getIdleCount();
}

@ManagedAttribute(value = "The max number of connections", readonly = true)
Expand Down Expand Up @@ -141,7 +141,7 @@ public int getPendingCount()
@ManagedAttribute(value = "The number of pending connections", readonly = true)
public int getPendingConnectionCount()
{
return pool.getPendingConnectionCount();
return pool.getReservedCount();
}

@Override
Expand Down Expand Up @@ -201,29 +201,33 @@ protected void tryCreate(int maxPending)

private CompletableFuture<Void> tryCreateReturningFuture(int maxPending)
{
CompletableFuture<Void> future = new CompletableFuture<>();

if (LOG.isDebugEnabled())
LOG.debug("tryCreate {}/{} connections {}/{} pending", pool.size(), pool.getMaxEntries(), getPendingConnectionCount(), maxPending);

Pool<Connection>.Entry entry = pool.reserve(maxPending);
if (entry == null)
{
future.complete(null);
return future;
}
return CompletableFuture.completedFuture(null);

if (LOG.isDebugEnabled())
LOG.debug("newConnection {}/{} connections {}/{} pending", pool.size(), pool.getMaxEntries(), getPendingConnectionCount(), maxPending);

CompletableFuture<Void> future = new CompletableFuture<>();
destination.newConnection(new Promise<Connection>()
{
@Override
public void succeeded(Connection connection)
{
if (LOG.isDebugEnabled())
LOG.debug("Connection {}/{} creation succeeded {}", pool.size(), pool.getMaxEntries(), connection);
adopt(entry, connection);
if (!(connection instanceof Attachable))
{
failed(new IllegalArgumentException("Invalid connection object: " + connection));
return;
}
((Attachable)connection).setAttachment(entry);
onCreated(connection);
entry.enable(connection, false);
idle(connection, false);
future.complete(null);
proceed();
}
Expand All @@ -233,11 +237,12 @@ public void failed(Throwable x)
{
if (LOG.isDebugEnabled())
LOG.debug("Connection " + pool.size() + "/" + pool.getMaxEntries() + " creation failed", x);
pool.remove(entry);
entry.remove();
future.completeExceptionally(x);
requester.failed(x);
}
});

return future;
}

Expand All @@ -246,19 +251,6 @@ protected void proceed()
requester.succeeded();
}

private void adopt(Pool<Connection>.Entry entry, Connection connection)
{
if (!(connection instanceof Attachable))
throw new IllegalArgumentException("Invalid connection object: " + connection);
Attachable attachable = (Attachable)connection;
attachable.setAttachment(entry);
if (LOG.isDebugEnabled())
LOG.debug("onCreating {}", entry);
onCreated(connection);
entry.enable(connection);
idle(connection, false);
}

protected Connection activate()
{
Pool<Connection>.Entry entry = pool.acquire();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
public interface Attachable
{
/**
* @return the object attached to this stream
* @return the object attached to this instance
* @see #setAttachment(Object)
*/
Object getAttachment();

/**
* Attaches the given object to this stream for later retrieval.
*
* @param attachment the object to attach to this stream
* @param attachment the object to attach to this instance
*/
void setAttachment(Object attachment);
}
Loading

0 comments on commit 25e3f1c

Please sign in to comment.