blob: 7607ce2faf8835f268709a074ccb874e34003537 [file] [log] [blame]
Francesco Furfari677c4592006-10-10 12:02:17 +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
Humberto Cervantes Macedabd7de442006-04-04 16:05:02 +00009 *
Francesco Furfari677c4592006-10-10 12:02:17 +000010 * http://www.apache.org/licenses/LICENSE-2.0
Humberto Cervantes Macedabd7de442006-04-04 16:05:02 +000011 *
Francesco Furfari677c4592006-10-10 12:02:17 +000012 * 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.
Humberto Cervantes Macedabd7de442006-04-04 16:05:02 +000018 */
Francesco Furfari677c4592006-10-10 12:02:17 +000019
Humberto Cervantes Macedabd7de442006-04-04 16:05:02 +000020package org.apache.felix.wireadmin;
21
22import java.util.Dictionary;
23import java.util.Properties;
24
25import org.osgi.framework.BundleActivator;
26import org.osgi.framework.BundleContext;
27import org.osgi.framework.BundleException;
28import org.osgi.framework.ServiceRegistration;
29import org.osgi.service.wireadmin.WireAdmin;
30import org.osgi.service.wireadmin.WireConstants;
31import org.osgi.service.wireadmin.WireAdminListener;
32import org.osgi.service.wireadmin.WireAdminEvent;
33/**
34 * The activator
35 *
Karl Paulsd312acc2007-06-18 20:38:33 +000036 * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
Humberto Cervantes Macedabd7de442006-04-04 16:05:02 +000037 */
38public class Activator implements BundleActivator {
39
40 private final static String WIREADMIN_PID="org.apache.felix.wireadmin";
41 private ServiceRegistration m_reg=null;
42 private WireAdminImpl m_wai=null;
43
44 /**
45 * Called upon starting of the bundle.
46 *
47 * @param context The bundle context passed by the framework
48 * @exception Exception
49 */
50 public void start(BundleContext bundleContext) throws BundleException {
51
52 m_wai= new WireAdminImpl(bundleContext);
53
54 // Register the service
55 Dictionary properties=new Properties();
56 properties.put(WireConstants.WIREADMIN_PID,WIREADMIN_PID);
57 m_reg = bundleContext.registerService(WireAdmin.class.getName(),m_wai,properties);
58
59 // Event dispatching does not start until the reference is set
60 m_wai.setServiceReference(m_reg.getReference());
61
62 if(bundleContext.getProperty("fr.imag.adele.wireadmin.traceEvt") != null)
63 {
64 String value = bundleContext.getProperty("fr.imag.adele.wireadmin.traceEvt");
65 if(value.equals("true"))
66 {
67 Dictionary props=new Properties();
68 props.put(WireConstants.WIREADMIN_EVENTS,new Integer(0x80|0x40|0x20|0x10|0x08|0x04|0x02|0x01));
69 properties.put(WireConstants.WIREADMIN_PID,WIREADMIN_PID);
70 bundleContext.registerService(WireAdminListener.class.getName(),new eventTracer(),props);
71 }
72 }
73 }
74
75 /**
76 * Called upon stopping the bundle.
77 *
78 * @param context The bundle context passed by the framework
79 * @exception Exception
80 */
81 public void stop(BundleContext bundleContext) throws BundleException
82 {
83 m_wai.releaseAll();
84 m_wai = null;
85 }
86
87 class eventTracer implements WireAdminListener
88 {
89 public void wireAdminEvent(WireAdminEvent evt)
90 {
91 int type = evt.getType();
92 if((type & WireAdminEvent.WIRE_CREATED)!=0)
93 {
94 WireAdminImpl.traceln("Received event WIRE_CREATED");
95 }
96 if((type & WireAdminEvent.WIRE_CONNECTED)!=0)
97 {
98 WireAdminImpl.traceln("Received event WIRE_CONNECTED");
99 }
100 if((type & WireAdminEvent.WIRE_UPDATED)!=0)
101 {
102 WireAdminImpl.traceln("Received event WIRE_UPDATED");
103 }
104 if((type & WireAdminEvent.WIRE_TRACE)!=0)
105 {
106 WireAdminImpl.traceln("Received event WIRE_TRACE");
107 }
108 if((type & WireAdminEvent.WIRE_DISCONNECTED)!=0)
109 {
110 WireAdminImpl.traceln("Received event WIRE_DISCONNECTED");
111 }
112 if((type & WireAdminEvent.WIRE_DELETED)!=0)
113 {
114 WireAdminImpl.traceln("Received event WIRE_DELETED");
115 }
116 if((type & WireAdminEvent.PRODUCER_EXCEPTION)!=0)
117 {
118 WireAdminImpl.traceln("Received event PRODUCER_EXCEPTION");
119 evt.getThrowable().printStackTrace();
120 }
121 if((type & WireAdminEvent.CONSUMER_EXCEPTION)!=0)
122 {
123 WireAdminImpl.traceln("Received event CONSUMER_EXCEPTION");
124 evt.getThrowable().printStackTrace();
125 }
126 }
127 }
Karl Paulsd312acc2007-06-18 20:38:33 +0000128}