View Javadoc

1   /*
2    * Copyright 2006-2008 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  
17  package org.springframework.osgi.service.importer;
18  
19  import java.util.Map;
20  
21  /**
22   * Listener tracking binding and unbinding of OSGi services used as normal
23   * object references inside a Spring application context. Implementations can
24   * throws exceptions if they need/have to but they are not be propagated to
25   * other listeners nor do they stop the other listeners from being notified.
26   * 
27   * @author Costin Leau
28   * 
29   */
30  public interface OsgiServiceLifecycleListener {
31  
32  	/**
33  	 * Called when a service is being binded inside the proxy (be it single or
34  	 * multi value). The service properties are made available as a {@link Map}
35  	 * which can be safely cast to a {@link java.util.Dictionary} if needed.
36  	 * 
37  	 * @param service the OSGi service instance
38  	 * @param properties the service properties
39  	 * @throws Exception custom exception that is logged but not propagated to
40  	 * other listeners
41  	 */
42  	 void bind(Object service, Map properties) throws Exception;
43  
44  	/**
45  	 * Called when a service is being unbinded inside the proxy (be it single or
46  	 * multi value). The service properties are made available as a {@link Map}
47  	 * which can be safely cast to a {@link java.util.Dictionary} if needed.
48  	 * 
49  	 * @param service the OSGi service instance
50  	 * @param properties the service properties
51  	 * @throws Exception custom exception that is logged but not propagated to
52  	 * other listeners
53  	 */
54  	 void unbind(Object service, Map properties) throws Exception;
55  }