tailMap = ketamaNodes.tailMap(hash);
51 | // if(tailMap.isEmpty()) {
52 | // hash=ketamaNodes.firstKey();
53 | // } else {
54 | // hash=tailMap.firstKey();
55 | // }
56 | // }
57 | // rv= ketamaNodes.get(hash);
58 | // return rv;
59 | // }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/avatar-cache/src/main/java/com/dianping/avatar/cache/annotation/Cache.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Project: avatar
3 | *
4 | * File Created at 2010-7-13
5 | * $Id$
6 | *
7 | * Copyright 2010 Dianping.com Corporation Limited.
8 | * All rights reserved.
9 | *
10 | * This software is the confidential and proprietary information of
11 | * Dianping Company. ("Confidential Information"). You shall not
12 | * disclose such Confidential Information and shall use it only in
13 | * accordance with the terms of the license agreement you entered into
14 | * with Dianping.com.
15 | */
16 | package com.dianping.avatar.cache.annotation;
17 |
18 | import java.lang.annotation.ElementType;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.RetentionPolicy;
21 | import java.lang.annotation.Target;
22 |
23 | /**
24 | *
25 | * Annotation for cache method and class. If class is annotated by {@link Cache}
26 | * ,it will be considered to cache instance,the cache parameters will be made
27 | * from {@link CacheParam} fields and {@link #fields()} declaring fields.
28 | *
29 | *
30 | *
31 | * Generally, {@link CacheParam} will be convenient and clear, but if want to
32 | * take fields from super classes and that are not be annotated by
33 | * {@link CacheParam}, it is useful to declare them through {@link #fields()}.
34 | *
35 | *
36 | *
37 | * If using {@link CacheParam} the fields order will be decided for
38 | * order property. If order
39 | *
40 | *
41 | * @author guoqing.chen
42 | *
43 | */
44 | @Target( { ElementType.METHOD, ElementType.TYPE })
45 | @Retention(RetentionPolicy.RUNTIME)
46 | public @interface Cache {
47 |
48 | /**
49 | * cache category, correspond to 'name' attribute in cache configuration
50 | */
51 | String category();
52 |
53 | /**
54 | * Cache operation for method
55 | */
56 | com.dianping.avatar.cache.annotation.CacheOperation operation() default com.dianping.avatar.cache.annotation.CacheOperation.SetAndGet;
57 |
58 | /**
59 | * Default fields will be cached
60 | */
61 | String[] fields() default "";
62 | }
63 |
--------------------------------------------------------------------------------
/cache-core/src/test/java/com/dianping/cache/core/ketama/KetamaHashAlgorithmTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Project: com.dianping.cache-core-2.0.0
3 | *
4 | * File Created at 2011-4-19
5 | * $Id$
6 | *
7 | * Copyright 2010 dianping.com.
8 | * All rights reserved.
9 | *
10 | * This software is the confidential and proprietary information of
11 | * Dianping Company. ("Confidential Information"). You shall not
12 | * disclose such Confidential Information and shall use it only in
13 | * accordance with the terms of the license agreement you entered into
14 | * with dianping.com.
15 | */
16 | package com.dianping.cache.core.ketama;
17 |
18 | import java.util.ArrayList;
19 | import java.util.Arrays;
20 | import java.util.HashMap;
21 | import java.util.List;
22 | import java.util.Map;
23 | import java.util.Map.Entry;
24 |
25 | /**
26 | * TODO Comment of KetamaHashTest
27 | * @author jian.liu
28 | *
29 | */
30 | public class KetamaHashAlgorithmTest {
31 |
32 | // public static void main(String[] args) {
33 | // MockKetamaNodeLocator ketamaNodeLocator = new MockKetamaNodeLocator(Arrays.asList("192.168.8.46:11211", "192.168.8.47:11211", "192.168.8.45:11211", "192.168.8.48:11211"));
34 | // Map> stats = new HashMap>();
35 | // for (int i = 0; i < 100; i++) {
36 | // String key = "cache-key-" + i;
37 | // String primary = ketamaNodeLocator.getPrimary(key);
38 | //// System.out.println(key + "=" + primary);
39 | // if (!stats.containsKey(primary)) {
40 | // stats.put(primary, new ArrayList());
41 | // }
42 | // List list = stats.get(primary);
43 | // list.add(key);
44 | // }
45 | // for (Entry> entry : stats.entrySet()) {
46 | // List nodeList = entry.getValue();
47 | //// String nodeString = "";
48 | //// for (String node : nodeList) {
49 | //// nodeString += node + ", ";
50 | //// }
51 | // System.out.println("------------" + entry.getKey() + "[" + nodeList.size() + "]" + "------------");
52 | // for (String node : nodeList) {
53 | // System.out.println(node);
54 | // }
55 | // }
56 | // }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/cache-server/src/main/resources/log/log4j.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/avatar-cache/src/main/resources/META-INF/com/dianping/avatar/cache/avatar-1.0.xsd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/cache-core/src/main/java/com/dianping/cache/local/ElementAttributes.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Project: cache-core
3 | *
4 | * File Created at 2010-7-19
5 | * $Id$
6 | *
7 | * Copyright 2010 Dianping.com Corporation Limited.
8 | * All rights reserved.
9 | *
10 | * This software is the confidential and proprietary information of
11 | * Dianping Company. ("Confidential Information"). You shall not
12 | * disclose such Confidential Information and shall use it only in
13 | * accordance with the terms of the license agreement you entered into
14 | * with Dianping.com.
15 | */
16 | package com.dianping.cache.local;
17 |
18 | /**
19 | * Every item in the cache is associated with an element attributes object. It is used to track the life of
20 | * the object
21 | * @author danson.liu
22 | */
23 | public class ElementAttributes {
24 |
25 | /**
26 | * in milliseconds
27 | */
28 | private long createTime;
29 |
30 | /**
31 | * in milliseconds
32 | */
33 | private long lastAccessTime;
34 |
35 | private long maxIdleTimeSeconds = -1;
36 |
37 | private long maxLifeSeconds = -1;
38 |
39 | public ElementAttributes() {
40 | createTime = System.currentTimeMillis();
41 | lastAccessTime = createTime;
42 | }
43 |
44 | public long getCreateTime() {
45 | return createTime;
46 | }
47 |
48 | public void setCreateTime(long createTime) {
49 | this.createTime = createTime;
50 | }
51 |
52 | public long getLastAccessTime() {
53 | return lastAccessTime;
54 | }
55 |
56 | public void setLastAccessTime(long lastAccessTime) {
57 | this.lastAccessTime = lastAccessTime;
58 | }
59 |
60 | public long getMaxIdleTimeSeconds() {
61 | return maxIdleTimeSeconds;
62 | }
63 |
64 | public void setMaxIdleTimeSeconds(long maxIdleTimeSeconds) {
65 | this.maxIdleTimeSeconds = maxIdleTimeSeconds;
66 | }
67 |
68 | public long getMaxLifeSeconds() {
69 | return maxLifeSeconds;
70 | }
71 |
72 | public void setMaxLifeSeconds(long maxLifeSeconds) {
73 | this.maxLifeSeconds = maxLifeSeconds;
74 | }
75 |
76 | /**
77 | *
78 | */
79 | public void setLastAccessTimeNow() {
80 | setLastAccessTime(System.currentTimeMillis());
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/cache-core/src/main/java/com/dianping/cache/memcached/MemcachedClientConfiguration.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Project: avatar-cache
3 | *
4 | * File Created at 2010-7-12
5 | * $Id$
6 | *
7 | * Copyright 2010 Dianping.com Corporation Limited.
8 | * All rights reserved.
9 | *
10 | * This software is the confidential and proprietary information of
11 | * Dianping Company. ("Confidential Information"). You shall not
12 | * disclose such Confidential Information and shall use it only in
13 | * accordance with the terms of the license agreement you entered into
14 | * with Dianping.com.
15 | */
16 | package com.dianping.cache.memcached;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 | import net.spy.memcached.transcoders.Transcoder;
22 |
23 | import com.dianping.cache.core.CacheClientConfiguration;
24 |
25 | /**
26 | * The configuration for memcached client implementation(Spymemcached)
27 | *
28 | * @author guoqing.chen
29 | *
30 | */
31 | public class MemcachedClientConfiguration implements CacheClientConfiguration {
32 |
33 | /**
34 | * All servers
35 | */
36 | private List servers = new ArrayList();
37 |
38 | /**
39 | * Transcoder
40 | */
41 | private Transcoder