/** * Read the initial alarm configuration * * @throws Exception on error */ private void readConfiguration() throws Exception { // Read alarm hierarchy final BenchmarkTimer timer = new BenchmarkTimer(); final int pv_count; synchronized (this) { alarm_tree = rdb.readConfiguration(); // Determine PVs final ArrayList<AlarmPV> tmp_pv_array = new ArrayList<AlarmPV>(); findPVs(alarm_tree, tmp_pv_array); // Turn into plain array pv_list = tmp_pv_array.toArray(new AlarmPV[tmp_pv_array.size()]); tmp_pv_array.clear(); // Sort PVs by name Arrays.sort( pv_list, new Comparator<AlarmPV>() { @Override public int compare(final AlarmPV pv1, final AlarmPV pv2) { return pv1.getName().compareTo(pv2.getName()); } }); // Create hash pv_map = new HashMap<String, AlarmPV>(); for (AlarmPV pv : pv_list) pv_map.put(pv.getName(), pv); pv_count = pv_list.length; } timer.stop(); // LDAP results: Read 12614 PVs in 2.69 seconds, 4689.0 PVs/sec System.out.format( "Read %d PVs in %.2f seconds: %.1f PVs/sec\n", pv_count, timer.getSeconds(), pv_count / timer.getSeconds()); }
/** Start PVs */ private void startPVs() { final long delay = Preferences.getPVStartDelay(); // Must not sync while calling PV, because Channel Access updates // might arrive while we're trying to start/stop channels, // and those updates will try to lock the Alarm Server, // which then results in a deadlock: // a) We lock AlarmServer, then try to call CA, // which takes internal JNI locks // b) CA takes internal locks, calls PV update callback, which // then tries to lock the AlarmServer when locating the PV by name final AlarmPV pvs[]; synchronized (this) { pvs = pv_list.clone(); } for (AlarmPV pv : pvs) { try { pv.start(); if (delay > 0) Thread.sleep(delay); } catch (Exception ex) { Activator.getLogger().log(Level.SEVERE, "Error starting PV " + pv.getName(), ex); } } }