| 632 | |
| 633 | |
| 634 | @Override |
| 635 | public void removeChild(Container child) { |
| 636 | |
| 637 | if (child == null) { |
| 638 | return; |
| 639 | } |
| 640 | |
| 641 | try { |
| 642 | if (child.getState().isAvailable()) { |
| 643 | child.stop(); |
| 644 | } |
| 645 | } catch (LifecycleException e) { |
| 646 | log.error(sm.getString("containerBase.child.stop"), e); |
| 647 | } |
| 648 | |
| 649 | try { |
| 650 | // child.destroy() may have already been called which would have |
| 651 | // triggered this call. If that is the case, no need to destroy the |
| 652 | // child again. |
| 653 | if (!LifecycleState.DESTROYING.equals(child.getState())) { |
| 654 | child.destroy(); |
| 655 | } |
| 656 | } catch (LifecycleException e) { |
| 657 | log.error(sm.getString("containerBase.child.destroy"), e); |
| 658 | } |
| 659 | |
| 660 | boolean removed = false; |
| 661 | childrenLock.writeLock().lock(); |
| 662 | try { |
| 663 | removed = children.remove(child.getName()) != null; |
| 664 | } finally { |
| 665 | childrenLock.writeLock().unlock(); |
| 666 | } |
| 667 | |
| 668 | if (removed) { |
| 669 | fireContainerEvent(REMOVE_CHILD_EVENT, child); |
| 670 | } |
| 671 | |
| 672 | } |
| 673 | |
| 674 | |
| 675 | @Override |