JBoss series of 28 four: the deployment of a cluster JBoss-based micro-containers JBossCache

Example Introduction

JBoss micro-containers (JBoss Microcontainer) is a second-generation core JBoss architecture that first-generation JBoss core set architecture (pure JMX MBean) advantages, the concept of POJO Bean added, the container is a lightweight and to manage POJOs their deployment, configuration and so on. JBoss AS 6, JBoss AS 5 are based on this architecture. Detailed reference http://www.jboss.org/jbossmc .

According to the previous example, can be used independently i.e. JBossCache / for deployment (in the program in JBossCache replication example ), can also be deployed via the JBoss micrcontainer, the present example demonstrates JBossCache by deploying micro-container by JBoss, and presentation by JBossCache copy the data in the cluster. This example is similar to JBoss series twenty-two: JBossCache copy the sample , except that this example will copy the program need to be deployed with JBoss, standards-compliant Java enterprise applications standards.

GWT is an abbreviation GoogleWeb Toolkit, GWT allows developers to use the Java programming language to quickly build and maintain complex but high-performance JavaScript front-end applications, thus reducing development effort and speed up the development speed, detailed on GWT, please refer to http: // www .gwtproject.org / , the present exemplary example user interface built using GWT.

This example needs to run on two machines, two machines were installed JBoss AS 5 (refer to software installation and data download ), both based on JBoss, we need to do JBossCache relevant configuration, this and this sample application needs to be deployed to two Taiwan JBoss above. This example architecture substantially as shown below:


JBossCache deployed in micro-containers on JBoss (JBoss micro-container activated by JBoss); JBossCache other nodes constituting a cluster cache and local area network, shared data; JBossCache the EJB service providing operator interface data cache to add, delete, change,; the GWT the server acquires the data by caching services EJB; GWT GWT client server acquired display data to the end user.

Example run

Compiler package generated deployment file

The JBoss Cluster Framework Demo describes the method shown, any download from SourceForge or compiled DEMO_HOME, deployment file jbosscache-jboss-ear.ear located in DEMO_HOME / dist directory.

JBossCache start deploying in JBoss micro-container

Let's start by starting the JBoss micro-container JBoss AS 5, in order to simplify we bind two network cards on the same physical cluster to simulate two physical machines. After installing JBoss AS 5, to the lower JBOSS_HOME / server directory exemplary two copies of all, two analog JBoss example, as follows:

cp -r all/ node1
cp -r all/ node2
Before starting the JBoss example we first need to configure JBossCache. Node1 and node2 respectively edit the deploy / cluster / jboss-cache-manager.sar / META-INF / jboss-cache-manager-jboss-beans.xml file, JBossCache add custom properties in newConfigurations <map> of:

<bean name="CacheConfigurationRegistry" class="org.jboss.ha.cachemanager.DependencyInjectedConfigurationRegistry">
     	<property name="newConfigurations">
     		<map keyClass="java.lang.String" valueClass="org.jboss.cache.config.Configuration">
     		  // 自定义 JBossCache 的配置添加在此
     		</map>
     	</property>
</bean>
As described above, the custom JBossCache follows:

<entry><key>my-custom-cache</key>
   <value>      
      <bean name="MyCustomCacheConfig" class="org.jboss.cache.config.Configuration">
         <property name="transactionManagerLookupClass">org.jboss.cache.transaction.BatchModeTransactionManagerLookup</property>
         <property name="clusterName">${jboss.partition.name:DefaultPartition}-CustomizedCache</property>
         <property name="multiplexerStack">${jboss.default.jgroups.stack:udp}</property>
         <property name="fetchInMemoryState">true</property>
         <property name="nodeLockingScheme">PESSIMISTIC</property>
         <property name="isolationLevel">REPEATABLE_READ</property>
         <property name="useLockStriping">false</property>
         <property name="cacheMode">REPL_ASYNC</property>

<property name="syncReplTimeout">17500</property>
         <property name="lockAcquisitionTimeout">15000</property>
         <property name="stateRetrievalTimeout">60000</property>
         <property name="useRegionBasedMarshalling">false</property>
         <property name="inactiveOnStartup">false</property>
         <property name="serializationExecutorPoolSize">0</property>        
         <property name="listenerAsyncPoolSize">0</property>
         <property name="exposeManagementStatistics">true</property>
         <property name="buddyReplicationConfig">
            <bean class="org.jboss.cache.config.BuddyReplicationConfig">
               <property name="enabled">false</property>
               <property name="buddyPoolName">default</property>
               <property name="buddyCommunicationTimeout">17500</property>
               <property name="autoDataGravitation">false</property>
               <property name="dataGravitationRemoveOnFind">true</property>
               <property name="dataGravitationSearchBackupTrees">true</property>
               <property name="buddyLocatorConfig">
                  <bean class="org.jboss.cache.buddyreplication.NextMemberBuddyLocatorConfig">
                     <property name="numBuddies">1</property>
                     <property name="ignoreColocatedBuddies">true</property>
                   </bean>
               </property>
            </bean>
         </property>
         <property name="cacheLoaderConfig">
            <bean class="org.jboss.cache.config.CacheLoaderConfig">
                   <property name="passivation">true</property>
                   <property name="shared">false</property>
                   
                   <property name="individualCacheLoaderConfigs">
                     <list>
                        <bean class="org.jboss.cache.loader.FileCacheLoaderConfig">
                           <property name="location">${jboss.server.data.dir}${/}customized</property>
                           <property name="async">false</property>
                           <property name="fetchPersistentState">true</property>
                           <property name="purgeOnStartup">true</property>
                           <property name="ignoreModifications">false</property>
                           <property name="checkCharacterPortability">false</property>
                        </bean>
                     </list>
                   </property>
            </bean>
         </property>
      </bean>      
   </value>
   </entry>
As specified above, the configuration property multiplexerStack we use udp protocol stack, the definition of the protocol stack in deploy / cluster / jgroups-channelfactory.sar / META-INF / jgroups-channelfactory-stacks.xml file; clusterName attribute specifies the name cache; cacheMode property know cached copy mode REPL_ASYNC, that is, all the nodes state to keep pace; buddyReplicationConfig properties configured not enabled by default buddy replication; cacheLoaderConfig attribute configured cache loader, which uses the file cache load, that is, the cached content will be loaded into a disk file .

In order to run JBoss cluster in conflict prevention, we need to do the following:

Edit node1 / deploy / messaging / messaging-service.xml, an attribute value modification ServerPeerID:

<attribute name="ServerPeerID">${jboss.messaging.ServerPeerID:1}</attribute>
Edit node2 / deploy / messaging / messaging-service.xml, modify the property value ServerPeerID 2:

<attribute name="ServerPeerID">${jboss.messaging.ServerPeerID:2}</attribute>
Edit node1 / deploy / jbossweb.sar / server.xml file Engine element, add jvmRoute = "node1":

<Engine name="jboss.web" defaultHost="localhost" jvmRoute="node1">
Edit node2 / deploy / jbossweb.sar / server.xml file Engine element, add jvmRoute = "node2":

<Engine name="jboss.web" defaultHost="localhost" jvmRoute="node2">
Use the following command to start respectively node1 and node2:

./run.sh -c node1 -b <ip 1> -g test -u 239.255.100.100
./run.sh -c node2 -b <ip 2> -g test -u 239.255.100.100
  • -c specifies the start JBoss instance name
  • -b bind a local ip address
  • -g Specify a partition name
  • -u bind a multicast address

Note For details refer to start JBoss JBoss 5 documents: http://www.jboss.org/jbossas/docs/5-x .

We http: // <ip 1>: 8080 / jbosscache / access node1 example, the initial screen will appear as shown in FIG 8-13; click the Add button in the input box Fqn path / a / b / c, add caching example, as shown in FIG. 8-14; using the same approach we add k2 / v2, k3 / v3. At this point we can access another node view a cached copy results, visit http: // <ip2>: 8080 / jbosscache /, expand the cache Fqn path, click on the cache node c, we found the cache contents have been copied node1 to node2, as follows It shows:




Examples of analysis

Sample code is in cluster / jbosscache / jboss in ( https://github.com/kylinsoong/cluster/tree/master/jbosscache/jboss ), comprising a total of four modules:

  • service - service module for the EJB
  • ui - a user interface module for the GWT
  • test - for the EJB client, used to cache user interface testing EJB services provided
  • ear - packaged module is responsible for the package generated jbosscache-jboss-ear.ear

EJB service module

The EJB interface module class JBossCacheService, which defines the following interfaces to the server using GWT:

public void addCacheContent(String fqn, String key, String value)  throws Exception;
public List<String> getFqnStrs() throws Exception;
public Map getCacheNodeContent(String fqn)  throws Exception;
addCacheContent () method of the key-value pair to node fqn specified path; getCacheNodeContent () method to specify the cache node path data acquired by the related nodes fqn; getFqnStrs () Gets all cache node path. In EJB implementation class JBossCacheSession service, we get an example of the cache by CacheManager:

Context ctx = new InitialContext();
	cacheManager = (CacheManager) ctx.lookup("java:CacheManager");
	cache = cacheManager.getCache(CACHE_KEY, true);
	cache.start();
We will explain in detail in the subsequent CacheManager will. Add or get caching method to achieve the following:

public void addCacheContent(String fqn, String key, String value)  throws Exception {
	logger.info("add " + key + " -> " + value + " to " + fqn);
	getCache().put(Fqn.fromString(fqn), key, value);
}
public Map getCacheNodeContent(String fqn) throws Exception {
	logger.info("get Cache Node content [" + fqn + "]");
	return getCache().getData(Fqn.fromString(fqn));
}

As previously mentioned, the JBossCache Cache interface provides a number of methods used to operate JBossCache, here we use the put () and getData () method.

GWT user interface module

The module defines the user interface, detailed questions about Google GWT development, please refer to related documents, here we GWT client defines the interface JBossCacheService,

public interface JBossCacheService extends RemoteService{
	String ping(String name) throws IllegalArgumentException;
	NodeEntity initTree();
	List<CacheEntity> getCacheContent(String path) throws IllegalArgumentException;
	Integer addCacheContent(String fqn, String key, String value) throws IllegalArgumentException;
}
GWT JBossCacheService server side implementation, as follows:

public class JBossCacheServiceImpl extends RemoteServiceServlet implements JBossCacheService {

	@EJB
	private com.kylin.jbosscache.custom.service.JBossCacheService jbosscacheService;
The injection EJB service implemented by the cache operation EJB interface.

The test module

The module is an EJB client, if jbosscache-jboss-ear.ear successful deployment, you can test whether the module code deployment is successful, the code modules that you can introduce Eclipse, add JBOSS_HOME / client in the jar to the classpath, run JBossCacheServiceClient can be transported and deployed on the JBoss EJB services.

Examples of management

We can be monitored via 3 ways. From simple monitoring JBoss log, there are at JBOSS_HOME / server / $ PROFILE / log detailed log, JBoss is running, there will be relevant in the JBoss console output, as follows:

---------------------------------------------------------
GMS: address is IP 1:47535 (cluster=test-CustomizedCache)
---------------------------------------------------------
11:02:11,744 INFO  [RPCManagerImpl] Cache local address is IP 1:47535
11:02:11,744 INFO  [RPCManagerImpl] state was retrieved successfully (in 2.01 seconds)
11:02:11,753 INFO  [ComponentRegistry] JBoss Cache version: JBossCache 'Cascabel' 3.1.0.GA
11:11:30,591 INFO  [RPCManagerImpl] Received new cluster view: [IP 1:47535|1] [IP 1:47535, IP 2:36250]

Above, the use of JBossCache JGroups bottom, we can see the name of the channel output JGroups protocol stack is initialized test-CustomizedCache; local cache address IP 1: 47535; initial state of the cache is successful transfer of information, the cache should be noted that the state transition is JBoss cluster important features in a cluster, when a new node is added, it is first of all to obtain the state of the cluster, so that the application is guaranteed availability; cached version is JBossCache 'Cascabel' 3.1.0.GA; cluster view, the present examples of the two nodes, so the view [IP 1: 47535 | 1] [IP 1: 47535, IP2: 36250].

We can also be managed by jconsole, add parameters when you start -Djboss.platform.mbeanserver JBoss, JBoss start running after the completion of this jconsole:

jconsole
JBoss connecting the respective examples, in MBeans column select jboss.cache, my-custom-cache management to monitor, as shown below, we can see my-custom-cache from our custom figures, we can see the click to expand as well as to other related properties JBossCache run statistics.


JBoss JMX monitoring and management console by itself bound, JBoss startup is complete log in http: // <ip>: 8080 / jmx-console /, click jboss.cache, we can see that we define JBossCache, we can through the relevant JMX MBeans attributes relevant monitoring manageable.





Reproduced in: https: //my.oschina.net/iwuyang/blog/197239

Guess you like

Origin blog.csdn.net/weixin_34384915/article/details/91897382