⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httpdebug.java

📁 一个类似于openJMS分布在ObjectWeb之下的JMS消息中间件。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		  // The rigth URL		  buf.append(urlAgent(id));		  idx = j;		}	      }	      buf.append(dump[idx++]);	    }	    idx++; // skip ']'	    idx++; // skip ','	    // get ",update="	    if (dump[idx] == ',')	      buf.append('\n');	    else	      throw new IllegalArgumentException();	    idx++;	    while (dump[idx] != '=') buf.append(dump[idx++]);	    buf.append(dump[idx++]);	    //	    if (dump[idx++] != '[') throw new IllegalArgumentException();	    while (dump[idx] != ']') buf.append(dump[idx++]);	    idx++;	    // get deadline if there is one	    if (dump[idx] != ')') {	      if (dump[idx] == ',')		buf.append('\n');	      else		throw new IllegalArgumentException();	      idx++;	      while (dump[idx] != ')') buf.append(dump[idx++]);	    }	    idx++;	    if (dump[idx] == ')') 	      break;	    else	      buf.append("\n<hr>");	  } catch (IllegalArgumentException exc) {	    // search next '('	    throw exc;	  }	}      } catch (Exception exc) {	exc.printStackTrace();      }    }    void listServices(String cmd, StringBuffer buf) {      int sub = -1;      String sclass = null;      if (cmd.startsWith(CMD_START)) {	sub = 1;	sclass = cmd.substring(CMD_START.length() +1);      } else if (cmd.startsWith(CMD_STOP)) {	sub = 2;	sclass = cmd.substring(CMD_STOP.length() +1);      } else if (cmd.startsWith(CMD_REMOVE)) {	sub = 3;	sclass = cmd.substring(CMD_REMOVE.length() +1);      }      buf.append("<H2>List of services</H2>\n");      buf.append("<TABLE BORDER=\"1\" WIDTH=\"100%\">\n");      if (sub == 3) {	buf.append("<TR><TD><PRE>");	try {	  ServiceManager.stop(sclass);	  buf.append("\nService <").append(sclass).append("> stopped.");	} catch (Exception exc) {	  buf.append("\nCan't stop service \"")	    .append(sclass).append("\" :\n\t")	    .append(exc.getMessage());	}	try {	  ServiceManager.unregister(sclass);	  buf.append("\nService <").append(sclass).append("> unregistred.");	} catch (Exception exc) {	  buf.append("\nCan't unregister service \"")	    .append(sclass).append("\" :\n\t")	    .append(exc.getMessage());	}	buf.append("</PRE></TD></TR>\n");      }      ServiceDesc services[] = ServiceManager.getServices();      for (int i=0; i<services.length; i++ ){	buf.append("<TABLE BORDER=\"1\" WIDTH=\"100%\">\n");	buf.append("<TR><TD CLASS=FONT1 VALIGN=\"TOP\" COLSPAN=\"2\">")	  .append(services[i].getClassName());	if (services[i].getClassName().equals(sclass)) {	  if (sub == 1) {	    try {	      ServiceManager.start(sclass);	    } catch (Exception exc) {	      buf.append("<PRE>\nCan't start service: \n\t")		.append(exc.getMessage())		.append("</PRE>");	    }	  } else if (sub == 2) {	    try {	      ServiceManager.stop(sclass);	    } catch (Exception exc) {	      buf.append("<PRE>\nCan't stop service: \n\t")		.append(exc.getMessage())		.append("</PRE>");	    }	    	  }	}	buf.append("</TD></TR>");	buf.append("<TR><TD ROWSPAN=\"2\" WIDTH=\"70%\"><PRE>")	  .append("\narguments=").append(services[i].getArguments())	  .append("\ninitialized=").append(services[i].isInitialized())	  .append("\nrunning=").append(services[i].isRunning())	  .append("</PRE></TD>\n");	buf.append("<TD CLASS=FONT1 ALIGN=\"CENTER\" BGCOLOR=\"#3366FF\">")	  .append("<A href=\"")	  .append(base).append(CMD_SERVICES);	if (services[i].isRunning()) {	  buf.append(CMD_STOP + "+")	    .append(services[i].getClassName())	    .append("\">STOP</A>\n");	} else {	  buf.append(CMD_START + "+")	    .append(services[i].getClassName())	    .append("\">START</A>\n");	}	buf.append("</TD></TR>\n");	buf.append("<TR><TD CLASS=FONT1 ALIGN=\"CENTER\" BGCOLOR=\"#3366FF\">")	  .append("<A href=\"")	  .append(base).append(CMD_SERVICES)	  .append(CMD_REMOVE + "+")	  .append(services[i].getClassName())	  .append("\">REMOVE</A>\n")	  .append("</TD></TR>\n");// 	buf.append("<TR><TD><PRE><CODE>\n");// 	buf.append("class=" + services[i].getClassName() + "\n");// 	buf.append("args=" + services[i].getArguments());// 	buf.append("</CODE></PRE></TD></TR>\n");		buf.append("</TABLE>");      }      buf.append("</TABLE>");      return;    }    /**     *  Parses an AgentId from a char array, it determines the sub-array     * that contain an AgentId, then you can get it with fromString:     * <pre>     * end = dumpAgentId(dump, start);     * if (end != -1)     *   id = AgentId.fromString(new String(dump, start, end-start));     * </pre>     *     * @param dump	The char array.     * @param idx	The current index in array (shoul be the first     *			charracter of the AgentId: '#').     *     * @return		The index of first char after the AgentId, -1 if     *			thebeginning of the array do not correspond to an     *			AgentId.     */    int dumpAgentId(char dump[], int idx) {      if (dump[idx] != '#')	return -1;      int j = idx+1;      while ((j < dump.length) &&	     (dump[j] >= '0') && (dump[j] <= '9')) j++;      if ((j == (idx +1)) || (dump[j] != '.') || (j == dump.length))	return -1;      idx = j; j = j+1;      while ((j < dump.length) &&	     (dump[j] >= '0') && (dump[j] <= '9')) j++;      if ((j == (idx +1)) || (dump[j] != '.') || (j == dump.length))	return -1;      idx = j; j = j+1;      while ((j < dump.length) &&	     (dump[j] >= '0') && (dump[j] <= '9')) j++;     if (j == (idx +1)) return -1;     return j;    }    /**     * Executes a dump command.     *     * @ param agentid     String which contains the agentid      * like #x.y.z ,x,y,z are numbers.     */    void dumpAgent(String cmd, StringBuffer buf) {      AgentId id = null;      try {	if (cmd.charAt(0) != '/') throw new IllegalArgumentException();	id = AgentId.fromString(new String("#" + cmd.substring(1)));	if (id == null) throw new IllegalArgumentException();      } catch (IllegalArgumentException exc) {	buf.append("<H2>Error</H2>\n" +		   "<P>\n" +		   "Can't parse AgentId #x.y.z in \"" + cmd + "\"\n" +		   "</P>\n");	return;      }      buf.append("<H2>Dump agent " + id + "</H2>\n");      Agent agent = (Agent) AgentServer.engine.agents.get(id);      if (agent == null) {	buf.append("<P CLASS=FONT2>\n" +		   "Agent not loaded in memory.\n" +		   "</P>\n");	return;      }      try {	char dump[] = agent.toString().toCharArray();	for (int i=0; i<dump.length; i++) {	  if (dump[i] == '(') {	    buf.append("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");	    buf.append("<TR><TD CLASS=FONT1><PRE>\n");	  } else if (dump[i] == ',') {	    buf.append("\n");	  } else if (dump[i] == ')') {	    buf.append("</PRE></TD></TR>\n");	    buf.append("</TABLE>");	  } else if (dump[i] == '#') {	    id = null;	    int j = dumpAgentId(dump, i);	    if (j != -1)	      id = AgentId.fromString(new String(dump, i, j-i));	    if (id == null) {	      buf.append(dump[i]);	    } else {	      // TODO: the rigth URL	      buf.append(urlAgent(id));	      i = j -1;	    }	  } else {	    buf.append(dump[i]);	  }	}      } catch (IllegalArgumentException exc) {	buf.setLength(0);	buf.append("<H2>Error</H2>\n" +		   "<P>\n" +		   "Can't parse AgentId #x.y.z in \"" + cmd + "\"\n" +		   "</P>\n");	return;      }    }    /**     *     */    void debug(String cmd, StringBuffer buf) {      ServerSocket server = null;      int listen = -1;      buf.append("<H2>Debug Tool</H2>\n");      try {	server = new ServerSocket(0);      } catch (IOException exc) {	buf.append(exc.toString()).append(" during connection.\n");	return;      }      listen = server.getLocalPort();      // The applet      buf.append("<APPLET CODE=\"AppletDebug.class\" CODEBASE=\"")	.append(CMD_CLASS).append("\" WIDTH=\"800\" HEIGHT=\"200\">\n")	.append("<PARAM NAME=\"host\" VALUE=\"").append(host).append("\"/>\n")	.append("<PARAM NAME=\"port\" VALUE=\"").append(listen).append("\"/>\n")	.append("<PARAM NAME=\"url\" VALUE=\"").append(base).append(CMD_DEBUG_WAIT).append("\"/>\n")	.append("</APPLET>\n");            // The Internal Frame      buf.append("<IFRAME name=\"debug\" src=\"")	.append(CMD_DEBUG_WAIT)	.append("\" width=\"800\" height=\"400\" scrolling=\"auto\" frameborder=\"1\">\n")	.append("Your browser does not support internal frames (HTML 4.0)\n.")	.append("</IFRAME>\n");//       DebugMonitor dmon = new DebugMonitor(server);//       bp.start();    }    void loadClass(String cmd) {      BufferedOutputStream bos = null;//       System.out.println("load:" + cmd);      try {	bos = new BufferedOutputStream(socket.getOutputStream());	File file = new File(cmd.substring(1));	byte[] c = new byte[(int) file.length()];	new FileInputStream(file).read(c);	bos.write(c, 0, c.length);      } catch (IOException exc) {	exc.printStackTrace();      } finally {	try {	  bos.flush();	  bos.close();	} catch (IOException exc) {}      }    }  }  class DebugMonitor extends Daemon {    ServerSocket server = null;    int listen = -1;    public DebugMonitor() {      super("DebugMonitor");      // Get the logging monitor from HttpDebug (overload Daemon setup)      logmon = HttpDebug.xlogmon;      try {	server = new ServerSocket(0);	listen = server.getLocalPort();      } catch (IOException exc) {	server = null;	listen = -1;      }    }    public void run() {      Socket socket = null;      PrintWriter writer = null;      //       while (isRunning) {// 	canStop = true;// 	socket = server.accept();// 	writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()), true);// 	while (isRunning) {// 	  canStop = false;// 	  System.out.println("writes:" + base + HttpDebugMonitor.CMD_DEBUG_RUN);// 	  writer.println(base + HttpDebugMonitor.CMD_DEBUG_RUN);// 	  if (writer.checkError())// 	    throw new IOException();// 	  canStop = true;// 	  try {// 	    Thread.currentThread().sleep(1000);// 	  } catch (InterruptedException exc) {}// 	  canStop = false;// 	  System.out.println("writes:" + base + HttpDebugMonitor.CMD_DEBUG_WAIT);// 	  writer.println(base + HttpDebugMonitor.CMD_DEBUG_WAIT);// 	  if (writer.checkError())// 	    throw new IOException();// 	  canStop = true;// 	  try {// 	    System.out.println("wait");// 	    Thread.currentThread().sleep(10000);// 	  } catch (InterruptedException exc) {}// 	}//       } catch (IOException exc) {// 	try {// 	  socket.close();// 	} catch (IOException exc2) {}// 	exc.printStackTrace();//       } finally {//         finish();//       }    }       protected void close() {}    protected void shutdown() {}  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -