SimpleHttpServer的学习之UML
如何分析一个稍微大点的源码呢?
静态分析
除了看代码,就是 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的更多相关文章
- 设计模式学习起点 UML类图笔记
UML类图笔记 大学开设的软件设计课程一般都会学习UML类图,大部分关于设计模式的描述都是使用的UML类图,可以说类图的表示是学习设计模式的起点.UML定义类之间的关系主要有六种:泛化关系.实现关系. ...
- 学习建模 - UML
最轻量级的工具下载地址 http://staruml.io/download 下载解压依赖:libgcrypt11 https://pan.baidu.com/s/1i3wb6M5 学习地址 http ...
- SimpleHttpServer的学习之总体架构
http://www.cnblogs.com/hansongjiang/p/4213491.html 从代码中我们看到SimpleHttpServer这个类直接依赖4个类,但是最重要的类,当属其属性, ...
- SimpleHttpServer的学习(1)
闲来没事,分析一下一个简单的HttpServer github地址: https://github.com/Filirom1/SimpleHTTPServer 实现的功能很简单就是一个FTP服务器 默 ...
- UML学习-1 UML 简介
UML 是什么 Unified Modeling Language(UML)又称统一建模语言或标准建模语言,是始于 1997 年一个 OMG 标准,它是一个支持模型化和软件系统开发的图形化语言,为软件 ...
- 学习 lind UML 资源 十月 第二弹
step one 来分析一下 UML 资源 管理
- UML学习备忘
两大类UML图: 行为图(behavior diagrams)和结构图(structure diagrams) 行为图将引导系统分析员分析且理清"系统该做些什么"?系统分析 ...
- UML学习之初步总结
UML(Unified Modeling Language)即统一建模语言,是一种开放的方法,用于说明.可视化.构建和编写一个正在开发的.面向对象的.软件密集系统的制品的开放方法.UML展现了一系列最 ...
- 解析UML箭头、线条代表的意义(转)
在学习UML过程中,你经常会遇到UML类图关系,这里就向大家介绍一下UML箭头.线条代表的意义,相信通过本文的介绍你对UML中箭头.线条的意义有更明确的认识. AD: 本节向大家学习一下UML箭头.线 ...
随机推荐
- NOI2015考试小结
这次NOI2015有幸获得金牌考进了国家集训队,意味着我的OI退役时间既省选之后有延迟了好几个月,又有了新的目标吧. 先说一下考试之外的感受吧,学军宿舍很牛X,接待NOIers而不提供插座,唯一可以用 ...
- itext 落雨 out of membery Memory Optimization
Memory Optimization If a document deals with a lot of data or large elements, such as images, it is ...
- Ubuntu环境下手动配置openSSH
配置openSSH 1.手动下载压缩文件(.tar.gz) zlib-1.2.7.tar.gz openssl-1.0.1j.tar.gz openssh-6.0p1.tar.gz 2.安装zlib ...
- POJ1416——Shredding Company(DFS)
Shredding Company DescriptionYou have just been put in charge of developing a new shredder for the S ...
- hadoop博客
http://www.cnblogs.com/scotoma/ http://www.cnblogs.com/xia520pi/
- AIDL与stub
Stub翻译成中文是存根的意思,注意Stub对象是在被调用端进程,也就是服务端进程,至此,服务端aidl服务端得编码完成了. stub是为了方便client,service交互而生成出来的代码.A ...
- NFC(9)NDEF文本格式规范及读写示例(解析与封装ndef 文本)
只有遵守NDEF文本格式规范的数据才能写到nfc标签上. NDEF文本格式规范 不管什么格式的数据本质上都是由一些字节组成的.对于NDEF文本格式来说. 1,这些数据的第1个字节描述了数据的状态, 2 ...
- C#.Net 如何动态加载与卸载程序集(.dll或者.exe)3---- 动态加载Assembly应用程序
下载 supergraphfiles.exe 示例文件. 应用程序体系结构 在我专攻代码之前,我想谈谈我尝试做的事.您可能记得,SuperGraph 让您从函数列表中进行选择.我希望能够在具体的目录中 ...
- bzoj1061 1283
以前写的1061但一直没懂,后来懂了但忘写解题报告了 做了1283顺便补一下吧 1061 我是orz https://www.byvoid.com/blog/noi-2008-employee/#mo ...
- Unity3D中使用3DMAX建模规范
1.将3Dmax中的单位制设置为厘米. 如果使用3DMax来建模的话,可将3DMax的系统默认单位改成厘米 〉Customize - Units Setup - Metric - Display U ...