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

静态分析

除了看代码,就是 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. 拼音操作工具类 - PinyinUtil.java

    拼音操作工具类,提供字符串转换成拼音数组.汉字转换成拼音.取汉字的首字母等方法. 源码如下:(点击下载 -PinyinUtil.java.pinyin4j-2.5.0.jar ) import net ...

  2. 1003: [ZJOI2006]物流运输trans - BZOJ

    Description 很久以前,在一个遥远的星系,一个黑暗的帝国靠着它的超级武器统治者整个星系.某一天,凭着一个偶然的机遇,一支反抗军摧毁了帝国的超级武器,并攻下了星系中几乎所有的星球.这些星球通过 ...

  3. Hibernate应用SQL查询返回实体类型

    Hibernate应用SQL查询返回实体类型 Hibernate使用SQL查询返回实体类型 以前,使用SQL查询,结果放在 RS 结果集中,还要去转换影射到Java类中.Hibernate中,可以自动 ...

  4. aJax提交——服务端不能用request存储数据,session存数据客户端可以接收到

    aJax提交与普通提交是两种迥异的提交方式,这两种提交方式决定了客户端与服务端交互时存储.传输数据的方式也不同. aJax提交,客户端的请求数据存储在data中,服务端用request.getPara ...

  5. OpenSessionInViewFilter 的配置及替代方案(转)

    鸣谢:http://justsee.iteye.com/blog/1174999,http://blog.csdn.net/sunsea08/article/details/4545186 Sprin ...

  6. 论MOBA类游戏五号位的重要性

    观众朋友们,也许你对题目很好奇,才打开这篇文章.为什么技术圈中会出现游戏类的软文?如果时间充足,可以继续往下看. MOBA 类游戏的兴起,逐渐吞噬游戏市场,以病毒式的扩张方式肆意改变着游戏玩家内心对游 ...

  7. 发现一个可以在线运行JS代码的网站

    平时可以在这里玩 http://jsbin.com/

  8. vim查找/替换字符串 及一些高级用法

    例: 32 ./run 0_39.pkt 0_39.jpg 33 ./run 0_3.pkt 0_3.jpg 34 ./run 0_40.pkt 0_40.jpg 35 ./run 0_41.pkt ...

  9. 【转】VMware设置共享文件夹之后Ubuntu中看不到怎么办?

    一.共享文件夹设置好了,但是在虚拟机中的Ubuntu系统下却看不到,怎么办? 一种可能的原因是系统没有自动挂载,解决办法: 1.安装:               sudo apt-get insta ...

  10. SQLite入门与分析(四)---Page Cache之事务处理(1)

    写在前面:从本章开始,将对SQLite的每个模块进行讨论.讨论的顺序按照我阅读SQLite的顺序来进行,由于项目的需要,以及时间关系,不能给出一个完整的计划,但是我会先讨论我认为比较重要的内容.本节讨 ...