??xml version="1.0" encoding="utf-8" standalone="yes"?>日本午夜精品久久久久,欧美高清性hdvideosex,国产成人小视频http://www.aygfsteel.com/shijian/archive/2013/07/06/378641.html矛_ | Fat Mind矛_ | Fat MindSat, 06 Jul 2013 06:57:00 GMThttp://www.aygfsteel.com/shijian/archive/2013/07/06/378641.htmlhttp://www.aygfsteel.com/shijian/comments/378641.htmlhttp://www.aygfsteel.com/shijian/archive/2013/07/06/378641.html#Feedback0http://www.aygfsteel.com/shijian/comments/commentRss/378641.htmlhttp://www.aygfsteel.com/shijian/services/trackbacks/378641.html

http://incubator.apache.org/kafka/design.html

1.Why we built this
    asdQactivity stream dataQ数据是M|站的一部分Q反映网站用情况,如:那些内容被搜索、展C。通常Q此部分数据被以log方式记录在文Ӟ然后定期的整合和分析。odQoperation dataQ是关于机器性能数据Q和其它不同途径整合的操作数据?br />     在近几年Qasd和od变成一个网站重要的一部分Q更复杂的基设施是必ȝ?br />      数据特点Q?br />         a、大吞吐量的不变的adQ对实时计算是一个挑战,会很Ҏ(gu)过10倍or100倍?/span> 
        b、传l的记录log方式?span class="Apple-style-span" style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; color: #000000; ">respectable and scalable方式L持离U处理,但是延迟太高?br />
    Kafka is intended to be a single queuing platform that can support both offline and online use cases.

2.Major Design Elements

There is a small number of major design decisions that make Kafka different from most other messaging systems:

  1. Kafka is designed for persistent messages as the common caseQ?span class="Apple-style-span" style="font-size: 14px; ">消息持久
  2. Throughput rather than features are the primary design constraintQ?span class="Apple-style-span" style="font-size: 14px; ">吞吐量是W一要求
  3. State about what has been consumed is maintained as part of the consumer not the serverQ?span class="Apple-style-span" style="font-size: 14px; ">状态由客户端维?/span>
  4. Kafka is explicitly distributed. It is assumed that producers, brokers, and consumers are all spread over multiple machinesQ?span class="Apple-style-span" style="font-size: 14px; ">必须是分布式
3.Basics
    Messages are the fundamental unit of communicationQ?br />     Messages are
 published to a topic by a producer which means they are physically sent to a server acting as a brokerQ消息被生者发布到一个topicQ意味着物理的发送消息到brokerQ?br />     多个consumer订阅一个topicQ则此topic的每个消息都会被分发到每个consumerQ?br />     kafka是分布式Qproducer、broker、consumerQ均可以由集的多台机器l成Q相互协?a logic groupQ?br />     属于同一个consumer group的每一个consumer processQ每个消息能准确的由其中的一个process消费Q?span class="Apple-style-span" style="color: #222222; font-family: Arial, sans-serif; font-size: 15px; line-height: 22px; ">A more common case in our own usage is that we have multiple logical consumer groups, each consisting of a cluster of consuming machines that act as a logical whole.
    kafka不管一个topic有多个consumerQ其消息仅会存储一份?br />
4.Message Persistence and Caching

4.1 Don't fear the filesystem !
    kafka完全依赖文gpȝd储和cache消息Q?br />     大家通常对磁盘的直觉?很慢'Q则使h们对持久化结构,是否能提供有竞争力的性能表示怀疑;实际上,盘到底有多慢或多块Q完全取决于如何使用盘Q?span class="Apple-style-span" style="color: #222222; font-family: Arial, sans-serif; font-size: 15px; line-height: 22px; ">a properly designed disk structure can often be as fast as the network.
    http://baike.baidu.com/view/969385.htm raid-5 
    http://www.china001.com/show_hdr.php?xname=PPDDMV0&dname=66IP341&xpos=172 盘U类
    盘序d的性能非常高, linear writes on a 6 7200rpm SATA RAID-5 array is about 300MB/secQ?/span>These linear reads and writes are the most predictable of all usage patterns, and hence the one detected and optimized best by the operating system using read-ahead and write-behind techniques。顺序读写是最可预见的模式Q因此操作系l通过read-head和write-behind技术去优化?br />     C操作pȝQ用mem作ؓdisk的cacheQAny modern OS will happily divert all free memory to disk caching with little performance penalty when the memory is reclaimed. All disk reads and writes will go through this unified cache. 
    JvmQa、对象的内存开销是非常大的,通常是数据存储的2倍;b、当heap数据增大Ӟgc代h(hun)来大Q?/span>
    As a result of these factors using the filesystem and relying on pagecache is superior to maintaining an in-memory cache or other structure。依赖文件系l和pagecache是优于mem cahce或其它结构的?/span>
    数据压羃QDoing so will result in a cache of up to 28-30GB on a 32GB machine without GC penalties. 
    This suggests a design which is very simple: maintain as much as possible in-memory and flush to the filesystem only when necessary. 可能的l持在内存中Q仅当必L写回到文件系l?
    当数据被立即写回到持久化的文Ӟ而未调用flushQ其意味着数据仅被写入到os pagecaheQ在后箋某个旉由os flush。Then we add a configuration driven flush policy to allow the user of the system to control how often data is flushed to the physical disk (every N messages or every M seconds) to put a bound on the amount of data "at risk" in the event of a hard crash. 提供flush{略?/span>

4.2 
Constant Time Suffices
    
The persistent data structure used in messaging systems metadata is often a BTree. BTrees are the most versatile data structure available, and make it possible to support a wide variety of transactional and non-transactional semantics in the messaging system.
    Disk seeks come at 10 ms a pop, and each disk can do only one seek at a time so parallelism is limited. Hence even a handful of disk seeks leads to very high overhead. 
    Furthermore BTrees require a very sophisticated page or row locking implementation to avoid locking the entire tree on each operation.
The implementation must pay a fairly high price for row-locking or else effectively serialize all reads.
    持久化消息的元数据通常是BTreel构Q但盘l构Q其代h(hun)太大。原因:寻道、避免锁整棵树?br />     
Intuitively a persistent queue could be built on simple reads and appends to files as is commonly the case with logging solutions.
    持久化队列可以构建在dappend to 文g。所以不支持BTree的一些语义,但其好处是:O(1)消耗,无锁d?br />     
the performance is completely decoupled from the data size--one server can now take full advantage of a number of cheap, low-rotational speed 1+TB SATA drives. 
Though they have poor seek performance, these drives often have comparable performance for large reads and writes at 1/3 the price and 3x the capacity.

4.3 Maximizing Efficiency
    Furthermore we assume each message published is read at least once (and often multiple times), hence we optimize for consumption rather than production. 更进一步,我们假设被发布的消息臛_会读一ơ,因此优化consumer优先于producer?br />     
There are two common causes of inefficiency :
        two many network requests, Q?
 APIs are built around a "message set" abstractionQ?
This allows network requests to group messages together and amortize the overhead of the network roundtrip rather than sending a single message at a time.Q?仅提供批量操作apiQ则每次|络开销是^分在一l消息,而不是单个消息?br />     and excessive byte copying.Q?
The message log maintained by the broker is itself just a directory of message sets that have been written to disk.
Maintaining this common format allows optimization of the most important operation : network transfer of persistent log chunks.Q?br />     To understand the impact of sendfile, it is important to understand the common data path for transfer of data from file to socket:
  1. The operating system reads data from the disk into pagecache in kernel space
  2. The application reads the data from kernel space into a user-space buffer
  3. The application writes the data back into kernel space into a socket buffer
  4. The operating system copies the data from the socket buffer to the NIC buffer where it is sent over the network
    利用os提供的zero-copyQ?
only the final copy to the NIC buffer is needed.

4.4 End-to-end Batch Compression
    In many cases the bottleneck is actually not CPU but network. This is particularly true for a data pipeline that needs to send messages across data centers.
Efficient compression requires compressing multiple messages together rather than compressing each message individually. 
Ideally this would be possible in an end-to-end fashion — that is, data would be compressed prior to sending by the producer and remain compressed on the server, only being decompressed by the eventual consumers. 
    
A batch of messages can be clumped together compressed and sent to the server in this form. This batch of messages will be delivered all to the same consumer and will remain in compressed form until it arrives there.
    理解Qkafka 
producer api 提供扚w压羃Qbroker不对此批消息做Q何操作,且以压羃的方式,一赯发送到consumer?br />
4.5 Consumer state
    Keeping track of what has been consumed is one of the key things a messaging system must provide. 
State tracking requires updating a persistent entity and potentially causes random accesses. 
    
Most messaging systems keep metadata about what messages have been consumed on the broker. That is, as a message is handed out to a consumer, the broker records that fact locally. 大部分消息系l,存储是否被消费的元信息在broker。则是说Q一个消息被分发C个consumerQbroker记录?br />     问题Q当consumer消费p|后,会导致消息丢失;改进Q每ơconsumer消费后,lbroker ackQ若broker在超时时间未收到ackQ则重发此消息?br />     问题Q?.当消Ҏ(gu)功,但未ackӞ会导致消?? 2.
 now the broker must keep multiple states about every single message  3.当broker是多台机器时Q则状态之间需要同?br />
4.5.1 Message delivery semantics
    
So clearly there are multiple possible message delivery guarantees that could be provided : at most once 、at least once、exactly once?br />     
This problem is heavily studied, and is a variation of the "transaction commit" problem. Algorithms that provide exactly once semantics exist, two- or three-phase commits and Paxos variants being examples, but they come with some drawbacks. They typically require multiple round trips and may have poor guarantees of liveness (they can halt indefinitely). 
    消费分发语义Q是 ‘事务提交’ 问题的变U。算法提?exactly onece 语义Q两阶段 or 三阶D|交,paxos 均是例子Q但它们存在~点。典型的问题是要求多ơround tripQ且
poor guarantees of liveness?br />     
Kafka does two unusual things with respect to metadata. 
First the stream is partitioned on the brokers into a set of distinct partitions. 
Within a partition messages are stored in the order in which they arrive at the broker, and will be given out to consumers in that same order. This means that rather than store metadata for each message (marking it as consumed, say), we just need to store the "high water mark" for each combination of consumer, topic, and partition.  
    
4.5.2 
Consumer state
    In Kafka, the consumers are responsible for maintaining state information (offset) on what has been consumed. 
Typically, the Kafka consumer library writes their state data to zookeeper.
    
This solves a distributed consensus problem, by removing the distributed part!
    
There is a side benefit of this decision. A consumer can deliberately rewind back to an old offset and re-consume data.

4.5.3 Push vs. pull
    
A related question is whether consumers should pull data from brokers or brokers should push data to the subscriber.
There are pros and cons to both approaches.
    However a push-based system has difficulty dealing with diverse consumers as the broker controls the rate at which data is transferred. push目标是consumer能在最大速率L费,可不q的是,当consume速率于生速率Ӟthe consumer tends to be overwhelmed?br />     
A pull-based system has the nicer property that the consumer simply falls behind and catches up when it can. This can be mitigated with some kind of backoff protocol by which the consumer can indicate it is overwhelmed, but getting the rate of transfer to fully utilize (but never over-utilize) the consumer is trickier than it seems. Previous attempts at building systems in this fashion led us to go with a more traditional pull model.  不存在push问题Q且也保证充分利用consumer能力?br />
5. Distribution
    Kafka is built to be run across a cluster of machines as the common case. There is no central "master" node. Brokers are peers to each other and can be added and removed at anytime without any manual configuration changes. Similarly, producers and consumers can be started dynamically at any time. Each broker registers some metadata (e.g., available topics) in Zookeeper. Producers and consumers can use Zookeeper to discover topics and to co-ordinate the production and consumption. The details of producers and consumers will be described below.

6. Producer

6.1 Automatic producer load balancing
    Kafka supports client-side load balancing for message producers or use of a dedicated load balancer to balance TCP connections. 
 
    The advantage of using a level-4 load balancer is that each producer only needs a single TCP connection, and no connection to zookeeper is needed. 
The disadvantage is that the balancing is done at the TCP connection level, and hence it may not be well balanced (if some producers produce many more messages then others, evenly dividing up the connections per broker may not result in evenly dividing up the messages per broker).
    
Client-side zookeeper-based load balancing solves some of these problems. It allows the producer to dynamically discover new brokers, and balance load on a per-request basis. It allows the producer to partition data according to some key instead of randomly.

    The working of the zookeeper-based load balancing is described below. Zookeeper watchers are registered on the following events—

  • a new broker comes up
  • a broker goes down
  • a new topic is registered
  • a broker gets registered for an existing topic

    Internally, the producer maintains an elastic pool of connections to the brokers, one per broker. This pool is kept updated to establish/maintain connections to all the live brokers, through the zookeeper watcher callbacks. When a producer request for a particular topic comes in, a broker partition is picked by the partitioner (see section on semantic partitioning). The available producer connection is used from the pool to send the data to the selected broker partition.
    producer通过zkQ管理与broker的连接。当一个请求,Ҏ(gu)partition rule 计算分区Q从q接池选择对应的connectionQ发送数据?br />
6.2 Asynchronous send

    Asynchronous non-blocking operations are fundamental to scaling messaging systems.
    
This allows buffering of produce requests in a in-memory queue and batch sends that are triggered by a time interval or a pre-configured batch size. 

6.3 Semantic partitioning
    
The producer has the capability to be able to semantically map messages to the available kafka nodes and partitions. 
This allows partitioning the stream of messages with some semantic partition function based on some key in the message to spread them over broker machines. 




矛_ | Fat Mind 2013-07-06 14:57 发表评论
]]>
Jsl习Q操Ucookiehttp://www.aygfsteel.com/shijian/archive/2012/09/09/387339.html矛_ | Fat Mind矛_ | Fat MindSun, 09 Sep 2012 07:18:00 GMThttp://www.aygfsteel.com/shijian/archive/2012/09/09/387339.htmlhttp://www.aygfsteel.com/shijian/comments/387339.htmlhttp://www.aygfsteel.com/shijian/archive/2012/09/09/387339.html#Feedback0http://www.aygfsteel.com/shijian/comments/commentRss/387339.htmlhttp://www.aygfsteel.com/shijian/services/trackbacks/387339.html1.Js代码Qlogin.js文g

//用户的登陆信息写入cookies
function SetCookie(form)//两个参数Q一个是cookie的名子,一个是?/span>
{   
    var name = form.name.value;
    var password = form.password.value;
    var Days = 1; //?nbsp;cookie 被保存 7 ?nbsp;
    var exp  = new Date(); //生成一个现在的日期Q加上保存期限,然后讄cookie的生存期限!
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = "user="+ escape(name) + "/" + escape(password) + ";expires=" + exp.toGMTString();
}
//取cookies函数--正则表达?不会Q学习正则表辑ּ)  
function getCookie(name)      
{
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
    if(arr != nullreturn unescape(arr[2]); 
    return null;
}
//取cookies函数--普通实?nbsp;     
  function   readCookie(form){   
      var   cookieValue   =   "";   
      var   search   =   "user=";   
      if(document.cookie.length   >   0)     {   
          offset   =   document.cookie.indexOf(search);
          if(offset !=  -1){     
              offset   +=   search.length;   
              end   =   document.cookie.indexOf(";",offset);   
              if   (end  ==  -1)   
                    end   =   document.cookie.length;
              //获取cookies里面的?nbsp;         
              cookieValue   =   unescape(document.cookie.substring(offset,end))
              if(cookieValue != null){
                    var str = cookieValue.split("/");
                    form.name.value = str[0];
                    form.password.value = str[1]; 
              }
          }   
      }    
  }   
//删除cookieQ(servlet里面Q设|时间ؓ0Q设|ؓ-1和session的范围是一LQ,javascript好像是有点区?/span>
function delCookie()
{
    var name = "admin";
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}

 

2.jsp代码Q文件login.jsp

<%@ page contentType="text/html; charset=gb2312" language="java"
    import="java.sql.*" errorPage=""%>
    
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
        <title>javascript 控制 cookie</title>
        <link href="css/style.css" rel="stylesheet" type="text/css">
        <script type="text/javascript" src="js/login.js"></script>
    </head>
    <script language="javascript">
    function checkEmpty(form){
        for(i=0;i<form.length;i++){
            if(form.elements[i].value==""){
                alert("表单信息不能为空");
                return false;
            }
        }
    }
</script>
    <body onload="readCookie(form)"> <!-- 作ؓJavaScript控制的cookie-->
        <div align="center">
            <table width="324" height="225" border="0" cellpadding="0" cellspacing="0">
                <tr height="50">
                    <td ></td>
                </tr>
                <tr align="center">
                    <td background="images/back.jpg">
                        <br>
                        <br>
                        登陆
                        <form name="form" method="post" action="" onSubmit="return checkEmpty(form)">
                            <input type="hidden" name="id" value="-1">
                            <table width="268" border="1" cellpadding="0" cellspacing="0">
                                <tr align="center">
                                    <td width="63" height="30">
                                        用户名:
                                    </td>
                                    <td width="199">
                                        <input type="text" name="name" id="name">
                                    </td>
                                </tr>
                                <tr align="center">
                                    <td height="30">
                                        密码Q?br />                                    </td>
                                    <td>
                                        <input type="password" name="password" id="password">
                                    </td>
                                </tr>
                            </table>
                            <br>
                            <input type="submit" value="提交">
                            <input type="checkbox" name="cookie" onclick="SetCookie(form)">C?nbsp;         
                        </form>
                    </td>
                </tr>
            </table>
        </div>
    </body>
</html>

 


目的Q当你再ơ打开login.jsp面Q表单里面的内容已经写好了,是你上一ơ的登陆信息Q?/p>


问题Q?.JavaScript里面取cookie都是写死的,不是很灵z!
            2.JavaScript的cookie是按照字W串的Ş式存攄Q所以拿出的时候,你要按照你放q去的Ş式来选择Q?/div>
            3.本来是想实现自动登陆的,可我的每个页面都要session的检查!一个客LQ一个服务器端,没能实现Q?/div>

 

 



矛_ | Fat Mind 2012-09-09 15:18 发表评论
]]>单元试利器 ?powermock [使用结]http://www.aygfsteel.com/shijian/archive/2012/03/29/371819.html矛_ | Fat Mind矛_ | Fat MindThu, 29 Mar 2012 04:39:00 GMThttp://www.aygfsteel.com/shijian/archive/2012/03/29/371819.htmlhttp://www.aygfsteel.com/shijian/comments/371819.htmlhttp://www.aygfsteel.com/shijian/archive/2012/03/29/371819.html#Feedback0http://www.aygfsteel.com/shijian/comments/commentRss/371819.htmlhttp://www.aygfsteel.com/shijian/services/trackbacks/371819.html官方 Q?a >http://code.google.com/p/powermock/ 

1. 使用mockito的同学,推荐阅读如下部分

    - document [必选]
        - getting started
        - motavition
    - mockito extends [必选]
        - mockito 1.8+ useage
    - common
    - tutorial
    - faq [必选]


2. 附gQ实际开发中使用到的
powermock的一些特性,化后的例子(仅ؓ说明powermock api使用Q?/span>。主要包?/span> Q?/span>

 

-          修改U有?/span>

-          U有Ҏ(gu)

-            试U有Ҏ(gu)

-            Mock

-            Verify

-          静态方?/span>

-            Mock

-            抛出异常

-            Verify

-          Mockc部分方?/span>

-          Mock Java core libraryQ如Q?/span>Thread

-          Mock 构造器

/Files/shijian/powermock.rar





矛_ | Fat Mind 2012-03-29 12:39 发表评论
]]>
Annotation一Ҏ(gu)ȝhttp://www.aygfsteel.com/shijian/archive/2011/06/25/353002.html矛_ | Fat Mind矛_ | Fat MindSat, 25 Jun 2011 12:09:00 GMThttp://www.aygfsteel.com/shijian/archive/2011/06/25/353002.htmlhttp://www.aygfsteel.com/shijian/comments/353002.htmlhttp://www.aygfsteel.com/shijian/archive/2011/06/25/353002.html#Feedback0http://www.aygfsteel.com/shijian/comments/commentRss/353002.htmlhttp://www.aygfsteel.com/shijian/services/trackbacks/353002.htmlAnnotation

 

题记Q徏议关?/span>spring问题Q请记得查看spring reference?/span>

 

一?/span>annotation前生后世

Annotations do not directly affect program semantics, but they do affect the way programs are treated by tools and libraries, which can in turn affect the semantics of the running program. Annotations can be read from source files, class files, or reflectively at run time.

译:annotation不会直接影响E序的语义,xxx?/span>Annotation可以从源文g?/span>class文g、通过反射在运行时d?/span>

 

参考:http://www.developer.com/print.php/3556176

1.       定义

Annotation type declarations are similar to normal interface declarations. An at-sign (@) precedes the interface keyword. Each method declaration defines an element of the annotation type. Method declarations must not have any parameters or a throws clause. Return types are restricted to primitives, StringClassenums, annotations, and arrays of the preceding types. Methods can have default values.

Annotation声明与普通的interface非常怼Q在关键?/span>interface前加@。每一个方法的声明定义一?/span>annotation的元素。方法不能有M的参数或throws异常。返回类型被限制为:原始cd?/span>String?/span>Class?/span>enum?/span>annotation、前面描q的cdl成的数l?/span>method定义允许有默认倹{?/span>

 

2.       Java annotation

There are two types of annotations available with JDK5:

1Q?nbsp;Simple annotations: These are the basic types supplied with Tiger, which you can use to annotate your code only; you cannot use those to create a custom annotation type.

三个基本?/span>annotationQ如Q?/span>Override?/span>Deprecated?/span>SuppresswarningsQ不能用它d义新?/span>annotation?/span>

2Q?nbsp;Meta annotations: These are the annotation types designed for annotating annotation-type declarations. Simply speaking, these are called the annotations-of-annotations.

?/span>annotationQ定?/span>annotation的类型。如Q?/span>Target?/span>Retention?/span>Documented?/span>Inherited?/span>

A.      TargetQ声?/span>annotation注解的目标类型。如@Target(ElementType.TYPE)?/span>@Target(ElementType.METHOD)

B.      RetentionQ声?/span>annotation被保留的长度。如Q?/span>RetentionPolicy.SOURCE?/span>RetentionPolicy.CLASS?/span>RetentionPolicy.RUNTIME

C.      DocumentedQ声明被注解?/span>target生成doc是否需要显C?/span>annotation信息?/span>

D.      InheritedQ?/span>xxx

 

3.       annotation作用

aQ?nbsp;不媄响程序原本语义的情况下,增加信息+工具=声明式编E。如Q?/span>spring aop

bQ?nbsp;~译?/span> Q?/span>

 

 

二、利?/span>annotation实现aop

1. 思\

AQ自定义注解定义规则Q何时执行)

BQ标记行为(执行什么)

CQ通过反射生成代理Q在对象执行MҎ(gu)Ӟq行拦截判断是否W合规则Q若W合Q执行对应的行ؓ?/span>

2. 例子

场景Q一个表演家Q表演节目后Q观众拍手鼓?/span>

原始Q表演家拥有所有观众的引用Q在自己表演完后Q通知观众鼓掌

问题Q表演家应该x表演自n的事情,有哪些观众、观众是否鼓掌,不是其所x?/span>

改进Q?/span>AOP方式Q表演家仅关注表演,观众鼓掌由其它h负责

ȝQ?/span>

面向切面~程 (AOP) 提供从另一个角度来考虑E序l构以完善面向对象编E(OOPQ?/span> 面向对象应用程序分解成各个层次的对象,?/span>AOP程序分解成各个切面或者说x炏V这使得可以模块化诸如事务管理等q些横切多个对象的关注点?/span>

 

三?/span>spring aop如何使用annotation

1. 基本方式Q通过ProxyFactoryBean

aQ通知

bQ切入点

bQ通知+切入?/span> à 切面

cQ实际对?/span>+接口+切面 à 接口代理Q)

2. 自动代理方式Q?/span>

基本方式的问题是Q?/span>xml配置文gJ琐?/span>

1Q基?/span>spring上下文的通知?/span>Bean的自动代理(利用PostBeanProcessor Q)

BeanNameAutoProxyCreatorQ有属性:beanNamesQ被代理对象Q?/span>interceptorNamesQ通知Q。自动代?/span>beanNames指定?/span>beanQ此?/span>interceptorNames指定通知Q但interceptor需要实现特定的接口Q如Q?/span>MethodBeforeAdvice?/span>

2Q?nbsp;ZaspectJ注解驱动

使用aspectJ风格的注解。原理:生成代理Q仅Ҏ(gu)U别。?/span>AspectJ 提供的一个库来做切点Q?/span>pointcutQ解析和匚w?/span>

4.       <aop:config>Q优点:Mc都能{化ؓ切面Q不需要特D接口或注解Q原?/span>pojo对象

5.       aop参数传递,见:spring reference 6.3.3.6 通知参数

aQ?nbsp;around切点Q必M?/span>ProceedingJoinPoint参数Q通过ProceedingJoinPoint取得Ҏ(gu)的所有信息?/span>

bQ?nbsp;其它切点Q利?/span>JoinPoint取得Ҏ(gu)的所有参数?/span>

cQ?nbsp;通过参数名绑定传递参敎ͼ未理?/span>?/span>

 

 

四?/span>annotation相关技?/span>

1. cglib

它的原理是?/span>Enhancer生成一个原有类的子c,q且讄?/span>callback?/span>proxyQ?/span> 则原有类的每个方法调用都会{用实CMethodInterceptor接口?/span>proxy?/span>intercept() 函数?/span>

2.  asm

ASM is an all purpose Java bytecode manipulation and analysis framework. It can be used to modify existing classes or dynamically generate classes, directly in binary form. Provided common transformations and analysis algorithms allow to easily assemble custom complex transformations and code analysis tools.

ASM offer similar functionality as other bytecode frameworks, but it is focused on simplicity of use and performance. 

单理?/span>asm是比cglib更高U的code generate lib?/span>

 

五?/span>others问题

1. Generics 

Generics - This long-awaited enhancement to the type system allows a type or method to operate on objects of various types while providing compile-time type safety. It adds compile-time type safety to the Collections Framework and eliminates the drudgery of casting. See theGenerics Tutorial. (JSR 14)

泛型提供了编译时cd查安全。这点很重要?/span> Q?/span>

 

2. Z?/span>spring aop aspectJ anonotation?/span>pointcut声明Q必L解在Ҏ(gu)?/span> Q通过Ҏ(gu)唯一标识一?/span>pointcut Q?/span>

猜测Q?/span>@Pointcut?/span>Target属性指定仅?/span>method。方法签名成?/span>pointcut?/span>id?/span>

  

 



矛_ | Fat Mind 2011-06-25 20:09 发表评论
]]>
Reference思?/title><link>http://www.aygfsteel.com/shijian/archive/2010/12/18/341064.html</link><dc:creator>矛_ | Fat Mind</dc:creator><author>矛_ | Fat Mind</author><pubDate>Sat, 18 Dec 2010 08:52:00 GMT</pubDate><guid>http://www.aygfsteel.com/shijian/archive/2010/12/18/341064.html</guid><wfw:comment>http://www.aygfsteel.com/shijian/comments/341064.html</wfw:comment><comments>http://www.aygfsteel.com/shijian/archive/2010/12/18/341064.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/shijian/comments/commentRss/341064.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/shijian/services/trackbacks/341064.html</trackback:ping><description><![CDATA[     摘要:  一、Java数据cd   数据cd是对内存位|的抽象表达 Q很多编E语a都依赖于特定的计机cd和对数据cd属性的具体~译实现Q比如word和integer数据cd的大等QJava通过JVM保证数据所占存储空间的大小不会随硬件的改变发生变化Q? 1.   Primitive data type QA primiti...  <a href='http://www.aygfsteel.com/shijian/archive/2010/12/18/341064.html'>阅读全文</a><img src ="http://www.aygfsteel.com/shijian/aggbug/341064.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/shijian/" target="_blank">矛_ | Fat Mind</a> 2010-12-18 16:52 <a href="http://www.aygfsteel.com/shijian/archive/2010/12/18/341064.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Proxy学习http://www.aygfsteel.com/shijian/archive/2010/12/12/340380.html矛_ | Fat Mind矛_ | Fat MindSat, 11 Dec 2010 18:24:00 GMThttp://www.aygfsteel.com/shijian/archive/2010/12/12/340380.htmlhttp://www.aygfsteel.com/shijian/comments/340380.htmlhttp://www.aygfsteel.com/shijian/archive/2010/12/12/340380.html#Feedback0http://www.aygfsteel.com/shijian/comments/commentRss/340380.htmlhttp://www.aygfsteel.com/shijian/services/trackbacks/340380.html题记Q很镉K没有学到q个旉啦,怀念大三?/em>

一、摘?/span>

1.       什么是“代理”

2.       代理模式与适配器模式、装饰者模式的区别Q适用场景

3.       手工代理

4.       动态代理的原理

 

二、什么是“代理”

       如:一?/span>CEOQ会有一个助理,M需?/span>CEO处理的事情,都会l过助理qo、整理后交给CEO。助理就?/span>CEO的代理?/span>

       自己理解Q代理就是ؓ帮实际的执行者,做数据的qo和控Ӟ为实际执行者屏蔽掉外部其它因素的媄响,专心d应该做的事情?/span>

 

三、代理模式与适配器模式、装饰者模式的区别Q适用场景

1、代理模?/span>

HeadFirst 定义Qؓ另一个对象提供一个替w或占位W以控制对这个对象的讉K?br />

如上图,代理模式的结构?/span>

适用的场景,如:q程讉K、访问权限控制、日志记录等?br />

装饰者模式,IOcdl构如下Q?/span>



可以?/span>OutputStream à FileOutputStream à BufferedOutputStreamQ功能依ơ增强,为对象增加更多的行ؓ?/span>

自己理解Q目的不一P代理是ؓ控制对被代理对象的访问;装饰者,是对被装饰者功能的增强Q避免过度用承实C同的功能?/span>

 

适配器模式,其区别从cd卛_分L出来Q如?/span> Q?br />


ClienthExecuteClassQ但ExecuteClass暴露的接口不W合client的要求,在双方系l都不修改的情况下,利用适配器模式解x问题?br />

三、手工代?br />


场景Q根?/span>idQ获?/span>ItemQ代理检查用L权限是否有权限查?/span>ItemQ已l记?/span>log日志。具体代码很Ҏ(gu)实现?br />

四、动态代?/span>

对上面的场景Q如果用动态代理,步骤Q?/span>

1. Ҏ(gu)interfaceQ通过loaderQ生?/span>Class对象

Class clazz = Proxy.getProxyClass(ItemService.class.getClassLoader(), ItemService.class);

2. 通过反射Q获?/span>Class对象?/span>Construct对象Q注意:Construct对象需要的参数cdQ?/span>

Constructor c = clazz.getConstructor(InvocationHandler.class);

3. 调用Construct对象 newInstance()生成实例对象

proxy = (ItemService)c.newInstance(this); //this?/span>InvocationHandler实例

 

思考问题:实现原理是什?/span> Q?/span>



 

对于上面场景Q实际动态生成的代理的类图。对代理的Q何调用都会,super.handle.invoke()Q用户实?/span>InvocationHandlerQ覆?/span>invokeҎ(gu)Q实现基于方法的控制?/span>

从类图,也解释了Z么只能实?#8220;接口”的动态代理,因ؓ代理本n需要?/span>ProxyQ如果实?#8220;c?#8221;的代理,意味着要同时承两个类Q与Java不支持多l承相违背?br />

附代码是从网上摘抄过来的Q代理的源码Q?br />

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.lang.reflect.UndeclaredThrowableException;
public final class $Proxy0 extends Proxy implements Manager {
private static Method m1;
private static Method m0;
private static Method m3;
private static Method m2;

static {
   
try {
    m1 = Class.forName("java.lang.Object").getMethod("equals",
      
new Class[] { Class.forName("java.lang.Object") });
    m0 = Class.forName("java.lang.Object").getMethod("hashCode",
      
new Class[0]);
    m3 = Class.forName("com.ml.test.Manager").getMethod("modify",
      
new Class[0]);
    m2 = Class.forName("java.lang.Object").getMethod("toString",
      
new Class[0]);
   } catch (NoSuchMethodException nosuchmethodexception) {
    
throw new NoSuchMethodError(nosuchmethodexception.getMessage());
   } catch (ClassNotFoundException classnotfoundexception) {
    
throw new NoClassDefFoundError(classnotfoundexception.getMessage());
   }
}

public $Proxy0(InvocationHandler invocationhandler) {
   
super(invocationhandler);
}
@Override
public final boolean equals(Object obj) {
   
try {
    
return ((Boolean) super.h.invoke(this, m1, new Object[] { obj }))
      .booleanValue();
   } catch (Throwable throwable) {
    
throw new UndeclaredThrowableException(throwable);
   }
}
@Override
public final int hashCode() {
   
try {
    
return ((Integer) super.h.invoke(this, m0, null)).intValue();
   } catch (Throwable throwable) {
    
throw new UndeclaredThrowableException(throwable);
   }
}
}




矛_ | Fat Mind 2010-12-12 02:24 发表评论
]]>
ThreadLocal理?/title><link>http://www.aygfsteel.com/shijian/archive/2010/12/11/340354.html</link><dc:creator>矛_ | Fat Mind</dc:creator><author>矛_ | Fat Mind</author><pubDate>Sat, 11 Dec 2010 10:50:00 GMT</pubDate><guid>http://www.aygfsteel.com/shijian/archive/2010/12/11/340354.html</guid><wfw:comment>http://www.aygfsteel.com/shijian/comments/340354.html</wfw:comment><comments>http://www.aygfsteel.com/shijian/archive/2010/12/11/340354.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/shijian/comments/commentRss/340354.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/shijian/services/trackbacks/340354.html</trackback:ping><description><![CDATA[<font class="Apple-style-span" color="#0000c0" face="'Courier New'" size="2"><br style="font-family: Verdana; " /> </font><font class="Apple-style-span" size="1"><em style="font-family: Verdana; ">题记Q一直对ThreadLocal疑惑,听完facebook大牛演讲?ȝ点东ѝ?/em></font><br /> <br /> <font class="Apple-style-span" size="1"><span style="font-family: Verdana; "> 一、ThreadLocal的作用,整体l构</span></font><br /> <br /> <font class="Apple-style-span" size="1"><span style="font-family: Verdana; "> 二、源代码单分?/span></font><br /> <font class="Apple-style-span" size="1"><span style="font-family: Verdana; ">   1.setҎ(gu)</span></font><br /> <font class="Apple-style-span" size="1"><span style="font-family: Verdana; ">   2.getҎ(gu)</span></font><br /> <br /> <font class="Apple-style-span" size="1"><span style="font-family: Verdana; "> 三、用场景实?ibatis SqlMapClientImp</span></font><br /> <br /> <font class="Apple-style-span" size="1"><span style="font-family: Verdana; "> 后记Q折腑֍天,文章的样式也调整不好Q打包上传。但愿能帮到别h?/span></font><br /> <a href="/Files/shijian/ThreadLocal.rar" style="font-size: 8pt; "><span style="font-family: Verdana; ">http://www.aygfsteel.com/Files/shijian/ThreadLocal.rar</span></a><font class="Apple-style-span" size="1"><span style="font-family: Verdana; "> [</span></font><strong style="font-size: 8pt; "><span style="color: red; font-family: Verdana; ">L“web版式视图”阅读</span></strong><font class="Apple-style-span" size="1"><span style="font-family: Verdana; ">]<br /> </span></font><br /><br /><strong> 遗留问题Q?br /></strong><br /> <p style="text-indent: -18pt; "><span style="font-size: 8pt; "><span lang="EN-US" style="font-family: Verdana; ">      1.Thread</span><span style="font-family: Verdana; ">?/span><span lang="EN-US" style="font-size: 10pt; color: #0000c0; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: silver; font-family: Verdana; background-position: initial initial; background-repeat: initial initial; ">ThreadLocalMap threadLocals</span><span lang="EN-US" style="font-size: 10pt; color: #0000c0; font-family: Verdana; "> 属?/span><span style="font-size: 10pt; color: #0000c0; font-family: Verdana; ">什么时候实例化</span><span style="font-size:10.0pt;font-family:"Courier New";color:#0000C0"> </span><span style="font-size: 10pt; color: #0000c0; font-family: Verdana; ">Q?/span><span style="font-size:10.0pt;font-family:"Courier New";color:#0000C0"> </span><span style="font-size: 10pt; color: #0000c0; font-family: Verdana; ">U程实例化时?/span><span style="font-size:10.0pt;font-family:"Courier New";color:#0000C0"> </span><span style="font-size: 10pt; color: #0000c0; font-family: Verdana; ">Q?br /> <font face="'Courier New'"><span style="font-family: Verdana; ">{:W一ơsetӞ会判断是否ؓnullQ若为nullQ初始化?/span><br /> </font></span></span><span lang="EN-US" style="mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin; mso-bidi-font-family:Calibri;mso-bidi-theme-font:minor-latin"><span style="mso-list:Ignore"><span style="font:7.0pt "Times New Roman""><font color="#0000C0" face="'Courier New'" size="3"><span style="font-size: 13px;"><br /> </span></font></span><span style="font: normal normal normal 7pt/normal 'Times New Roman'; font-family: Verdana; ">2.</span></span></span><span lang="EN-US" style="font-size: 10pt; color: black; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: silver; font-family: Verdana; background-position: initial initial; background-repeat: initial initial; ">ThreadLocalMap</span><span lang="EN-US" style="font-size: 10pt; color: black; font-family: Verdana; "> replaceStaleEntry(key, value, i); </span><span style="font-size: 10pt; color: black; font-family: Verdana; ">做了什?/span><span style="font-size:10.0pt;font-family:"Courier New"; color:black"> </span><span style="font-size: 10pt; color: black; font-family: Verdana; ">Q?/span><span style="font-size:10.0pt;font-family:"Courier New"; color:black"> <br /> </span><span style="font-size: 10pt; color: black; font-family: Verdana; ">{:全清z?/span><span lang="EN-US" style="font-size: 10pt; color: black; font-family: Verdana; ">stale</span><span style="font-size: 10pt; color: black; font-family: Verdana; ">对象Q存攑ֽ前对象在发现的第一?/span><span lang="EN-US" style="font-size: 10pt; color: black; font-family: Verdana; ">stale</span><span style="font-size: 10pt; color: black; font-family: Verdana; ">位置。因为Entry是承WeakRerfenceQQ何一ơ的垃圾攉Q都会导致其引用的对象被回收?br /> </span><span lang="EN-US" style="mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin; mso-bidi-font-family:Calibri;mso-bidi-theme-font:minor-latin"><span style="mso-list:Ignore"><span style="font:7.0pt "Times New Roman""><font face="宋体" size="3"><span style="font-size: 13px;"></span></font></span></span></span><span style="font-size:10.0pt;font-family:宋体;mso-ascii-font-family:"Courier New"; mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family: "Courier New";mso-bidi-font-family:"Courier New";color:black"> </span><span style="font-size:10.0pt; font-family:宋体;mso-ascii-font-family:"Courier New";mso-fareast-font-family: 宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:"Courier New"; mso-bidi-font-family:"Courier New";color:black"><br /> </span><span style="font-size: 10pt; color: black; font-family: Verdana; "> 4.?/span><span lang="EN-US" style="font-size: 10pt; color: black; font-family: Verdana; ">Map</span><span style="font-size: 10pt; color: black; font-family: Verdana; ">方式的一些区?/span><span style="font-size:10.0pt;font-family:"Courier New";color:black"> </span><span style="font-size: 10pt; color: black; font-family: Verdana; ">Q?br /> </span><span lang="EN-US" style="font-size: 10pt; color: black; font-family: Verdana; ">Map</span><span style="font-size: 10pt; color: black; font-family: Verdana; ">{略Q?/span><span lang="EN-US" style="font-size: 10pt; color: black; font-family: Verdana; ">a</span><span style="font-size: 10pt; color: black; font-family: Verdana; ">、相?/span><span lang="EN-US" style="font-size: 10pt; color: black; font-family: Verdana; ">hash&key</span><span style="font-size: 10pt; color: black; font-family: Verdana; ">Q覆?/span><span lang="EN-US" style="font-size: 10pt; color: black; font-family: Verdana; ">value</span><span style="font-size: 10pt; color: black; font-family: Verdana; ">Q?/span><span style="font-size:10.0pt;font-family:"Courier New";color:black"> <span lang="EN-US" style="font-family: Verdana; ">b</span></span><span style="font-size: 10pt; color: black; font-family: Verdana; ">、相?/span><span lang="EN-US" style="font-size: 10pt; color: black; font-family: Verdana; ">hash</span><span style="font-size: 10pt; color: black; font-family: Verdana; ">Q?/span><span lang="EN-US" style="font-size: 10pt; color: black; font-family: Verdana; ">key</span><span style="font-size: 10pt; color: black; font-family: Verdana; ">不同Q当前元素做为单向链的第一个元素,原来W一个元素做为当前元素的下一个?br /> </span><span lang="EN-US" style="font-size: 10pt; color: black; font-family: Verdana; ">ThreadLocalMap{略Qa相同Q?/span><span style="font-size: 10pt; color: black; font-family: Verdana; ">是不存在</span><span lang="EN-US" style="font-size: 10pt; color: black; font-family: Verdana; ">b</span><span style="font-size: 10pt; color: black; font-family: Verdana; ">情况Q以</span><span lang="EN-US" style="font-size: 10pt; color: black; font-family: Verdana; ">ThreadLocal</span><span style="font-size: 10pt; color: black; font-family: Verdana; ">作ؓ</span><span lang="EN-US" style="font-size: 10pt; color: black; font-family: Verdana; ">key</span><span style="font-size: 10pt; color: black; font-family: Verdana; ">Q?/span><span lang="EN-US" style="font-size: 10pt; color: black; font-family: Verdana; ">ThreadLocal</span><span lang="EN-US" style="font-size: 10pt; color: black; "><font class="Apple-style-span" face="宋体"><span style="font-family: Verdana; ">?/span></font></span><span lang="EN-US" style="font-size: 10pt; color: #0000c0; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: yellow; font-family: Verdana; background-position: initial initial; background-repeat: initial initial; ">threadLocalHashCode?/span><span style="font-size: 10pt; color: #0000c0; "><font class="Apple-style-span" face="宋体"><span style="font-family: Verdana; ">原子AtomicInteger计算getAndAdd(0x61c88647</span></font><span id="wmqeeuq" class="Apple-style-span" style="color: #000000; font-size: 14px; "><span style="font-size: 10pt; color: #0000c0; font-family: Verdana; ">)得到Q在</span><span lang="EN-US" style="font-size: 10pt; color: #0000c0; font-family: Verdana; ">Entry[]</span><span style="font-size: 10pt; color: #0000c0; font-family: Verdana; ">数组的位|,通过</span><span lang="EN-US" style="font-size: 10pt; color: #0000c0; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: yellow; font-family: Verdana; ">threadLocalHashCode</span><span lang="EN-US" style="font-size: 10pt; color: #0000c0; font-family: Verdana; "> & (length-1)</span><span style="font-size: 10pt; color: #0000c0; font-family: Verdana; ">计算</span><span style="font-size: 10pt; color: #0000c0; "><font class="Apple-style-span" face="'Courier New'"><span style="font-family: Verdana; ">Q对于b情况Ql查?/span></font></span></span></span><span lang="EN-US" style="font-size: 10pt; color: #0000c0; font-family: Verdana; ">Entry[]</span><span style="font-size: 10pt; color: #0000c0; font-family: Verdana; ">数组?/span><span style="font-size: 10pt; color: #0000c0; "><span id="wmqeeuq" class="Apple-style-span" style="color: #000000; font-size: 14px; "><span style="font-size: 10pt; color: #0000c0; "><font class="Apple-style-span" face="'Courier New'"><span style="font-family: Verdana; ">下一个位|,是否可存放(key相同或nullQ;当size>=threshold(len*2/3)做resize=oldLen*2.</span></font></span></span></span> </p> <span style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px; "><span><span style="font: normal normal normal 7pt/normal 'Times New Roman'; "><br /> </span><span style="font: normal normal normal 7pt/normal 'Times New Roman'; font-family: Verdana; "> 3.</span></span><span style="font-size: 10pt; color: black; font-family: Verdana; ">ThreadLocalMap  getEntryAfterMiss(ThreadLocal key, int i, Entry e)</span><span style="font-size: 10pt; color: black; font-family: Verdana; ">Q?br /> </span><span style="font-size: 10pt; color: black; font-family: Verdana; "> {:作用Q查找没有存攑֜</span><span style="font-size: 10pt; color: black; font-family: Verdana; ">hash</span><span style="font-size: 10pt; color: black; font-family: Verdana; ">计算?/span><span style="font-size: 10pt; color: black; font-family: Verdana; ">index</span><span style="font-size: 10pt; color: black; font-family: Verdana; ">位置的元素。ؓ什么出现此情况Q见4Q由ThreadLocalMap{略军_.<br /> <br /> </span></span><img src ="http://www.aygfsteel.com/shijian/aggbug/340354.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/shijian/" target="_blank">矛_ | Fat Mind</a> 2010-12-11 18:50 <a href="http://www.aygfsteel.com/shijian/archive/2010/12/11/340354.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>玩命的cookiehttp://www.aygfsteel.com/shijian/archive/2010/11/08/337567.html矛_ | Fat Mind矛_ | Fat MindMon, 08 Nov 2010 13:41:00 GMThttp://www.aygfsteel.com/shijian/archive/2010/11/08/337567.htmlhttp://www.aygfsteel.com/shijian/comments/337567.htmlhttp://www.aygfsteel.com/shijian/archive/2010/11/08/337567.html#Feedback0http://www.aygfsteel.com/shijian/comments/commentRss/337567.htmlhttp://www.aygfsteel.com/shijian/services/trackbacks/337567.html

题记Q一?/span>cookieQ整个下午都没有扑ֈ解决的办法?/span>

 

一、遇到的问题

1. 情景Q访?/span>http://list.mall.daily.taobao.net/50024400/xxxQ当前页面通过ajaxhq告Q请求的域ؓhttp://tmatch.simba.taobao.com/xxxQ广告引擎向面U?/span>seesion范围?/span>cookie?/span>_backQ用于标识翻;

      2. 问题Q?/span>

点击当前面的翻,IE下广告不页Q通过firebug?/span>httpwatchҎ(gu)Q发?/span>IE?/span>cookie“_back”不正。开始猜是引擎U?/span>cookie的逻辑存在问题Q但很多地方都在使用此接口,均没有问题?/span>

且有人的机器页正常Q此时怀疑是览器设|问题?再用httpwatch观察“httph?/span>”Q发?/span>_back没有回传l引擎(其实httpwatch?/span>cookies也可以观察到Q如果发?/span>cookie的话Q会昄?/span>SentQ之前只观察?/span>ReceivedQ? 认是浏览器的问题?/span>

3. 解决Q打开IE隐私设计Q通常默认讄?/span>“?/span>”Q拒l?/span>“没有隐私政策的第三方cookie ...”Q意味着_backq没有成功写入客LQ所有请求引擎导致不能正回?/span>_backQ翻失败?/span>

         q么说淘宝所有的q告的翻都是不可用?/span> Q肯定不是。问题在W一?/span> Cookie 来自(zhn)正览的网站,它们可以是永久的或时的Q第三方 Cookie 来自(zhn)正览的网站上的其他网站的q告”Q对于浏览器“taobao.net?/span>taobao.com”是不同的两个网站,所以引擎的_back是无法种在客L。此情景?/span>daliy环境Q线上的环境讉K的是list.mall.daily.taobao.com,所以不存在W三?/span>cookie”的概念,q告是可以正显C?/span>

 

二、关?/span>cookie知?/span>

 

1.IE Cookie的格?/span>

W一?/span>“名称Q第二行?/span>”Q第三行所属域” ...比如“.taobao.com”存在cnaQ此cookie会被览器自动发送到M属于此域的子域;www.taobao.com\taobao.comQ后面的是根域,前一个是二域?/span>xp存放目录为:C:\Documents and Settings\<username>\Cookies\Q文件命名:你的用户?/span>@生成COOKIE?/span>domain[COOKIE改变的次?/span>].txt

  参考:http://blog.csdn.net/zhangxinrun/archive/2010/07/31/5779574.aspx

 

2.Js Cookie跨域?/span>

 http://blog.csdn.net/tongdoudpj/archive/2009/05/10/4166096.aspx

 

3.cookie?/span>session的关p?/span>

Ҏ(gu)的原因:http协议的无状态性,cookie的出现就是ؓ了解册个问题?/span>

session是一U在客户端与服务器之间保持状态的解决Ҏ(gu)。服务端存储内容Q返回对应的keyl客LQ当下次讉KӞ带上?/span>keyQ实现状态的l持?/span>

session实现Q?/span>

1.依赖cookieQ?/span>The session cookie is stored in temporary memory and is not retained after the browser is closed。(实际试QIE8Q未?描述的位|找?/span>sessionU别cookie对应的文Ӟ猜测‘临时存储在浏览器内存’Q当关闭览器时则丢失keyQ?/span>

2.url重写?/span>Servlet规范定义此功能。当览器禁?/span>cookieӞqsessionU别的内容也不会被存储?/span>resp.encodeRedirectURL(url)Q且仅当用cookie时有效,重写l果如:http://www.demo.com/cookie.do;jsessionid=19gfy1sg740dl1whwd72lbqlhb

疑问Q?/span>server如何判断Q是否需要重写呢Q从实验现象看,判断是否收到name=JSESSIONID ?/span>cookieQ若无,则进?/span>url重写?/span>

           最好的方式Q翻?/span>tomcat?/span>jetty的源码实玎ͼ但未扑ֈ对应的代码?/span>

关于cookie的详l信息参见: http://en.wikipedia.org/wiki/HTTP_cookie

 



矛_ | Fat Mind 2010-11-08 21:41 发表评论
]]>
关于单元试http://www.aygfsteel.com/shijian/archive/2010/11/02/336853.html矛_ | Fat Mind矛_ | Fat MindTue, 02 Nov 2010 13:31:00 GMThttp://www.aygfsteel.com/shijian/archive/2010/11/02/336853.htmlhttp://www.aygfsteel.com/shijian/comments/336853.htmlhttp://www.aygfsteel.com/shijian/archive/2010/11/02/336853.html#Feedback0http://www.aygfsteel.com/shijian/comments/commentRss/336853.htmlhttp://www.aygfsteel.com/shijian/services/trackbacks/336853.html
题记Q新同学分n?#8220;试驱动”Q第一ơ感觉测试驱动离自己那么q。因此开始尝试。记下自q一点x?/em>

1.一切从试开?br />   不管在写复杂的代码,q是单的代码Q一切从试开始。练习成自己~码的习惯?br />   自己的做法只能算?#8220;伪测试驱?#8221;Q因是有详细的设计,但遵循此做法Q对于需求的变更、代码存在的bugQ导致编码修改的时候,心里是踏实的?br />   目前自己q不能感觉到对后期的l护会带来什么样的结果?
  推荐《测试驱动开始》?br />
2.工具
  junit、mockito、emma

  junitQ这是大家熟知的Q学到新点:a。参数化试  b。privateҎ(gu)试Q反) c。runwith & UniteQ组l测试单?br />   mockitoQ轻量的mock工具。测试中很麻烦的一个问题是Q环境依赖,比如Qweb中依赖容器生成request对象。mockito很好的解军_部分问题QstaticcMprivateҎ(gu)未能解决Q?br />   emma,代码覆盖率检查工Peclipse插g。效果:U色=未测试;黄色=试不完_只是部分逻辑Q绿?试完整。(注意Q不能绝对的q求覆盖率,一定要C2/8原则Q将主要的精力关注主要的逻辑Q?br />
3.习惯
  a。代码结构,3部分QprepareQ包含mockQ准备数据、action执行、assert验证
  b。方法命名:被测试方法名$试目的Q如Qrun$ParameterIsNull
  c。测试Ac,有两个方法run()和prepare()QrunҎ(gu)调用prepareQ且prepare执行非常耗时间。想要单独测试run()Ҏ(gu) Q?br />      {案QB extends AQ复写prepareҎ(gu)Q等于是mock prepareҎ(gu)Q,单独的测试runҎ(gu)逻辑?br />   d。持l写试代码的习?br />


  



矛_ | Fat Mind 2010-11-02 21:31 发表评论
]]>.java源文件是如何被找到的Q?/title><link>http://www.aygfsteel.com/shijian/archive/2010/10/17/335338.html</link><dc:creator>矛_ | Fat Mind</dc:creator><author>矛_ | Fat Mind</author><pubDate>Sat, 16 Oct 2010 17:29:00 GMT</pubDate><guid>http://www.aygfsteel.com/shijian/archive/2010/10/17/335338.html</guid><wfw:comment>http://www.aygfsteel.com/shijian/comments/335338.html</wfw:comment><comments>http://www.aygfsteel.com/shijian/archive/2010/10/17/335338.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/shijian/comments/commentRss/335338.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/shijian/services/trackbacks/335338.html</trackback:ping><description><![CDATA[<p align="center" style="text-align: center; "><span style="background-color: yellow;">已迁往 http://fatmind.iteye.com</span><br /><br /> </p> <p><span style="font-family:宋体;Times New Roman";Times New Roman"">题记Q?/span>.java<span style="font-family:宋体;Times New Roman";Times New Roman"">源文件是如何被找到的Q?/span>.class<span style="font-family:宋体;Times New Roman";Times New Roman"">字节码文件是如何被找到的Q?/span><span style="font-family: 宋体; "><em><strong>内容Q全部借鉴《Java深度历险?/strong></em></span></p> <p>Package<span style="font-family: 宋体;Times New Roman";Times New Roman"">Q命名空间的问题Q隔ȝ之间的关pR?/span></p> <p>Import<span style="font-family:宋体;Times New Roman";Times New Roman"">Q声明引入的cȝ路径Q仅在编译时有作用,~译后的文gQ类的声明已lؓ全\径)Q好?#8220;明晰的代码结构,分离在多个文Ӟ帮助实现动态链接的功能”?/span></p> <p style="margin-left:21.0pt;text-indent:-21.0pt; tab-stops:list 21.0pt">一?span style="font-family:宋体;Times New Roman";Times New Roman"">~译</span></p> <p><strong><span>package edu.nctu;</span></strong></p> <p><strong> </strong></p> <p><strong><span>import com.taobao.Test;</span></strong></p> <p><strong><span>import edu.nctu.*;</span></strong></p> <p><strong> </strong></p> <p><strong><span>public class C</span></strong></p> <p><strong>{</strong></p> <p style="text-indent:21.0pt"><strong>public void print() {</strong></p> <p><strong><span>              System.out.println("package test") ;</span></strong></p> <p><strong>       }</strong></p> <p><strong>}</strong></p> <p><strong> </strong></p> <p><span style="font-family:宋体;Times New Roman";Times New Roman"">步骤Q?/span></p> <p>1. <span style="font-family:宋体;Times New Roman";Times New Roman"">Ҏ(gu)</span>classpath<span style="font-family:宋体;Times New Roman";Times New Roman"">建立Q?#8220;cȝ对\径参考表”</span></p> <p><span style="font-family:宋体;Times New Roman";Times New Roman"">如:</span>javac –cp .;d:/test/<span style="font-family:宋体;Times New Roman";Times New Roman"">Q在</span>d:/<span style="font-family: 宋体;Times New Roman";Times New Roman"">下执行,l果Q?/span>d:/<span style="font-family:宋体;Times New Roman";Times New Roman"">Q?/span>d:/test/<span style="font-family:宋体;Times New Roman";Times New Roman"">?/span></p> <p>2. <span style="font-family:宋体;Times New Roman";Times New Roman"">?#8220;cȝ对\径参考表”作ؓ相对起始路径Q验证能够找到所有要用的</span>package<span style="font-family:宋体;Times New Roman";Times New Roman"">?/span></p> <p align="left" style="text-align:left;text-autospace:none"><span style="font-family:宋体;Times New Roman";Times New Roman"">Ҏ(gu)</span>import<span style="font-family:宋体;Times New Roman";Times New Roman"">引入?/span>package<span style="font-family:宋体;Times New Roman";Times New Roman"">或全限定cdQ?/span><span style="font-size:10.0pt; font-family:"Lucida Console";Lucida Console";">import packagename.classname</span><span style="font-size:10.0pt; font-family:宋体;Lucida Console";Lucida Console";Lucida Console";">Q?/span><span style="font-size:10.0pt;font-family:MingLiU;Times New Roman";">?/span><span style="font-size:10.0pt;font-family:"Lucida Console";Lucida Console";">packagename</span><span style="font-size:10.0pt;font-family:MingLiU;Times New Roman";">之中?/span><span style="font-size:10.0pt; font-family:"Lucida Console";Lucida Console";">“.”</span><span style="font-size:10.0pt; font-family:MingLiU;Times New Roman";">?/span><span style="font-size:10.0pt; font-family:"Lucida Console";Lucida Console";">“/”</span><span style="font-size:10.0pt; font-family:MingLiU;Times New Roman";">取代</span><span style="font-size:10.0pt; font-family:"Lucida Console";Lucida Console";">.</span></p> <p><span>       2.1 </span><span style="font-family:宋体;Times New Roman";Times New Roman"">?/span>com.taobao.*<span style="font-family:宋体;Times New Roman";Times New Roman"">形式Q验证在</span>d:/<span style="font-family:宋体;Times New Roman";Times New Roman"">目录下是否存?/span>com/taobao/<span style="font-family:宋体;Times New Roman";Times New Roman"">目录Q若不存在,依次?/span>d:/test/<span style="font-family:宋体;Times New Roman";Times New Roman"">?/span></p> <p><span>       2.2 </span><span style="font-family:宋体;Times New Roman";Times New Roman"">?/span>com.taobao.Test<span style="font-family:宋体;Times New Roman";Times New Roman"">形式Q验证是否存?/span>com/taobao/Test<span style="font-family:宋体;Times New Roman";Times New Roman"">Q与上相同?/span></p> <p>3. <span style="font-family:宋体;Times New Roman";Times New Roman"">建立“cd考表”?#8220;相对cd考表”</span></p> <p><span>       3.1 </span><span style="font-family:宋体;Times New Roman";Times New Roman"">cd考表Q?/span>com.taobao.Test</p> <p><span>       3.2 </span><span style="font-family:宋体;Times New Roman";Times New Roman"">cȝ对参考表Q?/span>com.taobao.*</p> <p>4. <span style="font-family:宋体;Times New Roman";Times New Roman"">解析</span>class{} <span style="font-family:宋体;Times New Roman";Times New Roman"">包含的代?/span></p> <p style="text-indent:21.0pt"><span style="font-family:宋体;Times New Roman";Times New Roman"">是否全限定类?/span></p> <p><span>       4.1 </span><span style="font-family:宋体;Times New Roman";Times New Roman"">是,l对路径</span> =<span style="font-family:宋体;Times New Roman";Times New Roman"">“cȝ对\径参考表”</span>+<span style="font-family:宋体;Times New Roman";Times New Roman"">全限定类名,查找Q不存在为错误;</span></p> <p><span>       4.2 </span><span style="font-family:宋体;Times New Roman";Times New Roman"">否,l对路径</span> =<span style="font-family:宋体;Times New Roman";Times New Roman"">“cȝ对\径参考表”Q查找;</span></p> <p>              4.2.1<span style="font-family:宋体;Times New Roman";Times New Roman"">是,~译</span></p> <p>              4.2.2<span style="font-family:宋体;Times New Roman";Times New Roman"">否,解析</span>package</p> <p>                     4.2.2.1 <span style="font-family:宋体;Times New Roman";Times New Roman"">在类参考表Q是否存?/span>1<span style="font-family:宋体;Times New Roman";Times New Roman"">以上的同名类Q出错;否则Q绝对\?/span> =<span style="font-family:宋体;Times New Roman";Times New Roman"">“cȝ对\径参考表”</span>+ <span style="font-family:宋体;Times New Roman";Times New Roman"">“cd考表”Q正?/span></p> <p>                     4.2.2.2 <span style="font-family:宋体;Times New Roman";Times New Roman"">在类参考表找不刎ͼl对路径</span><span> = </span><span style="font-family:宋体;Times New Roman";Times New Roman"">“cȝ对\径参考表”</span>+ <span style="font-family:宋体;Times New Roman";Times New Roman"">“相对cd考表”Q若存在一个以上的c,出错Q否则,正确?/span></p> <p><span style="font-family:宋体;Times New Roman";Times New Roman"">提醒Q?/span></p> <p style="margin-left:18.0pt;text-indent:-18.0pt; tab-stops:list 18.0pt"><span style="Times New Roman""><span>1.<span style="font:7.0pt "Times New Roman"">       </span></span></span><span style="font-family:宋体;Times New Roman";Times New Roman"">如果已经存在</span><strong>A .class</strong><span style="font-family:宋体;Times New Roman";Times New Roman"">文gQ?/span><strong>A .java</strong><span style="font-family:宋体;Times New Roman";Times New Roman"">不是必须的;<br /> </span></p> <p style="margin-left:18.0pt;text-indent:-18.0pt; tab-stops:list 18.0pt"><span style="Times New Roman""><span>2.<span style="font:7.0pt "Times New Roman"">       </span></span></span><span style="font-family:宋体;Times New Roman";Times New Roman"">~译器在扑ֈ源码或字节码Q对会验证是否属于此</span>package<span style="font-family:宋体;Times New Roman";Times New Roman"">Q但没有通过</span>make<span style="font-family:宋体;Times New Roman";Times New Roman"">机制的编译,是不会验证的Qmake机制Q即~译器自动维护具有相互依赖关pȝ文gQjavac命o直接~译文gQ如Qjavac -cp d:/test com.edu.C.javaQ编译器角度Qcom.edu.C.java 是一个文件名Q且没有通过make机制Q所?cp指定的\径徏立的</span><span style="font-family: 宋体; ">“cȝ对\径参考表”也不会用,~译器直接在当前目录下查?/span><span style="font-family: 宋体; ">com.edu.C.javaQ结?ClassNotFoundException ?/span></p> <p style="margin-left:21.0pt;text-indent:-21.0pt; tab-stops:list 21.0pt">二?span style="font-family:宋体;Times New Roman";Times New Roman"">q行</span></p> <p style="margin-left:18.0pt;text-indent:-18.0pt; tab-stops:list 18.0pt"><span style="Times New Roman"">1?nbsp;</span><span style="font-family:宋体;Times New Roman";Times New Roman"">~译l束后,</span>import<span style="font-family:宋体;Times New Roman";Times New Roman"">指o已经不存在,c被替换?#8220;全限定类?#8221;</span></p> <p style="margin-left:18.0pt;text-indent:-18.0pt; tab-stops:list 18.0pt"><span style="Times New Roman"">2?nbsp;</span><span style="font-family:宋体;Times New Roman";Times New Roman"">q行时类的加载,都是通过</span>classloader<span style="font-family:宋体;Times New Roman";Times New Roman"">q行Q所以必遵循正的“包目?#8221;l构Q不是否直接通过命o行执行?/span></p> <p><span style="font-family:宋体;Times New Roman";Times New Roman"">步骤Q?/span></p> <p style="margin-left:18.0pt;text-indent:-18.0pt; tab-stops:list 18.0pt"><span style="Times New Roman""><span>1.<span style="font:7.0pt "Times New Roman"">       </span></span></span><span style="font-family:宋体;Times New Roman";Times New Roman"">建立“字节码\径参考表”Q根?/span>classpath</p> <p style="margin-left:18.0pt;text-indent:-18.0pt; tab-stops:list 18.0pt"><span style="Times New Roman""><span>2.<span style="font:7.0pt "Times New Roman"">       </span></span></span><span style="font-family:宋体;Times New Roman";Times New Roman"">l对路径</span> = <span style="font-family:宋体;Times New Roman";Times New Roman"">“字节码\径参考表”</span>+ <span style="font-family:宋体;Times New Roman";Times New Roman"">全限定类名,查找Q加载;找不刎ͼ报错?/span></p> <p style="margin-left:18.0pt;text-indent:-18.0pt; tab-stops:list 18.0pt"><span style="font-family:宋体;Times New Roman";Times New Roman""><em><strong><br /> <br /> <br /> </strong></em></span></p><img src ="http://www.aygfsteel.com/shijian/aggbug/335338.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/shijian/" target="_blank">矛_ | Fat Mind</a> 2010-10-17 01:29 <a href="http://www.aygfsteel.com/shijian/archive/2010/10/17/335338.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>~码的一些理?/title><link>http://www.aygfsteel.com/shijian/archive/2010/10/05/333775.html</link><dc:creator>矛_ | Fat Mind</dc:creator><author>矛_ | Fat Mind</author><pubDate>Tue, 05 Oct 2010 13:12:00 GMT</pubDate><guid>http://www.aygfsteel.com/shijian/archive/2010/10/05/333775.html</guid><wfw:comment>http://www.aygfsteel.com/shijian/comments/333775.html</wfw:comment><comments>http://www.aygfsteel.com/shijian/archive/2010/10/05/333775.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/shijian/comments/commentRss/333775.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/shijian/services/trackbacks/333775.html</trackback:ping><description><![CDATA[     摘要: 已迁往  http://fatmind.iteye.com主要参考: 1.宝宝的文章《中文化和国际化问题析?   2.阮一峰的|络日志       http://www.ruanyifeng.com/blog/2007/10/ascii_unicode_and_utf-8.html  ...  <a href='http://www.aygfsteel.com/shijian/archive/2010/10/05/333775.html'>阅读全文</a><img src ="http://www.aygfsteel.com/shijian/aggbug/333775.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/shijian/" target="_blank">矛_ | Fat Mind</a> 2010-10-05 21:12 <a href="http://www.aygfsteel.com/shijian/archive/2010/10/05/333775.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> վ֩ģ壺 <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ؿ˹</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ȫ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">̩˳</a>| <a href="http://" target="_blank">Ǹ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ڶ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">˷</a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ƽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank">ף</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ӻ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ݳ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">齭</a>| <a href="http://" target="_blank">ϲ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>