如何分析一个稍微大点的源码呢?

静态分析

除了看代码,就是 uml图,UML虽然在书本类与类之间的关系很复杂,可能要一本书,但是最核心的其实很简单;

(1)继承 extends

(2)实现接口 implements

以上两个没啥说的,很easy.

(3)关联和依赖,这两者我一块说,不区分。简单来说,就是当前类直接使用哪些类。我们看项目中的主类依赖关系,从主类别开始逐层深入不断分析。

代码和和图一结合,很简单吧

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.simpleHTTPServer; import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger; /**
*
* @author romain
*/
public class SimpleHTTPServer { //默认端口
public static final int DEFAULT_PORT = 8000;
//默认目录
public static final File DEFAULT_FILE = new File(".");
//自定义端口
private final int port;
//自定义目录
private final File rootDir;
//最大线程数
private int maxThreads = 10;
//连接超时时间
private int clientTimeoutInMillis = 1000;
//依赖的一个类,多线程的为用户服务
private ServerMultiThreadedWorkers server;
private boolean started = false; public SimpleHTTPServer() {
this(DEFAULT_PORT, DEFAULT_FILE);
} public SimpleHTTPServer(int port, File rootDir) {
this.port = port;
this.rootDir = rootDir;
} public void start() {
if (!started) {
System.out.println("Serving HTTP on 0.0.0.0 port 8000 ...");
//z请求处理类,此处又直接依赖RequestHandlerFactory类,和RequestHandlerStaticSiteFactory
RequestHandlerFactory requestHandlerFactory = new RequestHandlerStaticSiteFactory(rootDir);
server = new ServerMultiThreadedWorkers(port, clientTimeoutInMillis, maxThreads, requestHandlerFactory);
server.start();
started = true;
} else {
throw new RuntimeException("Server already started (HTTP port=" + port + ", rootDir=" + rootDir.getAbsolutePath() + ")"); }
} public void stop() {
if (started) {
server.terminate();
try {
//直接使用了Thread类
Thread.sleep(500);
} catch (InterruptedException ex) {
Logger.getLogger(SimpleHTTPServer.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
System.out.println("Server not started (HTTP port=" + port + ", rootDir=" + rootDir.getAbsolutePath() + ")");
}
} /**
* @param maxThreads the maxThreads to set
*/
public void setMaxThreads(int maxThreads) {
this.maxThreads = maxThreads;
} /**
* @param clientTimeoutInMillis the clientTimeoutInMillis to set
*/
public void setClientTimeoutInMillis(int clientTimeoutInMillis) {
this.clientTimeoutInMillis = clientTimeoutInMillis;
} /**
*
* @param args. First arg is the port number.
*/
public static void main(String[] args) {
int port = DEFAULT_PORT;
if (args.length > 0) {
port = Integer.parseInt(args[0]);
}
SimpleHTTPServer server = new SimpleHTTPServer(port, DEFAULT_FILE);
server.start(); //Use Ctrl + C to stop.
}
}
 

SimpleHttpServer的学习之UML的更多相关文章

  1. 设计模式学习起点 UML类图笔记

    UML类图笔记 大学开设的软件设计课程一般都会学习UML类图,大部分关于设计模式的描述都是使用的UML类图,可以说类图的表示是学习设计模式的起点.UML定义类之间的关系主要有六种:泛化关系.实现关系. ...

  2. 学习建模 - UML

    最轻量级的工具下载地址 http://staruml.io/download 下载解压依赖:libgcrypt11 https://pan.baidu.com/s/1i3wb6M5 学习地址 http ...

  3. SimpleHttpServer的学习之总体架构

    http://www.cnblogs.com/hansongjiang/p/4213491.html 从代码中我们看到SimpleHttpServer这个类直接依赖4个类,但是最重要的类,当属其属性, ...

  4. SimpleHttpServer的学习(1)

    闲来没事,分析一下一个简单的HttpServer github地址: https://github.com/Filirom1/SimpleHTTPServer 实现的功能很简单就是一个FTP服务器 默 ...

  5. UML学习-1 UML 简介

    UML 是什么 Unified Modeling Language(UML)又称统一建模语言或标准建模语言,是始于 1997 年一个 OMG 标准,它是一个支持模型化和软件系统开发的图形化语言,为软件 ...

  6. 学习 lind UML 资源 十月 第二弹

    step one 来分析一下  UML 资源 管理

  7. UML学习备忘

    两大类UML图: 行为图(behavior diagrams)和结构图(structure diagrams)     行为图将引导系统分析员分析且理清"系统该做些什么"?系统分析 ...

  8. UML学习之初步总结

    UML(Unified Modeling Language)即统一建模语言,是一种开放的方法,用于说明.可视化.构建和编写一个正在开发的.面向对象的.软件密集系统的制品的开放方法.UML展现了一系列最 ...

  9. 解析UML箭头、线条代表的意义(转)

    在学习UML过程中,你经常会遇到UML类图关系,这里就向大家介绍一下UML箭头.线条代表的意义,相信通过本文的介绍你对UML中箭头.线条的意义有更明确的认识. AD: 本节向大家学习一下UML箭头.线 ...

随机推荐

  1. jquery取消事件冒泡和取消默认行为

    $('button').click(functon(e){ /*code*/ e.stopPropagation();//取消事件冒泡 e.preventDefault();//取消默认行为 })

  2. java去掉List中的重复值代码

    1. list中为字符串的情况,代码如下: public static void main(String[] args) { List<String> li = new ArrayList ...

  3. SetTimer在无窗口和有窗口线程的使用 . .

    今天犯了一个粗心的错误,在无窗口线程中,SetTimer中设置计时器ID,而WM_TIMER消息响应函数中得到的计时器ID却不是之前设置的计时器ID. 对应计时器ID的输出的是一个随机数字. 原来在m ...

  4. 【leetcode】Longest Common Prefix (easy)

    Write a function to find the longest common prefix string amongst an array of strings. 思路:找最长公共前缀 常规 ...

  5. ASP.NET 4.5.256 has not been registered on the Web server

    请见:http://answers.microsoft.com/en-us/insider/forum/insider_apps-insider_other/aspnet-45256-has-not- ...

  6. 深入理解Java内存模型(二)——重排序

    本文属于作者原创,原文发表于InfoQ:http://www.infoq.com/cn/articles/java-memory-model-2 数据依赖性 如果两个操作访问同一个变量,且这两个操作中 ...

  7. codeforces #313 div1 E

    首先我们要注意到一个事情 如果一个灯塔向左覆盖,那么比他小的某个灯塔如果向左覆盖的端点大于当前塔向左覆盖的端点,他一定向右覆盖 对于当前灯塔向右覆盖也是同理 那么我们只需要记录当前覆盖到的端点就可以完 ...

  8. Servlet课程0425(五) sendRedirect实现不同页面共享数据

    Login.java //登录界面 package com.tsinghua; import javax.servlet.http.*; import java.io.*; public class ...

  9. 轻量级Java_EE企业应用实战-第5章Hibernate的基本用法-001

    1. package org.crazyit.app.domain; import javax.persistence.*; /** * Description: <br/> * ��վ: ...

  10. *IntelliJ idea创建创建Maven管理的Java Web项目

    配置IntelliJ在IntelliJ的设置中,可以设置maven的安装目录,settings.xml文件的位置,和本地仓库的位置等信息.