blob: 5c99c7b2af40ed4ebe801b1ac746278d87f686d0 [file] [log] [blame]
Marcel Offermansa962bc92009-11-21 17:59:33 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
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 */
19package org.apache.felix.dependencymanager;
20
21import java.util.ArrayList;
22import java.util.Collections;
23import java.util.List;
24
25import org.osgi.framework.BundleContext;
26
27/**
28 * The dependency manager. Manages all services and their dependencies.
29 *
30 * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
31 */
32public class DependencyManager {
33 private final BundleContext m_context;
34 private final Logger m_logger;
35 private List m_services = Collections.synchronizedList(new ArrayList());
36
37 /**
38 * Creates a new dependency manager.
39 *
40 * @param context the bundle context
41 * @param logger
42 */
43 public DependencyManager(BundleContext context, Logger logger) {
44 m_context = context;
45 m_logger = logger;
46 }
47
48 /**
49 * Adds a new service to the dependency manager. After the service was added
50 * it will be started immediately.
51 *
52 * @param service the service to add
53 */
54 public void add(Service service) {
55 m_services.add(service);
56 service.start();
57 }
58
59 /**
60 * Removes a service from the dependency manager. Before the service is removed
61 * it is stopped first.
62 *
63 * @param service the service to remove
64 */
65 public void remove(Service service) {
66 service.stop();
67 m_services.remove(service);
68 }
69
70 /**
71 * Creates a new service.
72 *
73 * @return the new service
74 */
75 public Service createService() {
76 return new ServiceImpl(m_context, this, m_logger);
77 }
78
79 /**
80 * Creates a new service dependency.
81 *
82 * @return the service dependency
83 */
84 public ServiceDependency createServiceDependency() {
85 return new ServiceDependency(m_context, m_logger);
86 }
87
88 public ConfigurationDependency createConfigurationDependency() {
89 return new ConfigurationDependency(m_context, m_logger);
90 }
91
92 /**
93 * Returns a list of services.
94 *
95 * @return a list of services
96 */
97 public List getServices() {
98 return Collections.unmodifiableList(m_services);
99 }
100
101}