/** start the connection manager. */ public void start() { if (!_lifecycle.toActive()) return; if (0 < _idleTimeout && _idleTimeout < 1000) _alarm.queue(1000); else if (1000 < _idleTimeout && _idleTimeout < 60000) _alarm.queue(_idleTimeout); else _alarm.queue(60000); }
/** Alarm listener. */ @Override public void handleAlarm(Alarm alarm) { if (!_lifecycle.isActive()) return; try { _alarmConnections.clear(); synchronized (_connectionPool) { _alarmConnections.addAll(_connectionPool); } for (int i = _alarmConnections.size() - 1; i >= 0; i--) { ManagedPoolItem item = _alarmConnections.get(i); if (!item.isValid()) item.destroy(); } _alarmConnections.clear(); fillIdlePool(); } finally { if (!_lifecycle.isActive()) { } else if (0 < _idleTimeout && _idleTimeout < 1000) _alarm.queue(1000); else if (1000 < _idleTimeout && _idleTimeout < 60000) _alarm.queue(_idleTimeout); else _alarm.queue(60000); } }
private synchronized void updateAlarms() { // activeAlarms.clear(); for (TagBlankEntity tagBlankEntity : deviceEntity.getTagBlankEntities()) { for (AlarmBlank alarmBlank : tagBlankEntity.getAlarmBlanks()) { StringBuffer sb = new StringBuffer(); try { sb.append(values.get(tagBlankEntity.getTagDescr()).getRegister()); sb.append(alarmBlank.getCondition()); String script = sb.toString(); Boolean res = (Boolean) AlarmUtil.getInstance().getScriptEngine().eval(script); Alarm alarm = new Alarm(alarmBlank); if (res == true) { if (activeAlarms.contains(alarm)) { continue; } else { activeAlarms.add(alarm); AlarmEntity alarmEntity = new AlarmEntity(); alarmEntity.setAlarmBlank(alarmBlank); alarmEntity.setAlarmTime(alarm.getStartTime()); DataHelper.getInstance().saveAlarm(alarmEntity); } } else { if (activeAlarms.contains(alarm)) { activeAlarms.remove(alarm); } } } catch (RuntimeException ex) { ex.printStackTrace(); } catch (ScriptException e) { e.printStackTrace(); } } } }
/** Stops the manager. */ public void stop() { if (!_lifecycle.toStop()) return; log.finer(this + " stopping"); if (_alarm != null) _alarm.dequeue(); }
/** * Returns the type's configured value * * @param builder the context builder * @param node the configuration node * @param parent */ @Override public Object valueOf(String text) { try { if (text == null) return null; else if ("".equals(text)) return new Date(Alarm.getCurrentTime()); QDate date = new QDate(); date.parseDate(text); return new Date(date.getGMTTime()); } catch (Exception e) { throw ConfigException.create(e); } }
private boolean sendError(FacesContext context, String lifecycle, Exception e) { for (Throwable cause = e; cause != null; cause = cause.getCause()) { if (cause instanceof DisplayableException) { if (e instanceof RuntimeException) throw (RuntimeException) e; else throw new FacesException(e); } else if (cause instanceof ServletException) throw new FacesException(e); else if (cause instanceof JspException) throw new FacesException(e); } ExternalContext extContext = context.getExternalContext(); Object response = extContext.getResponse(); if (!(response instanceof HttpServletResponse)) { context.renderResponse(); if (e instanceof RuntimeException) throw (RuntimeException) e; else throw new RuntimeException(e); } log.log(Level.WARNING, e.toString(), e); HttpServletResponse res = (HttpServletResponse) response; try { context.renderResponse(); context.responseComplete(); res.setStatus(500, "JSF Exception"); res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println("<body>"); out.println("<h3>JSF exception detected in " + lifecycle + " phase</h3>"); String msg = e.getMessage(); out.println("<span style='color:red;font:bold'>" + Html.escapeHtml(msg) + "</span><br/>"); out.println("<h3>Context: " + context.getViewRoot() + "</h3>"); out.println("<code><pre>"); String errorId = null; if (e instanceof FacesException && msg.startsWith("id=")) { int p = msg.indexOf(' '); errorId = msg.substring(3, p); } printComponentTree(out, errorId, context, context.getViewRoot(), 0); out.println("</pre></code>"); if (!Alarm.isTest()) { out.println("<h3>Stack Trace</h3>"); out.println("<pre>"); if (e.getCause() != null) e.getCause().printStackTrace(out); else e.printStackTrace(out); out.println("</pre>"); } out.println("</body>"); // clear, so we don't just loop Application app = context.getApplication(); ViewHandler view = app.getViewHandler(); UIViewRoot viewRoot = context.getViewRoot(); viewRoot = view.createView(context, viewRoot.getViewId()); context.setViewRoot(viewRoot); // view.writeState(context); // XXX: no need to output state, but review. return true; } catch (IOException e1) { throw new RuntimeException(e); } }