File: LifeCycleImplementingRequestLogImpl.java

package info (click to toggle)
trapperkeeper-webserver-jetty9-clojure 1.7.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 1,100 kB
  • sloc: xml: 531; java: 120; makefile: 24; sh: 10
file content (67 lines) | stat: -rw-r--r-- 2,210 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.puppetlabs.trapperkeeper.services.webserver.jetty9.utils;

import ch.qos.logback.access.jetty.RequestLogImpl;
import org.eclipse.jetty.util.component.LifeCycle;

/*
	Sit down, it's story time.
	Once upon a time logback had a RequestLogImpl that you could just drop in
	Jetty and use without any modifications. Developers used this and it was
	good. Then, during Jetty 9.3 development, the RequestLog interface that
	RequestLogImpl implemented was "refactored"[0] to no longer extend Jetty's
	LifeCycle interface (this is distinct from Logback's LifeCycle interface,
	so try to keep up).
	Implementing Jetty's LifeCycle interface turns out to be important because
	Jetty uses it to decide whether or not to automatically start a Bean[1].
	Many people were sad about this[2] and tried to make the RequestLogImpl
	again start automatically with Jetty[3], but their efforts have so far not
	been merged.
	In order for our RequestLogImpl to automatically start, we decide to extend
	the existing built-in logback implementation and have it implement Jetty's
	LifeCycle interface, which it already does, but doesn't declare.

	[0] - https://github.com/eclipse/jetty.project/commit/e3bda4ef
	[1] - https://github.com/eclipse/jetty.project/blob/0c8273f2ca1f9bf2064cd9c4c939d2546443f759/jetty-util/src/main/java/org/eclipse/jetty/util/component/ContainerLifeCycle.java#L98
	[2] - https://jira.qos.ch/browse/LOGBACK-1052
	[3] - https://github.com/qos-ch/logback/pull/269

	And Jetty and Logback lived happily ever after.

 */

public class LifeCycleImplementingRequestLogImpl extends RequestLogImpl implements LifeCycle {
  @Override
  public boolean isRunning() {
      return isStarted();
  }

  @Override
  public boolean isStarting() {
      return false;
  }

  @Override
  public boolean isStopping() {
      return false;
  }

  @Override
  public boolean isStopped() {
      return !isStarted();
  }

  @Override
  public boolean isFailed() {
      return false;
  }

  @Override
  public void addLifeCycleListener(Listener listener) {
      // we'll implement this when asked
  }

  @Override
  public void removeLifeCycleListener(Listener listener) {
      // we'll implement this when asked
  }
}