Search in sources :

Example 1 with Lock

use of nl.nn.adapterframework.util.Lock in project iaf by ibissource.

the class ShowMonitors method executeSub.

public ActionForward executeSub(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    // Initialize action
    initAction(request);
    if (ibisManager == null)
        return (mapping.findForward("noIbisContext"));
    String forward = null;
    DynaActionForm monitorForm = getPersistentForm(mapping, form, request);
    if (isCancelled(request)) {
        log.debug("edit is canceled");
        forward = determineExitForward(monitorForm);
    } else {
        // debugFormData(request,form);
        String action = request.getParameter("action");
        String indexStr = request.getParameter("index");
        String triggerIndexStr = request.getParameter("triggerIndex");
        int index = -1;
        if (StringUtils.isNotEmpty(indexStr)) {
            index = Integer.parseInt(indexStr);
        }
        int triggerIndex = -1;
        if (StringUtils.isNotEmpty(triggerIndexStr)) {
            triggerIndex = Integer.parseInt(triggerIndexStr);
        }
        MonitorManager mm = MonitorManager.getInstance();
        if ("getStatus".equals(action)) {
            response.setContentType("text/xml");
            PrintWriter out = response.getWriter();
            out.print(mm.getStatusXml().toXML());
            out.close();
            return null;
        }
        Lock lock = mm.getStructureLock();
        try {
            lock.acquireExclusive();
            forward = performAction(monitorForm, action, index, triggerIndex, response);
            log.debug("forward [" + forward + "] returned from performAction");
            mm.reconfigure();
        } catch (Exception e) {
            error("could not perform action [" + action + "] on monitorIndex [" + index + "] triggerIndex [" + triggerIndex + "]", e);
        } finally {
            lock.releaseExclusive();
        }
        if (response.isCommitted()) {
            return null;
        }
    }
    if (StringUtils.isEmpty(forward)) {
        log.debug("replacing empty forward with [success]");
        forward = "success";
    }
    initForm(monitorForm);
    ActionForward af = mapping.findForward(forward);
    if (af == null) {
        throw new ServletException("could not find forward [" + forward + "]");
    }
    // Forward control to the specified success URI
    log.debug("forward to [" + forward + "], path [" + af.getPath() + "]");
    return (af);
}
Also used : ServletException(javax.servlet.ServletException) MonitorManager(nl.nn.adapterframework.monitoring.MonitorManager) DynaActionForm(org.apache.struts.action.DynaActionForm) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) MonitorException(nl.nn.adapterframework.monitoring.MonitorException) ActionForward(org.apache.struts.action.ActionForward) PrintWriter(java.io.PrintWriter) Lock(nl.nn.adapterframework.util.Lock)

Aggregations

IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 ServletException (javax.servlet.ServletException)1 MonitorException (nl.nn.adapterframework.monitoring.MonitorException)1 MonitorManager (nl.nn.adapterframework.monitoring.MonitorManager)1 Lock (nl.nn.adapterframework.util.Lock)1 ActionForward (org.apache.struts.action.ActionForward)1 DynaActionForm (org.apache.struts.action.DynaActionForm)1