Search in sources :

Example 1 with CancelableRunnable

use of com.google.gerrit.server.git.WorkQueue.CancelableRunnable 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;
            }
        });
    }
}
Also used : DynamicOptions(com.google.gerrit.server.DynamicOptions) Event(com.google.gerrit.server.events.Event) CancelableRunnable(com.google.gerrit.server.git.WorkQueue.CancelableRunnable) UserScopedEventListener(com.google.gerrit.server.events.UserScopedEventListener) PrintWriter(java.io.PrintWriter)

Aggregations

DynamicOptions (com.google.gerrit.server.DynamicOptions)1 Event (com.google.gerrit.server.events.Event)1 UserScopedEventListener (com.google.gerrit.server.events.UserScopedEventListener)1 CancelableRunnable (com.google.gerrit.server.git.WorkQueue.CancelableRunnable)1 PrintWriter (java.io.PrintWriter)1