View Javadoc

1   /*
2    * Copyright 2006-2009 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.springframework.osgi.extender.event;
17  
18  import java.util.ArrayList;
19  import java.util.Collection;
20  import java.util.Collections;
21  import java.util.List;
22  
23  import org.osgi.framework.Bundle;
24  import org.osgi.framework.Filter;
25  import org.springframework.context.ApplicationContext;
26  import org.springframework.osgi.context.event.OsgiBundleApplicationContextEvent;
27  import org.springframework.osgi.service.importer.event.OsgiServiceDependencyEvent;
28  import org.springframework.util.Assert;
29  
30  /**
31   * Spring-DM Extender bootstrapping event. Used during the application context discovery phase, before an application
32   * context is fully initialized. Similar to {@link BootstrappingDependencyEvent}, this event contains the information
33   * regarding all unsatisfied dependencies.
34   * 
35   * Consider using this event {@link BootstrappingDependencyEvent} for getting a global overview of the waiting
36   * application and {@link BootstrappingDependencyEvent} for finding out specific information.
37   * 
38   * <p/> It can be used to receive status updates for contexts started by the extender.
39   * 
40   * @author Costin Leau
41   */
42  public class BootstrappingDependenciesEvent extends OsgiBundleApplicationContextEvent {
43  
44  	private final Collection<OsgiServiceDependencyEvent> dependencyEvents;
45  	private final Collection<String> dependencyFilters;
46  	private final Filter dependenciesFilter;
47  	private final long timeLeft;
48  
49  	/**
50  	 * Constructs a new <code>BootstrappingDependencyEvent</code> instance.
51  	 * 
52  	 * @param source
53  	 */
54  	public BootstrappingDependenciesEvent(ApplicationContext source, Bundle bundle,
55  			Collection<OsgiServiceDependencyEvent> nestedEvents, Filter filter, long timeLeft) {
56  		super(source, bundle);
57  		Assert.notNull(nestedEvents);
58  		this.dependencyEvents = nestedEvents;
59  		this.dependenciesFilter = filter;
60  		this.timeLeft = timeLeft;
61  
62  		List<String> depFilters = new ArrayList<String>(dependencyEvents.size());
63  
64  		for (OsgiServiceDependencyEvent dependency : nestedEvents) {
65  			depFilters.add(dependency.getServiceDependency().getServiceFilter().toString());
66  		}
67  
68  		dependencyFilters = Collections.unmodifiableCollection(depFilters);
69  	}
70  
71  	/**
72  	 * Returns the nested, dependency event that caused the bootstrapping event to be raised.
73  	 * 
74  	 * @return associated dependency event
75  	 */
76  	public Collection<OsgiServiceDependencyEvent> getDependencyEvents() {
77  		return dependencyEvents;
78  	}
79  
80  	public Filter getDependenciesAsFilter() {
81  		return dependenciesFilter;
82  	}
83  
84  	public Collection<String> getDependencyFilters() {
85  		return dependencyFilters;
86  	}
87  
88  	public long getTimeToWait() {
89  		return timeLeft;
90  	}
91  }