运行环境:JBoss Data Grid 6.3.0
Carmart既可以运行在Library mode下,也可以运行在Remote Client-Server mode下。
学习重点:
1. Library mode和Remote Client-Server mode编译时是如何切换的?
(1)编译前,选择library-jbossas profile,profile具体信息查看pom.xml。
@ApplicationScoped
public class LocalCacheContainerProvider extends CacheContainerProvider {
private Logger log = Logger.getLogger(this.getClass().getName());
private BasicCacheContainer manager;
public BasicCacheContainer getCacheContainer() {
if (manager == null) {
GlobalConfiguration glob = new GlobalConfigurationBuilder()
.nonClusteredDefault() //Helper method that gets you a default constructed GlobalConfiguration, preconfigured for use in LOCAL mode
.globalJmxStatistics().enable() //This method allows enables the jmx statistics of the global configuration.
.build(); //Builds the GlobalConfiguration object
Configuration loc = new ConfigurationBuilder()
.jmxStatistics().enable() //Enable JMX statistics
.clustering().cacheMode(CacheMode.LOCAL) //Set Cache mode to LOCAL - Data is not replicated.
.locking().isolationLevel(IsolationLevel.REPEATABLE_READ) //Sets the isolation level of locking
.eviction().maxEntries(4).strategy(EvictionStrategy.LIRS) //Sets 4 as maximum number of entries in a cache instance and uses the LIRS strategy - an efficient low inter-reference recency set replacement policy to improve buffer cache performance
.persistence().passivation(false).addSingleFileStore().purgeOnStartup(true) //Disable passivation and adds a SingleFileStore that is Purged on Startup
.build(); //Builds the Configuration object
manager = new DefaultCacheManager(glob, loc, true);
log.info("=== Using DefaultCacheManager (library mode) ===");
}
return manager;
}
@PreDestroy
public void cleanUp() {
manager.stop();
manager = null;
}
}
(2)编译前,选择remote-jbossas profile,profile具体信息查看pom.xml。
@ApplicationScoped
public class RemoteCacheContainerProvider extends CacheContainerProvider {
private Logger log = Logger.getLogger(this.getClass().getName());
private BasicCacheContainer manager;
public BasicCacheContainer getCacheContainer() {
if (manager == null) {
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.addServer()
.host(jdgProperty(DATAGRID_HOST))
.port(Integer.parseInt(jdgProperty(HOTROD_PORT)));
manager = new RemoteCacheManager(builder.build());
log.info("=== Using RemoteCacheManager (Hot Rod) ===");
}
return manager;
}
@PreDestroy
public void cleanUp() {
manager.stop();
manager = null;
}
}
2. 依赖注入到CarManager中的CacheContainerProvider,使用的到底是哪个实现?
@Inject
private CacheContainerProvider provider;
选择不同的profile进行编译时,只有一个实现,要么是library mode,要么是remote client-server mode,所以不会冲突。
3. EmbeddedCacheManager 返回的是Cache类型的缓存实例,RemoteCacheManager返回的是 RemoteCache类型的缓存实例,二者有共同的接口吗?
有,BasicCache。
private BasicCache carCache;
4. 编译、部署、运行
4.1 library mode
(1)编译:选择library-jbossas profile
(2)启动JBoss EAP 6.3
cd /Users/maping/Redhat/Eap/jboss-eap-6.3-jdg-carmart/bin
./standalone.sh。
(3)访问:http://localhost:8080/jboss-carmart。
4.2 remote client-server mode
(1)编译:选择remote-jbossas profile
(2)启动JBoss EAP 6.3
cd /Users/maping/Redhat/Eap/jboss-eap-6.3-jdg-carmart/bin
./standalone.sh
(3)修改JBoss Data Grid 6.3中的配置文件 standalone.xml,增加carcache
<subsystem xmlns="urn:infinispan:server:core:6.1" default-cache-container="local">
<cache-container name="local" default-cache="default" statistics="true">
<local-cache name="carcache" start="EAGER"
batching="false"
statistics="true">
<eviction strategy="LIRS" max-entries="4"/>
</local-cache>
<local-cache name="default" start="EAGER">
<locking isolation="NONE" acquire-timeout="30000" concurrency-level="1000" striping="false"/>
<transaction mode="NONE"/>
</local-cache>
<local-cache name="memcachedCache" start="EAGER">
<locking isolation="NONE" acquire-timeout="30000" concurrency-level="1000" striping="false"/>
<transaction mode="NONE"/>
</local-cache>
<local-cache name="namedCache" start="EAGER"/>
</cache-container>
<cache-container name="security"/>
</subsystem>
(4)启动JBoss Data Grid 6.3
/Users/maping/Redhat/Datagrid/jboss-datagrid-6.3.0-server/bin
./standalone.sh -c standalone-carmart.xml
(5)访问:http://localhost:8080/jboss-carmart。
Carmart既可以运行在Library mode下,也可以运行在Remote Client-Server mode下。
学习重点:
1. Library mode和Remote Client-Server mode编译时是如何切换的?
(1)编译前,选择library-jbossas profile,profile具体信息查看pom.xml。
@ApplicationScoped
public class LocalCacheContainerProvider extends CacheContainerProvider {
private Logger log = Logger.getLogger(this.getClass().getName());
private BasicCacheContainer manager;
public BasicCacheContainer getCacheContainer() {
if (manager == null) {
GlobalConfiguration glob = new GlobalConfigurationBuilder()
.nonClusteredDefault() //Helper method that gets you a default constructed GlobalConfiguration, preconfigured for use in LOCAL mode
.globalJmxStatistics().enable() //This method allows enables the jmx statistics of the global configuration.
.build(); //Builds the GlobalConfiguration object
Configuration loc = new ConfigurationBuilder()
.jmxStatistics().enable() //Enable JMX statistics
.clustering().cacheMode(CacheMode.LOCAL) //Set Cache mode to LOCAL - Data is not replicated.
.locking().isolationLevel(IsolationLevel.REPEATABLE_READ) //Sets the isolation level of locking
.eviction().maxEntries(4).strategy(EvictionStrategy.LIRS) //Sets 4 as maximum number of entries in a cache instance and uses the LIRS strategy - an efficient low inter-reference recency set replacement policy to improve buffer cache performance
.persistence().passivation(false).addSingleFileStore().purgeOnStartup(true) //Disable passivation and adds a SingleFileStore that is Purged on Startup
.build(); //Builds the Configuration object
manager = new DefaultCacheManager(glob, loc, true);
log.info("=== Using DefaultCacheManager (library mode) ===");
}
return manager;
}
@PreDestroy
public void cleanUp() {
manager.stop();
manager = null;
}
}
(2)编译前,选择remote-jbossas profile,profile具体信息查看pom.xml。
@ApplicationScoped
public class RemoteCacheContainerProvider extends CacheContainerProvider {
private Logger log = Logger.getLogger(this.getClass().getName());
private BasicCacheContainer manager;
public BasicCacheContainer getCacheContainer() {
if (manager == null) {
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.addServer()
.host(jdgProperty(DATAGRID_HOST))
.port(Integer.parseInt(jdgProperty(HOTROD_PORT)));
manager = new RemoteCacheManager(builder.build());
log.info("=== Using RemoteCacheManager (Hot Rod) ===");
}
return manager;
}
@PreDestroy
public void cleanUp() {
manager.stop();
manager = null;
}
}
2. 依赖注入到CarManager中的CacheContainerProvider,使用的到底是哪个实现?
@Inject
private CacheContainerProvider provider;
选择不同的profile进行编译时,只有一个实现,要么是library mode,要么是remote client-server mode,所以不会冲突。
3. EmbeddedCacheManager 返回的是Cache类型的缓存实例,RemoteCacheManager返回的是 RemoteCache类型的缓存实例,二者有共同的接口吗?
有,BasicCache。
private BasicCache
4. 编译、部署、运行
4.1 library mode
(1)编译:选择library-jbossas profile
(2)启动JBoss EAP 6.3
cd /Users/maping/Redhat/Eap/jboss-eap-6.3-jdg-carmart/bin
./standalone.sh。
(3)访问:http://localhost:8080/jboss-carmart。
4.2 remote client-server mode
(1)编译:选择remote-jbossas profile
(2)启动JBoss EAP 6.3
cd /Users/maping/Redhat/Eap/jboss-eap-6.3-jdg-carmart/bin
./standalone.sh
(3)修改JBoss Data Grid 6.3中的配置文件 standalone.xml,增加carcache
<subsystem xmlns="urn:infinispan:server:core:6.1" default-cache-container="local">
<cache-container name="local" default-cache="default" statistics="true">
<local-cache name="carcache" start="EAGER"
batching="false"
statistics="true">
<eviction strategy="LIRS" max-entries="4"/>
</local-cache>
<local-cache name="default" start="EAGER">
<locking isolation="NONE" acquire-timeout="30000" concurrency-level="1000" striping="false"/>
<transaction mode="NONE"/>
</local-cache>
<local-cache name="memcachedCache" start="EAGER">
<locking isolation="NONE" acquire-timeout="30000" concurrency-level="1000" striping="false"/>
<transaction mode="NONE"/>
</local-cache>
<local-cache name="namedCache" start="EAGER"/>
</cache-container>
<cache-container name="security"/>
</subsystem>
(4)启动JBoss Data Grid 6.3
/Users/maping/Redhat/Datagrid/jboss-datagrid-6.3.0-server/bin
./standalone.sh -c standalone-carmart.xml
(5)访问:http://localhost:8080/jboss-carmart。
没有评论:
发表评论