码迷,mamicode.com
首页 > 编程语言 > 详细

kestrel用java来利用

时间:2014-09-09 11:04:18      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:http   os   io   使用   java   ar   div   sp   on   

kestrel用的是scala,java无法直接使用。如想用java来运行kestrel,需要利用Xmemcached库。
 
创建queue_kestrel.java
# cd
# mkdir test
# export source_dir=~/test
# vi queue_kestrel.java
 
-----------------------------------------------------
import net.rubyeye.xmemcached.MemcachedClient;
import net.rubyeye.xmemcached.XMemcachedClientBuilder;
import net.rubyeye.xmemcached.command.KestrelCommandFactory;
import net.rubyeye.xmemcached.utils.AddrUtil;
 
public class queue_kestrel {
public static void main(String[] args) throws Exception {
XMemcachedClientBuilder builder=null;
MemcachedClient client=null;
int expirationTime=0;
String queueName="test";
String host="192.168.172.99";
String port = "22133";
builder=new XMemcachedClientBuilder(AddrUtil.getAddresses(host+":"+port));
builder.setCommandFactory(new KestrelCommandFactory());
try {
client=builder.build();
client.set(queueName,expirationTime,"hello");
String res=client.get(queueName);
System.out.println(res);
} catch (java.io.IOException e){}
}
}
----------------------------------------------------
 
准备必要的库。
xmemcached
# wget http://xmemcached.googlecode.com/files/xmemcached-1.3.7-bin-with-dependencies.tar.gz
# tar zxvf xmemcached-1.3.7-bin-with-dependencies.tar.gz
# cp xmemcached-1.3.7/xmemcached-1.3.7.jar xmemcached-1.3.7/lib/slf4j-api-1.5.7.jar $source_dir
 
slf4j
# wget http://www.slf4j.org/dist/slf4j-1.6.6.zip
# unzip slf4j-1.6.6.zip
# cp slf4j-1.6.6/slf4j-jdk14-1.6.6.jar $source_dir
 
kestrel
# cp /usr/local/kestrel/kestrel_2.9.1-2.2.0.jar $source_dir
 
运行
启动kestrel服务器。
# java -jar /usr/local/kestrel/kestrel_2.9.1-2.2.0.jar &
 
编译queue_kestrel.java并运行。
# cd $source_dir
# javac -cp ./xmemcached-1.3.7.jar:./slf4j-api-1.5.7.jar:./slf4j-jdk14-1.6.6.jar:./kestrel_2.9.1-2.2.0.jar: queue_kestrel.java
# java -cp ./xmemcached-1.3.7.jar:./slf4j-api-1.5.7.jar:./slf4j-jdk14-1.6.6.jar:./kestrel_2.9.1-2.2.0.jar: queue_kestrel

kestrel用java来利用

标签:http   os   io   使用   java   ar   div   sp   on   

原文地址:http://www.cnblogs.com/callme/p/3961477.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!