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 package org.apache.hc.core5.http.impl.bootstrap;
28
29 import org.apache.hc.core5.http.ExceptionListener;
30 import org.apache.hc.core5.http.impl.io.HttpService;
31 import org.apache.hc.core5.http.io.HttpServerConnection;
32 import org.apache.hc.core5.http.protocol.HttpCoreContext;
33 import org.apache.hc.core5.io.CloseMode;
34
35 class Worker implements Runnable {
36
37 private final HttpService httpservice;
38 private final HttpServerConnection conn;
39 private final ExceptionListener exceptionListener;
40
41 Worker(
42 final HttpService httpservice,
43 final HttpServerConnection conn,
44 final ExceptionListener exceptionListener) {
45 super();
46 this.httpservice = httpservice;
47 this.conn = conn;
48 this.exceptionListener = exceptionListener;
49 }
50
51 public HttpServerConnection getConnection() {
52 return this.conn;
53 }
54
55 @Override
56 public void run() {
57 try {
58 while (!Thread.interrupted() && this.conn.isOpen()) {
59 final HttpCoreContext context = HttpCoreContext.create();
60 this.httpservice.handleRequest(this.conn, context);
61 }
62 this.conn.close();
63 } catch (final Exception ex) {
64 this.exceptionListener.onError(this.conn, ex);
65 } finally {
66 this.conn.close(CloseMode.IMMEDIATE);
67 }
68 }
69
70 }