本文整理汇总了Java中net.rubyeye.xmemcached.exception.MemcachedException类的典型用法代码示例。如果您正苦于以下问题:Java MemcachedException类的具体用法?Java MemcachedException怎么用?Java MemcachedException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MemcachedException类属于net.rubyeye.xmemcached.exception包,在下文中一共展示了MemcachedException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doGet
import net.rubyeye.xmemcached.exception.MemcachedException; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException,
ServletException {
String addr =
System.getenv().containsKey("GAE_MEMCACHE_HOST")
? System.getenv("GAE_MEMCACHE_HOST") : "localhost";
String port =
System.getenv().containsKey("GAE_MEMCACHE_HOST")
? System.getenv("GAE_MEMCACHE_PORT") : "11211";
String key = "count";
MemcachedClientBuilder builder = new XMemcachedClientBuilder(
AddrUtil.getAddresses(addr + ":" + port));
MemcachedClient client = builder.build();
long count = 0L;
try {
count = client.incr(key, 1L, 0L);
} catch (TimeoutException | InterruptedException | MemcachedException e) {
throw new ServletException("Memcache error", e);
}
resp.setContentType("text/plain");
resp.getWriter().print("Value is " + count + "\n");
}
示例2: doWrite
import net.rubyeye.xmemcached.exception.MemcachedException; //导入依赖的package包/类
@Override
protected boolean doWrite(CaValue<K, V> val) {
K k = val.key();
V v = val.value();
try {
if (v == null) {
mc.delete(k.toString());
} else {
long ttl = val.ttl();
if (ttl > 0) {
mc.set(k.toString(), (int) ttl / 1000, v);
} else {
mc.set(k.toString(), 0, v);
}
}
} catch (TimeoutException | InterruptedException | MemcachedException e) {
LOG.error(e.getMessage(), e);
return false;
}
return true;
}
示例3: close
import net.rubyeye.xmemcached.exception.MemcachedException; //导入依赖的package包/类
@Override
public void close() throws IOException {
if (isClosed()) return;
super.close();
// if (mc != null) {
// mc.flush();
// mc.shutdown(60, TimeUnit.SECONDS);
// }
if (mc != null) {
try {
mc.flushAll();
} catch (TimeoutException | InterruptedException | MemcachedException e) {
LOG.warn(e.getMessage(), e);
} finally {
mc.shutdown();
}
}
}
示例4: mutiThreadWrite
import net.rubyeye.xmemcached.exception.MemcachedException; //导入依赖的package包/类
public void mutiThreadWrite() throws InterruptedException, TimeoutException, MemcachedException {
int threadCount = 8;
ExecutorService pool = Executors.newFixedThreadPool(threadCount);
CountDownLatch latch = new CountDownLatch(threadCount);
// MemcachedBenchJob.test = tester;
MemcachedTest[] muti = new MemcachedTest[threadCount];
for (int i = 0; i < threadCount; i++) {
muti[i] = new MemcachedTest(latch);
}
log.info("start");
long start = System.currentTimeMillis();
for (int i = 0; i < threadCount; i++) {
pool.execute(muti[i]);
}
latch.await();
long spend = System.currentTimeMillis() - start;
log.info(threadCount + "threads写入次数:" + threadCount * 10000 + " spend:" + spend + " ms");
assertEquals(threadCount * 10000, getSize());
}
示例5: mutiThreadGet
import net.rubyeye.xmemcached.exception.MemcachedException; //导入依赖的package包/类
public void mutiThreadGet() throws InterruptedException, TimeoutException, MemcachedException {
int threadCount = 8;
ExecutorService pool = Executors.newFixedThreadPool(threadCount);
CountDownLatch latch = new CountDownLatch(threadCount);
// MemcachedBenchJob.test = tester;
MemcachedTestGet[] muti = new MemcachedTestGet[threadCount];
for (int i = 0; i < threadCount; i++) {
muti[i] = new MemcachedTestGet(latch);
}
log.info("start");
long start = System.currentTimeMillis();
for (int i = 0; i < threadCount; i++) {
pool.execute(muti[i]);
}
latch.await();
long spend = System.currentTimeMillis() - start;
log.info(threadCount + "threads 获取次数:" + threadCount * 10000);
assertEquals(0, getSize());
}
示例6: main
import net.rubyeye.xmemcached.exception.MemcachedException; //导入依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException, MemcachedException, TimeoutException {
String hostport = "172.16.170.128:11211";
mc = MCUtil.createJedis(hostport);
// mc.set("hello", 0, "Hello,mc.xmemcached");
// String value = mc.get("hello");
// System.out.println("hello=" + value);
//
for (int i = 0; i < 10000; i++) {
BigObject bigObject = new BigObject();
// System.out.println(bigObject.toString());
mc.set("obj" + i, 0, bigObject);
}
long t1 = System.currentTimeMillis();
BigObject bo = mc.get("obj1");
long t2 = System.currentTimeMillis();
System.out.println(t2 - t1);
System.out.println(bo.toString());
// MCStats(mc);
mc.shutdown();
}
示例7: main
import net.rubyeye.xmemcached.exception.MemcachedException; //导入依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException, MemcachedException, TimeoutException {
String hostport = "127.0.0.1:11211";
mc = MCUtil.createJedis(hostport);
//
for (int i = 0; i < 10000; i++) {
mc.set("obj" + i, 0, "i am a big string " + i);
}
long t1 = System.currentTimeMillis();
String str = mc.get("obj1");
long t2 = System.currentTimeMillis();
System.out.println(t2 - t1);
System.out.println(str);
// MCStats(mc);
mc.shutdown();
}
示例8: main
import net.rubyeye.xmemcached.exception.MemcachedException; //导入依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException, MemcachedException, TimeoutException {
String hostport = "172.16.170.128:11211";
mc = MCUtil.createJedis(hostport);
// mc.set("hello", 0, "Hello,mc.xmemcached");
// String value = mc.get("hello");
// System.out.println("hello=" + value);
//
for (int i = 0; i < 10000; i++) {
BigObject bigObject = new BigObject();
// System.out.println(bigObject.toString());
mc.set("obj"+i,0,bigObject);
}
long t1 = System.currentTimeMillis();
BigObject bo = mc.get("obj1");
long t2 = System.currentTimeMillis();
System.out.println(t2-t1);
System.out.println(bo.toString());
// MCStats(mc);
mc.shutdown();
}
示例9: main
import net.rubyeye.xmemcached.exception.MemcachedException; //导入依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException, MemcachedException, TimeoutException {
String hostport = "127.0.0.1:11211";
mc = MCUtil.createJedis(hostport);
//
for (int i = 0; i < 10000; i++) {
mc.set("obj"+i,0,"i am a big string "+i);
}
long t1 = System.currentTimeMillis();
String str = mc.get("obj1");
long t2 = System.currentTimeMillis();
System.out.println(t2-t1);
System.out.println(str);
// MCStats(mc);
mc.shutdown();
}
示例10: main
import net.rubyeye.xmemcached.exception.MemcachedException; //导入依赖的package包/类
public static void main(String[] args)
throws IOException, TimeoutException, InterruptedException, MemcachedException {
MemcachedClientBuilder builder = new XMemcachedClientBuilder("localhost:11211");
MemcachedClient client = builder.build();
try {
ICacheEntrySerializer ces = DefaultCacheEntrySerializer.instance;
TestValue.Value v1 = new TestValue.Value();
CacheEntry ce = new CacheEntry("key", v1);
byte[] dataSet = ces.serialize(ce);
client.set("key", 0, dataSet);
System.out.println(dataSet.length);
byte[] dataGet = client.get("key");
System.out.println(dataGet.length);
} finally {
client.shutdown();
}
}
示例11: loginpass
import net.rubyeye.xmemcached.exception.MemcachedException; //导入依赖的package包/类
/**
* 验证登录,添加Cookie
*
* @param userLogin
* @param model
* @return
* @throws MemcachedException
* @throws InterruptedException
* @throws TimeoutException
* @throws IOException
*/
@RequestMapping("loginpass")
public String loginpass(UserPasswdBean userPasswdBean, Model model,
HttpServletRequest request, HttpServletResponse response)
throws IOException, TimeoutException, InterruptedException,
MemcachedException {
String userName = new String(userPasswdBean.getUserName().getBytes("iso8859-1"),"utf-8");
String userPasswd = new String(userPasswdBean.getUserPasswd().getBytes("iso8859-1"),"utf-8");
UserInfoBean u = landAndRegistrationBll.getUserInfoBySelect(userName);
if(u == null){
logger.info("用户名或密码错误!");
model.addAttribute("msg", "用户名或密码错误!");
return "admin/adminlogin";
}else{
UserPasswdBean password = landAndRegistrationBll.getUserPasswordBySelect(userName);
if(password.getUserType() == 2){
logger.info("没有权限!");
model.addAttribute("userName", userName);
model.addAttribute("msg", "没有权限!");
return "admin/adminlogin";
}else{
if (landAndRegistrationBll.checkLoginAccount(userName,
userPasswd) == true) {
HttpSession session = request.getSession();
session.setAttribute("adminInfo", u);
return "redirect:index";
} else {
logger.info("密码错误!");
model.addAttribute("userName", userName);
model.addAttribute("msg", "密码错误!");
return "admin/adminlogin";
}
}
}
}
示例12: get
import net.rubyeye.xmemcached.exception.MemcachedException; //导入依赖的package包/类
private ServiceResponse get(String key) throws TimeoutException, InterruptedException, MemcachedException {
if (key != null) {
Object value = this.client.get(key);
if (value != null) {
return getResponse(Http.HTTP_OK, value);
} else {
return getResponse(Http.HTTP_NOT_FOUND, String.format("Key: %s is Not Found", key));
}
}
return null;
}
示例13: add
import net.rubyeye.xmemcached.exception.MemcachedException; //导入依赖的package包/类
private ServiceResponse add(String key, String value, int exp) throws TimeoutException, InterruptedException, MemcachedException {
if (key != null && value != null) {
if (exp < 0) {
exp = 0;
}
if (this.client.set(key, exp, value)) {
return getResponse(Http.HTTP_OK, null);
} else {
return getResponse(Http.HTTP_INTERNAL_SERVER_ERROR, String.format("Add key: %s Fail", key));
}
}
return null;
}
示例14: replace
import net.rubyeye.xmemcached.exception.MemcachedException; //导入依赖的package包/类
private ServiceResponse replace(String key, String value, int exp) throws TimeoutException, InterruptedException, MemcachedException {
if (key != null && value != null) {
if (exp < 0) {
exp = 0;
}
if (this.client.replace(key, exp, value)) {
return getResponse(Http.HTTP_OK, null);
} else {
return getResponse(Http.HTTP_INTERNAL_SERVER_ERROR, String.format("Replace key: %s Fail", key));
}
}
return null;
}
示例15: delete
import net.rubyeye.xmemcached.exception.MemcachedException; //导入依赖的package包/类
private ServiceResponse delete(String key) throws TimeoutException, InterruptedException, MemcachedException {
if (key != null) {
if (this.client.delete(key)) {
return getResponse(Http.HTTP_OK, null);
} else {
return getResponse(Http.HTTP_INTERNAL_SERVER_ERROR, String.format("Delete key: %s Fail", key));
}
}
return null;
}