티스토리 뷰
이번에는 JBOSS와 Infinispan 연동에 대해 알아보도록 하겠습니다.
설치 환경
maven 2.2.1
java 1.6.0_23
jboss 5.1
infinispan 5.1.3
Step1. JBOSS Node 생성
clustering을 위한 jboss node를 2개 생성한다.
$ cp -r $JBOSS_HOME/server/default $JBOSS_HOME/server/node1
$ cp -r $JBOSS_HOME/server/default $JBOSS_HOME/server/node2
step 2. Web Project 생성
mvn archetype:generate -DgroupId=com.mycompany.app \
-DartifactId=my-webapp -DarchetypeArtifactId=maven-archetype-webapp
step 3. 테스트 소스코드 작성
java/Session.java
package rocksea;
import org.infinispan.Cache;
import org.infinispan.notifications.Listener;
import org.infinispan.notifications.cachelistener.annotation.CacheEntryCreated;
import org.infinispan.notifications.cachelistener.annotation.CacheEntryModified;
import org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved;
import org.infinispan.notifications.cachelistener.annotation.CacheEntryVisited;
import org.infinispan.notifications.cachelistener.event.CacheEntryEvent;
import org.infinispan.notifications.cachelistener.event.CacheEntryVisitedEvent;
import org.infinispan.notifications.cachemanagerlistener.event.Event;
import org.infinispan.util.concurrent.NotifyingFuture;
import java.util.Arrays;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
public class Session {
public void makeSession(String key, String value) {
Cache<String, String> cache = SampleCacheContainer.getCache();
String result = cache.put(key, value);
System.out.println("makeSession : "+result);
}
public String getSession(String key) {
Cache<String, String> cache = SampleCacheContainer.getCache();
String result = cache.get(key);
System.out.println("getSession : "+result);
return result;
}
public boolean modifySession(String key, String value, String toValue) {
Cache<String, String> cache = SampleCacheContainer.getCache();
boolean worked = cache.replace(key, value, toValue);
System.out.println("modifySession : "+worked);
return worked;
}
}
webapp/make_session.jsp
<%@ page contentType="text/html; charset=euc-kr" %>
<%@ page import="java.io.*" %>
<%@ page import="rocksea.Session" %>
<%
Session ss = new Session();
ss.makeSession("another","Best");
out.println("RESULT :"+ss.getSession("another"));
%>
<html>
<body>
<h2>MakeSession</h2>
</body>
</html>
webapp/get_session.jsp
<%@ page contentType="text/html; charset=euc-kr" %>
<%@ page import="java.io.*" %>
<%@ page import="rocksea.Session" %>
<%
Session ss = new Session();
out.println("RESULT :"+ss.getSession("another"));
%>
<html>
<body>
<h2>MakeSession</h2>
</body>
</html>
resources/infinispan-clustered-udp.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
This is just a very simplistic example configuration file. For more information, please see
http://docs.jboss.org/infinispan/5.0/apidocs/config.html
-->
<infinispan
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:infinispan:config:5.0 http://www.infinispan.org/schemas/infinispan-config-5.0.xsd"
xmlns="urn:infinispan:config:5.0">
<global>
<globalJmxStatistics enabled="true" jmxDomain="Infinispan" />
<transport>
<properties>
<property name="configurationFile" value="jgroups-udp.xml" />
</properties>
</transport>
</global>
<default>
<locking concurrencyLevel="5000" />
<clustering mode="distributed">
<sync />
</clustering>
</default>
<namedCache name="stock tickers">
<locking isolationLevel="REPEATABLE_READ" useLockStriping="false" lockAcquisitionTimeout="10000" />
</namedCache>
<namedCache name="wine cache">
<locking lockAcquisitionTimeout="500" />
<eviction maxEntries="500" wakeUpInterval="100" />
<lazyDeserialization enabled="true" />
</namedCache>
<namedCache name="another">
<expiration lifespan="1000" maxIdle="500" />
<clustering mode="replicated">
<async useReplQueue="true" replQueueMaxElements="100" />
</clustering>
</namedCache>
</infinispan>
Step4. mvn packaging
maven을 이용한 packaging
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-webapp</artifactId>
<packaging>war</packaging>
<version>cache</version>
<name>my-webapp Maven Webapp</name>
<url>http://maven.apache.org</url>
<!-- by rocksea-->
<properties>
<!--
Which Infinispan version do you want to use? Released versions are always more reliable than snapshots!
-->
<version.infinispan>5.1.3.FINAL</version.infinispan>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- by rocksea-->
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId>
<version>${version.infinispan}</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- enforce java 1.6 and maven 2.1.0 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.0-beta-1</version>
<executions>
<execution>
<id>enforce-java</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireJavaVersion>
<version>[1.6,)</version>
</requireJavaVersion>
<requireMavenVersion>
<version>[2.1.0,)</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<!-- by default, compile to JDK 1.6 compatibility -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
<finalName>cache</finalName>
</build>
</project>
maven을 이용하여 war 파일을 생성한다.
$ mvn package
생성된 war파일을 jboss의 deploy folder로 copy한다.
cp target/cache.war /home/rocksea/jboss5/server/node1/deploy/
cp target/cache.war /home/rocksea/jboss5/server/node2/deploy/
Step5. JBOSS 실행
jboss를 실행한다.
nohup ./run.sh -b 192.168.0.10 -c node1 -g node1 > /home/rocksea/jboss5/bin/log/node1_nohup.out 2>&1 &
nohup ./run.sh -b 192.168.0.10 -c node2 -g node2 > /home/rocksea/jboss5/bin/log/node2_nohup.out 2>&1 &
Step6. Browser Test
node1번 JBOSS의 make_session.jsp web url 호출
[ 그림 1] node1 세션 생성
log 확인
( JGroups 이라는 multicast communication toolkit을 이용하여 clustering 을 하고 있다는것을확인할수있습니다. )
node2번 JBOSS의 make_session.jsp web url 호출
[ 그림 2] node2 세션 확인
위 테스트에서와 같이 node1에서 session을 생성하게 되면 node2에 세션을 clustering하게 됩니다.
이것으로 포스팅을 마치도록 하겠습니다.
참조 URL : https://docs.jboss.org/author/display/ISPN/User+Guide
by rocksea.
'Developer' 카테고리의 다른 글
[ SSL ] nginx + ssl (0) | 2012.07.04 |
---|---|
[ HBASE ] 1천만건 Test 입력 테스트 (0) | 2012.06.22 |
[ Maven Installation Guide ] maven 설치 가이드 (0) | 2012.06.15 |
[ Cache Server ] Infinispan quick start guide (0) | 2012.06.07 |
[ Error ] java.lang.IllegalArgumentException: Wrong arguments. new for target java.lang.reflect.Constructor expected=[java.net.URI] actual=[java.io.File] (0) | 2012.06.05 |
- Total
- Today
- Yesterday
- 가정법
- NGINX
- 비교구문
- PostgreSQL
- 베트남
- JBOSS
- Python
- hdfs
- 스페인 여행
- 도덕경
- k8s
- 여행
- 해외여행
- 비지니스 영어
- 영작
- 대명사 구문
- ubuntu
- hadoop
- 영문법
- Business English
- Python Django
- 조동사
- nodejs
- memcached
- it
- redis
- mongoDB
- 다낭
- AWS
- maven
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |