Mercurial Hosting > luan
annotate src/org/eclipse/jetty/util/component/AggregateLifeCycle.java @ 1070:a44fc6b53757
fix use of HttpGenerator._buffer
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 10 Nov 2016 01:23:37 -0700 |
parents | 1d0c304e12b5 |
children |
rev | line source |
---|---|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2 // ======================================================================== |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4 // ------------------------------------------------------------------------ |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5 // All rights reserved. This program and the accompanying materials |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
6 // are made available under the terms of the Eclipse Public License v1.0 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
7 // and Apache License v2.0 which accompanies this distribution. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
8 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
9 // The Eclipse Public License is available at |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
10 // http://www.eclipse.org/legal/epl-v10.html |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
11 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
12 // The Apache License v2.0 is available at |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
13 // http://www.opensource.org/licenses/apache2.0.php |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
14 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
15 // You may elect to redistribute this code under either of these licenses. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
16 // ======================================================================== |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
17 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
18 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
19 package org.eclipse.jetty.util.component; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
20 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
21 import java.io.IOException; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
22 import java.util.ArrayList; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
23 import java.util.Collection; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
24 import java.util.Collections; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
25 import java.util.Iterator; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
26 import java.util.List; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
27 import java.util.concurrent.CopyOnWriteArrayList; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
28 |
820
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
29 import org.slf4j.Logger; |
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
30 import org.slf4j.LoggerFactory; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
31 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
32 /** |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
33 * An AggregateLifeCycle is an {@link LifeCycle} implementation for a collection of contained beans. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
34 * <p> |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
35 * Beans can be added the AggregateLifeCycle either as managed beans or as unmanaged beans. A managed bean is started, stopped and destroyed with the aggregate. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
36 * An unmanaged bean is associated with the aggregate for the purposes of {@link #dump()}, but it's lifecycle must be managed externally. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
37 * <p> |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
38 * When a bean is added, if it is a {@link LifeCycle} and it is already started, then it is assumed to be an unmanaged bean. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
39 * Otherwise the methods {@link #addBean(Object, boolean)}, {@link #manage(Object)} and {@link #unmanage(Object)} can be used to |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
40 * explicitly control the life cycle relationship. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
41 * <p> |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
42 * If adding a bean that is shared between multiple {@link AggregateLifeCycle} instances, then it should be started before being added, so it is unmanaged, or |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
43 * the API must be used to explicitly set it as unmanaged. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
44 * <p> |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
45 */ |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
46 public class AggregateLifeCycle extends AbstractLifeCycle implements Destroyable, Dumpable |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
47 { |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
48 private static final Logger LOG = LoggerFactory.getLogger(AggregateLifeCycle.class); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
49 private final List<Bean> _beans=new CopyOnWriteArrayList<Bean>(); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
50 private boolean _started=false; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
51 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
52 private class Bean |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
53 { |
912
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
54 Bean(LifeCycle b,boolean managed) |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
55 { |
912
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
56 _bean = b; |
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
57 _managed = managed; |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
58 } |
912
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
59 final LifeCycle _bean; |
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
60 final boolean _managed; |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
61 |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
62 public String toString() |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
63 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
64 return "{"+_bean+","+_managed+"}"; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
65 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
66 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
67 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
68 /* ------------------------------------------------------------ */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
69 /** |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
70 * Start the managed lifecycle beans in the order they were added. |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
71 * @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStart() |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
72 */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
73 @Override |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
74 protected void doStart() throws Exception |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
75 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
76 for (Bean b:_beans) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
77 { |
912
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
78 if (b._managed) |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
79 { |
912
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
80 LifeCycle l = b._bean; |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
81 if (!l.isRunning()) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
82 l.start(); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
83 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
84 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
85 // indicate that we are started, so that addBean will start other beans added. |
912
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
86 _started = true; |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
87 super.doStart(); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
88 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
89 |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
90 /* ------------------------------------------------------------ */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
91 /** |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
92 * Stop the joined lifecycle beans in the reverse order they were added. |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
93 * @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStart() |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
94 */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
95 @Override |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
96 protected void doStop() throws Exception |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
97 { |
912
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
98 _started = false; |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
99 super.doStop(); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
100 List<Bean> reverse = new ArrayList<Bean>(_beans); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
101 Collections.reverse(reverse); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
102 for (Bean b:reverse) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
103 { |
912
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
104 if (b._managed) |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
105 { |
912
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
106 LifeCycle l = b._bean; |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
107 if (l.isRunning()) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
108 l.stop(); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
109 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
110 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
111 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
112 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
113 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
114 /* ------------------------------------------------------------ */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
115 /** |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
116 * Destroy the joined Destroyable beans in the reverse order they were added. |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
117 * @see org.eclipse.jetty.util.component.Destroyable#destroy() |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
118 */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
119 public void destroy() |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
120 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
121 List<Bean> reverse = new ArrayList<Bean>(_beans); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
122 Collections.reverse(reverse); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
123 for (Bean b:reverse) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
124 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
125 if (b._bean instanceof Destroyable && b._managed) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
126 { |
912
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
127 Destroyable d = (Destroyable)b._bean; |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
128 d.destroy(); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
129 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
130 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
131 _beans.clear(); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
132 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
133 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
134 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
135 /* ------------------------------------------------------------ */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
136 /** Is the bean contained in the aggregate. |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
137 * @param bean |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
138 * @return True if the aggregate contains the bean |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
139 */ |
912
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
140 private boolean contains(LifeCycle bean) |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
141 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
142 for (Bean b:_beans) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
143 if (b._bean==bean) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
144 return true; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
145 return false; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
146 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
147 |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
148 /* ------------------------------------------------------------ */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
149 /** |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
150 * Add an associated bean. |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
151 * If the bean is a {@link LifeCycle}, then it will be managed if it is not |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
152 * already started and umanaged if it is already started. The {@link #addBean(Object, boolean)} |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
153 * method should be used if this is not correct, or the {@link #manage(Object)} and {@link #unmanage(Object)} |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
154 * methods may be used after an add to change the status. |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
155 * @param o the bean object to add |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
156 * @return true if the bean was added or false if it has already been added. |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
157 */ |
912
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
158 public boolean addBean(LifeCycle o) |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
159 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
160 // beans are joined unless they are started lifecycles |
912
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
161 return addBean(o,!o.isStarted()); |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
162 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
163 |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
164 /* ------------------------------------------------------------ */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
165 /** Add an associated lifecycle. |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
166 * @param o The lifecycle to add |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
167 * @param managed True if the LifeCycle is to be joined, otherwise it will be disjoint. |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
168 * @return true if bean was added, false if already present. |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
169 */ |
912
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
170 public boolean addBean(LifeCycle o, boolean managed) |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
171 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
172 if (contains(o)) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
173 return false; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
174 |
912
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
175 Bean b = new Bean(o,managed); |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
176 _beans.add(b); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
177 |
912
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
178 // Start the bean if we are started |
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
179 if (managed && _started) |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
180 { |
912
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
181 try |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
182 { |
912
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
183 o.start(); |
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
184 } |
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
185 catch(Exception e) |
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
186 { |
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
187 throw new RuntimeException(e); |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
188 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
189 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
190 return true; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
191 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
192 |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
193 /* ------------------------------------------------------------ */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
194 /** Get dependent beans |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
195 * @return List of beans. |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
196 */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
197 public Collection<Object> getBeans() |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
198 { |
912
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
199 // return new ArrayList<Object>(_beans); |
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
200 ArrayList<Object> beans = new ArrayList<Object>(); |
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
201 for (Bean b:_beans) { |
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
202 beans.add(b._bean); |
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
203 } |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
204 return beans; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
205 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
206 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
207 |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
208 /* ------------------------------------------------------------ */ |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
209 /** |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
210 * Remove an associated bean. |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
211 */ |
912
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
212 public boolean removeBean (LifeCycle o) |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
213 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
214 Iterator<Bean> i = _beans.iterator(); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
215 while(i.hasNext()) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
216 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
217 Bean b=i.next(); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
218 if (b._bean==o) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
219 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
220 _beans.remove(b); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
221 return true; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
222 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
223 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
224 return false; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
225 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
226 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
227 public String dump() |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
228 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
229 return dump(this); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
230 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
231 |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
232 public static String dump(Dumpable dumpable) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
233 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
234 StringBuilder b = new StringBuilder(); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
235 try |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
236 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
237 dumpable.dump(b,""); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
238 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
239 catch (IOException e) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
240 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
241 LOG.warn("",e); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
242 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
243 return b.toString(); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
244 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
245 |
912
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
246 private void dump(Appendable out) throws IOException |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
247 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
248 dump(out,""); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
249 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
250 |
912
1d0c304e12b5
simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents:
910
diff
changeset
|
251 private void dumpThis(Appendable out) throws IOException |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
252 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
253 out.append(String.valueOf(this)).append(" - ").append(getState()).append("\n"); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
254 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
255 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
256 public static void dumpObject(Appendable out,Object o) throws IOException |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
257 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
258 try |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
259 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
260 if (o instanceof LifeCycle) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
261 out.append(String.valueOf(o)).append(" - ").append((AbstractLifeCycle.getState((LifeCycle)o))).append("\n"); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
262 else |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
263 out.append(String.valueOf(o)).append("\n"); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
264 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
265 catch(Throwable th) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
266 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
267 out.append(" => ").append(th.toString()).append('\n'); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
268 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
269 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
270 |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
271 public void dump(Appendable out,String indent) throws IOException |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
272 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
273 dumpThis(out); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
274 int size=_beans.size(); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
275 if (size==0) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
276 return; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
277 int i=0; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
278 for (Bean b : _beans) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
279 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
280 i++; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
281 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
282 out.append(indent).append(" +- "); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
283 if (b._managed) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
284 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
285 if (b._bean instanceof Dumpable) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
286 ((Dumpable)b._bean).dump(out,indent+(i==size?" ":" | ")); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
287 else |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
288 dumpObject(out,b._bean); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
289 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
290 else |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
291 dumpObject(out,b._bean); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
292 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
293 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
294 if (i!=size) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
295 out.append(indent).append(" |\n"); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
296 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
297 |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
298 public static void dump(Appendable out,String indent,Collection<?>... collections) throws IOException |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
299 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
300 if (collections.length==0) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
301 return; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
302 int size=0; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
303 for (Collection<?> c : collections) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
304 size+=c.size(); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
305 if (size==0) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
306 return; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
307 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
308 int i=0; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
309 for (Collection<?> c : collections) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
310 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
311 for (Object o : c) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
312 { |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
313 i++; |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
314 out.append(indent).append(" +- "); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
315 |
864
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
316 if (o instanceof Dumpable) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
317 ((Dumpable)o).dump(out,indent+(i==size?" ":" | ")); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
318 else |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
319 dumpObject(out,o); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
320 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
321 |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
322 if (i!=size) |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
323 out.append(indent).append(" |\n"); |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
324 } |
e21ca9878a10
simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
325 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
326 } |