private void cleanUp(ManagedApplication ma) { try { MachineMonitor monitor = ma.getMonitor(); if (monitor != null) monitor.stopTimer(); } catch (Exception e) { ma.getLogger().finest(Utils.writeException(e)); } try { IMessageServerClient client = ma.getMessagingClient(); if (client != null) client.closeConnection(); } catch (Exception e) { ma.getLogger().finest(Utils.writeException(e)); } }
/** * Loads a new application. * * @param application * @return the managed application that was created * @throws AlreadyExistingException if the application already exists * @throws InvalidApplicationException if the application contains critical errors * @throws IOException if the messaging could;not be initialized */ public ManagedApplication loadNewApplication(File applicationFilesDirectory) throws AlreadyExistingException, InvalidApplicationException, IOException { LoadResult lr = RuntimeModelIo.loadApplication(applicationFilesDirectory); if (RoboconfErrorHelpers.containsCriticalErrors(lr.getLoadErrors())) throw new InvalidApplicationException(lr.getLoadErrors()); Application application = lr.getApplication(); if (null != findApplicationByName(application.getName())) throw new AlreadyExistingException(application.getName()); final IMessageServerClient client = this.messagingClientFactory.create(); client.setApplicationName(application.getName()); client.setMessageServerIp(this.messageServerIp); client.setSourceName(MessagingUtils.SOURCE_DM); client.openConnection(new DmMessageProcessor(application)); client.bind(MessagingUtils.buildRoutingKeyToDm()); ManagedApplication ma = new ManagedApplication(application, applicationFilesDirectory, client); this.appNameToManagedApplication.put(application.getName(), ma); ma.getLogger() .fine("Application " + application.getName() + " was successfully loaded and added."); return ma; }