日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

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

系統(tǒng) 1844 0

Terracotta 簡(jiǎn)介;

Terracotta 是一款由美國(guó) Terracotta 公司開(kāi)發(fā)的著名開(kāi)源 Java 集群平臺(tái)。它在 JVM Java 應(yīng)用之間實(shí)現(xiàn)了一個(gè)專(zhuān)門(mén)處理集群功能的抽象層,以其特有的增量檢測(cè)、智能定向傳送、分布式協(xié)作、服務(wù)器鏡像、分片等技術(shù),允許用戶(hù)在不改變現(xiàn)有系統(tǒng)代碼的情況下實(shí)現(xiàn)單機(jī) Java 應(yīng)用向集群話(huà)應(yīng)用的無(wú)縫遷移。使得用戶(hù)可以專(zhuān)注于商業(yè)邏輯的開(kāi)發(fā),由 Terracotta 負(fù)責(zé)實(shí)現(xiàn)高性能、高可用性、高穩(wěn)定性的企業(yè)級(jí) Java 集群. Terracotta 公司在 2009 年收購(gòu)了著名的 Java 開(kāi)源緩存項(xiàng)目 Ehcache 以及 Java 任務(wù)調(diào)度項(xiàng)目 Quartz 。經(jīng)過(guò)對(duì)該項(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):

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

首先以 express mode模式為例說(shuō)明

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 安裝目錄名稱(chēng)都沒(méi)有空格。

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

context.xml 文件(此文件可參見(jiàn)安裝目錄下的sessions\conf-samples的例子文件)拷貝到我們自己項(xiàng)目的 META-INF 文件夾下,具體內(nèi)容根據(jù)使用的不同中間件進(jìn)行不同配置,一下是使用tomcat5.5的配置,其他的也可看光放文檔說(shuō)明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下,啟動(dòng)tomcat5.5/bin/下的startup.bat即可,然后到Terracotta Console控制臺(tái)查看object brower下是否出現(xiàn)tc:session。也可運(yùn)行 terracotta自帶的例子,位于安裝目錄下的sessions\samples\下,驗(yàn)證時(shí)客氣起雙tomcat分配不同的端口號(hào),打開(kāi)兩個(gè)瀏覽器窗口進(jìn)行驗(yàn)證。

?

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

2.集成hibernate二級(jí)緩存

集成的時(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" />

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

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

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

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

快捷模式不需要 tc-config Xml 文件的支持,直接啟動(dòng) start-tc-server Bat (win下)就可以,而客戶(hù)化模式需要在 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>

?

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

? <instrumented-classes>

???????? <include>

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

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

中配置需要在 terracotta 中共享的類(lèi),

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

這里如果使用的 acegi 安全框架,目前 terracotta1 版本只能在客戶(hù)化模式下配置,不能使用 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 模式不需要拷貝),可參看官方文檔說(shuō)明。

?

客戶(hù)化模式的啟動(dòng)需要 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

紅色部分很重要。

客戶(hù)化模式還需要根據(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í)需要啟動(dòng)服務(wù)端時(shí)指定name名稱(chēng),如上所示,配置多server時(shí)刻以很容易實(shí)現(xiàn)容災(zāi)數(shù)據(jù)備份等, 一個(gè) server down 了,另一個(gè) server 可無(wú)感知切換至激活狀態(tài)

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

以上大致寫(xiě)了一些,以作備忘。

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


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

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

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

【本文對(duì)您有幫助就好】

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 灵璧县| 丰原市| 上犹县| 谷城县| 南开区| 天镇县| 凤翔县| 卢氏县| 安宁市| 丰城市| 鄂尔多斯市| 久治县| 江北区| 洪泽县| 太原市| 连州市| 建湖县| 甘孜县| 蛟河市| 乡城县| 时尚| 浙江省| 平乐县| 康保县| 濉溪县| 屏山县| 专栏| 乌什县| 河曲县| 东宁县| 溧水县| 上犹县| 双城市| 清流县| 枞阳县| 大同县| 白银市| 昭苏县| 宜昌市| 海宁市| 元谋县|