Jboss eap-6.3缓存配置

时间:2015-07-25 08:14:00

标签: caching infinispan jboss-eap-6 jboss-cache

我们如何在jboss eap 6.3服务器中配置缓存,并在j2ee等其他应用程序中使用它

请在这里帮助.. !!

2 个答案:

答案 0 :(得分:2)

使用jboss eap配置进行缓存:

步骤

1)jboss eap 6.3的 standalone-ha.xml 中的子系统

 <subsystem xmlns="urn:jboss:domain:infinispan:1.5">
            <cache-container name="DataCacheContainer" aliases="demo" default-cache="EdgeCache" start="EAGER" module="org.jboss.as.clustering.infinispan">
                <transport lock-timeout="60000"/>
                <replicated-cache name="EdgeCache" mode="ASYNC" batching="true">
                    <eviction strategy="LRU" max-entries="250000"/>
                    <file-store/>
                </replicated-cache>
                <replicated-cache name="SubdivCache" mode="SYNC" batching="true">
                    <eviction strategy="LIRS" max-entries="25000"/>
                    <file-store/>
                </replicated-cache>
            </cache-container>
            <cache-container name="LocatorCacheContainer" default-cache="trainLocatorCache">
                <local-cache name="LocatorCache"/>
            </cache-container>
            <cache-container name="ScheduleCacheContainer" default-cache="tgeoControlPtCache">
                <local-cache name="ControlPtCache"/>
            </cache-container>
            <cache-container name="singleton" aliases="cluster ha-partition" default-cache="default">
                <transport lock-timeout="60000"/>
                <replicated-cache name="default" mode="SYNC" batching="true">
                    <locking isolation="REPEATABLE_READ"/>
                </replicated-cache>
            </cache-container>
            <cache-container name="web" aliases="standard-session-cache" default-cache="repl" module="org.jboss.as.clustering.web.infinispan">
                <transport lock-timeout="60000"/>
                <replicated-cache name="repl" mode="ASYNC" batching="true">
                    <file-store/>
                </replicated-cache>
                <replicated-cache name="sso" mode="SYNC" batching="true"/>
                <distributed-cache name="dist" l1-lifespan="0" mode="ASYNC" batching="true">
                    <file-store/>
                </distributed-cache>
            </cache-container>
            <cache-container name="ejb" aliases="sfsb sfsb-cache" default-cache="repl" module="org.jboss.as.clustering.ejb3.infinispan">
                <transport lock-timeout="60000"/>
                <replicated-cache name="repl" mode="ASYNC" batching="true">
                    <eviction strategy="LRU" max-entries="10000"/>
                    <file-store/>
                </replicated-cache>
                <replicated-cache name="remote-connector-client-mappings" mode="SYNC" batching="true"/>
                <distributed-cache name="dist" l1-lifespan="0" mode="ASYNC" batching="true">
                    <eviction strategy="LRU" max-entries="10000"/>
                    <file-store/>
                </distributed-cache>
            </cache-container>

2)使用url:

从代码中查找这些缓存容器
 private static Cache<Integer, DataObject> cache;
    private static Cache<String, Integer> DivCache;


            InitialContext ic = new InitialContext();

            CacheContainer cc = (CacheContainer)    ic.lookup("java:jboss/infinispan/container/DataCacheContainer");

            cc.start();

            cache = cc.getCache("EdgeCache");
            divCache = cc.getCache("SubDivCache");
            cache.start();
            divCache.start();

            logger.info("Cache Objects started successfully...");

3)现在您可以将数据存储在这些缓存对象中。

cache.put(&#34;一个&#34;,&#34;两个&#34;); divCache.put(&#34;三&#34;&#34; 4&#34);

答案 1 :(得分:1)

您好我在“使用Jboss EAP 6.3中的Infinispan进行缓存”

以下是相同的步骤 -

  1. 需要创建一个项目(Maven / Dynamic web)。
  2. 如果您的项目是maven项目,请在pom.xml中添加一个依赖项,无论您需要什么版本 -

    /api/v1/{division}/crm/Accounts?$filter=Classification1 eq guid'the-guid-you-retrieved'
    
  3. 3.在项目中创建示例类,然后添加此代码段 -

        <dependency>
            <groupId>org.infinispan</groupId>
            <artifactId>infinispan-core</artifactId>
            <version>7.1.0.Final</version>
        </dependency> 
    

    4.现在需要将此“userInputCache添加到您的infinispan.xml”文件下面的代码是相同的 -

    Cache<String, String> userInputCache;
    EmbeddedCacheManager cm = new DefaultCacheManager("infinispan.xml");
    userInputCache = cm.getCache("demoClusterCache");
    userInputCache.put("demo", "DemoCacheValue");
    System.out.println("cache value is :+ userInputCache.get("demo")); 
    

    5.如果你需要在分布式和集群环境中配置这个缓存,那么我们还有jgroups.xml文件,那么下面还需要添加这个代码 -

    <infinispan
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="urn:infinispan:config:7.1 http://www.infinispan.org/schemas/infinispan-config-7.1.xsd"
            xmlns="urn:infinispan:config:7.1">         
            <jgroups>
                <stack-file name="udp" path="jgroups.xml" />
            </jgroups>          
            <cache-container default-cache="default" >
                 <transport stack="udp" node-name="demo" />              
                 <replicated-cache name="repl" mode="SYNC" />
                 <distributed-cache name="dist" mode="SYNC" owners="2" />  
    
                 <local-cache name="demoClusterCache">
                    <eviction strategy="LIRS" max-entries="10" />
                </local-cache>  
    
             </cache-container>    
    </infinispan>
    

    6.执行您缓存数据的第一个示例类 - 祝您好运