0

我们如何在 jboss eap 6.3 服务器中配置缓存并将其用于其他不同的应用程序,如 j2ee 等

请在这里提供帮助.. !!

4

2 回答 2

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("一", "二"); divCache.put("三","四");

于 2016-08-12T12:41:50.527 回答
1

嗨,我做了“在 Jboss EAP 6.3 中使用 Infinispan 进行缓存”

以下是相同的步骤-

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

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

3.在您的项目中创建示例类,并在其中添加此代码片段-

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")); 

4.现在需要添加这个“userInputCache到你的infinispan.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>

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

<?xml version="1.0" encoding="UTF-8"?>

<config xmlns="urn:org:jgroups"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/JGroups-3.4.xsd">
    <!--
    Note that the buffer sizes here are very small, you'll definitely want higher values in production.
    But the Linux defaults are also very small, and using higher values here without changing the system
    settings would only result in startup warnings.14.96.226.125
     -->
     <UDP
            mcast_addr="${jgroups.udp.mcast_addr:228.8.8.8}"
            mcast_port="${jgroups.udp.mcast_port:45566}"
            tos="8"
            ucast_recv_buf_size="200k"
            ucast_send_buf_size="200k"
            mcast_recv_buf_size="200k"
            mcast_send_buf_size="200k"
            loopback="true"
            max_bundle_size="64000"
            max_bundle_timeout="30"
            ip_ttl="${jgroups.udp.ip_ttl:2}"
            enable_bundling="true"
            enable_diagnostics="false"
            bundler_type="old"

            thread_naming_pattern="pl"

            thread_pool.enabled="true"
            thread_pool.min_threads="2"
            thread_pool.max_threads="30"
            thread_pool.keep_alive_time="60000"
            thread_pool.queue_enabled="true"
            thread_pool.queue_max_size="100"
            thread_pool.rejection_policy="Discard"

            oob_thread_pool.enabled="true"
            oob_thread_pool.min_threads="2"
            oob_thread_pool.max_threads="30"
            oob_thread_pool.keep_alive_time="60000"
            oob_thread_pool.queue_enabled="false"
            oob_thread_pool.queue_max_size="100"
            oob_thread_pool.rejection_policy="Discard"
            /> 

    <PING timeout="3000" num_initial_members="3"/>
    <MERGE2 max_interval="30000" min_interval="10000"/>
    <FD_SOCK/>
    <FD_ALL timeout="15000"/>
    <VERIFY_SUSPECT timeout="5000"/>
    <!-- Commented when upgraded to 3.1.0.Alpha (remove eventually)
    <pbcast.NAKACK  exponential_backoff="0"
                    use_mcast_xmit="true"
                    retransmit_timeout="300,600,1200"
                    discard_delivered_msgs="true"/> -->
    <pbcast.NAKACK2
            xmit_interval="1000"
            xmit_table_num_rows="100"
            xmit_table_msgs_per_row="10000"
            xmit_table_max_compaction_time="10000"
            max_msg_batch_size="100"/>

    <!-- Commented when upgraded to 3.1.0.Alpha (remove eventually)
    <UNICAST timeout="300,600,1200"/>  -->
    <UNICAST2
            stable_interval="5000"
            xmit_interval="500"
            max_bytes="1m"
            xmit_table_num_rows="20"
            xmit_table_msgs_per_row="10000"
            xmit_table_max_compaction_time="10000"
            max_msg_batch_size="100"
            conn_expiry_timeout="0"/>
    <pbcast.STABLE stability_delay="500" desired_avg_gossip="5000" max_bytes="1m"/>
    <pbcast.GMS print_local_addr="false" join_timeout="3000" view_bundling="true"/>
    <UFC max_credits="200k" min_threshold="0.20"/>
    <MFC max_credits="200k" min_threshold="0.20"/>
    <FRAG2 frag_size="8000"  />
    <RSVP timeout="60000" resend_interval="500" ack_on_delivery="true" />
</config>

6.执行你的第一个示例类,你已经缓存了数据 - 祝你好运

于 2015-08-06T10:14:25.693 回答