<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    paulwong

    使用WILDFLY中的分布式緩存INFISHPAN

    項目部署的應用服務器:WILDFLY
    1. 通過http://127.0.0.1:9991/console/App.html#infinispan添加CACHE
      <cache-container name="tickets" default-cache="default" jndi-name="java:jboss/infinispan/tickets">
             <local-cache name="default" batching="true">
                    <locking isolation="REPEATABLE_READ"/>
             </local-cache>
      </cache-container>

    2. pom.xml添加依賴包
              <dependency>
                  <groupId>org.infinispan</groupId>
                  <artifactId>infinispan-core</artifactId>
                  <scope>provided</scope>
              </dependency>
              
              <dependency>
                  <groupId>org.infinispan</groupId>
                  <artifactId>infinispan-client-hotrod</artifactId>
                  <scope>provided</scope>
              </dependency>

          <dependency>
              <groupId>org.jgroups</groupId>
              <artifactId>jgroups</artifactId>
              <scope>provided</scope>
          </dependency>

              <dependency>
                  <groupId>org.infinispan</groupId>
                  <artifactId>infinispan-spring</artifactId>
                  <version>6.0.2.Final</version>
              </dependency>
              
              <dependency>
                  <groupId>org.infinispan</groupId>
                  <artifactId>infinispan-jcache</artifactId>
                  <version>6.0.2.Final</version>
              </dependency>

    3. 添加攔截器,WEB-INF/beans.xml
      <?xml version="1.0"?>
      <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation
      ="http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd">
          <interceptors>
              <class>org.infinispan.jcache.annotation.CacheResultInterceptor</class>
              <class>org.infinispan.jcache.annotation.CachePutInterceptor</class>
              <class>org.infinispan.jcache.annotation.CacheRemoveEntryInterceptor</class>
              <class>org.infinispan.jcache.annotation.CacheRemoveAllInterceptor</class>
          </interceptors>
      </beans>

    4. 添加項目的全局依賴,WEB-INF/jboss-deployment-structure.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <jboss-deployment-structure>
          <deployment>
              <dependencies>
                  <module name="org.jboss.xnio" />
                  <module name="org.infinispan" export="true"/>
                  <module name="org.infinispan.commons" export="true"/>
                  <module name="org.infinispan.client.hotrod" export="true"/>
              </dependencies>
          </deployment>
      </jboss-deployment-structure>

    5. 在CDI BEAN中使用CACHE
      package com.paul.myejb;

      import javax.annotation.Resource;
      import javax.cache.annotation.CacheResult;
      import javax.ejb.Remote;
      import javax.ejb.Stateless;
      import javax.interceptor.Interceptors;

      import org.infinispan.Cache;
      import org.infinispan.manager.EmbeddedCacheManager;
      //import org.springframework.cache.annotation.Cacheable;
      import org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor;

      /**
       * Session Bean implementation class HelloWorldBean
       
      */
      @Stateless
      //@Local(HelloWorld.class)
      @Remote(HelloWorld.class)
      @Interceptors(SpringBeanAutowiringInterceptor.class)
      //@RolesAllowed({Roles.ADMIN})
      public class HelloWorldBean implements HelloWorld {
          
          @Resource(lookup = "java:jboss/infinispan/tickets")
          private EmbeddedCacheManager container;
          
          
          /**
           * Default constructor. 
           
      */
          public HelloWorldBean() {
          }

      //    @Transactional
      //    @Cacheable(value = "books", key = "#name")
          @CacheResult
          public String sayHello(String name) {
              System.out.println("NO CACHE");
              String result = "Hello " + name + ", I am HelloWorldBean.";
              Cache<String, String> cache = this.container.getCache();
              cache.put(name, result);
              return result;
          }

      }


    6. 修改modules/system/layers/base/org/infinispan/client/hotrod/main/modules.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <!--
        ~ JBoss, Home of Professional Open Source.
        ~ Copyright 2010, Red Hat, Inc., and individual contributors
        ~ as indicated by the @author tags. See the copyright.txt file in the
        ~ distribution for a full listing of individual contributors.
        ~
        ~ This is free software; you can redistribute it and/or modify it
        ~ under the terms of the GNU Lesser General Public License as
        ~ published by the Free Software Foundation; either version 2.1 of
        ~ the License, or (at your option) any later version.
        ~
        ~ This software is distributed in the hope that it will be useful,
        ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
        ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
        ~ Lesser General Public License for more details.
        ~
        ~ You should have received a copy of the GNU Lesser General Public
        ~ License along with this software; if not, write to the Free
        ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
        ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
        
      -->
      <module xmlns="urn:jboss:module:1.3" name="org.infinispan.client.hotrod">
          <properties>
              <property name="jboss.api" value="private"/>
          </properties>

          <resources>
              <resource-root path="infinispan-client-hotrod-6.0.2.Final.jar"/>
          </resources>

          <dependencies>
              <module name="javax.api"/>
              <!--下面這一行注釋掉-->
              <!--<module name="com.google.protobuf"/>-->
              <module name="org.apache.commons.pool"/>
              <module name="org.infinispan.commons"/>
              <module name="org.infinispan.query.dsl"/>
              <module name="org.jboss.logging"/>
          </dependencies>
      </module>

    以下是SPRING版本
    1. 添加依賴的SPRING BEAN
      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
          xmlns:xsi
      ="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
          xmlns:cache
      ="http://www.springframework.org/schema/cache"
          xmlns:p
      ="http://www.springframework.org/schema/p"
          xmlns:jee
      ="http://www.springframework.org/schema/jee"
          xsi:schemaLocation
      ="http://www.springframework.org/schema/context
                http://www.springframework.org/schema/context/spring-context-3.0.xsd
                http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                http://www.springframework.org/schema/cache
                http://www.springframework.org/schema/cache/spring-cache.xsd
                http://www.springframework.org/schema/jee 
                http://www.springframework.org/schema/jee/spring-jee.xsd"
      >

          <cache:annotation-driven />
          
          <bean id="cacheManager"
                class
      ="org.infinispan.spring.provider.ContainerCacheManagerFactoryBean">
                <constructor-arg ref="cacheContainer"  />
          </bean>
          
          <jee:jndi-lookup id="cacheContainer" jndi-name="java:jboss/infinispan/tickets" > 
          </jee:jndi-lookup>
          
          <!-- <bean id="cacheContainer"
                class="com.paul.myejb.common.util.cache.JndiSpringCacheManagerFactoryBean"
                p:infinispanJNDI="java:jboss/infinispan/tickets" /> 
      -->
          
      </beans>

    2. 使用CACHE
      package com.paul.myejb.spring;

      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.cache.CacheManager;
      import org.springframework.cache.annotation.Cacheable;
      import org.springframework.stereotype.Component;

      @Component
      public class MySpringBean {
          
          @Autowired
          private CacheManager cacheManager;
          
          @Cacheable(value = "my-local-cache", key = "#name")
          public String sayHello(String name)
          {
              System.out.println("MySpringBean NO CACHE");
              String result = "Hi " + name + ", I am Spring!";
              org.springframework.cache.Cache springCache = this.cacheManager.getCache("my-local-cache");
              System.out.println(springCache.get(name) == null ? "null" : springCache.get(name).get());
              springCache.put(name, result);
              return result;
          }

      }


    posted on 2015-02-23 13:40 paulwong 閱讀(1000) 評論(0)  編輯  收藏 所屬分類: 分布式性能優化JBOSS緩存

    主站蜘蛛池模板: a色毛片免费视频| 在线观看免费大黄网站| 亚洲AV综合色区无码二区偷拍 | 免费无码A片一区二三区| 亚洲AV成人片无码网站| 亚洲色爱图小说专区| 在人线av无码免费高潮喷水| 一级做a免费视频观看网站| 亚洲精品白色在线发布| 大胆亚洲人体视频| 18禁无遮挡无码国产免费网站| 亚洲欧美在线x视频| 亚洲精品视频在线| 免费看国产一级片| xxxxx免费视频| 国产免费一区二区三区免费视频 | 亚洲爆乳无码专区www| 亚洲AV永久精品爱情岛论坛| 最近中文字幕mv免费高清视频7 | 四虎永久在线观看免费网站网址 | 香蕉视频在线观看免费国产婷婷| 中文字幕无线码中文字幕免费| 久久亚洲国产最新网站| 亚洲AV无码一区二区三区系列| 超pen个人视频国产免费观看| 久久久久久国产精品免费免费男同 | 午夜毛片不卡高清免费| 久久国产精品免费视频| 无人视频免费观看免费视频 | 在线观看免费污视频| 最近中文字幕免费mv在线视频| 丁香六月婷婷精品免费观看| 亚洲中文字幕无码中文字| 久久丫精品国产亚洲av| 国产亚洲精品资在线| 免费A级毛片无码A| 免费激情视频网站| 国产精品视频免费一区二区| 久草视频在线免费看| 中国videos性高清免费| 一级毛片成人免费看a|