use of com.google.gerrit.server.events.UserScopedEventListener in project gerrit by GerritCodeReview.
the class StreamEvents method start.
@Override
public void start(ChannelSession channel, Environment env) throws IOException {
try (DynamicOptions pluginOptions = new DynamicOptions(injector, dynamicBeans)) {
try {
parseCommandLine(pluginOptions);
} catch (UnloggedFailure e) {
String msg = e.getMessage();
if (!msg.endsWith("\n")) {
msg += "\n";
}
err.write(msg.getBytes(UTF_8));
err.flush();
onExit(1);
return;
}
PrintWriter stdout = toPrintWriter(out);
CancelableRunnable writer = new CancelableRunnable() {
@Override
public void run() {
writeEvents(this, stdout);
}
@Override
public void cancel() {
onExit(0);
}
@Override
public String toString() {
StringBuilder b = new StringBuilder();
b.append("Stream Events");
if (currentUser.getUserName().isPresent()) {
b.append(" (").append(currentUser.getUserName().get()).append(")");
}
return b.toString();
}
};
eventListenerRegistration = eventListeners.add("gerrit", new UserScopedEventListener() {
@Override
public void onEvent(Event event) {
if (subscribedToEvents.isEmpty() || subscribedToEvents.contains(event.getType())) {
offer(writer, event);
}
}
@Override
public CurrentUser getUser() {
return currentUser;
}
});
}
}
Aggregations