黄色网页视频 I 影音先锋日日狠狠久久 I 秋霞午夜毛片 I 秋霞一二三区 I 国产成人片无码视频 I 国产 精品 自在自线 I av免费观看网站 I 日本精品久久久久中文字幕5 I 91看视频 I 看全色黄大色黄女片18 I 精品不卡一区 I 亚洲最新精品 I 欧美 激情 在线 I 人妻少妇精品久久 I 国产99视频精品免费专区 I 欧美影院 I 欧美精品在欧美一区二区少妇 I av大片网站 I 国产精品黄色片 I 888久久 I 狠狠干最新 I 看看黄色一级片 I 黄色精品久久 I 三级av在线 I 69色综合 I 国产日韩欧美91 I 亚洲精品偷拍 I 激情小说亚洲图片 I 久久国产视频精品 I 国产综合精品一区二区三区 I 色婷婷国产 I 最新成人av在线 I 国产私拍精品 I 日韩成人影音 I 日日夜夜天天综合

terracotta集成session復(fù)制及Hibernate二級緩存

系統(tǒng) 1997 0

Terracotta 簡介;

Terracotta 是一款由美國 Terracotta 公司開發(fā)的著名開源 Java 集群平臺。它在 JVM Java 應(yīng)用之間實(shí)現(xiàn)了一個(gè)專門處理集群功能的抽象層,以其特有的增量檢測、智能定向傳送、分布式協(xié)作、服務(wù)器鏡像、分片等技術(shù),允許用戶在不改變現(xiàn)有系統(tǒng)代碼的情況下實(shí)現(xiàn)單機(jī) Java 應(yīng)用向集群話應(yīng)用的無縫遷移。使得用戶可以專注于商業(yè)邏輯的開發(fā),由 Terracotta 負(fù)責(zé)實(shí)現(xiàn)高性能、高可用性、高穩(wěn)定性的企業(yè)級 Java 集群. Terracotta 公司在 2009 年收購了著名的 Java 開源緩存項(xiàng)目 Ehcache 以及 Java 任務(wù)調(diào)度項(xiàng)目 Quartz 。經(jīng)過對該項(xiàng)目的深度整合, Terracotta 推出了易用性更高的分布式緩存、分布式任務(wù)調(diào)度以及分布式 Web Session 等快捷解決方案.以上引自老馬的文章,具體可參加作者博客了解http://lima01.iteye.com/。

配置環(huán)境:

我的配置環(huán)境是:winxp,jdk1.5—17,spring2.5,hibernate3.3,tomcat5.5, terracotta版本是3.2.1_1,目前最新版本是3.2.1_2,可在http://www.terracotta.org/dl/oss-download-catalog下載。

實(shí)戰(zhàn):

首先需要說明的是 terracotta分為express mode(快捷模式)和客戶化模式, express mode能夠讓大家快速上手,不需要復(fù)雜的配置就可運(yùn)行起來,而 客戶化模式則有很多高級功能,而且需要配置相應(yīng)的文件,初學(xué)可以先運(yùn)行 express mode作為學(xué)習(xí)。

首先以 express mode模式為例說明

1.首先下載 terracotta 3.2.1_1。jar,前提是機(jī)器已經(jīng)安裝jdk及配置好了java_home,利用java -jar terracotta 3.2.1_1。jar命令安裝 terracotta ,安裝時(shí)最好保持jdk及 terracotta 安裝目錄名稱都沒有空格。

2.首先集成session復(fù)制,將terracotta安裝目錄下的 sessions文件夾下的 terracotta-session-1.0.1.jar 拷貝到tomcat-5.5\server\lib文件夾下,然后

context.xml 文件(此文件可參見安裝目錄下的sessions\conf-samples的例子文件)拷貝到我們自己項(xiàng)目的 META-INF 文件夾下,具體內(nèi)容根據(jù)使用的不同中間件進(jìn)行不同配置,一下是使用tomcat5.5的配置,其他的也可看光放文檔說明http://www.terracotta.org/documentation/ga/product-documentation

例如:

<Context>

<Valve className="org.terracotta.session.TerracottaTomcat55xSessionValve" tcConfigUrl="localhost:9510"/>

</Context>

?

<!-- tomcat 5.5.x -->

將我們的web工程發(fā)布到webapps下,啟動tomcat5.5/bin/下的startup.bat即可,然后到Terracotta Console控制臺查看object brower下是否出現(xiàn)tc:session。也可運(yùn)行 terracotta自帶的例子,位于安裝目錄下的sessions\samples\下,驗(yàn)證時(shí)客氣起雙tomcat分配不同的端口號,打開兩個(gè)瀏覽器窗口進(jìn)行驗(yàn)證。

?

客戶化模式的session復(fù)制可參見老馬博客文章。

2.集成hibernate二級緩存

集成的時(shí)候需要注意將 將安裝后的 terracotta 文件夾下的 ehcache-core-2.0.1.jar ehcache-terracotta-2.0.1.jar slf4j-api-1.5.8.jar slf4j-jdk14-1.5.8.jar 等文件拷貝到項(xiàng)目的 lib 文件夾下,配置hibernate屬性

<prop key="hibernate.cache.use_query_cache">true</prop>
??? ??? ??? <prop key="hibernate.cache.use_second_level_cache">true</prop>
??? ??? ??? ? <prop key=" hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> ?

加粗部分根據(jù)使用的hibernate不同版本配置,在hibernate3.3中就需要配置為

    
      <property
    
    
      name
    
    
      =
    
    
      "hibernate.cache.region.factory_class"
    
    
      >
    
    



net.sf.ehcache.hibernate.EhCacheRegionFactory
    
      </property>

    
  

For Hibernate 3.2則是上面加粗部分配置。

ehcache.xml文件的配置為大致如下:

?

< defaultCache

????? maxElementsInMemory = "10"

????? eternal = "false"

????? timeToIdleSeconds = "120"

? ???? timeToLiveSeconds = "120"

????? >

??? < terracotta />

??? </ defaultCache >

? < terracottaConfig url = "localhost:9510" />

?? 需要注意的是快捷模式下無法使用 valueMode="identity" 模式

具體可根據(jù)需要進(jìn)行擴(kuò)展。下面要講述的客戶化模式配置會有很大卻別。

以上是express模式的大致配置。下面記錄客戶化模式

3.客戶化模式下的session復(fù)制及緩存

快捷模式不需要 tc-config Xml 文件的支持,直接啟動 start-tc-server Bat (win下)就可以,而客戶化模式需要在 tc-config . Xml 文件中進(jìn)行配置。

驗(yàn)證session復(fù)制的時(shí)候就不需要驚醒context。xml的配置及terracotta-session-1.0.1.jar的拷貝,一切都在 tc-config . Xml配置文件中配置大致配置如下:


?<servers>

?<!-- For more information on working with the Terracotta configuration file, including how to add
????? more servers, see http://www.terracotta.org/web/display/docs/About+Terracotta+Configuration+Files.
?????
????? Edit the following server element so that its host attribute contains the value matching the
????? hostname for the Terracotta server. -->
???
???? <server host="localhost">
??? ?<data>data/server-data</data>?
????? <logs>logs/server-logs</logs>?
????? <l2-group-port>9530</l2-group-port>?
<dso>
???????? <persistence>
?????????? <mode>permanent-store</mode>
???????? </persistence>
?????? </dso>

?? </server>
????


?????
??? <update-check>
?????? <enabled>true</enabled>
??? </update-check>

?</servers>
?
?<!-- Check that the TIM shown in the <module> element's name attribute matches the Tomcat version you
????? are using. The TIM listed here, "tim-tomcat-5.5" is for Tomcat 5.5. For example, if you are using
????? Tomcat 6.0, edit the name to "tim-tomcat-6.0".? -->
??????
? <clients>
??? <modules>
????? <module name="tim-tomcat-5.5" version="2.1.2" />
????? <module name="tim-tomcat-common" version="2.1.2" />
????? <module name="tim-session-common" version="2.1.2" />
??? ? <module name="tim-ehcache-2.0" version="1.5.2" />
??
???? <module name="tim-concurrent-collections" version="1.3.2" />
??? ? <module name="tim-distributed-cache" version="1.3.2" />
????
??? ??? ? <module name="tim-svt" version="1.3.2" />
??? ??? ?<module name="tim-quartz-1.7" version="1.3.2" />
??? ??? ?<module name="tim-async-processing" version="1.3.2" />
??? ??? ?<module name="tim-annotations" version="1.5.1" />

??? ??
??? </modules>
? </clients>

?<!-- Using <web-application> elements, enter the context root of the web application being clustered.
????? If you are clustering more than one web application, use one <web-application> element per application.
????? Two example <web-application> elements are shown below. Edit or remove these elements as needed.
????? To set the value of the <web-application> element to the default web-application context, use the
????? special value "ROOT" (without quotation marks). -->

?<application>
? <dso>
????? <additional-boot-jar-classes>
??????? <include>java.util.Locale</include>
??? ??? ?<include>java.lang.String$Case

?<instrumented-classes>
???????? <include>
?????????? <class-expression>org.acegisecurity.captcha.CaptchaSecurityContextImpl</class-expression>
???????? </include>
???????
????
?????? </instrumented-classes>
??? ?
??? <web-applications>
????? <web-application >myapplication</web-application>
??? </web-applications>
? </dso>
?</application>
</tc:tc-config>

?

首先前提是通過已經(jīng)通過 tim-get.bat install 命令安裝了相應(yīng)的 tim jar 文件。

? <instrumented-classes>

???????? <include>

?????????? <class-expression>org.acegisecurity.captcha.CaptchaSecurityContextImpl</class-expression>

???????? </include>

中配置需要在 terracotta 中共享的類,

一般在如果使用了 hibernate 情況下, test.hbm.xml 文件中 many-to-one 關(guān)系對應(yīng)的 class = "com.test.oa.domain.BaAt" 都需要在 <include> 中配置,不然啟動中間件時(shí)會報(bào)錯(cuò),控制臺也會提示您需要 include 相應(yīng)的類,

這里如果使用的 acegi 安全框架,目前 terracotta1 版本只能在客戶化模式下配置,不能使用 express 模式。

?

??? <web-applications>

????? <web-application >myWebApplication</web-application>

</web-applications>

?

配置相應(yīng)的 web 工程.

如果集成 ehcache 時(shí),還需要將 tim-ehcache-2.0-1.5.2.jar tim-distributed-cache-1.3.2.jar tim-concurrent-collections-1.3.2.jar 、等拷貝到項(xiàng)目的 lib 下( express 模式不需要拷貝),可參看官方文檔說明。

?

客戶化模式的啟動需要 startupTC.bat 的支持,還是以 tomcat 為例,在 tomcat bin 目錄下建立 startupTC.bat 內(nèi)容如下:

set TC_INSTALL_DIR=D:\terracotta(安裝目錄)

set TC_CONFIG_PATH=D:\terracotta\bin\tc-config.xml(安裝目錄下的自建配置文件)

call %TC_INSTALL_DIR%\bin\dso-env.bat -q

set JAVA_OPTS=%JAVA_OPTS% %TC_JAVA_OPTS% -Xms256m -Xmx1024m -XX:MaxPermSize=128m

pause

startup.bat

紅色部分很重要。

客戶化模式還需要根據(jù) tc-config Xml 重新生成 boot.jar ,位置在 terracotta\lib\dso-boot

?

常用命令如下:

tim-get.bat upgrade tc-config.xml

make-boot-jar.bat -f tc-config.xml

start-tc-server.bat -n jerry -f D:\terracotta\bin\tc-config.xml

多server時(shí)需要啟動服務(wù)端時(shí)指定name名稱,如上所示,配置多server時(shí)刻以很容易實(shí)現(xiàn)容災(zāi)數(shù)據(jù)備份等, 一個(gè) server down 了,另一個(gè) server 可無感知切換至激活狀態(tài)

啟動 startupTC.bat后進(jìn)入 terracotta控制臺查看效果,如附件所示。

以上大致寫了一些,以作備忘。

terracotta集成session復(fù)制及Hibernate二級緩存筆記


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論