默认情况下是jar包形式,需要修改为war包形式时,才能被tomcat插件调用使用。
war
alimaven
aliyun maven
http://maven.aliyun.com/nexus/content/groups/public/
net-cn
Human Readable Name for this Mirror.
http://maven.net.cn/content/groups/public/
repo2
Human Readable Name for this Mirror.
http://repo2.maven.org/maven2/
CN
OSChina Central
http://maven.oschina.net/content/groups/public/
nexus
Team Nexus Repository
http://192.168.1.178:8081/nexus/content/groups/public
org.apache.maven.plugins
maven-compiler-plugin
3.3
1.7
1.7
UTF-8
src\main\webapp\WEB-INF\lib
org.apache.maven.plugins
maven-surefire-plugin
2.15
true
org.apache.maven.plugins
maven-war-plugin
2.4
WebContent 在WebContent目录下,一般有META-INF和WEB-INF两个目录。
true //设置为True时,在编译的过程中,如果没有查找到WebContent\WEB-INF\web.xml文件,则会报错。
org.apache.maven.plugins
maven-jar-plugin
2.4
org.apache.tomcat.maven
tomcat7-maven-plugin
2.1
8080
/
UTF-8
tomcat7
org.eclipse.jetty
jetty-maven-plugin
9.2.11.v20150529
10
/
org.wildfly.plugins
wildfly-maven-plugin
1.1.0.Alpha5
127.0.0.1
9990
admin
admin
spring4ajax.war
beanmap的注入
在学习SmartFrame框架时,发现一段IOC控制的代码有点意思,于是摘下来。
public class IocHelper {
static {
try {
// 获取并遍历所有的 Bean 类
Map, Object> beanMap = BeanHelper.getBeanMap();
for (Map.Entry, Object> beanEntry : beanMap.entrySet()) {
// 获取 Bean 类与 Bean 实例
Class> beanClass = beanEntry.getKey();
Object beanInstance = beanEntry.getValue();
// 获取 Bean 类中所有的字段(不包括父类中的方法)
Field[] beanFields = beanClass.getDeclaredFields();
if (ArrayUtil.isNotEmpty(beanFields)) {
// 遍历所有的 Bean 字段
for (Field beanField : beanFields) {
// 判断当前 Bean 字段是否带有 Inject 注解
if (beanField.isAnnotationPresent(Inject.class)) {
// 获取 Bean 字段对应的接口
Class> interfaceClass = beanField.getType();
// 获取 Bean 字段对应的实现类
Class> implementClass = findImplementClass(interfaceClass);
// 若存在实现类,则执行以下代码
if (implementClass != null) {
// 从 Bean Map 中获取该实现类对应的实现类实例
Object implementInstance = beanMap.get(implementClass);
// 设置该 Bean 字段的值
if (implementInstance != null) {
beanField.setAccessible(true); // 将字段设置为 public
beanField.set(beanInstance, implementInstance); // 设置字段初始值
} else {
throw new InitializationError("依赖注入失败!类名:" + beanClass.getSimpleName() + ",字段名:" + interfaceClass.getSimpleName());
}
}
}
}
}
}
} catch (Exception e) {
throw new InitializationError("初始化 IocHelper 出错!", e);
}
}
/**
* 查找实现类
*/
public static Class> findImplementClass(Class> interfaceClass) {
Class> implementClass = interfaceClass;
// 判断接口上是否标注了 Impl 注解
if (interfaceClass.isAnnotationPresent(Impl.class)) {
// 获取强制指定的实现类
implementClass = interfaceClass.getAnnotation(Impl.class).value();
} else {
// 获取该接口所有的实现类
List> implementClassList = ClassHelper.getClassListBySuper(interfaceClass);
if (CollectionUtil.isNotEmpty(implementClassList)) {
// 获取第一个实现类
implementClass = implementClassList.get(0);
}
}
// 返回实现类对象
return implementClass;
}
}
搭建zookeeper伪集群
1.在~/cluster/zookeeper目录下,安装3份zookeeper程序副本,分别命名为server1,server2,server3
2.执行以下命令。
cp server1/conf/zoo_sample.cfg server1/conf/zoo.cfg
3.在zoo.cfg文件中添加如下命令
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/abc/cluster/zookeeper/data/server1/data
dataLogDir=/home/abc/cluster/zookeeper/data/server1/log
clientPort=2181
server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890
4.因为是伪集群,故另外两份必须如下设置。
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/abc/cluster/zookeeper/data/server2/data
dataLogDir=/home/abc/cluster/zookeeper/data/server2/log
clientPort=2182
server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/abc/cluster/zookeeper/data/server3/data
dataLogDir=/home/abc/cluster/zookeeper/data/server3/log
clientPort=2183
server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890
5.执行余下这些命令
mkdir -p /home/abc/cluster/zookeeper/data/server1/data
mkdir -p /home/abc/cluster/zookeeper/data/server2/data
mkdir -p /home/abc/cluster/zookeeper/data/server3/data
echo "1" > /home/abc/cluster/zookeeper/data/server1/data/myid
echo "2" > /home/abc/cluster/zookeeper/data/server2/data/myid
echo "3" > /home/abc/cluster/zookeeper/data/server3/data/myid
6.启动集群
cd ~/cluster/zookeeper
server1/bin/zkServer.sh start
server2/bin/zkServer.sh start
server3/bin/zkServer.sh start
原来一直误会了四层和七层的含义。
四层负载均衡指的是负载均衡设备通过报文中的目标IP地址和端口负载均衡算法,选择到达目的的内部服务器;
七层负载均衡,也被称为“内容交换”,指的是负载均衡设备通过报文中的应用层信息(URL、HTTP头部等信息)和负载均衡算法,选择到达目的的内部服务器。
在IDEA中使用Tomcat调试Web项目
1.创建项目使用org.apache.maven.archetype:maven-archetype-webapp 如下。
2.在pom.xml中加入Tomcat7的插件
webapi
org.apache.tomcat.maven
tomcat7-maven-plugin
2.1
8080
/
UTF-8
tomcat7
3.在配置中的命令行中选择,tomcat7:run项。
4.在run菜单中启用调试。
5.其它方式调试
proxy代理工具
具有MOCK数据功能的代理Proxy工具如下:
1.http://anyproxy.io/cn/这个是阿里的开源,最大特色是支持非桌面服务器部署。
2.fiddler
zkclient和curator开源
开源的两个zookeeper的客户端,简化了程序员的开发工具。
开源客户端,原生api的不足
连接的创建是异步的,需要开发人员自行编码实现等待
连接没有自动的超时重连机制
Zk本身没提供序列化机制,需要开发人员自行指定,从而实现数据的序列化和反序列化
Watcher注册一次只会生效一次,需要不断的重复注册
Watcher的使用方式不符合java本身的术语,如果采用监听器方式,更容易理解
不支持递归创建树形节点
开源客户端—ZkClient介绍
Github上一个开源的zk客户端,由datameer的工程师Stefan Groschupf和Peter Voss一起开发
– 解决session会话超时重连
– Watcher反复注册
– 简化开发api
– 还有…..
– https://github.com/sgroschupf/zkclient
开源客户端—Curator介绍
1. 使用CuratorFrameworkFactory工厂的两个静态方法创建客户端
a) static CuratorFramework newClient(String connectString, int sessionTimeoutMs, int connectionTimeoutMs,
RetryPolicy retryPolicy)
b) static CuratorFramework newClient(String connectString, RetryPolicy retryPolicy)
2. Start()方法启动
参数说明
connectString 分开的ip:port对
retryPolicy 重试策略,默认四种:Exponential BackoffRetry,RetryNTimes ,RetryOneTime,
RetryUntilElapsed
sessionTimeoutMs 会话超时时间,单位为毫秒,默认60000ms
connectionTimeoutMs 连接创建超时时间,单位为毫秒,默认是15000ms
CAP定理
2000年7月加州大学伯克利分校Eric Brewer教授首次提出了CAP猜想,并成为分布式计算领域的公认定理。该定理认为一个分布式系统不可能同时满足一致性(C:Consistency),可用性(A:Availability)和分区容错性(P:Partition Tolerance),这三个基本需求,最多只能满足其中两项。
五种一致性
推荐书籍:从PAXOS到ZOOKEEPER分布式一致性原理与实践,
链接:http://pan.baidu.com/s/1bpabUxh 密码:1v91
zookeeper的简单例子
import org.apache.zookeeper.*;
import org.apache.zookeeper.ZooDefs.Ids;
import org.apache.zookeeper.data.Stat;
import java.util.concurrent.CountDownLatch;
class DataMonitor implements Watcher, AsyncCallback.StatCallback{
public ZooKeeper zk = null;
private int i = 0;
public int iexistcheck = 0;
public DataMonitor(){
}
public void process(WatchedEvent event) {
String path = event.getPath();
System.out.println("process: iexistcheck="+iexistcheck+" - "+"i:="+i+",path:"+path+" - state:" + event.getState());
i++;
}
public void processResult(int rc, String path, Object ctx, Stat stat) {
System.out.println("processResult.1:iexistcheck="+iexistcheck+" - "+"i:="+i+",rc:" + rc + " - path:"+path+" - state:" + stat);
try {
System.out.println("processResult.2.getData:iexistcheck="+iexistcheck+" - "+"i:="+i+" - "+new String(zk.getData("/test", false, null)));
}catch (Exception e){
System.out.print("processResult.3:exception.....iexistcheck="+iexistcheck+" - "+"i:="+i);
}finally {
System.out.println("processResult.4:iexistcheck="+iexistcheck+" - "+"i:="+i+",end......end......end..");
}
}
}
public class ZooKeeperTest {
private static CountDownLatch downLatch = new CountDownLatch(1);
private static final int TIME_OUT = 300000;
private static final String HOST = "localhost:2181";
public static void main(String[] args) throws Exception{
DataMonitor dm = new DataMonitor();
ZooKeeper zookeeper = new ZooKeeper(HOST, TIME_OUT, dm);
dm.zk = zookeeper;
zookeeper.exists("/test", true, dm, dm);
Stat stat = null;
for(int i = 0; i < 30; i++){
String buf = "value="+i;
System.out.println("loop i="+i);
if(zookeeper.exists("/test", false) == null)
{
//PERSISTENT_SEQUENTIAL模式情况下,真正路径是从返回值获取。其格式为/test0000000028。
//EPHEMERAL模式下,该节点是临时节点,当超时或session断开时,它也跟随着消失。适合检验机器岩机与否等状态。防单点或执备切换等。
String node_real = zookeeper.create("/test", "znode1".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
System.out.println("nodename:"+node_real);
}
//第三个参数为版本号,当前输入的版本号与目标版本的版本号是相同的情况,才能更新到数据。否则会更新失败。
if(stat == null){
stat = zookeeper.setData(node_real, buf.getBytes() , -1);
}else{
stat = zookeeper.setData(node_real, buf.getBytes() , stat.getVersion());
}
System.out.println("Czxid:" + stat.getCzxid() + " - Mzxid:" + stat.getMzxid() + " - Version:" + stat.getVersion());
if(i > 5){
if(i % 3 == 0){
dm.iexistcheck = i;
zookeeper.exists("/test", true, dm, dm);
}
}
Thread.sleep(1000);
}
zookeeper.delete("/test", -1);
Thread.sleep(5000);
zookeeper.close();
}
}
org.apache.zookeeper
zookeeper
3.4.8
com.sun.jmx
jmxri
com.sun.jdmk
jmxtools
javax.jms
jms
loop i=0 process: iexistcheck=0 - i:=0,path:null - state:SyncConnected processResult.1:iexistcheck=0 - i:=1,rc:-101 - path:/test - state:null processResult.3:exception.....iexistcheck=0 - i:=1processResult.4:iexistcheck=0 - i:=1,end......end......end.. process: iexistcheck=0 - i:=1,path:/test - state:SyncConnected Czxid:1055 - Mzxid:1056 - Version:1 loop i=1 Czxid:1055 - Mzxid:1057 - Version:2 loop i=2 Czxid:1055 - Mzxid:1058 - Version:3 loop i=3 Czxid:1055 - Mzxid:1059 - Version:4 loop i=4 Czxid:1055 - Mzxid:1060 - Version:5 loop i=5 Czxid:1055 - Mzxid:1061 - Version:6 loop i=6 Czxid:1055 - Mzxid:1062 - Version:7 processResult.1:iexistcheck=6 - i:=1,rc:0 - path:/test0000000029 - state:1055,1062,1480343483194,1480343489294,7,0,0,0,7,0,1055 processResult.2.getData:iexistcheck=6 - i:=1 - value=6 processResult.4:iexistcheck=6 - i:=1,end......end......end.. loop i=7 process: iexistcheck=6 - i:=1,path:/test0000000029 - state:SyncConnected Czxid:1055 - Mzxid:1063 - Version:8 loop i=8 Czxid:1055 - Mzxid:1064 - Version:9 loop i=9 Czxid:1055 - Mzxid:1065 - Version:10 processResult.1:iexistcheck=9 - i:=2,rc:0 - path:/test0000000029 - state:1055,1065,1480343483194,1480343492344,10,0,0,0,7,0,1055 processResult.2.getData:iexistcheck=9 - i:=2 - value=9 processResult.4:iexistcheck=9 - i:=2,end......end......end..
高性能PHP架构套件
新浪网站在升级PHP7时,大量使用了以下组件系统。
Yaf: PHP Framework in PHP extension
Yar: Light, concurrent RPC framework
Yac: PHP Contents cache