private void getEventInfo(long eventPK) { String prefsFile = getResources().getString(R.string.preferencesFilename); SharedPreferences prefs = getSharedPreferences(prefsFile, 0); String key = getResources().getString(R.string.preferencesUserpass); String userpass = prefs.getString(key, ""); ServerCommunicator comm = new ServerCommunicator(this, TAG); comm.sendGetEventRequest(userpass, eventPK); }
/** Stop all the PVs, disconnect from JMS */ public void stop() { if (nag_timer != null) { nag_timer.cancel(); nag_timer = null; } messenger.sendAnnunciation("Alarm server exiting"); stopPVs(); messenger.stop(); }
/** * Update 'global' JMS clients and RDB * * @param pv Alarm PV * @param severity Alarm severity (highest, latched) * @param message Alarm message * @param value Value that triggered * @param timestamp Time of last alarm update */ public void sendGlobalUpdate( final AlarmPV pv, final SeverityLevel severity, final String message, final String value, final Timestamp timestamp) { // Send to JMS messenger.sendGlobalUpdate(pv, severity, message, value, timestamp); // Persist global alarm state change in separate queue & thread // so that it won't delay the alarm server from updating work_queue.execute( new Runnable() { @Override public void run() { try { rdb.writeGlobalUpdate(pv, severity.isActive()); recoverFromRDBErrors(); } catch (Exception ex) { // Remember that there was an error had_RDB_error = true; Activator.getLogger().log(Level.SEVERE, "Exception during global alarm update", ex); } } }); }
/** * Update JMS clients and RDB * * @param pv Alarm PV * @param current_severity Current channel severity * @param current_message Current message * @param severity Alarm severity (highest, latched) * @param message Alarm message * @param value Value that triggered * @param timestamp Time of last alarm update */ public void sendStateUpdate( final AlarmPV pv, final SeverityLevel current_severity, final String current_message, final SeverityLevel severity, final String message, final String value, final Timestamp timestamp) { messenger.sendStateUpdate( pv, current_severity, current_message, severity, message, value, timestamp); // Move the persistence of states into separate queue & thread // so that it won't delay the alarm server from updating. // ReplacableRunnable: // If there is already an update request for this PV on the queue, // replace it with the new one because it's out of date and no // longer needs to be writting to the RDB anyway. work_queue.executeReplacable( new ReplacableRunnable<AlarmPV>(pv) { @Override public void run() { try { rdb.writeStateUpdate( pv, current_severity, current_message, severity, message, value, timestamp); recoverFromRDBErrors(); } catch (Exception ex) { // Remember that there was an error had_RDB_error = true; Activator.getLogger().log(Level.SEVERE, "Exception during alarm state update", ex); } } }); }
/** Start all the PVs, connect to JMS */ public void start() { messenger.start(); messenger.sendAnnunciation(Messages.StartupMessage); startPVs(); // Conditionally enable nagging double nag_period; try { nag_period = AlarmServerPreferences.getNagPeriod(); } catch (Exception ex) { Activator.getLogger() .log( Level.WARNING, "Invalid '" + AlarmServerPreferences.NAG_PERIOD + "', repeated annunciations disabled", ex); nag_period = 0.0; } if (nag_period > 0) { nag_timer = new NagTimer( Math.round(nag_period * 1000), new NagTimerHandler() { @Override public int getActiveAlarmCount() { int active = 0; // Sync on access to pv_list synchronized (AlarmServer.this) { for (AlarmPV pv : pv_list) if (pv.getAlarmLogic().getAlarmState().getSeverity().isActive()) ++active; } return active; } @Override public void nagAboutActiveAlarms(final int active) { final String message; if (active == 1) message = "There is 1 active alarm"; else message = NLS.bind("There are {0} active alarms", active); messenger.sendAnnunciation(message); } }); nag_timer.start(); } }
/** * If this is the first successful RDB update after errors, tell everybody to re-load the * configuration because otherwise they get out of sync. * * @throws Exception on error */ protected void recoverFromRDBErrors() throws Exception { if (!had_RDB_error) return; // We should be on the work queue thread work_queue.assertOnThread(); Activator.getLogger().info("RDB connection recovered, re-loading configuration"); updateConfig(null); // If that worked out, reset error and inform clients had_RDB_error = false; messenger.sendReloadMessage(); }
/** * Set maintenance mode. * * @param maintenance_mode * @see AlarmLogic#getMaintenanceMode() */ public void setMaintenanceMode(final boolean maintenance_mode) { // Any change? if (maintenance_mode == AlarmLogic.getMaintenanceMode()) return; // Configure alarm logic AlarmLogic.setMaintenanceMode(maintenance_mode); // Send update to clients messenger.sendIdleMessage(); // Entering maintenance mode: Ack' all INVALID alarms if (maintenance_mode) { synchronized (this) { for (AlarmPV pv : pv_list) { final AlarmLogic logic = pv.getAlarmLogic(); if (logic.getAlarmState().getSeverity() == SeverityLevel.INVALID) logic.acknowledge(true); } } } }
/** * Update JMS clients and RDB about 'enabled' state of PV * * @param pv Alarm PV * @param enabled Enabled or not? */ public void sendEnablementUpdate(final AlarmPV pv, final boolean enabled) { messenger.sendEnablementUpdate(pv, enabled); // Handle in separate queue & thread work_queue.execute( new Runnable() { @Override public void run() { try { rdb.writeEnablementUpdate(pv, enabled); recoverFromRDBErrors(); } catch (Exception ex) { // Remember that there was an error had_RDB_error = true; Activator.getLogger().log(Level.SEVERE, "Exception during enablement update", ex); } } }); }
/** * Perform annunciation * * @param level Alarm severity * @param message Text message to send to annunciator */ public void sendAnnunciation(final SeverityLevel level, final String message) { resetNagTimer(); messenger.sendAnnunciation(level, message); }
/** Release all resources */ public void close() { messenger.stop(); rdb.close(); }