[AMQ-9315] Add connectedTimestamp to Connection and JMX view

This commit is contained in:
Matt Pavlovich 2023-10-02 10:18:26 -05:00
parent 538b04aa0c
commit 578d86d726
7 changed files with 49 additions and 1 deletions

View File

@ -121,7 +121,6 @@ public interface Connection extends Service {
void updateClient(ConnectionControl control);
/**
* Returns the number of active transactions established on this Connection.
*
@ -136,4 +135,10 @@ public interface Connection extends Service {
*/
public Long getOldestActiveTransactionDuration();
/**
* Returns the time in ms since epoch when connection was established.
*
* @return time in ms since epoch when connection was established.
*/
public Long getConnectedTimestamp();
}

View File

@ -161,6 +161,7 @@ public class TransportConnection implements Connection, Task, CommandVisitor {
private TransportConnectionStateRegister connectionStateRegister = new SingleTransportConnectionStateRegister();
private final ReentrantReadWriteLock serviceLock = new ReentrantReadWriteLock();
private String duplexNetworkConnectorId;
private final long connectedTimestamp;
/**
* @param taskRunnerFactory - can be null if you want direct dispatch to the transport
@ -218,6 +219,7 @@ public class TransportConnection implements Connection, Task, CommandVisitor {
}
});
connected = true;
connectedTimestamp = System.currentTimeMillis();
}
/**
@ -1724,4 +1726,9 @@ public class TransportConnection implements Connection, Task, CommandVisitor {
public Response processBrokerSubscriptionInfo(BrokerSubscriptionInfo info) throws Exception {
return null;
}
@Override
public Long getConnectedTimestamp() {
return this.connectedTimestamp;
}
}

View File

@ -191,4 +191,9 @@ public class ConnectionView implements ConnectionViewMBean {
public boolean isNetworkConnection() {
return connection.isNetworkConnection();
}
@Override
public long getConnectedTimestamp() {
return connection.getConnectedTimestamp();
}
}

View File

@ -133,4 +133,10 @@ public interface ConnectionViewMBean extends Service {
*/
@MBeanInfo("Connection is a network connection.")
boolean isNetworkConnection();
/**
* @return the time in ms since epoch when connection was established
*/
@MBeanInfo("Time in ms since epoch when connection was established.")
long getConnectedTimestamp();
}

View File

@ -81,6 +81,9 @@ public class SchedulerBroker extends BrokerFilter implements JobListener {
this.context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT);
// we only get response on unexpected error
this.context.setConnection(new Connection() {
private final long connectedTimestamp = System.currentTimeMillis();
@Override
public Connector getConnector() {
return null;
@ -183,6 +186,12 @@ public class SchedulerBroker extends BrokerFilter implements JobListener {
return null;
}
@Override
public Long getConnectedTimestamp() {
return connectedTimestamp;
}
@Override
public void start() throws Exception {}

View File

@ -218,6 +218,9 @@ public class DefaultAuthenticationPolicyTest {
ConnectionContext ctx = new ConnectionContext();
Connection connection = new Connection() {
private final long connectedTimestamp = System.currentTimeMillis();
@Override
public Connector getConnector() {
return null; //To change body of implemented methods use File | Settings | File Templates.
@ -327,6 +330,12 @@ public class DefaultAuthenticationPolicyTest {
public Long getOldestActiveTransactionDuration() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public Long getConnectedTimestamp() {
return connectedTimestamp;
}
};
ctx.setConnection(connection);

View File

@ -104,6 +104,8 @@ public class QueueOptimizedDispatchExceptionTest {
final ConnectionContext contextNotInTx = new ConnectionContext();
contextNotInTx.setConnection(new Connection() {
private final long connectedTimestamp = System.currentTimeMillis();
@Override
public void stop() throws Exception {
}
@ -207,6 +209,11 @@ public class QueueOptimizedDispatchExceptionTest {
public Long getOldestActiveTransactionDuration() {
return null;
}
@Override
public Long getConnectedTimestamp() {
return connectedTimestamp;
}
});
final DestinationStatistics destinationStatistics = new DestinationStatistics();