use of org.osgi.framework.ServiceRegistration in project felix by apache.
the class MyCtrlPoint method deviceNotifyReceived.
/*
* (non-Javadoc)
*
* @see org.cybergarage.upnp.device.NotifyListener#deviceNotifyReceived(org.cybergarage.upnp.ssdp.SSDPPacket)
*/
public void deviceNotifyReceived(SSDPPacket ssdpPacket) {
Activator.logger.DEBUG("[Importer] deviceNotifyReceived");
Activator.logger.PACKET(ssdpPacket.toString());
/*
* if the packet is
* NOTIFY or ISALIVE or *new* ROOT then create and register the UPnPDevice and
* all the embeeded device too
* DEVICE or SERVICE then if they already exist in OSGi do nothing otherwise I'll create and
* register all the UPnPDevice need starting from the root device
* *root* BYEBYE then I'll unregister it and all its children from OSGi Framework
* *service* BYEBYE then I'll re-register the UPnPDevice that contain the service with the updated
* properties
* *device* BYEBYE then I'll re-register the UPnPDevice that contain the device with the updated
* properties and also unregister the UPnPDevice that has left
*/
String usn = ssdpPacket.getUSN();
ParseUSN parseUSN = new ParseUSN(usn);
String udn = parseUSN.getUDN();
ServiceReference[] refs = null;
String filter = "(&" + UPNP_DEVICE_FLTR + EXPORT_FLTR + ")";
try {
refs = context.getServiceReferences(UPnPDevice.class.getName(), filter);
} catch (InvalidSyntaxException e) {
e.printStackTrace();
}
if (refs != null) {
for (int i = 0; i < refs.length; i++) {
UPnPDevice dev = (UPnPDevice) context.getService(refs[i]);
Dictionary dic = dev.getDescriptions(null);
if (((String) dic.get(UPnPDevice.UDN)).equals(udn)) {
return;
}
}
}
if (ssdpPacket.isAlive()) {
Activator.logger.DEBUG("[Importer] ssdpPacket.isAlive");
if (devices.containsKey(udn)) {
Activator.logger.DEBUG("[Importer] Device already discovered");
if (parseUSN.isService()) {
doServiceUpdating(udn, parseUSN.getServiceType());
}
} else {
doDeviceRegistration(udn);
}
} else if (ssdpPacket.isByeBye()) {
Activator.logger.DEBUG("[Importer] ssdpPacket.isByeBye");
synchronized (devices) {
if (devices.containsKey(udn)) {
if (parseUSN.isDevice()) {
Activator.logger.DEBUG("[Importer] parseUSN.isDevice ...unregistering all the children devices ");
// unregistering all the children devices
UPnPDeviceImpl dev = ((OSGiDeviceInfo) devices.get(udn)).getOSGiDevice();
removeOSGiandUPnPDeviceHierarchy(dev);
} else if (parseUSN.isService()) {
Activator.logger.DEBUG("[Importer] parseUSN.isService ...registering modified device again ");
/*
* I have to unregister the UPnPDevice and register it again
* with the updated properties
*/
UPnPDeviceImpl device = ((OSGiDeviceInfo) devices.get(udn)).getOSGiDevice();
ServiceRegistration registar = ((OSGiDeviceInfo) devices.get(udn)).getRegistration();
String[] oldServicesID = (String[]) (device.getDescriptions(null).get(UPnPService.ID));
String[] oldServiceType = (String[]) (device.getDescriptions(null).get(UPnPService.TYPE));
Device cyberDevice = findDeviceCtrl(this, udn);
Vector vec = new Vector();
for (int i = 0; i < oldServiceType.length; i++) {
Service ser = cyberDevice.getService(oldServicesID[i]);
if (!(ser.getServiceType().equals(parseUSN.getServiceType()))) {
vec.add(oldServicesID[i]);
}
}
// new serviceID
String[] actualServicesID = new String[vec.size()];
actualServicesID = (String[]) vec.toArray(new String[] {});
// new serviceType
String[] actualServiceType = new String[oldServiceType.length - 1];
vec.clear();
for (int i = 0; i < oldServiceType.length; i++) {
if (!(oldServiceType[i].equals(parseUSN.getServiceType()))) {
vec.add(oldServiceType[i]);
}
}
actualServiceType = (String[]) vec.toArray(new String[] {});
// unrigistering and registering again with the new properties
unregisterUPnPDevice(registar);
device.setProperty(UPnPService.ID, actualServicesID);
device.setProperty(UPnPService.TYPE, actualServiceType);
registerUPnPDevice(null, device, device.getDescriptions(null));
searchForListener(cyberDevice);
}
}
}
// synchronized(devices)
} else {
/*
* if it is a service means that it has deleted when the
* owner was unregister so I can skip this bye-bye
*
* //TODO Understand the comment
*
*/
}
}
use of org.osgi.framework.ServiceRegistration in project felix by apache.
the class MetatypeInventoryPrinter method unregister.
void unregister() {
ServiceRegistration registration = this.registration;
this.registration = null;
if (registration != null) {
registration.unregister();
}
}
use of org.osgi.framework.ServiceRegistration in project felix by apache.
the class Felix4350Test method doTest.
protected void doTest(String componentName) throws Exception {
ServiceRegistration dep1Reg = register(new SimpleComponent(), 0);
ServiceRegistration dep2Reg = register(new SimpleComponent2(), 1000);
final ComponentDescriptionDTO main = findComponentDescriptorByName(componentName);
TestCase.assertNotNull(main);
// needs to be async
asyncEnable(main);
// dep2 getService has not yet returned
delay(300);
dep1Reg.unregister();
// dep2 getService has returned
delay(2000);
Felix4350Component.check(0, 0, false);
dep1Reg = register(new SimpleComponent(), 0);
delay(300);
Felix4350Component.check(1, 0, true);
// does not need to be asyncv??
disableAndCheck(main);
dep1Reg.unregister();
dep2Reg.unregister();
Felix4350Component.check(1, 1, false);
dep1Reg = register(new SimpleComponent(), 0);
dep2Reg = register(new SimpleComponent2(), 1000);
Felix4350Component.check(1, 1, false);
// needs to be async
asyncEnable(main);
delay(300);
dep1Reg.unregister();
delay(100);
dep1Reg = register(new SimpleComponent(), 0);
delay(2000);
// n.b. counts are cumulative
Felix4350Component.check(2, 1, true);
}
use of org.osgi.framework.ServiceRegistration in project felix by apache.
the class SimpleService2Impl method drop.
public void drop() {
ServiceRegistration sr = getRegistration();
if (sr != null) {
setRegistration(null);
sr.unregister();
}
}
use of org.osgi.framework.ServiceRegistration in project sling by apache.
the class MockBundleContextDynamicReferencesTest method testAddRemoveOptionalUnaryService.
@Test
public void testAddRemoveOptionalUnaryService() {
ServiceRegistration reg1aOptional = bundleContext.registerService(ServiceInterface1Optional.class.getName(), dependency1aOptional, null);
assertDependency1Optional(dependency1aOptional);
reg1aOptional.unregister();
assertDependency1Optional(null);
}
Aggregations