'Articles'에 해당되는 글 116건

  1. 2014/07/18 용비 JedisLock Lock Mechanism
  2. 2014/07/11 용비 Gradle Build Script with Dependencies jars
  3. 2014/07/10 용비 eclipse error : 기본 클래스 ***을(를) 찾을 수 없습니다
  4. 2014/07/10 용비 Jetty HttpClient Use Case
  5. 2014/07/08 용비 [Shell Script in CentOS] Redis Install

JedisLock Lock Mechanism

Articles 2014/07/18 18:17 용비
JedisLock lock = new JedisLock(jedis, lockkey, acquireTimeout, expirationTimeout);

lock.acquire();
lock.release();

When lock.acquire() method called, in JedisLock class, jedis client setnx method call with lockkey like next.

if (jedis.setnx(lockKey, expiresStr) == 1) {
   ..........
}

결국 Jedis Lock을 잡기 위해서는 lockkey로 redis에 key, value를 입력한 다음 처리하게 된다.
받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://www.yongbi.net/rss/response/607

Gradle Version : 1.12

One jar Package included all dependencies

apply plugin: 'java'
version '1.0'

jar {
//All dependencies into one jar.
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
manifest {
attributes 'Implementation-Title':'Title', 'Implementation-Version': version
}
}


repositories {
    mavenCentral()
}

dependencies {
compile project(':common:logger')
compile group:"redis.clients", name:"jedis", version:"2.4.2"
compile group:"org.apache.httpcomponents", name:"httpclient", version:"4.3.3"
compile group:"org.apache.httpcomponents", name:"httpmime", version:"4.3.3"
compile group:"org.eclipse.jetty", name:"jetty-servlet", version:"9.2.0.RC0"
compile group:"com.sun.jersey", name:"jersey-bundle", version:"1.18.1"
compile group:"com.google.code.gson", name:"gson", version:"2.2.4"
compile group:"com.github.jedis-lock", name:"jedis-lock", version:"1.0.0"
compile group:"org.mongodb", name:"mongo-java-driver", version:"2.12.1"
compile group:"com.ning", name:"async-http-client", version:"1.8.9"
testCompile group:"junit", name:"junit", version:"4.11+"
}

One jar Package referenced all dependencies (Copy into lib folder)

apply plugin: 'java'
version '1.0'

//Copy all dependencies
task copyToLib( type: Copy ) {
    into "$buildDir/libs/lib"
    from configurations.runtime
}

jar {
       //Copy all dependencies
       dependsOn copyToLib

manifest {
attributes 'Implementation-Title':'Title', 'Implementation-Version': version
}
}


repositories {
    mavenCentral()
}

dependencies {
compile project(':common:logger')
compile group:"redis.clients", name:"jedis", version:"2.4.2"
compile group:"org.apache.httpcomponents", name:"httpclient", version:"4.3.3"
compile group:"org.apache.httpcomponents", name:"httpmime", version:"4.3.3"
compile group:"org.eclipse.jetty", name:"jetty-servlet", version:"9.2.0.RC0"
compile group:"com.sun.jersey", name:"jersey-bundle", version:"1.18.1"
compile group:"com.google.code.gson", name:"gson", version:"2.2.4"
compile group:"com.github.jedis-lock", name:"jedis-lock", version:"1.0.0"
compile group:"org.mongodb", name:"mongo-java-driver", version:"2.12.1"
compile group:"com.ning", name:"async-http-client", version:"1.8.9"
testCompile group:"junit", name:"junit", version:"4.11+"
}
받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://www.yongbi.net/rss/response/602

eclipse 상에서 프로젝트 작업을 하다가, main() method를 포함하고 있는 다른 클래스들을 지웠을 때, 특히 maven project에서 maven clean을 실행하고 난 이후에 제목과 같은 오류가 발생하면서 프로그램이 실행되지 않을 때가 있다.

그럴 때는 Menu->Project->clean을 하면 된다.
받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://www.yongbi.net/rss/response/601

Jetty HttpClient Use Case

Articles 2014/07/10 14:12 용비
Jetty HttpClient를 이용하여 HTTP 호출

try {
//Synchronous Request
HttpClient httpClient = new HttpClient();
//set up httpClient
httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
httpClient.start();
//Request-Response Exchange
ContentExchange contentExchange = new ContentExchange();
contentExchange.setMethod(method);
contentExchange.setURL(url);
//Request Header
if (keyApply) {
if (baseApply)
contentExchange.addRequestHeader("Authorization", "Basic " + authBase64Encode);
else
contentExchange.addRequestHeader("Authorization", key);
}
//Request Body
contentExchange.addRequestHeader("Content-Type", contentType);
if (data == null || data.length == 0) {
contentExchange.addRequestHeader("Content-Length", "0");
resultData.append("Content-Length : 0\n");
}
else {
contentExchange.addRequestHeader("Content-Length", String.valueOf(data.length));
resultData.append("Content-Length : " + String.valueOf(data.length) + "\n");
contentExchange.setRequestContentSource(new ByteArrayInputStream(data));
}
httpClient.send(contentExchange);
//Wait for Response Done
int exchangeStatus = contentExchange.waitForDone();
//Response Data
int responseStatus = contentExchange.getResponseStatus();
resultData.append("Response Status : " + responseStatus + "\n");
if (exchangeStatus == HttpExchange.STATUS_COMPLETED) {
//Response Data
String response = contentExchange.getResponseContent();
if (response != null && !response.isEmpty())
resultData.append("Response Data : \n" + response + "\n");
else
resultData.append("Response Data is null.\n");
}
} catch (Exception e1) {
e1.printStackTrace();
resultData.setText(e1.getMessage());
//throw new ServletException(e1);
}

받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://www.yongbi.net/rss/response/600

#!/bin/sh

read_profile() {
  local value=$(cat ~/.bash_profile)
  echo "$value"
}

chk_profile() {
  local profile_value=$(read_profile)
  chk_value="$1"
 
  local chk_result=0
  if echo "$profile_value" | grep -q "$1"; then
    # Check Value exists in Bash Profile
    chk_result=1
  else
    # Check Value does not exist in Bash Profile
    chk_result=0
  fi
 
  echo "$chk_result"
}

env_set() {
  # AG_HOME
  if [ ! -d "$HOME/ag" ]; then
    mkdir $HOME/ag
  fi

  local chk_ag__home_result=$(chk_profile "AG_HOME")
   
  if [[ "$chk_ag__home_result" != "1" ]]; then
    echo "export AG_HOME=$HOME/ag" >> ~/.bash_profile
  fi
 
  AG_HOME_SHELL=$HOME/ag
 
  # REDIS_HOME
  local chk_redis_home_result=$(chk_profile "REDIS_HOME")
 
  if [[ "$chk_redis_home_result" != "1" ]]; then
    echo "export REDIS_HOME=\$AG_HOME/redis" >> ~/.bash_profile
  fi
 
  # Redis configuration file location
  if [ ! -d "$AG_HOME_SHELL/conf" ]; then
    mkdir $AG_HOME_SHELL/conf
  fi
 
  local chk_redis_conf_path_result=$(chk_profile "REDIS_CONF_PATH")
 
  if [[ "$chk_redis_conf_path_result" != "1" ]]; then
    echo "export REDIS_CONF_PATH=\$AG_HOME/conf/redis.conf" >> ~/.bash_profile
  fi
 
  # Redis log file location
  if [ ! -d "$AG_HOME_SHELL/logs" ]; then
    mkdir $AG_HOME_SHELL/logs
  fi
 
  local chk_redis_log_path_result=$(chk_profile "REDIS_LOG_PATH")
 
  if [[ "$chk_redis_log_path_result" != "1" ]]; then
    echo "export REDIS_LOG_PATH=\$AG_HOME/logs/redis.log" >> ~/.bash_profile
  fi
 
  # Redis Server Run Path
  local chk_redis_server_run_result=$(chk_profile "REDIS_SERVER_RUN")
 
  if [[ "$chk_redis_server_run_result" != "1" ]]; then
    echo "export REDIS_SERVER_RUN=\$REDIS_HOME/src/redis-server" >> ~/.bash_profile
  fi
 
  # Redis Client Run Path
  local chk_redis_client_run_result=$(chk_profile "REDIS_CLIENT_RUN")
 
  if [[ "$chk_redis_client_run_result" != "1" ]]; then
    echo "export REDIS_CLIENT_RUN=\$REDIS_HOME/src/redis-cli" >> ~/.bash_profile
  fi
 
  # Management Layer IVP Host : 10.217.37.28, 172.27.139.98
  local chk_ag_ml_host_result=$(chk_profile "AG_ML_HOST")
 
  if [[ "$chk_ag_ml_host_result" != "1" ]]; then
    echo "export AG_ML_HOST=172.27.139.98:8080" >> ~/.bash_profile
  fi
 
  # alias for redis server run
  local chk_alias_redis_run=$(chk_profile "redis_run")
 
  if [[ "$chk_alias_redis_run" != "1" ]]; then
    echo "alias redis_run='nohup \$REDIS_SERVER_RUN \$REDIS_CONF_PATH >> \$REDIS_LOG_PATH 2>1&'" >> ~/.bash_profile
  fi
 
  # alias for redis server shutdown
  local chk_alias_redis_shutdown=$(chk_profile "redis_shutdown")
 
  if [[ "$chk_alias_redis_shutdown" != "1" ]]; then
    echo "alias redis_shutdown='\$REDIS_CLIENT_RUN shutdown'" >> ~/.bash_profile
  fi
 
  # Apply Profile
  source ~/.bash_profile
  sleep 1

}

server_run() {
   local run_result=$(nohup $REDIS_SERVER_RUN $REDIS_CONF_PATH >> $REDIS_LOG_PATH 2>1&)
   echo "$run_result"
}

server_run_chk() {
   local run_chk=$(ps -ef | grep r[e]dis)
   #local run_chk=$(ps -ef | pgrep redis)
   echo "$run_chk"
}

server_healthchk() {
   local health_result=$($REDIS_CLIENT_RUN ping)
   echo "$health_result"
}

# Check input parameters
while getopts "i:p:" o;
do
  case "${o}" in
  i)
    NODE_IP=${OPTARG}
    ;;
  p)
    NODE_PORT=${OPTARG}
    ;;
  *)
    echo "Invalid parameter."
    exit 1
    ;;
  \?)
    echo "Invalid parameter."
    exit 1
    ;;
  esac
done

echo "Step 1 : Check and setting default environments....."
  sleep 1
  env_set
echo "  done"
sleep 1

# Redis Server Start
echo "Step 2 : Run the redis server....."
  sleep 1
  source ~/.bash_profile
  sleep 1
 
  chk_run_result=$(server_run_chk)

  if [[ -z "$chk_run_result" ]]; then
    result_run=$(server_run)
    if [[ -z "$result_run" ]]; then
      echo "  Redis server is runned."
    else
      echo "  Error. Redis server cannot run."
      echo "  " $result_run
      exit 1
    fi
  else
    echo "  Redis server is alreay running..."
  fi
sleep 1

# Redis Server Health Check
echo "Step 3 : Redis server health check......"
  sleep 1
  source ~/.bash_profile
  sleep 1
 
  result_health=$(server_healthchk)
 
  if [[ "$result_health" == "PONG" ]]; then
    echo "  Redis server health check : " $result_health
  else
    echo "  Error. Redis server health check is failed."
    echo "  Result health check : " $result_health
    exit 1
  fi
sleep 1

# IVP Send
echo "Step 4 : IVP send to management layer....."
  sleep 1
  NODE_NAME=$(hostname -s)
  if [[ -z "$NODE_IP" ]]; then
    NODE_IP=$(hostname -i)
  fi

  if [[ -z "$NODE_PORT" ]]; then
    NODE_PORT=6379
  fi

  curl -i -X PUT -H "Content-Type:application/json" http://$AG_ML_HOST/_AG_/sl/nodes/$NODE_IP -d '{"port":"'"$NODE_PORT"'"}'

받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://www.yongbi.net/rss/response/599