mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 08:25:44 +01:00
recreate the EventBus on restart to avoid classloader leaks
This commit is contained in:
@@ -39,6 +39,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import sonia.scm.SCMContext;
|
import sonia.scm.SCMContext;
|
||||||
import sonia.scm.Stage;
|
import sonia.scm.Stage;
|
||||||
|
import sonia.scm.event.RecreateEventBusEvent;
|
||||||
import sonia.scm.event.ScmEventBus;
|
import sonia.scm.event.ScmEventBus;
|
||||||
|
|
||||||
import javax.servlet.FilterConfig;
|
import javax.servlet.FilterConfig;
|
||||||
@@ -72,7 +73,7 @@ public class BootstrapContextFilter extends GuiceFilter
|
|||||||
*
|
*
|
||||||
* @throws ServletException
|
* @throws ServletException
|
||||||
*/
|
*/
|
||||||
@Subscribe(async = false)
|
@Subscribe
|
||||||
public void handleRestartEvent(RestartEvent event) throws ServletException
|
public void handleRestartEvent(RestartEvent event) throws ServletException
|
||||||
{
|
{
|
||||||
logger.warn("received restart event from {} with reason: {}",
|
logger.warn("received restart event from {} with reason: {}",
|
||||||
@@ -87,6 +88,10 @@ public class BootstrapContextFilter extends GuiceFilter
|
|||||||
logger.warn("destroy filter pipeline, because of a received restart event");
|
logger.warn("destroy filter pipeline, because of a received restart event");
|
||||||
destroy();
|
destroy();
|
||||||
|
|
||||||
|
logger.warn("send recreate eventbus event");
|
||||||
|
ScmEventBus.getInstance().post(new RecreateEventBusEvent());
|
||||||
|
ScmEventBus.getInstance().register(this);
|
||||||
|
|
||||||
logger.warn("reinitialize filter pipeline, because of a received restart event");
|
logger.warn("reinitialize filter pipeline, because of a received restart event");
|
||||||
initGuice();
|
initGuice();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ package sonia.scm.event;
|
|||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import com.github.legman.EventBus;
|
import com.github.legman.EventBus;
|
||||||
|
import com.github.legman.Subscribe;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -62,9 +62,13 @@ public class LegmanScmEventBus extends ScmEventBus
|
|||||||
* Constructs ...
|
* Constructs ...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public LegmanScmEventBus()
|
public LegmanScmEventBus() {
|
||||||
{
|
eventBus = create();
|
||||||
eventBus = new EventBus(NAME);
|
}
|
||||||
|
|
||||||
|
private EventBus create() {
|
||||||
|
logger.info("create new event bus {}", NAME);
|
||||||
|
return new EventBus(NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
@@ -118,8 +122,15 @@ public class LegmanScmEventBus extends ScmEventBus
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe(async = false)
|
||||||
|
public void recreateEventBus(RecreateEventBusEvent recreateEventBusEvent) {
|
||||||
|
logger.info("shutdown event bus executor");
|
||||||
|
eventBus.shutdown();
|
||||||
|
eventBus = create();
|
||||||
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** event bus */
|
/** event bus */
|
||||||
private final EventBus eventBus;
|
private EventBus eventBus;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package sonia.scm.event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This event forces the {@link ScmEventBus} to recreate the underlying implementation and to clear all its caches.
|
||||||
|
* Note: After this event is fired, every subscription is removed from the event bus.
|
||||||
|
*/
|
||||||
|
public final class RecreateEventBusEvent {}
|
||||||
Reference in New Issue
Block a user