1 | // Copyright 2004-2007 Jean-Francois Poilpret |
2 | // |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | // you may not use this file except in compliance with the License. |
5 | // You may obtain a copy of the License at |
6 | // |
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | // |
9 | // Unless required by applicable law or agreed to in writing, software |
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | // See the License for the specific language governing permissions and |
13 | // limitations under the License. |
14 | |
15 | package net.sourceforge.hiveboard; |
16 | |
17 | import org.mortbay.jetty.Server; |
18 | import org.mortbay.log.Log; |
19 | |
20 | import net.sourceforge.hiveboard.pack.HiveBoardPackHandler; |
21 | |
22 | /** |
23 | * @author Jean-Francois Poilpret |
24 | */ |
25 | public class HiveBoard |
26 | { |
27 | static final private long PENDING_REQUESTS_WAIT = 500L; |
28 | static final private long SYSTEM_EXIT_WAIT = 500L; |
29 | |
30 | public HiveBoard(Server server) |
31 | { |
32 | _server = server; |
33 | } |
34 | |
35 | public void shutdown() throws Exception |
36 | { |
37 | Log.info("Shutting down HiveBoard server..."); |
38 | // Graceful shutdown: stop handler |
39 | HiveBoardPackHandler handler = (HiveBoardPackHandler) _server.getHandler(); |
40 | handler.setShutdown(true); |
41 | while (handler.getPendingRequests() > 0) |
42 | { |
43 | delay(PENDING_REQUESTS_WAIT); |
44 | } |
45 | handler.stop(); |
46 | Log.info("HiveBoard server handler stopped."); |
47 | delay(SYSTEM_EXIT_WAIT); |
48 | System.exit(0); |
49 | } |
50 | |
51 | // CSOFF: EmptyBlockCheck |
52 | static private void delay(long ms) |
53 | { |
54 | try |
55 | { |
56 | Thread.sleep(ms); |
57 | } |
58 | catch (InterruptedException e) |
59 | { |
60 | // Intentionally empty |
61 | } |
62 | } |
63 | // CSON: EmptyBlockCheck |
64 | |
65 | private final Server _server; |
66 | } |