001package com.khubla.pragmatach.plugin.adminapp;
002
003import java.lang.management.ManagementFactory;
004
005import com.khubla.pragmatach.framework.annotation.Controller;
006import com.khubla.pragmatach.framework.annotation.Route;
007import com.khubla.pragmatach.framework.annotation.View;
008import com.khubla.pragmatach.framework.api.PragmatachException;
009import com.khubla.pragmatach.framework.api.Response;
010
011/**
012 * @author tome
013 */
014@Controller(name = "pragmatachShowServerController")
015@View(view = "pragmatach/admin/server.html")
016public class ShowServerController extends SecuredAdminController {
017   /**
018    * find the current process id
019    */
020   private static String findProcessId() throws PragmatachException {
021      try {
022         final String jvmName = ManagementFactory.getRuntimeMXBean().getName();
023         final int index = jvmName.indexOf('@');
024         if (index < 1) {
025            return null;
026         } else {
027            return Long.toString(Long.parseLong(jvmName.substring(0, index)));
028         }
029      } catch (final Exception e) {
030         throw new PragmatachException("Exception in getProcessId", e);
031      }
032   }
033
034   /**
035    * server info
036    */
037   private String serverinfo;
038   /**
039    * hostname
040    */
041   private String hostname;
042   /**
043    * process id
044    */
045   private String processId;
046
047   public String getHostname() {
048      return hostname;
049   }
050
051   public String getProcessId() {
052      return processId;
053   }
054
055   public String getServerinfo() {
056      return serverinfo;
057   }
058
059   @Route(uri = "/pragmatach/admin/server")
060   public Response render() throws PragmatachException {
061      serverinfo = getRequest().getHttpServletRequest().getSession().getServletContext().getServerInfo();
062      processId = findProcessId();
063      try {
064         hostname = java.net.InetAddress.getLocalHost().getHostName();
065      } catch (final Exception e) {
066         hostname = "";
067      }
068      return super.render();
069   }
070
071   public void setHostname(String hostname) {
072      this.hostname = hostname;
073   }
074
075   public void setProcessId(String processId) {
076      this.processId = processId;
077   }
078
079   public void setServerinfo(String serverinfo) {
080      this.serverinfo = serverinfo;
081   }
082}