Search in sources :

Example 6 with RegistrationHandle

use of com.google.gerrit.extensions.registration.RegistrationHandle in project gerrit by GerritCodeReview.

the class LfsPluginServlet method install.

private void install(Plugin plugin) {
    if (!plugin.getName().equals(pluginName)) {
        return;
    }
    final GuiceFilter guiceFilter = load(plugin);
    plugin.add(new RegistrationHandle() {

        @Override
        public void remove() {
            filter.compareAndSet(guiceFilter, null);
        }
    });
    filter.set(guiceFilter);
}
Also used : RegistrationHandle(com.google.gerrit.extensions.registration.RegistrationHandle) GuiceFilter(com.google.inject.servlet.GuiceFilter)

Example 7 with RegistrationHandle

use of com.google.gerrit.extensions.registration.RegistrationHandle in project gerrit by GerritCodeReview.

the class LfsPluginServlet method load.

private GuiceFilter load(Plugin plugin) {
    if (plugin.getHttpInjector() != null) {
        final String name = plugin.getName();
        final GuiceFilter guiceFilter;
        try {
            guiceFilter = plugin.getHttpInjector().getInstance(GuiceFilter.class);
        } catch (RuntimeException e) {
            log.warn(String.format("Plugin %s cannot load GuiceFilter", name), e);
            return null;
        }
        try {
            ServletContext ctx = PluginServletContext.create(plugin, "/");
            guiceFilter.init(new WrappedFilterConfig(ctx));
        } catch (ServletException e) {
            log.warn(String.format("Plugin %s failed to initialize HTTP", name), e);
            return null;
        }
        plugin.add(new RegistrationHandle() {

            @Override
            public void remove() {
                guiceFilter.destroy();
            }
        });
        return guiceFilter;
    }
    return null;
}
Also used : ServletException(javax.servlet.ServletException) RegistrationHandle(com.google.gerrit.extensions.registration.RegistrationHandle) GuiceFilter(com.google.inject.servlet.GuiceFilter) ServletContext(javax.servlet.ServletContext)

Example 8 with RegistrationHandle

use of com.google.gerrit.extensions.registration.RegistrationHandle in project gerrit by GerritCodeReview.

the class PluginMetricMaker method newTrigger.

@Override
public RegistrationHandle newTrigger(Set<CallbackMetric<?>> metrics, Runnable trigger) {
    final RegistrationHandle handle = root.newTrigger(metrics, trigger);
    cleanup.add(handle);
    return new RegistrationHandle() {

        @Override
        public void remove() {
            handle.remove();
            cleanup.remove(handle);
        }
    };
}
Also used : RegistrationHandle(com.google.gerrit.extensions.registration.RegistrationHandle)

Aggregations

RegistrationHandle (com.google.gerrit.extensions.registration.RegistrationHandle)8 GuiceFilter (com.google.inject.servlet.GuiceFilter)4 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)3 Branch (com.google.gerrit.reviewdb.client.Branch)3 ChangeMessageModifier (com.google.gerrit.server.git.ChangeMessageModifier)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 Test (org.junit.Test)3 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)2 ServletContext (javax.servlet.ServletContext)2 ServletException (javax.servlet.ServletException)2 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 TestProjectInput (com.google.gerrit.acceptance.TestProjectInput)1 ListChangesOption (com.google.gerrit.extensions.client.ListChangesOption)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1