FileDocCategorySizeDatePackage
CreateSnapshotServlet.javaAPI DocJBoss 4.2.14551Fri Jul 13 21:02:14 BST 2007org.jboss.console.plugins.monitor

CreateSnapshotServlet

public class CreateSnapshotServlet extends HttpServlet
Created by IntelliJ IDEA. User: wburke Date: Nov 25, 2003 Time: 5:53:01 PM To change this template use Options | File Templates.

Fields Summary
static final long
serialVersionUID
private static final Logger
log
Constructors Summary
Methods Summary
protected voiddoGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)

   
        
             
   
      doit(req, resp);
   
protected voiddoPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)

      doit(req, resp);
   
protected voiddoit(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)


      String monitorName = req.getParameter("monitorName").trim();
      log.debug(monitorName);
      String objectName = req.getParameter("objectName").trim();
      log.debug(objectName);
      MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();
      ObjectName oname = null;
      try
      {
         oname = new ObjectName(objectName);
      }
      catch (MalformedObjectNameException e)
      {
         error("Malformed ObjectName ", req, resp);
         return;
      }
      String attribute = req.getParameter("attribute").trim();
      log.debug(attribute);
      Object val = null;
      try
      {
         val = mbeanServer.getAttribute(oname, attribute);
      }
      catch (Exception e)
      {
         error("Unable to pull attribute value from MBean, does the attribute exist? ", req, resp);
         return;
      }
      String period = req.getParameter("period").trim();
      log.debug(period);
      long timePeriod = 0;
      try
      {
         timePeriod = Long.parseLong(period);
      }
      catch (NumberFormatException e)
      {
         error("Illegal format for watch period.", req, resp);
         return;
      }
      try
      {
         SnapshotRecordingMonitor monitor = new SnapshotRecordingMonitor();

         monitor.setMonitorName(monitorName);
         monitor.setObservedObject(oname);
         monitor.setObservedAttribute(attribute);
         monitor.setPeriod(timePeriod);
         ObjectName sname = new ObjectName("jboss.snapshot:name=" + monitorName);
         mbeanServer.registerMBean(monitor, sname);
         resp.sendRedirect("/web-console/manageSnapshot.jsp?monitorObjectName=" + java.net.URLEncoder.encode(sname.toString()));
      }
      catch (Exception ex)
      {
         error("Failed to create non-persisted monitor: " + ex.toString(), req, resp);
      }


   
protected voiderror(java.lang.String msg, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)

      req.setAttribute("error", "Error: " + msg);
      //this.getServletContext().getRequestDispatcher("/createThresholdMonitor.jsp").forward(req, resp);
      req.getRequestDispatcher("/createSnapshot.jsp").forward(req, resp);
      return;