01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.endpoint;
19:
20: import java.util.ArrayList;
21: import java.util.List;
22:
23: import javax.annotation.PostConstruct;
24: import javax.annotation.PreDestroy;
25: import javax.annotation.Resource;
26:
27: import org.apache.cxf.Bus;
28: import org.apache.cxf.buslifecycle.BusLifeCycleListener;
29: import org.apache.cxf.buslifecycle.BusLifeCycleManager;
30:
31: public class ServerRegistryImpl implements ServerRegistry,
32: BusLifeCycleListener {
33:
34: List<Server> serversList;
35: Bus bus;
36: BusLifeCycleManager lifeCycleManager;
37:
38: public ServerRegistryImpl() {
39: serversList = new ArrayList<Server>();
40: }
41:
42: public Bus getBus() {
43: return bus;
44: }
45:
46: @Resource
47: public void setBus(Bus bus) {
48: this .bus = bus;
49: }
50:
51: @PostConstruct
52: public void register() {
53: if (null != bus) {
54: bus.setExtension(this , ServerRegistry.class);
55: lifeCycleManager = bus
56: .getExtension(BusLifeCycleManager.class);
57: if (null != lifeCycleManager) {
58: lifeCycleManager.registerLifeCycleListener(this );
59: }
60: }
61: }
62:
63: public void register(Server server) {
64: serversList.add(server);
65: }
66:
67: public void unregister(Server server) {
68: serversList.remove(server);
69: }
70:
71: public List<Server> getServers() {
72: return serversList;
73: }
74:
75: public void initComplete() {
76: // TODO Auto-generated method stub
77:
78: }
79:
80: @PreDestroy
81: public void preShutdown() {
82: // Shutdown the service.
83: // To avoid the CurrentModificationException, do not use serversList directly
84: Object[] servers = serversList.toArray();
85: for (int i = 0; i < servers.length; i++) {
86: Server server = (Server) servers[i];
87: server.stop();
88: }
89: }
90:
91: public void postShutdown() {
92: // Clean the serversList
93: serversList.clear();
94: }
95:
96: }
|