Add an MBean function to dump the current state of the pool (via a dump of the ConcurrentBag)

pull/113/head
Brett Wooldridge 11 years ago
parent 44509b26a7
commit a54e50a0ae

@ -366,6 +366,13 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
}
}
/** {@inheritDoc} */
@Override
public void dumpPoolState()
{
connectionBag.dumpState();
}
// ***********************************************************************
// Private methods
// ***********************************************************************

@ -32,4 +32,6 @@ public interface HikariPoolMBean
int getThreadsAwaitingConnection();
void closeIdleConnections();
void dumpPoolState();
}

@ -139,6 +139,12 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
return hashCode;
}
@Override
public String toString()
{
return String.format("%s(%s) wrapping %s", this.getClass().getSimpleName(), System.identityHashCode(this), delegate);
}
// ***********************************************************************
// IHikariConnectionProxy methods
// ***********************************************************************

@ -24,6 +24,9 @@ import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This is a specialized concurrent bag that achieves superior performance
* to LinkedBlockingQueue and LinkedTransferQueue for the purposes of a
@ -46,6 +49,8 @@ import java.util.concurrent.locks.AbstractQueuedLongSynchronizer;
*/
public class ConcurrentBag<T extends com.zaxxer.hikari.util.ConcurrentBag.IBagManagable>
{
private static final Logger LOGGER = LoggerFactory.getLogger(ConcurrentBag.class);
public static final int STATE_NOT_IN_USE = 0;
public static final int STATE_IN_USE = 1;
private static final int STATE_REMOVED = -1;
@ -299,6 +304,26 @@ public class ConcurrentBag<T extends com.zaxxer.hikari.util.ConcurrentBag.IBagMa
return sharedList.size();
}
public void dumpState()
{
for (T reference : sharedList) {
switch (reference.getState()) {
case STATE_IN_USE:
LOGGER.info(reference.toString() + " state IN_USE");
break;
case STATE_NOT_IN_USE:
LOGGER.info(reference.toString() + " state NOT_IN_USE");
break;
case STATE_REMOVED:
LOGGER.info(reference.toString() + " state REMOVED");
break;
case STATE_RESERVED:
LOGGER.info(reference.toString() + " state RESERVED");
break;
}
}
}
/**
* Our private synchronizer that handles notify/wait type semantics.
*/

@ -359,6 +359,13 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
});
}
/** {@inheritDoc} */
@Override
public void dumpPoolState()
{
connectionBag.dumpState();
}
// ***********************************************************************
// Private methods
// ***********************************************************************

@ -32,4 +32,6 @@ public interface HikariPoolMBean
int getThreadsAwaitingConnection();
void closeIdleConnections();
void dumpPoolState();
}

@ -139,6 +139,12 @@ public abstract class ConnectionProxy implements IHikariConnectionProxy
return hashCode;
}
@Override
public String toString()
{
return String.format("%s(%s) wrapping %s", this.getClass().getSimpleName(), System.identityHashCode(this), delegate);
}
// ***********************************************************************
// IHikariConnectionProxy methods
// ***********************************************************************

@ -23,6 +23,10 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This is a specialized concurrent bag that achieves superior performance
* to LinkedBlockingQueue and LinkedTransferQueue for the purposes of a
@ -45,6 +49,8 @@ import java.util.stream.Collectors;
*/
public class ConcurrentBag<T extends com.zaxxer.hikari.util.ConcurrentBag.IBagManagable>
{
private static final Logger LOGGER = LoggerFactory.getLogger(ConcurrentBag.class);
public static final int STATE_NOT_IN_USE = 0;
public static final int STATE_IN_USE = 1;
private static final int STATE_REMOVED = -1;
@ -290,6 +296,26 @@ public class ConcurrentBag<T extends com.zaxxer.hikari.util.ConcurrentBag.IBagMa
return sharedList.size();
}
public void dumpState()
{
sharedList.forEach(reference -> {
switch (reference.getState()) {
case STATE_IN_USE:
LOGGER.info(reference.toString() + " state IN_USE");
break;
case STATE_NOT_IN_USE:
LOGGER.info(reference.toString() + " state NOT_IN_USE");
break;
case STATE_REMOVED:
LOGGER.info(reference.toString() + " state REMOVED");
break;
case STATE_RESERVED:
LOGGER.info(reference.toString() + " state RESERVED");
break;
}
});
}
/**
* Our private synchronizer that handles notify/wait type semantics.
*/

Loading…
Cancel
Save