Clean up the Publisher interface and implementations
A message publisher is enabled when it is connected, which implies an
open Session.
Remove Publisher methods:
* enable - unused
* disable - unused
* getSession - unused
* isEnable - Only used by MessagePublisher internally
MessagePublisher, rename isEnable -> isConnected and make private.
Change-Id: Icc6d73f41f250e5376a2a4b1cb7f82c40ec721ff
diff --git a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/message/MessagePublisher.java b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/message/MessagePublisher.java
index 607f4d2..afa716f 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/message/MessagePublisher.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/message/MessagePublisher.java
@@ -45,7 +45,6 @@
private final Properties properties;
private final Gson gson;
private final Timer monitorTimer = new Timer();
- private boolean available = true;
private EventListener eventListener;
private final LinkedBlockingQueue<Event> queue = new LinkedBlockingQueue<>(MAX_EVENTS);
private CancelableRunnable publisher;
@@ -82,10 +81,10 @@
public void run() {
while (!canceled) {
try {
- if (isEnable() && session.isOpen()) {
+ if (isConnected()) {
Event event = queue.poll(200, TimeUnit.MILLISECONDS);
if (event != null) {
- if (isEnable() && session.isOpen()) {
+ if (isConnected()) {
publishEvent(event);
} else {
queue.put(event);
@@ -119,13 +118,13 @@
public void start() {
publisherThread = new Thread(publisher);
publisherThread.start();
- if (!session.isOpen()) {
+ if (!isConnected()) {
session.connect();
monitorTimer.schedule(
new TimerTask() {
@Override
public void run() {
- if (!session.isOpen()) {
+ if (!isConnected()) {
LOGGER.info("#start: try to reconnect");
session.connect();
}
@@ -133,7 +132,6 @@
},
MONITOR_FIRSTTIME_DELAY,
properties.getSection(Monitor.class).interval);
- available = true;
}
}
@@ -149,27 +147,6 @@
}
}
session.disconnect();
- available = false;
- }
-
- @Override
- public void enable() {
- available = true;
- }
-
- @Override
- public void disable() {
- available = false;
- }
-
- @Override
- public boolean isEnable() {
- return available;
- }
-
- @Override
- public Session getSession() {
- return session;
}
@Override
@@ -187,6 +164,10 @@
return this.eventListener;
}
+ private boolean isConnected() {
+ return session != null && session.isOpen();
+ }
+
private void publishEvent(Event event) {
session.publish(gson.toJson(event));
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/message/Publisher.java b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/message/Publisher.java
index b74b94c..f782b00 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/message/Publisher.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/message/Publisher.java
@@ -2,21 +2,12 @@
import com.google.gerrit.common.EventListener;
import com.googlesource.gerrit.plugins.rabbitmq.config.Properties;
-import com.googlesource.gerrit.plugins.rabbitmq.session.Session;
public interface Publisher {
void start();
void stop();
- void enable();
-
- void disable();
-
- boolean isEnable();
-
- Session getSession();
-
Properties getProperties();
String getName();