@Override public void onDataReceived(final EventCOMObject eventCOMObject) { // Make sure that it is indeed a Close App event for us! final Identifier name = (Identifier) eventCOMObject.getBody(); if (!provider.providerName.equals(name.getValue())) { Logger.getLogger(CloseAppEventListener.class.getName()).log(Level.FINE, "This Event is not for us! App Directory Id: " + provider.getAppDirectoryId() + " , Related: " + eventCOMObject.getRelated() + " name: " + name.getValue()); return; // If not, get out.. } Logger.getLogger(CloseAppEventListener.class.getName()).log(Level.FINE, "This Event is for us! App Directory Id: " + provider.getAppDirectoryId() + " , Related: " + eventCOMObject.getRelated() + " name: " + name.getValue()); // Even though the subscription will guarantee that... // It is better to double-check if it is a Close App Event request... if (!eventCOMObject.getObjType().equals(AppsLauncherHelper.STOPAPP_OBJECT_TYPE)) { return; // If not, get out.. } Logger.getLogger(CloseAppEventListener.class.getName()).log(Level.INFO, "New StopApp Event Received! " + "For provider: '" + name.getValue() + "' (Related link: " + eventCOMObject.getRelated() + ")"); final ObjectId source = eventCOMObject.getObjectId(); this.provider.closeGracefully(source); }
@Override public void onDataReceived(EventCOMObject eventCOMObject) { if (eventCOMObject.getObjType().equals(AppsLauncherHelper.STOPPING_OBJECT_TYPE)) { // Is it the ack from the app? Logger.getLogger(ClosingAppListener.class.getName()).log(Level.INFO, "The app with objId " + objId + " is stopping..."); } if (eventCOMObject.getObjType().equals(AppsLauncherHelper.STOPPED_OBJECT_TYPE)) { Logger.getLogger(ClosingAppListener.class.getName()).log(Level.INFO, "The app with objId " + objId + " is now stopped!"); try { // Send update to consumer stating that the app is stopped interaction.sendUpdate(objId); } catch (MALInteractionException ex) { Logger.getLogger(ClosingAppListener.class.getName()).log(Level.SEVERE, null, ex); } catch (MALException ex) { Logger.getLogger(ClosingAppListener.class.getName()).log(Level.SEVERE, null, ex); } // If so, then close the connection to the service eventService.closeConnection(); this.appClosed = true; } }