Reference Guide

Table Of Contents
App Event Listener
If an application registers an AppEventListener with the application service then it can receive
notification of pending uninstall or disable actions. These notifications are made prior to shutting
down the application in the OSGi runtime environment. The AppEventListener registered by the
application will hear of any application event for all installed applications. To use this method to
determine when an application should remove an installed debian package, it must filter the call-
back event for just the application id, and then look at the type of event.
private final AppEventListener listener = new AppListener();
. . .
@Activate
protected void activate() throws Exception {
. . .
appService.addAppEventListener(listener);
}
private final class AppListener implements AppEventListener {
@Override
public void handleAppEvent(ApplicationEventType event, Application app) {
if (app.id().equals(APP_ID)) {
if (event.equals(ApplicationEventType.UNINSTALLING) ||
event.equals(ApplicationEventType.DISABLING)) {
removeDebian();
}
}
}
}
Uploading and Installing the Debian Package
The path to remove the debian file is “/” and requires an action string with the action word
uninstall” and the name of the debian package. The REST API will return a status of 200, and the
string associated with the response is JSON structure with the current status of the controller and
admin services (sdnc and sdna).
. . .
URI uri = adminRest.uri(IpAddress.LOOPBACK_IPv4, "/");
// then we need to uninstall it
ResponseData response = adminRest.post(adminRest.login(),
uri, uninstallRequestBytes());
. . .
135