annotate src/org/eclipse/jetty/util/component/AggregateLifeCycle.java @ 910:9b65e8064f90

simplify AggregateLifeCycle
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 08 Oct 2016 21:30:32 -0600
parents e21ca9878a10
children 1d0c304e12b5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
54 Bean(Object b)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
55 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
56 _bean=b;
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
57 }
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
58 final Object _bean;
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
59 volatile boolean _managed=true;
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
60
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
61 public String toString()
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
62 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
63 return "{"+_bean+","+_managed+"}";
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
64 }
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
65 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
66
864
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
67 /* ------------------------------------------------------------ */
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 * Start the managed lifecycle beans in the order they were added.
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
70 * @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStart()
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
71 */
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
72 @Override
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
73 protected void doStart() throws Exception
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
74 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
75 for (Bean b:_beans)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
76 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
77 if (b._managed && b._bean instanceof LifeCycle)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
78 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
79 LifeCycle l=(LifeCycle)b._bean;
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
80 if (!l.isRunning())
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
81 l.start();
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
82 }
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 // indicate that we are started, so that addBean will start other beans added.
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
85 _started=true;
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
86 super.doStart();
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
87 }
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 * 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
92 * @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStart()
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
93 */
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
94 @Override
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
95 protected void doStop() throws Exception
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
96 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
97 _started=false;
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
98 super.doStop();
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
99 List<Bean> reverse = new ArrayList<Bean>(_beans);
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
100 Collections.reverse(reverse);
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
101 for (Bean b:reverse)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
102 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
103 if (b._managed && b._bean instanceof LifeCycle)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
104 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
105 LifeCycle l=(LifeCycle)b._bean;
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
106 if (l.isRunning())
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
107 l.stop();
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
108 }
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
111
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
112
864
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
113 /* ------------------------------------------------------------ */
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 * 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
116 * @see org.eclipse.jetty.util.component.Destroyable#destroy()
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
117 */
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
118 public void destroy()
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
119 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
120 List<Bean> reverse = new ArrayList<Bean>(_beans);
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
121 Collections.reverse(reverse);
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
122 for (Bean b:reverse)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
123 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
124 if (b._bean instanceof Destroyable && b._managed)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
125 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
126 Destroyable d=(Destroyable)b._bean;
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
127 d.destroy();
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
128 }
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 _beans.clear();
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
131 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
132
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
133
864
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
134 /* ------------------------------------------------------------ */
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
135 /** Is the bean contained in the aggregate.
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
136 * @param bean
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
137 * @return True if the aggregate contains the bean
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
138 */
910
9b65e8064f90 simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents: 864
diff changeset
139 private boolean contains(Object bean)
864
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
140 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
141 for (Bean b:_beans)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
142 if (b._bean==bean)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
143 return true;
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
144 return false;
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
145 }
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 * Add an associated bean.
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
150 * 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
151 * 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
152 * 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
153 * methods may be used after an add to change the status.
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
154 * @param o the bean object to add
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
155 * @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
156 */
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
157 public boolean addBean(Object o)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
158 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
159 // beans are joined unless they are started lifecycles
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
160 return addBean(o,!((o instanceof LifeCycle)&&((LifeCycle)o).isStarted()));
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
161 }
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 /** Add an associated lifecycle.
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
165 * @param o The lifecycle to add
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
166 * @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
167 * @return true if bean was added, false if already present.
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
168 */
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
169 public boolean addBean(Object o, boolean managed)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
170 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
171 if (contains(o))
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
172 return false;
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
173
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
174 Bean b = new Bean(o);
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
175 b._managed=managed;
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
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
178 if (o instanceof LifeCycle)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
179 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
180 LifeCycle l=(LifeCycle)o;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
181
864
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
182 // Start the bean if we are started
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
183 if (managed && _started)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
184 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
185 try
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
186 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
187 l.start();
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 catch(Exception e)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
190 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
191 throw new RuntimeException (e);
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 }
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
195 return true;
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
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
198 /* ------------------------------------------------------------ */
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
199 /** Get dependent beans
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
200 * @return List of beans.
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
201 */
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
202 public Collection<Object> getBeans()
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
203 {
910
9b65e8064f90 simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents: 864
diff changeset
204 List<Object> beans = new ArrayList<Object>();
9b65e8064f90 simplify AggregateLifeCycle
Franklin Schmidt <fschmidt@gmail.com>
parents: 864
diff changeset
205 beans.addAll(_beans);
864
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
206 return beans;
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
207 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
208
864
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 /* ------------------------------------------------------------ */
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
211 /** Get dependent beans of a specific class.
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
212 * If more than one bean of the type exist, the first is returned.
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
213 * @see #addBean(Object)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
214 * @param clazz
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
215 * @return bean or null
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 public <T> T getBean(Class<T> clazz)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
218 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
219 for (Bean b:_beans)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
220 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
221 if (clazz.isInstance(b._bean))
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
222 return (T)b._bean;
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
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
225 return null;
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
226 }
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
227
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 /**
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
230 * Remove an associated bean.
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 boolean removeBean (Object o)
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 Iterator<Bean> i = _beans.iterator();
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
235 while(i.hasNext())
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 Bean b=i.next();
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
238 if (b._bean==o)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
239 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
240 _beans.remove(b);
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
241 return true;
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 }
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
244 return false;
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
245 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
246
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 public void dumpStdErr()
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 try
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
251 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
252 dump(System.err,"");
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
253 }
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
254 catch (IOException e)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
255 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
256 LOG.warn("",e);
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 }
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 /* ------------------------------------------------------------ */
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
261 public String dump()
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
262 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
263 return dump(this);
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
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 public static String dump(Dumpable dumpable)
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 StringBuilder b = new StringBuilder();
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
270 try
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
271 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
272 dumpable.dump(b,"");
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
273 }
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
274 catch (IOException e)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
275 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
276 LOG.warn("",e);
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
277 }
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
278 return b.toString();
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
279 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
280
864
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
281 /* ------------------------------------------------------------ */
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
282 public void dump(Appendable out) throws IOException
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
283 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
284 dump(out,"");
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
285 }
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
286
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
287 /* ------------------------------------------------------------ */
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
288 protected void dumpThis(Appendable out) throws IOException
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 out.append(String.valueOf(this)).append(" - ").append(getState()).append("\n");
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
291 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
292
864
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
293 /* ------------------------------------------------------------ */
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
294 public static void dumpObject(Appendable out,Object o) throws IOException
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
295 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
296 try
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 if (o instanceof LifeCycle)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
299 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
300 else
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
301 out.append(String.valueOf(o)).append("\n");
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
302 }
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
303 catch(Throwable th)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
304 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
305 out.append(" => ").append(th.toString()).append('\n');
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
306 }
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
307 }
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
308
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
309 /* ------------------------------------------------------------ */
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
310 public void dump(Appendable out,String indent) throws IOException
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
311 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
312 dumpThis(out);
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
313 int size=_beans.size();
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
314 if (size==0)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
315 return;
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
316 int i=0;
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
317 for (Bean b : _beans)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
318 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
319 i++;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
320
864
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
321 out.append(indent).append(" +- ");
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
322 if (b._managed)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
323 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
324 if (b._bean instanceof Dumpable)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
325 ((Dumpable)b._bean).dump(out,indent+(i==size?" ":" | "));
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
326 else
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
327 dumpObject(out,b._bean);
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
328 }
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
329 else
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
330 dumpObject(out,b._bean);
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
331 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
332
864
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
333 if (i!=size)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
334 out.append(indent).append(" |\n");
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
335 }
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
336
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
337 /* ------------------------------------------------------------ */
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
338 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
339 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
340 if (collections.length==0)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
341 return;
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
342 int size=0;
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
343 for (Collection<?> c : collections)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
344 size+=c.size();
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
345 if (size==0)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
346 return;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
347
864
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
348 int i=0;
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
349 for (Collection<?> c : collections)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
350 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
351 for (Object o : c)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
352 {
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
353 i++;
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
354 out.append(indent).append(" +- ");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
355
864
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
356 if (o instanceof Dumpable)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
357 ((Dumpable)o).dump(out,indent+(i==size?" ":" | "));
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
358 else
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
359 dumpObject(out,o);
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
360 }
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
361
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
362 if (i!=size)
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
363 out.append(indent).append(" |\n");
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
364 }
e21ca9878a10 simplify ThreadPool use
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
365 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
366 }