Posts

Showing posts from April, 2013

Extends Session Time for Every Request

Extend Session Why I worte this post?


1. After loging application, session time starts {Session Time}
2. For example, Session time set as 30 It means, your Session will validate after 30minutes late from first login
3. if you want to extends session time from some request within 30minute
4. you have to add duration from
4. below is solution to extends session time
// this is the time session created long createdtime=session.getCreationTime(); // current Time long currentTime = System.currentTimeMillis(); long lastAcessedTime = session.getLastAccessedTime(); // duration from first session created int duration= (int)((currentTime - lastAcessedTime)/1000); // session time int inactive=session.getMaxInactiveInterval(); // set new session time (duration + original session Time) request.getSession().setMaxInactiveInterval(duration+ inactive);

Very Easy Setting Mod_jk

Why I write this post is I spend a lot of my time to setting up Apache and Tomcat7 width Mod_jk
There are lots of posts on website But proper to my computer setting
I Hope this guide to save your time yum remove httpd yum install httpd httpd-devel after httpd installed
you have to download tomcat-connectors.
the version what i installed is tomcat-connectors-1.2.35-src
cd native
./configure --with-apxs=/usr/sbin/apxs
make
make install

you can find mod_jk.so /etc/httpd/modules ### Mod_jk : connect tomcat ####
httpd.conf add below LoadModule jk_module modules/mod_jk.so

JkWorkerProperty worker.list=ajp13w
JkWorkerProperty worker.ajp13w.type=lb
JkWorkerProperty worker.ajp13w.balanced_workers=WAS1,WAS2
JkWorkerProperty worker.sticky_session=true

JkWorkerProperty worker.WAS1.type=ajp13
JkWorkerProperty worker.WAS1.host=localhost
JkWorkerProperty worker.WAS1.port=8009
JkWorkerProperty worker.WAS1.socket_timeout=3
JkWorkerProperty worker.WAS1.prepost_timeout=1000
JkWorkerProperty worker.WAS1.conn…

Spring Scope

Generally Spring has 5type of scopes
1. SingleTon : Spring IOC make one bean context for container2. Prototypes : Every request, Spring IOC make every new context3. Request : For One Request, Spring IOC make one bean context 4. Session : For Session, Spring IOC make one bean context 5. GlobalSession : ... First default Scope(Singleton) Student class package prototype; /** * @author jjhangu * */ public class Student { private String name = null; /** * @author jjhangu @create 2013. 4. 25. */ public String getName() { return name; } /** * @author jjhangu @create 2013. 4. 25. */ public void setName(String name) { this.name = name; } } Bus class package prototype; import java.util.ArrayList; import java.util.List; /** * @author jjhangu * */ public class Bus { private List students = new ArrayList(); public void addStudent(Student student) { students.add(student); } public String getStudents() { String names = ""; for (final Student st…
Today, I registered this Blogger for writing some useful codes. I hope this first step would bring me good things

Spring Annotation Qualifier

@Autowired Annotation finds which bean is proper to set
if there are more than one bean, @Autowired don't know which bean is proper
so use @Qualifier to target the proper bean

HelloController class public class Qualifier{ package com.sang.common.controller; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @Controller @RequestMapping("/welcome") public class HelloController { @Autowired @Qualifier("helloTwoWorld") private HelloWorld helloWorld; @RequestMapping(method = RequestMethod.GET) public String printWelcome(ModelMap model) { model.addAttribute("message", helloWorld.getName()); return "hello"; } } } HelloWorld class package com.sang…

This is How to Use SyntaxHighlighter in blogger

Hello SyntaxHighlighter If you want to make your codes clean in your blog
use this SyntaxHighlighter
It Probably make your code clean
follow this step
Hello SyntaxHighlighter

function helloSyntaxHighlighter() { return "hi!"; }

Awesome ?? ! function helloSyntaxHighlighter() { return "hi!"; }

cassandra nodetool troubleshooting

./nodetool -h localhost ring

if you can see this line

Failed to connect to '127.0.0.1:7199': Connection refused


change "cassandra-env.sh"

JVM_OPTS="$JVM_OPTS -Djava.rmi.server.hostname=<hostname>"

HttpClient setCookies from Webview in android

this is real

I seached a bunch of time but there are nothing to work

this is a solution

if you are interested in Huybrid Webview

doing this


URI uri = new URI("http://www.xxx.xxxx/files/test.jsp");

HttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(uri);

String cookies = CookieManager.getInstance().getCookie(
"http://203.233.82.229/files/test.jsp");
Log.i("cookie", "cookie " + cookies);

httpPost.setHeader("Cookie", cookies);
HttpResponse response = httpclient.execute(httpPost);

@Async in Spring Future

FutureAnnotaion class /** * (c)Copyright 2010-2010, BaruSoft Co., Ltd. All rights reserved
* * @description
* * @create 2013. 4. 18. * @author jjhangu */ package com.jjhangu.core; import java.util.concurrent.Future; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.AsyncResult; /** * @author jjhangu * */ public class FutureAnnotaion { @Async public Future getMessage(int j) { final int result = 0; for (int i = 0; i < 10000000; i++) { if (i == (10000000 - 1)) { System.out.println("finish : " + j); } } return new AsyncResult(result); } } FutureAnnotationMain class /** * (c)Copyright 2010-2010, BaruSoft Co., Ltd. All rights reserved
* * @description
* * @create 2013. 4. 18. * @author jjhangu */ package com.jjhangu.core; import java.util.concurrent.ExecutionException; import org.springframework.context.ApplicationContext; import org.springframework.context.support.Cla…

Cassandra Node and Cluster add

http://theeye.pe.kr/entry/an-example-of-adding-new-node-and-operating-nodes-on-cassandra

노드랑 클러스트 추가

java Object Poolable

GenericObjectPool의 설정에 관한 메모이다. 
아래의 사이트에서 번역해 온 내용임을 밝힌다. 
누군가 벌써 해놨을지도 모르지만..
http://commons.apache.org/pool/apidocs/org/apache/commons/pool/impl/GenericObjectPool.html

설정가능한 ObjectPool의 구현체


적절한 PoolableObjectFactory과 관련하여 GenericObjectPool은  임의의 오브젝트에게 견고한 풀링을 기능적으로 제공한다. 
GenericObjectPool은 수많은 설정가능한 파라메터를 제공한다. 
* maxActive : 주어진 시간에서의 풀(클라이언트가 보고있거나, 대기상태에 있는)에 의해 할당되어 관리되는오브젝트의 최대수. 설정이 양수가 아닌경우에는 한번에 풀에서 관리될 수 있는 오브젝트의 숫자에는 제한이 없다. 오브젝트의 수가 maxActive에 다다른 경우, 풀은 고갈되었다라고 말한다. 기본 설정은 8이다. 
* maxIdle : 어떠한 시간에 풀에서 대기상태로 관리되어 질수 있는 최대 수이다. 음수인경우에는 풀에서 대기상태로 있는 오브젝트의 수에 제한이 없는것으로 간주한다. 기본설정은 8이다. 
* whenExhaustedAction : borrowObject() 실행시 풀이 고갈되었을때의 행동을 지정한다. 
* WHEN_EXHAUSTED_FAIL, borrowObject() 인경우 NoSuchElementExcption을 던질것이다.
* WHEN_EXHAUSTED_GROW, borrowObject() 인경우 새로운 오브젝트를 만들고 그것을 리턴한다. (근본적으로 maxActive가 의미가 없어진다. )
* WHEN_EXHAUSTED_BLOCK, borrowObject() 인경우 새 오브젝트혹은 대기오브젝트가 사용가능해 질때까지  블럭- Object.wait()를 호출 - 시킨다. maxWait값이 양수인경우 수 밀리세컨드동안 borrowObject()를 블럭시키고 그후에 NoSuchElementEx…

1.2.3 user and password setting

1.In the cassandra.yaml, comment out the default AllowAllAuthorizer and add the CassandraAuthorizer as shown
here: #authorizer: org.apache.cassandra.auth.AllowAllAuthorizer authorizer: org.apache.cassandra.auth.CassandraAuthorizer

and restart -> now you can access to cassandra 
cassandra-cli -u cassandra -pw cassandra 
because cassandra/cassandra is default setting
============================================================================
2. if you use window and want to connect cqlsh 
refer to this blog
http://devasive.blogspot.kr/2012/10/cql-terminal-for-cassandra-on-windows.html
============================================================================
3. access on prom "cassandra_path/bin"/python cqlsh -u cassandra -p cassandra
CREATE USER spillman WITH PASSWORD 'Niner27'; CREATE USER akers WITH PASSWORD 'Niner2' SUPERUSER; CREATE USER boone WITH PASSWORD 'Niner75' NOSUPERUSER;
DROP USER user_name

Cassandra Gui Tool download site

currently cassandra port 8080 was change to 7199


download 0.8beta gui tool

http://code.google.com/a/apache-extras.org/p/cassandra-gui/downloads/list

2 day : get where

// make Users column tables


create column family Users with comparator=UTF8Type and default_validation_class=UTF8Type and key_validation_class=UTF8Type and column_metadata=[{column_name: fname, validation_class: UTF8Type}, {column_name: email, validation_class:UTF8Type}, {column_name: state, validation_class: UTF8Type, index_type:KEYS}];

//


set Users['song']['fname']='moo chan';
set Users['song']['email']='mcsong@example.com';
set Users['song']['state']='seoul';

set Users['choi']['fname']='won woo';
set Users['choi']['email']='wonwoo@example.com';
set Users['choi']['state']='seoul';

set Users['jang']['fname']='jang woo';
set Users['jang']['email']='jangwoo@example.com';
set Users['jang']['state']='boosan';

 get Users where state='seoul';

Cassandra Basic Use~!

this is basic Guide for users who start it first time

follow step by step from top to bottom

// make keyspace
[default@unknown] create keyspace MyKeyspace with placement_strategy='org.apache.cassandra.locator.SimpleStrategy' and strategy_op
tions ={replication_factor:1};

use MyKeyspace

// make column fammily
create column family User with comparator=UTF8Type and default_validation_class=UTF8Type and key_validation_class=UTF8Type;

// insert data
[default@MyKeyspace] set User['song']['fname']='moo chan';
Value inserted.
Elapsed time: 36 msec(s).
[default@MyKeyspace] set User['song']['email']='ehewitt@example.com';
Value inserted.

// count data
[default@MyKeyspace] count User['song'];
2 columns

// get data
[default@MyKeyspace] get User['song'];
=> (column=email, value=ehewitt@example.com, timestamp=1365494876521000)
=> (column=fname, value=moo chan, timestamp=1365494847746000)
Returned 2 results.
Elapsed time: 28 msec…

카산드라 설치 (윈도우)

카산드라 설치 (윈도우)
1. 파일을 다운 받는다.
2. 일단 JAVA_HOME이라는 환경변수가 잡아져있어야 한다
3. cassandra 설치한 폴더로 간다
4. cmd cassandra -f 실행  // -f 옵션은
5. cssandra-cli 로 접속한다.
 - cassandra-cli -h localhost -p 9160
6. Mission Complete

질문이 있으면 댓글 달아주세요

SNS Time Line if using No Sql

I'm not sure if it is best choice

plz share your opinion

1. if new topic is created, the data should be inserted into writer's friends time line.
2. if topic is deleted, the data should be removed from writer's friends time line.
3. if we are no more friends, all of friend's datas should be removed
4. if i'm your friend from now on, you data should be inserted into my time line.
..

mod_jk Thread 설정

yum install httpd httpd-devel

해서 httpd 설치

그다음

cd tomcat-connectors-1.2.35-src
./configure --with-apxs=/usr/local/apache2/bin/apxs
make
make install
하면 mod_jk.so 파일이 httpd의 모듈 디렉토리에 들어감


### Mod_jk : connect tomcat ####

LoadModule jk_module modules/mod_jk.so

JkWorkerProperty worker.list=ajp13w
JkWorkerProperty worker.ajp13w.type=lb
JkWorkerProperty worker.ajp13w.balanced_workers=WAS1,WAS2
JkWorkerProperty worker.sticky_session=true

JkWorkerProperty worker.WAS1.type=ajp13
JkWorkerProperty worker.WAS1.host=localhost
JkWorkerProperty worker.WAS1.port=8009
JkWorkerProperty worker.WAS1.socket_timeout=3
JkWorkerProperty worker.WAS1.prepost_timeout=1000
JkWorkerProperty worker.WAS1.connect_timeout=1000
JkWorkerProperty worker.WAS1.lbfactor=1

JkWorkerProperty worker.WAS2.type=ajp13
JkWorkerProperty worker.WAS2.host=192.168.0.32
JkWorkerProperty worker.WAS2.port=8009
JkWorkerProperty worker.WAS2.socket_timeout=3
JkWorkerProperty worker.WAS2.prepost_timeout=1000
JkWorkerProperty worker.WAS2.conn…