- 博客(60)
- 资源 (5)
- 收藏
- 关注
原创 锁和隔离(1)
我们的程序执行单元运行分为两种:进程和线程操作系统会为进程分配独立内存空间,将正在处理的数据和外部隔离,只有该进程能够对这片内存区域进行读写但是进程访问外部资源需要独占的时候存在排他性,因此需要加锁线程则为轻量级执行单元,进程内可以创建线程多个线程,可以充分利用资源,线程间共享内存,线程能够充分利用CPU资源多线程同时访问一片内存空间需要独占写入时候,需要加锁锁存在的目的为了确...
2019-08-03 16:15:55
150
原创 Spring boot结合flyway进行数据迁移
在Spring boot进行到一半的项目中使用flyway,按照flyway官方文档设置,需要重新跑flyway的baseline:因此在application.properties中确实配置了flyway.baselineOnMigrate=true运行后总是提示配置错误错误,baseline没有设置。通过查看源代码,发现Spring的autoconfiguration进行过flyw...
2019-06-06 11:45:56
474
原创 MongoDB学习笔记 - Aggregation (1)
MongoDB里面经常需要做一些统计任务,这里使用Aggregate 内嵌文档的例子,例如下面的文档,我们希望找到type 1的colors 的数量总和inventory collection 如下:{"_id" : 1, "item" : "ABC1","type",1, "description" : "product 1", colors: [ "blue","black",
2017-02-18 14:41:15
1212
原创 Kafka实战经验 - Kafka Consumer自定义offset管理
在项目中,大部分情况下,使用Kafka自动管理offset能够满足需求,但是在某些情况下需要使用手动管理Kafka offset,比如必须要求数据处理完成以后才能commit,确保partition的数据被处理完。因此可以使用kafka的ConsumerRebalanceListener进行处理:1) Subscribeconsumer.subscribe(topics,
2017-02-18 14:24:05
9369
原创 Kafka 学习笔记(4) - Consumer和Producer
Producer负责分发message到topic,并且要选择哪些message分发到这个topic的哪个partition,分发机制可能使用轮询,也可以使用一些semantic的方法针对Java而言, 现在Kafka推荐使用的是新的kafka client API public static void sendMessage() { Map configs
2015-10-31 23:21:22
5899
原创 Kafka 学习笔记(3) - HA
Kafka 将Partition分布在Cluster的多个Server,这个数字也是可以配置的其中一个Leader负责接收所有读写请求,其它的Followers进行replicate,如果Leader down了,那么其它Follower会变成Leader,这个功能应该就是Kafka借助了Zookeeper来实现的另外要注意的是,每个Server都是其中一些Partit
2015-10-17 11:41:07
1502
原创 Kafka 学习笔记(2) - Topic 和 Log
A topic is a category or feed name to which messages are published.每个Partition都是一个排序的和不可变的消息队列,新消息都会append到结尾,每个message都会分配一个sequential id, 叫做offset,作为message的唯一的id注意的是Kafka的Cluster会保存在某个配
2015-10-16 11:17:33
1721
原创 Rails源代码分析(49):ActionView::Helpers::AssetTagHelper
Usage: 1) using asset hosts ActionController::Base.asset_host = "assets.example.com" image_tag("rails.png") => stylesheet_link_tag("application") =
2009-05-18 12:46:00
1857
原创 Ruby学习笔记(1)
目的:打好基础,并且深入理解Ruby语言的原理,以及它的运行机制 Ruby In Nutshell快看完3章了,前面懒得写了,继续从Built-in Lib看:Ruby 的 Built-in Lib主要包括:1 ObjectsObject class, Kernal module 2 String and RegexString, Regex 3 Ar
2009-04-22 13:10:00
1646
原创 Java学习笔记(1)
精通一门语言不容易,发现之前虽然用了好多年的Java开发,最后只不过是重复使用自己常用的几个类。 所以每天深入学习几个类或者接口, Iterable是所有迭代器的基础接口实现这个接口允许对象成为 "foreach" 语句的目标Collection是所有集合相关的基础接口Collection 层次结构 中的根接口。Collection 表示一组对象,这
2009-04-17 13:39:00
1584
原创 Rails源代码分析(47):ActionView::Helpers::ActiveRecordHelper
这个Helper主要实现的方法包括如下:1 inputReturns a default input tag for the type of object returned by the method.For example, if @post has an attribute +title+ mapped to a +VARCHAR+ column that holds "Hello
2009-03-16 13:19:00
1782
原创 Rails源代码分析(46):ActionView::Partials
这个module,主要是为了支持,render的:partial属性if partial = options[:partial] partial = default_template_name if partial == true add_variables_to_assigns if collectio
2009-02-03 12:43:00
1961
原创 Rails源代码分析(45):ActionView Template (3)
PartialTemplate 实现:1 初始化做了改动, 根据partial_path抽取路径和collection的item变量名2 根据变量名设置变量 放入@locals[:object] 3 initialize_counter partial内置了一个counter变量,比如render :partial=>item :collection=>items
2009-01-15 13:32:00
1765
原创 Rails源代码分析(44):ActionView Template (2)
InlineTemplate主要区别在于初始化方法以及source的定义 module ActionView #:nodoc: class InlineTemplate < Template #:nodoc: def initialize(view, source, locals = {}, type = nil) @view = view
2009-01-15 13:31:00
1742
原创 Rails源代码分析(43):ActionView Template (1)
Template 可以看作一个Wrapper,用来包装整个输出对象,包括如下几个:TemplateInlineTemplate PartialTemplate def initialize(view, path, use_full_path, locals = {}) @view = view @finder = @view.finder
2009-01-08 12:51:00
2229
原创 Rails源代码分析(42):ActionView Base
贴代码: module CompiledTemplates #:nodoc: # holds compiled template code end include CompiledTemplates # Maps inline templates to their method names cattr_accessor :method_names @@
2009-01-05 12:41:00
2176
原创 Rails源代码分析(41):ActionView 概览
require action_view/template_handlerrequire action_view/template_handlers/compilablerequire action_view/template_handlers/builderrequire action_view/template_handlers/erbrequire action_view/t
2009-01-05 12:35:00
1980
原创 Rails源代码分析(40):ActionController Base的render方法
1 使用render方法 # Renders the content that will be returned to the browser as the response body. 1) Rendering an action # rendering is the most common form and the type used automati
2008-12-29 13:05:00
2739
原创 Rails源代码分析(39):ActionController 对 ActionView 模块的调用
def initialize_template_class(response) # 初始化View实例 response.template = ActionView::Base.new(self.class.view_paths, {}, self) # View可以扩展helper方法 response.template.ext
2008-12-26 14:39:00
1849
原创 Rails源代码分析(37):ActionController::Routing(8) Recognition Optimisation
留空,有空再写
2008-12-26 14:11:00
1125
原创 Rails源代码分析(35):ActionController::Routing(6) Segment
1 Segment的分类Segment. Abstract Base ClassDynamicSegment. This represents parts of the route that begin with a colon, like :action, :permalink or :id.ControllerSegment. This is actually a subclass ofD
2008-12-25 13:11:00
949
原创 Rails源代码分析(34):ActionController::Routing(5) Route
1 结构 class Route #:nodoc: attr_accessor :segments, :requirements, :conditions, :optimise def initialize @segments = [] @requirements = {} @conditions = {} @opt
2008-12-23 13:49:00
759
原创 Rails源代码分析(33):ActionController::Routing(4) Builder
1 说明 这个类用于根据path来创建Route对象2 代码分析 核心: def build(path, options) # Wrap the path with slashes path = "/#{path}" unless path[0] == ?/ path = "#{path}/" unless path[-1] == ?/
2008-12-22 12:52:00
945
原创 Rails源代码分析(32):ActionController::Routing(3) RouteSet
1 类结构RouteSetRouteSet::Mapper RouteSet::NamedRouteCollection 2 代码分析RouteSet::Mapper这个就是在config/routes.rb中用来创建route的方法 # Mapper instances are used to build routes. The object passed to the draw
2008-12-21 14:43:00
762
原创 Rails源代码分析(31):ActionController::Routing(2) PolymorphicRoutes
1 使用action_controller base:url_for :controller => posts, :action => nil def url_for(options = {}) options ||= {} case options when String options when
2008-12-21 13:39:00
631
原创 Rails源代码分析(30):ActionController::Routing(1)
这个Module穿插在整个ActionPack里面的各个地方,routing 在启动Rails的同时就会加载: def initialize_routing # 确认包含action_controller return unless configuration.frameworks.include?(:action_controller) # 加入config加
2008-12-17 12:48:00
1437
原创 Rails源代码分析(29):回到ActionController(1)
前面那么长时间都是在分析Controller,基本有了比较清晰的认识。现在回到controller里面看看还有哪些方面遗漏了类方法: class self # Factory for the standard create, process loop where the controller is discarded after processing. def proce
2008-12-15 18:37:00
614
原创 Rails源代码分析(28):ActionController::RequestForgeryProtection
这是controller的最后一个module:1 说明Protecting controller actions from CSRF attacks by ensuring that all forms are coming from the current web application, not a forged link from another site, is done by embe
2008-12-15 13:29:00
987
原创 Rails源代码分析(27):ActionController::RecordIdentifier
1 应用这个Module提供了一些包装方法来处理record相关的命名约定,以便于用更高层次的逻辑:使用例子如下 # routes map.resources :posts # view do %> "post_45" class="post"> What a wonderful world! end %>
2008-12-12 10:24:00
529
原创 Rails源代码分析(26):ActionController::HttpAuthentication::Basic::ControllerMethods
1 使用这个Module提供了一个简单的方法进行基于HTTP的验证,个人感觉没有太大的帮助,反而增加了复杂度,不如自己实现简单:class PostsController USER_NAME, PASSWORD = "dhh", "secret" before_filter :authenticate, :except => [ :index ]
2008-12-11 13:10:00
622
原创 Rails源代码分析(25):ActionController::SessionManagement
1 使用session的主要作用是保持几个请求同时用到的公用数据段类方法:session_store= # Set the session store to be used for keeping the session data between requests. # By default, sessions are stored in browser cookies (:c
2008-12-10 12:36:00
661
原创 Rails源代码分析(24):ActionController::Streaming
这个module提供了两个方法:1) send_file # Sends the file by streaming it 4096 bytes at a time. This way the # whole file doesnt need to be read into memory at once. This makes # it feasible to
2008-12-09 12:32:00
616
原创 Rails源代码分析(23):ActionController::Verification
1 使用这个Module提供了一个类级别方法,验证某个方法就是指定的先决条件。可以看作是一个特别的before_filter class GlobalController # # Prevent the #update_settings action from being invoked unless # # the admin_privileges
2008-12-08 13:28:00
467
原创 Rails源代码分析(22):ActionController::Caching(6) Sweeping
Sweeping 清理cache: class ListsController caches_action :index, :show, :public, :feed cache_sweeper :list_sweeper, :only => [ :edit, :destroy, :share ] end可以单独定义:class ListS
2008-12-05 12:21:00
607
原创 Rails源代码分析(21):ActionController::Caching(5) SqlCache
SqlCache 是改善ActiveRecord中一个action中查询的时候,可能多次都需要执行同样的sql语句的问题:module ActionController #:nodoc: module Caching module SqlCache def self.included(base) #:nodoc: if defined?(ActiveRecord)
2008-12-04 13:13:00
501
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人