Implement connection monitor feature
diff --git a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/Keys.java b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/Keys.java
index e3e18ba..56c2bed 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/Keys.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/Keys.java
@@ -14,7 +14,8 @@
GERRIT_SCHEME(null, "gerrit-scheme"),
GERRIT_PORT("gerritSshPort", "gerrit-port"),
GERRIT_FRONT_URL("gerritCanonicalWebUrl", "gerrit-front-url"),
- GERRIT_VERSION(null, "gerrit-version");
+ GERRIT_VERSION(null, "gerrit-version"),
+ CONNECTION_MONITOR_INTERVAL("monitorInterval", null);
public String property;
public String header;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/PluginChangeListener.java b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/PluginChangeListener.java
index cfce77c..982db87 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/PluginChangeListener.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/PluginChangeListener.java
@@ -14,6 +14,8 @@
public class PluginChangeListener implements ChangeListener, LifecycleListener {
private static final Logger LOGGER = LoggerFactory.getLogger(PluginChangeListener.class);
+ private final static int MONITOR_FIRATTIME_DELAY = 15000;
+ private final Properties properties;
private final AMQPSession.Factory factory;
private AMQPSession session;
private final Gson gson = new Gson();
@@ -21,7 +23,8 @@
private final ConnectionMonitorTask monitorTask;
@Inject
- public PluginChangeListener(AMQPSession.Factory factory, ConnectionMonitorTask monitorTask) {
+ public PluginChangeListener(Properties properties, AMQPSession.Factory factory, ConnectionMonitorTask monitorTask) {
+ this.properties = properties;
this.factory = factory;
this.monitorTask = monitorTask;
}
@@ -30,7 +33,7 @@
public void start() {
session = factory.create();
session.connect();
- monitorTimer.schedule(monitorTask, 15000, 15000);
+ monitorTimer.schedule(monitorTask, MONITOR_FIRATTIME_DELAY, properties.getConnectionMonitorInterval());
}
@Override
diff --git a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/Properties.java b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/Properties.java
index f38154a..5b26d23 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/Properties.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/Properties.java
@@ -27,6 +27,8 @@
private final static int DEFAULT_MESSAGE_PRIORITY = 1;
private final static int DEFAULT_GERRIT_PORT = 29418;
private final static String DEFAULT_GERRIT_SCHEME = "ssh";
+ private final static int DEFAULT_CONNECTION_MONITOR_INTERVAL = 15000;
+ private final static int MINIMUM_CONNECTION_MONITOR_INTERVAL = 5000;
private final Config config;
private final PluginConfig pluginConfig;
@@ -95,6 +97,14 @@
return StringUtils.stripToEmpty(Version.getVersion());
}
+ public int getConnectionMonitorInterval() {
+ int interval = pluginConfig.getInt(Keys.CONNECTION_MONITOR_INTERVAL.property, DEFAULT_CONNECTION_MONITOR_INTERVAL);
+ if (interval < MINIMUM_CONNECTION_MONITOR_INTERVAL) {
+ return MINIMUM_CONNECTION_MONITOR_INTERVAL;
+ }
+ return interval;
+ }
+
public AMQP.BasicProperties getBasicProperties() {
if (properties == null) {
Map<String, Object> headers = new HashMap<String, Object>();