├── README.md ├── cache-server ├── src │ ├── main │ │ ├── webapp │ │ │ ├── META-INF │ │ │ │ └── MANIFEST.MF │ │ │ ├── admin │ │ │ │ ├── CacheConsole.swf │ │ │ │ ├── assets │ │ │ │ │ └── image │ │ │ │ │ │ ├── betalogo.png │ │ │ │ │ │ ├── syslogo.png │ │ │ │ │ │ ├── 09unutool01.gif │ │ │ │ │ │ ├── 09unutool02.gif │ │ │ │ │ │ ├── 09unutool03.gif │ │ │ │ │ │ ├── 09unutool04.gif │ │ │ │ │ │ ├── 09unutool05.jpg │ │ │ │ │ │ ├── 09unutool08.gif │ │ │ │ │ │ ├── 09unutool09.gif │ │ │ │ │ │ ├── 09unutool05_2.jpg │ │ │ │ │ │ ├── 09unutool01-new.png │ │ │ │ │ │ ├── 09unutool02_old.gif │ │ │ │ │ │ └── 09unutool05_old.jpg │ │ │ │ ├── playerProductInstall.swf │ │ │ │ └── history │ │ │ │ │ ├── history.css │ │ │ │ │ └── historyFrame.html │ │ │ └── WEB-INF │ │ │ │ ├── jboss-web.xml │ │ │ │ ├── flex │ │ │ │ └── proxy-config.xml │ │ │ │ └── flex-application-config.xml │ │ ├── resources │ │ │ ├── config │ │ │ │ ├── applicationContext.properties │ │ │ │ ├── file-queue.properties │ │ │ │ ├── sqlmap │ │ │ │ │ ├── sqlmap-config.xml │ │ │ │ │ ├── hawk-sqlmap-config.xml │ │ │ │ │ ├── ServerGroup.xml │ │ │ │ │ ├── CacheConfiguration.xml │ │ │ │ │ ├── User.xml │ │ │ │ │ └── OperationLog.xml │ │ │ │ └── spring │ │ │ │ │ ├── appcontext-aop-core.xml │ │ │ │ │ ├── appcontext-context.xml │ │ │ │ │ ├── appcontext-security.xml │ │ │ │ │ ├── appcontext-server.xml │ │ │ │ │ └── appcontext-sms.xml │ │ │ └── log │ │ │ │ └── log4j.xml │ │ └── java │ │ │ └── com │ │ │ └── dianping │ │ │ ├── cache │ │ │ ├── queue │ │ │ │ ├── FileQueue.java │ │ │ │ └── FileQueueClosedException.java │ │ │ ├── remote │ │ │ │ ├── jms │ │ │ │ │ ├── MQSender.java │ │ │ │ │ ├── convert │ │ │ │ │ │ ├── Object2BytesConverter.java │ │ │ │ │ │ └── JDKObject2BytesConverter.java │ │ │ │ │ └── CacheMessageProducer.java │ │ │ │ ├── translator │ │ │ │ │ └── CacheKeyConfiguration2DTOTranslator.java │ │ │ │ └── sms │ │ │ │ │ └── CacheCleanFromDotNetConsumer.java │ │ │ ├── service │ │ │ │ ├── ServiceMonitorService.java │ │ │ │ ├── UserService.java │ │ │ │ ├── impl │ │ │ │ │ └── UserServiceImpl.java │ │ │ │ ├── ServerGroupService.java │ │ │ │ ├── OperationLogService.java │ │ │ │ ├── condition │ │ │ │ │ └── CacheKeyConfigSearchCondition.java │ │ │ │ ├── CacheKeyConfigurationService.java │ │ │ │ └── CacheConfigurationService.java │ │ │ ├── dao │ │ │ │ ├── UserDao.java │ │ │ │ ├── OperationLogDao.java │ │ │ │ ├── ServerGroupDao.java │ │ │ │ └── CacheConfigurationDao.java │ │ │ ├── support │ │ │ │ └── spring │ │ │ │ │ └── SpringLocator.java │ │ │ ├── entity │ │ │ │ ├── Resource.java │ │ │ │ ├── Role.java │ │ │ │ ├── ServerGroup.java │ │ │ │ ├── OperationLog.java │ │ │ │ ├── User.java │ │ │ │ ├── SupportedSpecification.java │ │ │ │ ├── CacheConfiguration.java │ │ │ │ └── CacheKeyConfiguration.java │ │ │ └── servlet │ │ │ │ └── Constants.java │ │ │ └── modules │ │ │ └── spring │ │ │ └── flex │ │ │ ├── CustomizedMessageInterceptor.java │ │ │ └── SecurityHelper.java │ └── test │ │ ├── java │ │ └── com │ │ │ └── dianping │ │ │ └── cache │ │ │ └── jms │ │ │ ├── CacheJmsSenderTest.java │ │ │ ├── NotifyMessageProducer.java │ │ │ └── JmsSenderTest.java │ │ └── resources │ │ └── config │ │ └── spring │ │ ├── applicationContext-cache-jms-sender-test.xml │ │ ├── applicationContext-jms-sender-test.xml │ │ └── applicationContext-jms-sender-test-amq.xml └── releasenote.txt ├── avatar-cache └── src │ ├── META-INF │ └── MANIFEST.MF │ ├── main │ ├── java │ │ ├── META-INF │ │ │ └── MANIFEST.MF │ │ └── com │ │ │ └── dianping │ │ │ └── avatar │ │ │ └── cache │ │ │ ├── annotation │ │ │ ├── CacheOperation.java │ │ │ ├── CacheParam.java │ │ │ └── Cache.java │ │ │ ├── support │ │ │ ├── CacheTracker.java │ │ │ └── DefaultCacheTracker.java │ │ │ ├── configuration │ │ │ ├── CacheItemConfigManager.java │ │ │ ├── DefaultCacheKeyType.java │ │ │ └── EnhancedCacheItemConfigManager.java │ │ │ ├── client │ │ │ ├── CacheClientConfigurationParser.java │ │ │ ├── EhcacheClientConfigurationParser.java │ │ │ ├── CacheClientConfigurationHelper.java │ │ │ └── MemcachedClientConfigurationParser.java │ │ │ ├── spring │ │ │ └── AvatarNamespacheHandler.java │ │ │ ├── CacheKey.java │ │ │ └── listener │ │ │ ├── CacheConfigurationUpdateListener.java │ │ │ └── CacheKeyConfigUpdateListener.java │ └── resources │ │ └── META-INF │ │ ├── spring.handlers │ │ ├── spring.schemas │ │ └── com │ │ └── dianping │ │ └── avatar │ │ └── cache │ │ └── avatar-1.0.xsd │ └── test │ ├── resources │ ├── META-INF │ │ └── cat │ │ │ └── client.xml │ ├── appcontext.properties │ ├── AOPDemo.xml │ └── AOPDemo2.xml │ └── java │ └── com │ └── dianping │ └── avatar │ └── cache │ ├── spring │ ├── BusinessInterface.java │ ├── BusinessInterfaceImpl.java │ ├── DemoInterceptor.java │ ├── DemoInterceptor2.java │ └── CacheBeanDefinitionParserTest.java │ └── TestCat.java ├── cache-core ├── src │ ├── META-INF │ │ └── MANIFEST.MF │ ├── main │ │ ├── java │ │ │ ├── META-INF │ │ │ │ └── MANIFEST.MF │ │ │ └── com │ │ │ │ └── dianping │ │ │ │ └── cache │ │ │ │ ├── core │ │ │ │ ├── CacheClientConfiguration.java │ │ │ │ ├── InitialConfiguration.java │ │ │ │ ├── Lifecycle.java │ │ │ │ ├── KeyAware.java │ │ │ │ └── CacheException.java │ │ │ │ ├── memcached │ │ │ │ ├── ExtendedConnectionFactory.java │ │ │ │ ├── ExtendedKetamaConnectionFactory.java │ │ │ │ ├── KvdbTranscoder.java │ │ │ │ ├── MemcachedClientConfiguration.java │ │ │ │ └── HessianSerializer.java │ │ │ │ ├── local │ │ │ │ ├── LocalCacheConfiguration.java │ │ │ │ ├── CacheElement.java │ │ │ │ └── ElementAttributes.java │ │ │ │ └── ehcache │ │ │ │ ├── EhcacheConfiguration.java │ │ │ │ └── LooseBlockingCache.java │ │ └── resources │ │ │ ├── ehcache.xml │ │ │ └── ehcache-distribution.xml │ └── test │ │ ├── resources │ │ └── com │ │ │ └── dianping │ │ │ └── cache │ │ │ └── core │ │ │ └── testClasspathBuilder.properties │ │ └── java │ │ └── com │ │ └── dianping │ │ └── cache │ │ ├── core │ │ ├── ketama │ │ │ ├── MockKetamaNodeLocatorConfiguration.java │ │ │ ├── MockKetamaNodeLocator.java │ │ │ └── KetamaHashAlgorithmTest.java │ │ ├── Person.java │ │ └── TestHessian.java │ │ └── kvdb │ │ └── KvdbClientImplTest.java └── pom.xml ├── cache-builder ├── src │ ├── META-INF │ │ └── MANIFEST.MF │ ├── main │ │ └── java │ │ │ ├── META-INF │ │ │ └── MANIFEST.MF │ │ │ └── com │ │ │ └── dianping │ │ │ └── cache │ │ │ └── builder │ │ │ ├── metadata │ │ │ ├── CacheMetadataParser.java │ │ │ ├── LocalCacheMetadataParser.java │ │ │ └── EhcacheMetadataParser.java │ │ │ └── CacheClientFactory.java │ └── test │ │ ├── resources │ │ └── com │ │ │ └── dianping │ │ │ └── cache │ │ │ └── builder │ │ │ └── metadata │ │ │ └── caches.xml │ │ └── java │ │ └── com │ │ └── dianping │ │ └── cache │ │ └── builder │ │ └── metadata │ │ └── TestXMLMetadataFactory.java └── pom.xml ├── avatar-cache-remote ├── src │ ├── META-INF │ │ └── MANIFEST.MF │ └── main │ │ └── java │ │ ├── META-INF │ │ └── MANIFEST.MF │ │ └── com │ │ └── dianping │ │ └── remote │ │ └── cache │ │ ├── dto │ │ ├── MessageType.java │ │ ├── EhcacheConfigDetailDTO.java │ │ ├── CacheConfigDetailDTO.java │ │ ├── LocalCacheRemoveDTO.java │ │ ├── CacheClearDTO.java │ │ ├── CacheConfigurationDTO.java │ │ ├── SingleCacheRemoveDTO.java │ │ ├── CacheMessageDTO.java │ │ ├── CacheConfigurationsDTO.java │ │ ├── MemcachedConfigDetailDTO.java │ │ ├── CacheKeyTypeVersionUpdateDTO.java │ │ └── GenericCacheConfigurationDTO.java │ │ ├── CacheConfigurationWebService.java │ │ └── CacheManageWebService.java └── pom.xml ├── .gitignore └── pom.xml /README.md: -------------------------------------------------------------------------------- 1 | avatar-cache 2 | ============ -------------------------------------------------------------------------------- /cache-server/src/main/webapp/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | 3 | -------------------------------------------------------------------------------- /avatar-cache/src/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /cache-core/src/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /cache-builder/src/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /avatar-cache-remote/src/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /avatar-cache/src/main/java/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /cache-core/src/main/java/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /cache-builder/src/main/java/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /avatar-cache-remote/src/main/java/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /cache-server/src/main/resources/config/applicationContext.properties: -------------------------------------------------------------------------------- 1 | #http://service.dianping.com/mailService/mailService_1.0.0=192.168.7.26:2008 -------------------------------------------------------------------------------- /avatar-cache/src/main/resources/META-INF/spring.handlers: -------------------------------------------------------------------------------- 1 | http\://www.dianping.com/schema/avatar=com.dianping.avatar.cache.spring.AvatarNamespacheHandler 2 | -------------------------------------------------------------------------------- /avatar-cache/src/main/resources/META-INF/spring.schemas: -------------------------------------------------------------------------------- 1 | http\://www.dianping.com/schema/avatar/avatar-1.0.xsd=META-INF/com/dianping/avatar/cache/avatar-1.0.xsd -------------------------------------------------------------------------------- /cache-server/src/main/webapp/admin/CacheConsole.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dianping/avatar-cache/HEAD/cache-server/src/main/webapp/admin/CacheConsole.swf -------------------------------------------------------------------------------- /cache-server/src/main/webapp/admin/assets/image/betalogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dianping/avatar-cache/HEAD/cache-server/src/main/webapp/admin/assets/image/betalogo.png -------------------------------------------------------------------------------- /cache-server/src/main/webapp/admin/assets/image/syslogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dianping/avatar-cache/HEAD/cache-server/src/main/webapp/admin/assets/image/syslogo.png -------------------------------------------------------------------------------- /cache-server/src/main/webapp/admin/playerProductInstall.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dianping/avatar-cache/HEAD/cache-server/src/main/webapp/admin/playerProductInstall.swf -------------------------------------------------------------------------------- /cache-server/src/main/webapp/admin/assets/image/09unutool01.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dianping/avatar-cache/HEAD/cache-server/src/main/webapp/admin/assets/image/09unutool01.gif -------------------------------------------------------------------------------- /cache-server/src/main/webapp/admin/assets/image/09unutool02.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dianping/avatar-cache/HEAD/cache-server/src/main/webapp/admin/assets/image/09unutool02.gif -------------------------------------------------------------------------------- /cache-server/src/main/webapp/admin/assets/image/09unutool03.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dianping/avatar-cache/HEAD/cache-server/src/main/webapp/admin/assets/image/09unutool03.gif -------------------------------------------------------------------------------- /cache-server/src/main/webapp/admin/assets/image/09unutool04.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dianping/avatar-cache/HEAD/cache-server/src/main/webapp/admin/assets/image/09unutool04.gif -------------------------------------------------------------------------------- /cache-server/src/main/webapp/admin/assets/image/09unutool05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dianping/avatar-cache/HEAD/cache-server/src/main/webapp/admin/assets/image/09unutool05.jpg -------------------------------------------------------------------------------- /cache-server/src/main/webapp/admin/assets/image/09unutool08.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dianping/avatar-cache/HEAD/cache-server/src/main/webapp/admin/assets/image/09unutool08.gif -------------------------------------------------------------------------------- /cache-server/src/main/webapp/admin/assets/image/09unutool09.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dianping/avatar-cache/HEAD/cache-server/src/main/webapp/admin/assets/image/09unutool09.gif -------------------------------------------------------------------------------- /cache-server/src/main/webapp/admin/assets/image/09unutool05_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dianping/avatar-cache/HEAD/cache-server/src/main/webapp/admin/assets/image/09unutool05_2.jpg -------------------------------------------------------------------------------- /cache-server/src/main/webapp/admin/assets/image/09unutool01-new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dianping/avatar-cache/HEAD/cache-server/src/main/webapp/admin/assets/image/09unutool01-new.png -------------------------------------------------------------------------------- /cache-server/src/main/webapp/admin/assets/image/09unutool02_old.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dianping/avatar-cache/HEAD/cache-server/src/main/webapp/admin/assets/image/09unutool02_old.gif -------------------------------------------------------------------------------- /cache-server/src/main/webapp/admin/assets/image/09unutool05_old.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dianping/avatar-cache/HEAD/cache-server/src/main/webapp/admin/assets/image/09unutool05_old.jpg -------------------------------------------------------------------------------- /cache-core/src/test/resources/com/dianping/cache/core/testClasspathBuilder.properties: -------------------------------------------------------------------------------- 1 | memcached=com.dianping.cache.memcached.MemcachedClientImpl 2 | ehcache=com.dianping.cache.ehcache.EhcacheClientImpl -------------------------------------------------------------------------------- /avatar-cache/src/test/resources/META-INF/cat/client.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /avatar-cache/src/test/java/com/dianping/avatar/cache/spring/BusinessInterface.java: -------------------------------------------------------------------------------- 1 | package com.dianping.avatar.cache.spring; 2 | 3 | public interface BusinessInterface { 4 | public void hello(); 5 | public int bye(); 6 | } -------------------------------------------------------------------------------- /cache-server/src/main/webapp/WEB-INF/jboss-web.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | / 5 | -------------------------------------------------------------------------------- /cache-server/src/main/resources/config/file-queue.properties: -------------------------------------------------------------------------------- 1 | metapath=/data/appdatas/cache-file-queue/meta/ 2 | datapath=/data/appdatas/cache-file-queue/data/ 3 | databakpath=/data/appdatas/cache-file-queue/bak/ 4 | databakon=false 5 | memcachesize=5000 6 | maxDataFileSize=52428800 7 | -------------------------------------------------------------------------------- /avatar-cache/src/test/resources/appcontext.properties: -------------------------------------------------------------------------------- 1 | http://service.dianping.com/cacheService/cacheConfigService_1.0.0=192.168.7.41:2007 2 | http://service.dianping.com/cacheService/cacheManageService_1.0.0=192.168.7.41:2007 3 | remoteServer.cacheService=192.168.7.41:2007 4 | avatar-cache.swallow.url=192.168.7.41:27017 -------------------------------------------------------------------------------- /avatar-cache/src/test/java/com/dianping/avatar/cache/spring/BusinessInterfaceImpl.java: -------------------------------------------------------------------------------- 1 | package com.dianping.avatar.cache.spring; 2 | 3 | public class BusinessInterfaceImpl implements BusinessInterface { 4 | 5 | public void hello() { 6 | System.out.println("hello Spring AOP."); 7 | } 8 | 9 | public int bye() { 10 | System.out.println("ByeByte AOP"); 11 | return 200; 12 | } 13 | 14 | 15 | } 16 | -------------------------------------------------------------------------------- /cache-server/src/main/webapp/admin/history/history.css: -------------------------------------------------------------------------------- 1 | /* This CSS stylesheet defines styles used by required elements in a flex application page that supports browser history */ 2 | 3 | #ie_historyFrame { width: 0px; height: 0px; display:none } 4 | #firefox_anchorDiv { width: 0px; height: 0px; display:none } 5 | #safari_formDiv { width: 0px; height: 0px; display:none } 6 | #safari_rememberDiv { width: 0px; height: 0px; display:none } 7 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/queue/FileQueue.java: -------------------------------------------------------------------------------- 1 | package com.dianping.cache.queue; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | 5 | /** 6 | * 文件队列 7 | * 8 | * @author Leo Liang 9 | */ 10 | public interface FileQueue { 11 | 12 | public T get(); 13 | 14 | public T get(long timeout, TimeUnit timeUnit); 15 | 16 | public void add(T m) throws FileQueueClosedException; 17 | 18 | public void close(); 19 | } 20 | -------------------------------------------------------------------------------- /cache-server/releasenote.txt: -------------------------------------------------------------------------------- 1 | ====version2.0.1==== 2 | 3 | 部署涉及资源: 4 | 1. 需要在hawk库中创建CacheOperationLog表 5 | 2. 需要在hawk库中创建权限相关数据,涉及资源包括 6 | cache-config-------------------- 7 | cache-config-create 8 | cache-config-update 9 | cache-config-remove 10 | cache-single-clear 11 | cache-log-------------- 12 | cache-key-config-create 13 | cache-key-config-update 14 | cache-key-config-remove 15 | cache-batch-clear 16 | cache-operate-log -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/queue/FileQueueClosedException.java: -------------------------------------------------------------------------------- 1 | package com.dianping.cache.queue; 2 | 3 | /** 4 | * 5 | * @author Leo Liang 6 | */ 7 | public class FileQueueClosedException extends Exception { 8 | 9 | private static final long serialVersionUID = 6780761235961823055L; 10 | 11 | public FileQueueClosedException() { 12 | super(); 13 | } 14 | 15 | public FileQueueClosedException(String msg) { 16 | super(msg); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /cache-core/src/main/resources/ehcache.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 9 | 10 | -------------------------------------------------------------------------------- /cache-server/src/main/resources/config/sqlmap/sqlmap-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /cache-builder/src/test/resources/com/dianping/cache/builder/metadata/caches.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /cache-server/src/main/resources/config/sqlmap/hawk-sqlmap-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /avatar-cache-remote/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | com.dianping 5 | avatar-cache-parent 6 | 2.4.2 7 | 8 | 4.0.0 9 | avatar-cache-remote 10 | jar 11 | avatar-cache-remote 12 | http://maven.apache.org 13 | 14 | 15 | com.dianping 16 | avatar-common-remote 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /cache-builder/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | 7 | com.dianping 8 | avatar-cache-parent 9 | 2.4.2 10 | 11 | cache-builder 12 | jar 13 | 14 | cache-builder 15 | http://maven.apache.org 16 | 17 | 18 | 19 | ${project.groupId} 20 | cache-core 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/remote/jms/MQSender.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: com.dianping.cache-server-2.0.1-old 3 | * 4 | * File Created at 2011-10-17 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.remote.jms; 17 | 18 | /** 19 | * MQSender 20 | * @author youngphy.yang 21 | * 22 | */ 23 | public interface MQSender { 24 | public void sendMessageToTopic(final Object msg); 25 | } 26 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/service/ServiceMonitorService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-server 3 | * 4 | * File Created at 2012-3-26 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.service; 17 | 18 | /** 19 | * 监控服务调用客户端状态 20 | * @author danson.liu 21 | * 22 | */ 23 | public interface ServiceMonitorService { 24 | 25 | String getClientStats(String clientIp, int skip, int size) throws Exception; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /cache-core/src/main/java/com/dianping/cache/core/CacheClientConfiguration.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.core; 17 | 18 | /** 19 | * The marker interface for configuring cache client. The concrete 20 | * implementations should provide details. 21 | * 22 | * @author guoqing.chen 23 | * 24 | */ 25 | public interface CacheClientConfiguration { 26 | 27 | } 28 | -------------------------------------------------------------------------------- /avatar-cache/src/main/java/com/dianping/avatar/cache/annotation/CacheOperation.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: avatar 3 | * 4 | * File Created at 2010-8-10 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 | /** 19 | * Cache operation 20 | */ 21 | public enum CacheOperation { 22 | /** 23 | * Set and get 24 | */ 25 | SetAndGet, 26 | /** 27 | * Remove cache 28 | */ 29 | Remove, 30 | /** 31 | * Update cache 32 | */ 33 | Update; 34 | } 35 | -------------------------------------------------------------------------------- /avatar-cache/src/main/java/com/dianping/avatar/cache/support/CacheTracker.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: avatar 3 | * 4 | * File Created at 2010-11-1 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.support; 17 | 18 | /** 19 | * Cache Profiler 20 | * @author danson.liu 21 | * 22 | */ 23 | public interface CacheTracker { 24 | 25 | /** 26 | * @param cacheDesc 27 | * @param timeCost 28 | */ 29 | void addGetInfo(String cacheDesc, long timeConsumed); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/service/UserService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-server 3 | * 4 | * File Created at 2011-9-22 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.service; 17 | 18 | import org.springframework.transaction.annotation.Transactional; 19 | 20 | import com.dianping.cache.entity.User; 21 | 22 | /** 23 | * TODO Comment of UserService 24 | * @author danson.liu 25 | * 26 | */ 27 | @Transactional 28 | public interface UserService { 29 | 30 | User findUser(String name); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /avatar-cache/src/main/java/com/dianping/avatar/cache/configuration/CacheItemConfigManager.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: avatar 3 | * 4 | * File Created at 2010-10-15 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.configuration; 17 | 18 | /** 19 | * Cache Item Config Manager 20 | * @author danson.liu 21 | * 22 | */ 23 | public interface CacheItemConfigManager { 24 | 25 | /** 26 | * @param category 27 | */ 28 | CacheKeyType getCacheKeyType(String category); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /cache-core/src/test/java/com/dianping/cache/core/ketama/MockKetamaNodeLocatorConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.dianping.cache.core.ketama; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | 7 | public class MockKetamaNodeLocatorConfiguration { 8 | 9 | protected Map socketAddresses = new HashMap(); 10 | 11 | public String getKeyForNode(String node, int repetition) { 12 | return getSocketAddressForNode(node) + "-" + repetition; 13 | } 14 | 15 | private String getSocketAddressForNode(String node) { 16 | String result=socketAddresses.get(node); 17 | if(result == null) { 18 | result = node; 19 | if (result.startsWith("/")) { 20 | result = result.substring(1); 21 | } 22 | socketAddresses.put(node, result); 23 | } 24 | return result; 25 | } 26 | 27 | public int getNodeRepetitions() { 28 | return 160; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/remote/jms/convert/Object2BytesConverter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: com.dianping.cache-server-2.0.1 3 | * 4 | * File Created at 2011-9-23 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.remote.jms.convert; 17 | 18 | import java.io.IOException; 19 | 20 | /** 21 | * Object2BytesConverter 22 | * @author youngphy.yang 23 | * 24 | */ 25 | public interface Object2BytesConverter { 26 | public byte[] convertObject2Bytes(Object object) throws IOException; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /avatar-cache-remote/src/main/java/com/dianping/remote/cache/dto/MessageType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: avatar 3 | * 4 | * File Created at 2010-10-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.remote.cache.dto; 17 | 18 | /** 19 | * MessageType 20 | * 21 | * @author pengshan.zhang 22 | * 23 | */ 24 | public enum MessageType { 25 | 26 | NOTHING, 27 | 28 | KEYTYPEVERSIONUPDATE, 29 | 30 | KEYTYPESUPDATE, 31 | 32 | SERVERSUPDATE, 33 | 34 | WEBCACHEREMOVE 35 | } 36 | -------------------------------------------------------------------------------- /cache-core/src/main/java/com/dianping/cache/core/InitialConfiguration.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.core; 17 | 18 | /** 19 | * The interface is used for the general purpose of retrieving configuration 20 | * items. 21 | * 22 | * @author guoqing.chen 23 | * 24 | */ 25 | public interface InitialConfiguration { 26 | 27 | /** 28 | * Initialize the cache client 29 | */ 30 | void init(CacheClientConfiguration config); 31 | } 32 | -------------------------------------------------------------------------------- /cache-server/src/main/webapp/admin/history/historyFrame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 27 | Hidden frame for Browser History support. 28 | 29 | 30 | -------------------------------------------------------------------------------- /cache-core/src/main/java/com/dianping/cache/core/Lifecycle.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.core; 17 | 18 | /** 19 | * Life cycle interface for representing Object that can be managed. Generally, 20 | * it will be extended by CacheClient implementation for destroy. 21 | * 22 | * @author guoqing.chen 23 | * 24 | */ 25 | public interface Lifecycle { 26 | 27 | /** 28 | * Start the Object 29 | */ 30 | void start(); 31 | 32 | /** 33 | * Shutdown the object 34 | */ 35 | void shutdown(); 36 | } 37 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-server 3 | * 4 | * File Created at 2011-9-22 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.dao; 17 | 18 | import com.dianping.avatar.dao.GenericDao; 19 | import com.dianping.avatar.dao.annotation.DAOAction; 20 | import com.dianping.avatar.dao.annotation.DAOActionType; 21 | import com.dianping.avatar.dao.annotation.DAOParam; 22 | import com.dianping.cache.entity.User; 23 | 24 | /** 25 | * @author danson.liu 26 | * 27 | */ 28 | public interface UserDao extends GenericDao { 29 | 30 | @DAOAction(action=DAOActionType.LOAD) 31 | User getUser(@DAOParam("name")String name); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # should not ignored # 2 | !*.java 3 | !*.gitignore 4 | !*.xml 5 | !*.jsp 6 | !*.html 7 | !*.htm 8 | !*.js 9 | !*.css 10 | !*.jpg 11 | !*.gif 12 | !*.properties 13 | 14 | 15 | # Compiled source # 16 | ################### 17 | *.com 18 | *.class 19 | *.dll 20 | *.exe 21 | *.o 22 | *.so 23 | 24 | # Packages # 25 | ############ 26 | # it's better to unpack these files and commit the raw source 27 | # git has its own built in compression methods 28 | *.7z 29 | *.dmg 30 | *.gz 31 | *.iso 32 | *.jar 33 | *.rar 34 | *.tar 35 | *.zip 36 | *.war 37 | *.ear 38 | 39 | # Logs and databases # 40 | ###################### 41 | *.log 42 | *.sql 43 | *.sqlite 44 | 45 | # OS generated files # 46 | ###################### 47 | .DS_Store 48 | .DS_Store? 49 | ._* 50 | .Spotlight-V100 51 | .Trashes 52 | Icon? 53 | ehthumbs.db 54 | Thumbs.db 55 | 56 | # eclipse generated files # 57 | ###################### 58 | .project 59 | .classpath 60 | .settings/ 61 | 62 | # temp folder # 63 | ###################### 64 | target/ 65 | build/ -------------------------------------------------------------------------------- /avatar-cache/src/test/resources/AOPDemo.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /cache-core/src/main/java/com/dianping/cache/memcached/ExtendedConnectionFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: com.dianping.memcachedb-0.0.1-SNAPSHOT 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.memcached; 17 | 18 | import net.spy.memcached.ConnectionFactory; 19 | import net.spy.memcached.transcoders.Transcoder; 20 | 21 | /** 22 | * TODO Comment of ExtendedConnectionFactory 23 | * @author jian.liu 24 | * 25 | */ 26 | public interface ExtendedConnectionFactory extends ConnectionFactory { 27 | 28 | /** 29 | * 30 | * @param transcoder 31 | */ 32 | void setTranscoder(Transcoder transcoder); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /cache-server/src/main/resources/config/spring/appcontext-aop-core.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /avatar-cache/src/main/java/com/dianping/avatar/cache/client/CacheClientConfigurationParser.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: avatar 3 | * 4 | * File Created at 2010-10-18 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.client; 17 | 18 | import com.dianping.cache.core.CacheClientConfiguration; 19 | import com.dianping.remote.cache.dto.CacheConfigDetailDTO; 20 | 21 | /** 22 | * Parse cache client configuration 23 | * @author danson.liu 24 | * 25 | */ 26 | public interface CacheClientConfigurationParser { 27 | 28 | /** 29 | * @param detail 30 | * @return 31 | */ 32 | CacheClientConfiguration parse(CacheConfigDetailDTO detail); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /avatar-cache-remote/src/main/java/com/dianping/remote/cache/dto/EhcacheConfigDetailDTO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: avatar-cache-remote 3 | * 4 | * File Created at 2010-10-18 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.remote.cache.dto; 17 | 18 | /** 19 | * Ehcache Config Detail DTO 20 | * @author danson.liu 21 | * 22 | */ 23 | public class EhcacheConfigDetailDTO extends CacheConfigDetailDTO { 24 | 25 | /** 26 | * 27 | */ 28 | private static final long serialVersionUID = 6622073723502785607L; 29 | 30 | /** 31 | * 32 | */ 33 | public EhcacheConfigDetailDTO() { 34 | clientClazz = "com.dianping.cache.ehcache.EhcacheClientImpl"; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-server 3 | * 4 | * File Created at 2011-9-22 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.service.impl; 17 | 18 | import com.dianping.cache.dao.UserDao; 19 | import com.dianping.cache.entity.User; 20 | import com.dianping.cache.service.UserService; 21 | 22 | /** 23 | * @author danson.liu 24 | * 25 | */ 26 | public class UserServiceImpl implements UserService { 27 | 28 | private UserDao userDao; 29 | 30 | @Override 31 | public User findUser(String nameOrEmail) { 32 | return userDao.getUser(nameOrEmail); 33 | } 34 | 35 | public void setUserDao(UserDao userDao) { 36 | this.userDao = userDao; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /cache-server/src/main/webapp/WEB-INF/flex/proxy-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 100 7 | 2 8 | 9 | 10 | true 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /avatar-cache-remote/src/main/java/com/dianping/remote/cache/dto/CacheConfigDetailDTO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: avatar-cache-remote 3 | * 4 | * File Created at 2010-10-18 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.remote.cache.dto; 17 | 18 | import com.dianping.remote.share.dto.AbstractDTO; 19 | 20 | /** 21 | * CacheConfigDetailDTO 22 | * @author danson.liu 23 | * 24 | */ 25 | public abstract class CacheConfigDetailDTO extends AbstractDTO { 26 | 27 | /** 28 | * 29 | */ 30 | private static final long serialVersionUID = 463815040207539685L; 31 | 32 | protected String clientClazz; 33 | 34 | public String getClientClazz() { 35 | return clientClazz; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /cache-core/src/main/java/com/dianping/cache/local/LocalCacheConfiguration.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 | import com.dianping.cache.core.CacheClientConfiguration; 19 | 20 | /** 21 | * The configuration for local cache client implementation 22 | * @author danson.liu 23 | * 24 | */ 25 | public class LocalCacheConfiguration implements CacheClientConfiguration { 26 | 27 | private long maxIdleTime = -1; 28 | 29 | public long getMaxIdleTime() { 30 | return maxIdleTime; 31 | } 32 | 33 | public void setMaxIdleTime(long maxIdleTime) { 34 | this.maxIdleTime = maxIdleTime; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /cache-core/src/main/java/com/dianping/cache/core/KeyAware.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.core; 17 | 18 | /** 19 | * The object that implements this interface will be set key. Generally, the 20 | * cache client implementations will drive from this interface for configuration 21 | * purpose. 22 | * 23 | * @author guoqing.chen 24 | * 25 | */ 26 | public interface KeyAware { 27 | 28 | /** 29 | * Set cache client unique key(the key be used to indicate the client 30 | * instance.) 31 | */ 32 | void setKey(String key); 33 | 34 | /** 35 | * Retrieve the unique key 36 | */ 37 | String getKey(); 38 | } 39 | -------------------------------------------------------------------------------- /cache-builder/src/main/java/com/dianping/cache/builder/metadata/CacheMetadataParser.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.cache.builder.metadata; 17 | 18 | import org.w3c.dom.Element; 19 | 20 | import com.dianping.cache.core.CacheClientConfiguration; 21 | 22 | /** 23 | * Parse the cache from XML 24 | * 25 | * @author guoqing.chen 26 | * 27 | */ 28 | public interface CacheMetadataParser { 29 | 30 | /** 31 | * Create a {@link CacheClientConfiguration} instance by Element. The 32 | * concrete implementation of {@link CacheClientConfiguration} will be found 33 | * in Element. 34 | */ 35 | CacheClientConfiguration parse(Element e); 36 | } 37 | -------------------------------------------------------------------------------- /avatar-cache/src/main/java/com/dianping/avatar/cache/spring/AvatarNamespacheHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: avatar 3 | * 4 | * File Created at 2010-8-9 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.spring; 17 | 18 | import org.springframework.beans.factory.xml.BeanDefinitionParser; 19 | import org.springframework.beans.factory.xml.NamespaceHandlerSupport; 20 | 21 | /** 22 | * The namespace handler for avatar:cache 23 | * 24 | * @author guoqing.chen 25 | * 26 | */ 27 | public class AvatarNamespacheHandler extends NamespaceHandlerSupport { 28 | 29 | /** 30 | * Register {@link BeanDefinitionParser} instance 31 | */ 32 | @Override 33 | public void init() { 34 | this.registerBeanDefinitionParser("cache", new CacheBeanDefinitionParser()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /cache-builder/src/main/java/com/dianping/cache/builder/CacheClientFactory.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.cache.builder; 17 | 18 | import java.util.List; 19 | 20 | import com.dianping.cache.core.CacheClient; 21 | 22 | 23 | /** 24 | * Cache service factory, it can retrieve available cache keys and find 25 | * {@link CacheService} implementation by cache key. 26 | * 27 | * @author guoqing.chen 28 | * 29 | */ 30 | public interface CacheClientFactory { 31 | 32 | /** 33 | * Retrieve all available cache keys 34 | */ 35 | List getCacheKeys(); 36 | 37 | /** 38 | * Retrieve a {@link CacheService} instance by key 39 | */ 40 | CacheClient findCacheClient(String cacheKey); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/service/ServerGroupService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: 3-com.dianping.cache-server-2.0.3 3 | * 4 | * File Created at 2011-12-21 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.service; 17 | 18 | import java.util.List; 19 | 20 | import org.springframework.transaction.annotation.Transactional; 21 | 22 | import com.dianping.avatar.exception.DuplicatedIdentityException; 23 | import com.dianping.cache.entity.ServerGroup; 24 | 25 | /** 26 | * TODO Comment of ServerGroupService 27 | * @author danson.liu 28 | * 29 | */ 30 | @Transactional 31 | public interface ServerGroupService { 32 | 33 | List findAll(); 34 | 35 | ServerGroup find(String group); 36 | 37 | ServerGroup create(ServerGroup serverGroup) throws DuplicatedIdentityException; 38 | 39 | ServerGroup update(ServerGroup serverGroup); 40 | 41 | void delete(String group); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /cache-server/src/main/resources/config/spring/appcontext-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /avatar-cache/src/test/java/com/dianping/avatar/cache/spring/DemoInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.dianping.avatar.cache.spring; 2 | 3 | import org.aopalliance.intercept.MethodInterceptor; 4 | import org.aopalliance.intercept.MethodInvocation; 5 | import org.springframework.beans.factory.InitializingBean; 6 | public class DemoInterceptor implements MethodInterceptor, InitializingBean{ 7 | 8 | public Object invoke(MethodInvocation methodInvocation) throws Throwable { 9 | System.out.println("Beginning method (1): " 10 | + methodInvocation.getMethod().getDeclaringClass() + "." 11 | + methodInvocation.getMethod().getName() + "()"); 12 | long startTime = System.currentTimeMillis(); 13 | try { 14 | Object result = methodInvocation.proceed(); 15 | if(result != null) { 16 | System.out.println("returned: " + result); 17 | } 18 | return result; 19 | } finally { 20 | System.out.println("Ending method (1): " 21 | + methodInvocation.getMethod().getDeclaringClass() + "." 22 | + methodInvocation.getMethod().getName() + "()"); 23 | System.out.println("Method invocation time (1): " 24 | + (System.currentTimeMillis() - startTime) + " ms."); 25 | } 26 | } 27 | 28 | @Override 29 | public void afterPropertiesSet() throws Exception { 30 | 31 | } 32 | } -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/service/OperationLogService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-server 3 | * 4 | * File Created at 2011-9-18 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.service; 17 | 18 | import java.util.Date; 19 | import java.util.Map; 20 | 21 | import org.springframework.transaction.annotation.Transactional; 22 | 23 | import com.dianping.cache.service.condition.OperationLogSearchCondition; 24 | import com.dianping.core.type.PageModel; 25 | 26 | /** 27 | * @author danson.liu 28 | * 29 | */ 30 | @Transactional 31 | public interface OperationLogService { 32 | 33 | void create(boolean succeed, String content, boolean critical); 34 | 35 | void create(boolean succeed, String operation, Map detail, boolean critical); 36 | 37 | PageModel paginate(PageModel paginater, OperationLogSearchCondition searchCondition); 38 | 39 | void delete(Date before); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/support/spring/SpringLocator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2015 by Shanghai HanTao Information Co., Ltd. 3 | * All rights reserved. 4 | */ 5 | package com.dianping.cache.support.spring; 6 | 7 | import org.springframework.beans.BeansException; 8 | import org.springframework.beans.factory.BeanFactoryUtils; 9 | import org.springframework.context.ApplicationContext; 10 | import org.springframework.context.ApplicationContextAware; 11 | 12 | /** 13 | * @author danson.liu 14 | * 15 | */ 16 | public class SpringLocator implements ApplicationContextAware{ 17 | 18 | private static ApplicationContext applicationContext; 19 | 20 | @SuppressWarnings("unchecked") 21 | public static T getBean(String name) { 22 | return (T) applicationContext.getBean(name); 23 | } 24 | 25 | @SuppressWarnings("unchecked") 26 | public static T getBean(Class clazz) { 27 | return (T) BeanFactoryUtils.beanOfType(applicationContext, clazz); 28 | } 29 | 30 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException{ 31 | SpringLocator.applicationContext = applicationContext; 32 | } 33 | 34 | public static ApplicationContext getApplicationContext() { 35 | return applicationContext; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /avatar-cache-remote/src/main/java/com/dianping/remote/cache/CacheConfigurationWebService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: avatar-cache-remote 3 | * 4 | * File Created at 2010-10-14 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.remote.cache; 17 | 18 | import java.util.List; 19 | 20 | import com.dianping.remote.cache.dto.CacheConfigurationsDTO; 21 | import com.dianping.remote.cache.dto.CacheKeyConfigurationDTO; 22 | 23 | /** 24 | * CacheConfiguration poll interface 25 | * @author danson.liu 26 | * 27 | */ 28 | public interface CacheConfigurationWebService { 29 | 30 | /** 31 | * retrieve all cache key configurations 32 | * @return 33 | */ 34 | List getKeyConfigurations(); 35 | 36 | /** 37 | * retrieve cache client configuration, e.g. memcached, kvdb 38 | * @return 39 | */ 40 | CacheConfigurationsDTO getCacheConfigurations(); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /cache-core/src/test/java/com/dianping/cache/kvdb/KvdbClientImplTest.java: -------------------------------------------------------------------------------- 1 | package com.dianping.cache.kvdb; 2 | 3 | import java.util.Arrays; 4 | 5 | import org.junit.Assert; 6 | import org.junit.Before; 7 | import org.junit.Ignore; 8 | import org.junit.Test; 9 | 10 | import com.dianping.cache.memcached.KvdbTranscoder; 11 | import com.dianping.cache.memcached.MemcachedClientConfiguration; 12 | import com.dianping.cache.memcached.MemcachedClientImpl; 13 | 14 | @Ignore 15 | public class KvdbClientImplTest { 16 | 17 | private MemcachedClientImpl kvdbClient; 18 | 19 | @Before 20 | public void before() { 21 | kvdbClient = new MemcachedClientImpl(); 22 | MemcachedClientConfiguration config = new MemcachedClientConfiguration(); 23 | config.setServers(Arrays.asList("10.1.1.114:22211", "10.1.1.114:22211,10.1.1.115:22211,10.1.1.116:22211")); 24 | config.setTranscoder(new KvdbTranscoder()); 25 | kvdbClient.setKey("demo-kvdb"); 26 | kvdbClient.init(config); 27 | kvdbClient.start(); 28 | } 29 | 30 | @Test 31 | public void test() throws InterruptedException { 32 | String key = "test-1"; 33 | String value = "foo"; 34 | kvdbClient.set(key, value, 0, null); 35 | Thread.sleep(1000); 36 | Object found = kvdbClient.get(key, null); 37 | Assert.assertNotNull(found); 38 | Assert.assertEquals(value, found); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/entity/Resource.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-server 3 | * 4 | * File Created at 2011-9-22 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.entity; 17 | 18 | import java.io.Serializable; 19 | 20 | /** 21 | * @author danson.liu 22 | * 23 | */ 24 | public class Resource implements Serializable { 25 | 26 | /** 27 | * 28 | */ 29 | private static final long serialVersionUID = 4060417168234170876L; 30 | 31 | private int id; 32 | 33 | private String name; 34 | 35 | private String des; 36 | 37 | public int getId() { 38 | return id; 39 | } 40 | 41 | public void setId(int id) { 42 | this.id = id; 43 | } 44 | 45 | public String getName() { 46 | return name; 47 | } 48 | 49 | public void setName(String name) { 50 | this.name = name; 51 | } 52 | 53 | public String getDes() { 54 | return des; 55 | } 56 | 57 | public void setDes(String des) { 58 | this.des = des; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/servlet/Constants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-server 3 | * 4 | * File Created at 2010-10-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.servlet; 17 | 18 | /** 19 | * @author pengshan.zhang 20 | * 21 | */ 22 | public class Constants { 23 | /** 24 | * Key type version update param value 25 | */ 26 | public final static String KEYTYPE_VERSION_UPDATE = "KEYTYPEVERSIONUPDATE"; 27 | 28 | /** 29 | * Local cache remove param value 30 | */ 31 | public final static String LOCAL_CACHE_REMOVE = "LOCALCACHEREMOVE"; 32 | 33 | /** 34 | * Key type version update message typel 35 | */ 36 | public final static int KEYTYPE_VERSION_UPDATE_MESSAGE = 1; 37 | 38 | /** 39 | * Local cache remove message type 40 | */ 41 | public final static int SINGLE_CACHE_REMOVE_MESSAGE = 2; 42 | } 43 | -------------------------------------------------------------------------------- /avatar-cache/src/test/resources/AOPDemo2.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /avatar-cache/src/main/java/com/dianping/avatar/cache/client/EhcacheClientConfigurationParser.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: avatar 3 | * 4 | * File Created at 2010-10-18 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.client; 17 | 18 | import com.dianping.cache.core.CacheClientConfiguration; 19 | import com.dianping.cache.ehcache.EhcacheConfiguration; 20 | import com.dianping.remote.cache.dto.CacheConfigDetailDTO; 21 | import com.dianping.remote.cache.dto.EhcacheConfigDetailDTO; 22 | 23 | /** 24 | * EhcacheClient Configuration Parser 25 | * @author danson.liu 26 | * 27 | */ 28 | public class EhcacheClientConfigurationParser implements CacheClientConfigurationParser { 29 | 30 | @Override 31 | public CacheClientConfiguration parse(CacheConfigDetailDTO detail) { 32 | assert detail instanceof EhcacheConfigDetailDTO; 33 | //Can extend some ehcache configuration here 34 | return new EhcacheConfiguration(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /avatar-cache/src/test/java/com/dianping/avatar/cache/spring/DemoInterceptor2.java: -------------------------------------------------------------------------------- 1 | package com.dianping.avatar.cache.spring; 2 | 3 | import org.aopalliance.intercept.MethodInterceptor; 4 | import org.aopalliance.intercept.MethodInvocation; 5 | import org.springframework.beans.factory.InitializingBean; 6 | public class DemoInterceptor2 implements MethodInterceptor, InitializingBean{ 7 | 8 | public Object invoke(MethodInvocation methodInvocation) throws Throwable { 9 | System.out.println("Beginning method (1): " 10 | + methodInvocation.getMethod().getDeclaringClass() + "." 11 | + methodInvocation.getMethod().getName() + "()"); 12 | long startTime = System.currentTimeMillis(); 13 | try { 14 | Object result = methodInvocation.proceed(); 15 | if(result != null) { 16 | System.out.println("returned: " + result); 17 | result = 100; 18 | System.out.println("revised: " + result); 19 | } 20 | return result; 21 | } finally { 22 | System.out.println("Ending method (1): " 23 | + methodInvocation.getMethod().getDeclaringClass() + "." 24 | + methodInvocation.getMethod().getName() + "()"); 25 | System.out.println("Method invocation time (1): " 26 | + (System.currentTimeMillis() - startTime) + " ms."); 27 | } 28 | } 29 | 30 | @Override 31 | public void afterPropertiesSet() throws Exception { 32 | 33 | } 34 | } -------------------------------------------------------------------------------- /cache-core/src/test/java/com/dianping/cache/core/Person.java: -------------------------------------------------------------------------------- 1 | package com.dianping.cache.core; 2 | 3 | import java.io.Serializable; 4 | 5 | @SuppressWarnings("serial") 6 | public class Person implements Serializable { 7 | 8 | private String id; 9 | private String name; 10 | private int age; 11 | 12 | public Person(String id, String name, int age) { 13 | this.id = id; 14 | this.name = name; 15 | this.age = age; 16 | } 17 | 18 | public String getId() { 19 | return id; 20 | } 21 | public void setId(String id) { 22 | this.id = id; 23 | } 24 | public String getName() { 25 | return name; 26 | } 27 | public void setName(String name) { 28 | this.name = name; 29 | } 30 | public int getAge() { 31 | return age; 32 | } 33 | public void setAge(int age) { 34 | this.age = age; 35 | } 36 | 37 | @Override 38 | public boolean equals(Object obj) { 39 | if (!(obj instanceof Person)) { 40 | return false; 41 | } 42 | if (this == obj) { 43 | return true; 44 | } 45 | if (obj == null) { 46 | return false; 47 | } 48 | Person tmp = (Person) obj; 49 | //不考虑字段为null情形 50 | return id.equals(tmp.id) && name.equals(tmp.name) && age == tmp.age; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /cache-builder/src/main/java/com/dianping/cache/builder/metadata/LocalCacheMetadataParser.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-builder 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.builder.metadata; 17 | 18 | import org.w3c.dom.Element; 19 | 20 | import com.dianping.cache.core.CacheClientConfiguration; 21 | import com.dianping.cache.local.LocalCacheConfiguration; 22 | 23 | /** 24 | * Local Cache metadata parser 25 | * @author danson.liu 26 | * 27 | */ 28 | public class LocalCacheMetadataParser implements CacheMetadataParser { 29 | 30 | @Override 31 | public CacheClientConfiguration parse(Element e) { 32 | LocalCacheConfiguration configuration = new LocalCacheConfiguration(); 33 | String maxIdleTime = e.getAttribute("maxIdleTime"); 34 | if (maxIdleTime != null && maxIdleTime.length() > 0) { 35 | configuration.setMaxIdleTime(Long.parseLong(maxIdleTime)); 36 | } 37 | return configuration; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /cache-builder/src/test/java/com/dianping/cache/builder/metadata/TestXMLMetadataFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-builder 3 | * 4 | * File Created at 2010-7-20 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.builder.metadata; 17 | 18 | import org.junit.Assert; 19 | import org.junit.Test; 20 | 21 | import com.dianping.cache.builder.CacheClientFactory; 22 | import com.dianping.cache.core.CacheClient; 23 | 24 | /** 25 | * Test class for XMLMetadataFactory 26 | * 27 | * @author guoqing.chen 28 | * 29 | */ 30 | public class TestXMLMetadataFactory { 31 | 32 | @Test 33 | public void testBuilderFromConfig() { 34 | CacheClientFactory factory = new XMLCacheClientFactory("classpath:caches.xml"); 35 | 36 | CacheClient client = factory.findCacheClient("memcached"); 37 | 38 | Assert.assertNotNull(client); 39 | 40 | try { 41 | factory.findCacheClient("444"); 42 | Assert.assertTrue(false); 43 | } catch (Exception e) { 44 | 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/remote/jms/CacheMessageProducer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-server 3 | * 4 | * File Created at 2010-10-15 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.remote.jms; 17 | 18 | import java.io.Serializable; 19 | import java.util.List; 20 | 21 | /** 22 | * A decorator for the AMQ and swallow producer client, on behalf of the compatibility with 23 | * the old systems using the AMQ. 24 | */ 25 | public class CacheMessageProducer implements Serializable { 26 | private static final long serialVersionUID = -5708176189195821560L; 27 | 28 | private List senders = null; 29 | 30 | public void sendMessageToTopic(final Object msg) { 31 | for(MQSender mqSender : senders) { 32 | mqSender.sendMessageToTopic(msg); 33 | } 34 | } 35 | 36 | public List getSenders() { 37 | return senders; 38 | } 39 | 40 | public void setSenders(List senders) { 41 | this.senders = senders; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /avatar-cache/src/main/java/com/dianping/avatar/cache/configuration/DefaultCacheKeyType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: com.dianping.avatar-cache-2.1.4 3 | * 4 | * File Created at 2011-9-15 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.avatar.cache.configuration; 17 | 18 | /** 19 | * @author liujian 20 | * 21 | */ 22 | public class DefaultCacheKeyType extends CacheKeyType { 23 | 24 | /** 25 | * @param category 26 | */ 27 | public DefaultCacheKeyType(String category) { 28 | setCategory(category); 29 | setDuration("2"); 30 | setIndexTemplate("{0}"); 31 | setIndexDesc(""); 32 | setCacheType(DEFAULT_CACHE_TYPE); 33 | setSync2Dnet(false); 34 | setHot(false); 35 | } 36 | 37 | @Override 38 | public String getKey(Object... params) { 39 | String accessKey = getCategory() + "." + getIndexTemplate() + "_" + getVersion(); 40 | String paramStr = ""; 41 | if (params == null) { 42 | params = new Object[] {null}; 43 | } 44 | for (int i = 0; i < params.length; i++) { 45 | paramStr += "(" + params[i] + ")"; 46 | } 47 | return accessKey.replace("{0}", paramStr); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /cache-builder/src/main/java/com/dianping/cache/builder/metadata/EhcacheMetadataParser.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-builder 3 | * 4 | * File Created at 2010-9-3 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.builder.metadata; 17 | 18 | import org.w3c.dom.Element; 19 | 20 | import com.dianping.cache.core.CacheClientConfiguration; 21 | import com.dianping.cache.ehcache.EhcacheConfiguration; 22 | 23 | /** 24 | * EhcacheMetadataParser for Ehcache local cache 25 | * 26 | * @author pengshan.zhang 27 | * 28 | */ 29 | public class EhcacheMetadataParser implements CacheMetadataParser { 30 | 31 | private static final String XML_FILE = "xmlFile"; 32 | 33 | @Override 34 | public CacheClientConfiguration parse(Element e) { 35 | EhcacheConfiguration configuration = new EhcacheConfiguration(); 36 | String xmlFile = e.getAttribute(XML_FILE); 37 | if (xmlFile != null && xmlFile.length() > 0) { 38 | configuration.setXmlFile(xmlFile); 39 | } 40 | return configuration; 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /cache-core/src/main/java/com/dianping/cache/local/CacheElement.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 wrapped in an CacheElement. This contains 20 | * information about the element: the key, the value and the its attributes 21 | *@author danson.liu 22 | */ 23 | public class CacheElement { 24 | 25 | private String key; 26 | 27 | private Object value; 28 | 29 | private ElementAttributes attributes; 30 | 31 | public String getKey() { 32 | return key; 33 | } 34 | 35 | public void setKey(String key) { 36 | this.key = key; 37 | } 38 | 39 | public Object getValue() { 40 | return value; 41 | } 42 | 43 | public void setValue(Object value) { 44 | this.value = value; 45 | } 46 | 47 | public ElementAttributes getAttributes() { 48 | return attributes; 49 | } 50 | 51 | public void setAttributes(ElementAttributes attributes) { 52 | this.attributes = attributes; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/remote/translator/CacheKeyConfiguration2DTOTranslator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-server 3 | * 4 | * File Created at 2010-10-15 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.remote.translator; 17 | 18 | import com.dianping.cache.entity.CacheKeyConfiguration; 19 | import com.dianping.remote.cache.dto.CacheKeyConfigurationDTO; 20 | import com.dianping.remote.share.Translator; 21 | import com.dianping.remote.util.DTOUtils; 22 | 23 | /** 24 | * Translator from {@link CacheKeyConfiguration} to {@link CacheKeyConfigurationDTO} 25 | * 26 | * @author danson.liu 27 | * 28 | */ 29 | public class CacheKeyConfiguration2DTOTranslator implements Translator { 30 | 31 | @Override 32 | public CacheKeyConfigurationDTO translate(CacheKeyConfiguration source) { 33 | assert source != null; 34 | CacheKeyConfigurationDTO cacheKeyType = new CacheKeyConfigurationDTO(); 35 | DTOUtils.copyProperties(cacheKeyType, source); 36 | return cacheKeyType; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /cache-server/src/test/java/com/dianping/cache/jms/CacheJmsSenderTest.java: -------------------------------------------------------------------------------- 1 | package com.dianping.cache.jms; 2 | 3 | 4 | import org.junit.Ignore; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.test.context.ContextConfiguration; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | 11 | import com.dianping.cache.remote.jms.CacheMessageProducer; 12 | import com.dianping.remote.cache.dto.CacheKeyTypeVersionUpdateDTO; 13 | import com.dianping.remote.cache.dto.CacheMessageDTO; 14 | 15 | @RunWith(SpringJUnit4ClassRunner.class) 16 | @ContextConfiguration(locations = "classpath:/config/spring/applicationContext-cache-jms-sender-test.xml") 17 | @Ignore 18 | public class CacheJmsSenderTest { 19 | 20 | @Autowired 21 | private CacheMessageProducer cacheMessageProducer; 22 | 23 | // @Test 24 | // public void queueMessage() { 25 | // } 26 | 27 | @Test 28 | public void topicMessage() { 29 | CacheMessageDTO msg = buildMessage(); 30 | cacheMessageProducer.sendMessageToTopic(msg); 31 | } 32 | 33 | /** 34 | * @return 35 | */ 36 | private CacheMessageDTO buildMessage() { 37 | CacheKeyTypeVersionUpdateDTO msg = new CacheKeyTypeVersionUpdateDTO(); 38 | msg.setAddTime(System.currentTimeMillis()); 39 | msg.setMsgValue("Test"); 40 | msg.setVersion("10"); 41 | return msg; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /avatar-cache/src/main/java/com/dianping/avatar/cache/annotation/CacheParam.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: avatar 3 | * 4 | * File Created at 2010-7-20 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 method parameter or field. If it annotated method parameter, 26 | * the order attribute will be ignored, the natural parameter order 27 | * will be adopted. 28 | *

29 | *

30 | * If annotated field,the order attribute will be available, and if two fields 31 | * have same order, the real order will be resolved by appearance order. 32 | *

33 | * 34 | * @author danson.liu 35 | * 36 | */ 37 | @Target( { ElementType.PARAMETER, ElementType.FIELD }) 38 | @Retention(RetentionPolicy.RUNTIME) 39 | public @interface CacheParam { 40 | /** 41 | * Parameter index 42 | */ 43 | int order() default 0; 44 | } 45 | -------------------------------------------------------------------------------- /avatar-cache-remote/src/main/java/com/dianping/remote/cache/dto/LocalCacheRemoveDTO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: avatar-cache-remote 3 | * 4 | * File Created at 2010-10-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.remote.cache.dto; 17 | 18 | import com.dianping.remote.share.annotation.JmsMessageBody; 19 | 20 | /** 21 | * Local cache removing message. 22 | * 23 | * @author pengshan.zhang 24 | * 25 | */ 26 | @JmsMessageBody(innerDestination="LOCAL_CACHE_REMOVE") 27 | public class LocalCacheRemoveDTO extends CacheMessageDTO { 28 | 29 | /** 30 | * Serial Version UID 31 | */ 32 | private static final long serialVersionUID = 6746249464661690655L; 33 | 34 | /** 35 | * Key type 36 | */ 37 | private String msgValue; 38 | 39 | /** 40 | * @param msgValue the msgValue to set 41 | */ 42 | public void setMsgValue(String msgValue) { 43 | this.msgValue = msgValue; 44 | } 45 | 46 | /** 47 | * @return the msgValue 48 | */ 49 | public String getMsgValue() { 50 | return msgValue; 51 | } 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /avatar-cache-remote/src/main/java/com/dianping/remote/cache/dto/CacheClearDTO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dianping.remote.cache.dto; 5 | 6 | import java.util.List; 7 | 8 | import com.dianping.remote.share.dto.AbstractDTO; 9 | 10 | /** 11 | * @author jian.liu 12 | * 13 | */ 14 | public class CacheClearDTO extends AbstractDTO { 15 | 16 | /** 17 | * 18 | */ 19 | private static final long serialVersionUID = 8063849999710998236L; 20 | 21 | private String cacheType; 22 | 23 | private String key; 24 | 25 | private String category; 26 | 27 | private List params; 28 | 29 | public CacheClearDTO(String cacheType, String key, String category, List params) { 30 | this.cacheType = cacheType; 31 | this.key = key; 32 | this.category = category; 33 | this.params = params; 34 | } 35 | 36 | public CacheClearDTO() { 37 | } 38 | 39 | public String getCacheType() { 40 | return cacheType; 41 | } 42 | 43 | public void setCacheType(String cacheType) { 44 | this.cacheType = cacheType; 45 | } 46 | 47 | public String getKey() { 48 | return key; 49 | } 50 | 51 | public void setKey(String key) { 52 | this.key = key; 53 | } 54 | 55 | public String getCategory() { 56 | return category; 57 | } 58 | 59 | public void setCategory(String category) { 60 | this.category = category; 61 | } 62 | 63 | public List getParams() { 64 | return params; 65 | } 66 | 67 | public void setParams(List params) { 68 | this.params = params; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/remote/jms/convert/JDKObject2BytesConverter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: com.dianping.cache-server-2.0.1 3 | * 4 | * File Created at 2011-9-23 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.remote.jms.convert; 17 | 18 | import java.io.ByteArrayOutputStream; 19 | import java.io.IOException; 20 | import java.io.ObjectOutputStream; 21 | 22 | /** 23 | * JDKObject2BytesConverter 24 | * @author youngphy.yang 25 | * 26 | */ 27 | public class JDKObject2BytesConverter implements Object2BytesConverter{ 28 | 29 | /** 30 | * parameter object should be serializable 31 | * @throws IOException 32 | */ 33 | @Override 34 | public byte[] convertObject2Bytes(Object object) throws IOException { 35 | byte[] result = null; 36 | if(object != null) { 37 | ByteArrayOutputStream bo = new ByteArrayOutputStream(); 38 | ObjectOutputStream oo = null; 39 | try { 40 | oo = new ObjectOutputStream(bo); 41 | oo.writeObject(object); 42 | result = bo.toByteArray(); 43 | } finally { 44 | if (oo != null) { 45 | oo.close(); 46 | } 47 | } 48 | } 49 | return result; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /avatar-cache-remote/src/main/java/com/dianping/remote/cache/dto/CacheConfigurationDTO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: avatar-cache-remote 3 | * 4 | * File Created at 2010-10-18 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.remote.cache.dto; 17 | 18 | import com.dianping.remote.share.annotation.JmsMessageBody; 19 | import com.dianping.remote.share.dto.AbstractDTO; 20 | 21 | 22 | /** 23 | * Cache Client Configuration 24 | * @author danson.liu 25 | * 26 | */ 27 | @JmsMessageBody(innerDestination="CACHE_CONFIG_UPDATE") 28 | public class CacheConfigurationDTO extends AbstractDTO { 29 | 30 | /** 31 | * 32 | */ 33 | private static final long serialVersionUID = -4167929878555896829L; 34 | 35 | /** 36 | * key for specified cache 37 | */ 38 | private String key; 39 | 40 | private CacheConfigDetailDTO detail; 41 | 42 | public String getKey() { 43 | return key; 44 | } 45 | 46 | public void setKey(String key) { 47 | this.key = key; 48 | } 49 | 50 | public CacheConfigDetailDTO getDetail() { 51 | return detail; 52 | } 53 | 54 | public void setDetail(CacheConfigDetailDTO detail) { 55 | this.detail = detail; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/dao/OperationLogDao.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-server 3 | * 4 | * File Created at 2011-9-18 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.dao; 17 | 18 | import java.util.Date; 19 | 20 | import com.dianping.avatar.dao.GenericDao; 21 | import com.dianping.avatar.dao.annotation.DAOAction; 22 | import com.dianping.avatar.dao.annotation.DAOActionType; 23 | import com.dianping.avatar.dao.annotation.DAOParam; 24 | import com.dianping.avatar.dao.annotation.DAOParamType; 25 | import com.dianping.cache.entity.OperationLog; 26 | import com.dianping.cache.service.condition.OperationLogSearchCondition; 27 | import com.dianping.core.type.PageModel; 28 | 29 | /** 30 | * @author danson.liu 31 | * 32 | */ 33 | public interface OperationLogDao extends GenericDao { 34 | 35 | @DAOAction(action = DAOActionType.INSERT) 36 | void create(@DAOParam(type=DAOParamType.ENTITY)OperationLog log); 37 | 38 | @DAOAction(action = DAOActionType.PAGE) 39 | PageModel paginate(@DAOParam("paginater")PageModel paginater, @DAOParam(type=DAOParamType.ENTITY)OperationLogSearchCondition searchCondition); 40 | 41 | @DAOAction(action = DAOActionType.DELETE) 42 | void delete(@DAOParam("before")Date before); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/service/condition/CacheKeyConfigSearchCondition.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: com.dianping.cache-server-2.0.0-SNAPSHOT 3 | * 4 | * File Created at 2011-2-27 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.service.condition; 17 | 18 | import java.io.Serializable; 19 | 20 | /** 21 | * TODO Comment of CacheKeyConfigSearchCondition 22 | * @author danson.liu 23 | * 24 | */ 25 | @SuppressWarnings("serial") 26 | public class CacheKeyConfigSearchCondition implements Serializable { 27 | 28 | private String category; 29 | 30 | private String cacheType; 31 | 32 | /** 33 | * @return the category 34 | */ 35 | public String getCategory() { 36 | return category; 37 | } 38 | 39 | /** 40 | * @param category the category to set 41 | */ 42 | public void setCategory(String category) { 43 | this.category = category != null ? category.trim() : null; 44 | } 45 | 46 | /** 47 | * @return the cacheType 48 | */ 49 | public String getCacheType() { 50 | return cacheType; 51 | } 52 | 53 | /** 54 | * @param cacheType the cacheType to set 55 | */ 56 | public void setCacheType(String cacheType) { 57 | this.cacheType = cacheType; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/entity/Role.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-server 3 | * 4 | * File Created at 2011-9-22 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.entity; 17 | 18 | import java.io.Serializable; 19 | import java.util.List; 20 | 21 | /** 22 | * @author danson.liu 23 | * 24 | */ 25 | public class Role implements Serializable { 26 | 27 | /** 28 | * 29 | */ 30 | private static final long serialVersionUID = 6522365609350296110L; 31 | 32 | private int id; 33 | private String name; 34 | private String resourceStr; 35 | private List resourceList; 36 | 37 | public int getId() { 38 | return id; 39 | } 40 | 41 | public void setId(int id) { 42 | this.id = id; 43 | } 44 | 45 | public String getName() { 46 | return name; 47 | } 48 | 49 | public void setName(String name) { 50 | this.name = name; 51 | } 52 | 53 | public String getResourceStr() { 54 | return resourceStr; 55 | } 56 | 57 | public void setResourceStr(String resourceStr) { 58 | this.resourceStr = resourceStr; 59 | } 60 | 61 | public List getResourceList() { 62 | return resourceList; 63 | } 64 | 65 | public void setResourceList(List resourceList) { 66 | this.resourceList = resourceList; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/dao/ServerGroupDao.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: 3-com.dianping.cache-server-2.0.3 3 | * 4 | * File Created at 2011-12-21 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.dao; 17 | 18 | import java.util.List; 19 | 20 | import com.dianping.avatar.dao.GenericDao; 21 | import com.dianping.avatar.dao.annotation.DAOAction; 22 | import com.dianping.avatar.dao.annotation.DAOActionType; 23 | import com.dianping.avatar.dao.annotation.DAOParam; 24 | import com.dianping.avatar.dao.annotation.DAOParamType; 25 | import com.dianping.cache.entity.ServerGroup; 26 | 27 | /** 28 | * TODO Comment of ServerGroupDao 29 | * @author danson.liu 30 | * 31 | */ 32 | public interface ServerGroupDao extends GenericDao { 33 | 34 | @DAOAction 35 | List findAll(); 36 | 37 | @DAOAction(action = DAOActionType.LOAD) 38 | ServerGroup find(@DAOParam("group") String group); 39 | 40 | @DAOAction(action = DAOActionType.INSERT) 41 | void create(@DAOParam(type = DAOParamType.ENTITY) ServerGroup serverGroup); 42 | 43 | @DAOAction(action = DAOActionType.UPDATE) 44 | void update(@DAOParam(type = DAOParamType.ENTITY) ServerGroup serverGroup); 45 | 46 | @DAOAction(action = DAOActionType.DELETE) 47 | void delete(@DAOParam("group") String group); 48 | 49 | } 50 | -------------------------------------------------------------------------------- /cache-server/src/main/resources/config/spring/appcontext-security.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/entity/ServerGroup.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: 3-com.dianping.cache-server-2.0.3 3 | * 4 | * File Created at 2011-12-21 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.entity; 17 | 18 | import java.io.Serializable; 19 | import java.util.Date; 20 | 21 | /** 22 | * @author danson.liu 23 | * 24 | */ 25 | public class ServerGroup implements Serializable { 26 | 27 | /** 28 | * 29 | */ 30 | private static final long serialVersionUID = 3041787596323303250L; 31 | 32 | private String group; 33 | 34 | private String servers; 35 | 36 | private Date createdTime; 37 | 38 | private Date updatedTime; 39 | 40 | public String getGroup() { 41 | return group; 42 | } 43 | 44 | public void setGroup(String group) { 45 | this.group = group; 46 | } 47 | 48 | public String getServers() { 49 | return servers; 50 | } 51 | 52 | public void setServers(String servers) { 53 | this.servers = servers; 54 | } 55 | 56 | public Date getCreatedTime() { 57 | return createdTime; 58 | } 59 | 60 | public void setCreatedTime(Date createdTime) { 61 | this.createdTime = createdTime; 62 | } 63 | 64 | public Date getUpdatedTime() { 65 | return updatedTime; 66 | } 67 | 68 | public void setUpdatedTime(Date updatedTime) { 69 | this.updatedTime = updatedTime; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /cache-core/src/main/java/com/dianping/cache/memcached/ExtendedKetamaConnectionFactory.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.memcached; 17 | 18 | import net.spy.memcached.KetamaConnectionFactory; 19 | import net.spy.memcached.transcoders.Transcoder; 20 | 21 | /** 22 | * TODO Comment of CustomizedConnectionFactory 23 | * @author jian.liu 24 | * 25 | */ 26 | public class ExtendedKetamaConnectionFactory extends KetamaConnectionFactory implements ExtendedConnectionFactory { 27 | 28 | private Transcoder transcoder; 29 | private long opQueueMaxBlockTime; 30 | 31 | public ExtendedKetamaConnectionFactory(int qLen, int bufSize, long opQueueMaxBlockTime) { 32 | super(qLen, bufSize, opQueueMaxBlockTime); 33 | this.opQueueMaxBlockTime = opQueueMaxBlockTime; 34 | } 35 | 36 | @Override 37 | public long getOpQueueMaxBlockTime() { 38 | return opQueueMaxBlockTime; 39 | } 40 | 41 | public ExtendedKetamaConnectionFactory() { 42 | this(DEFAULT_OP_QUEUE_LEN, DEFAULT_READ_BUFFER_SIZE, DEFAULT_OP_QUEUE_MAX_BLOCK_TIME); 43 | } 44 | 45 | @Override 46 | public Transcoder getDefaultTranscoder() { 47 | return transcoder; 48 | } 49 | 50 | public void setTranscoder(Transcoder transcoder) { 51 | this.transcoder = transcoder; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /cache-server/src/test/resources/config/spring/applicationContext-cache-jms-sender-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 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 | -------------------------------------------------------------------------------- /avatar-cache/src/main/java/com/dianping/avatar/cache/support/DefaultCacheTracker.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: avatar 3 | * 4 | * File Created at 2010-11-1 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.support; 17 | 18 | import com.dianping.avatar.log.AvatarLogger; 19 | import com.dianping.avatar.log.AvatarLoggerFactory; 20 | import com.dianping.avatar.tracker.CacheExecutionTrace; 21 | import com.dianping.avatar.tracker.ExecutionContextHolder; 22 | import com.dianping.avatar.tracker.TrackerContext; 23 | 24 | 25 | /** 26 | * Default Cache Profiler implementation 27 | * @author danson.liu 28 | * 29 | */ 30 | public class DefaultCacheTracker implements CacheTracker { 31 | 32 | private static AvatarLogger logger = AvatarLoggerFactory.getLogger(DefaultCacheTracker.class); 33 | 34 | public void addGetInfo(String cacheDesc, long timeConsumed) { 35 | try { 36 | if (ExecutionContextHolder.isTrackRequired()) { 37 | TrackerContext trackerContext = ExecutionContextHolder.getTrackerContext(); 38 | CacheExecutionTrace cacheExecutionTrace = trackerContext.getCacheExecutionTrace(); 39 | cacheExecutionTrace.addTimeConsumed(timeConsumed); 40 | cacheExecutionTrace.addRelatedKey(cacheDesc); 41 | } 42 | } catch (Exception e) { 43 | logger.warn("Failed to track cache execution.", e); 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /avatar-cache/src/test/java/com/dianping/avatar/cache/TestCat.java: -------------------------------------------------------------------------------- 1 | package com.dianping.avatar.cache; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.support.ClassPathXmlApplicationContext; 5 | 6 | import com.dianping.avatar.cache.CacheKey; 7 | import com.dianping.avatar.cache.CacheService; 8 | import com.dianping.avatar.cache.annotation.Cache; 9 | 10 | public class TestCat { 11 | 12 | static final String CATEGORY = "Adwords_Deal_API_Source"; 13 | 14 | public static void main(String[] args) throws InterruptedException { 15 | ApplicationContext content = new ClassPathXmlApplicationContext("AOPDemo2.xml"); 16 | CacheService service = (CacheService) content.getBean("cacheService"); 17 | 18 | String strKey = "Testkey1"; 19 | service.add(strKey, "value"); 20 | Thread.sleep(1000); 21 | System.out.println(service.get(strKey)); 22 | service.remove("memcached", strKey); 23 | System.out.println(service.get(strKey)); 24 | 25 | CacheKey key = new CacheKey(CATEGORY, "yong.you"); 26 | service.add(key, "cacheValue"); 27 | System.out.println(service.get(key)); 28 | service.remove(key); 29 | System.out.println(service.get(key)); 30 | 31 | // service.add(new User("test", "test")); 32 | 33 | } 34 | 35 | @Cache(category = CATEGORY, fields = { "name" }) 36 | public static class User { 37 | private String name; 38 | 39 | private String age; 40 | 41 | public User(String name, String age) { 42 | this.name = name; 43 | this.age = age; 44 | } 45 | 46 | public String getName() { 47 | return name; 48 | } 49 | 50 | public void setName(String name) { 51 | this.name = name; 52 | } 53 | 54 | public String getAge() { 55 | return age; 56 | } 57 | 58 | public void setAge(String age) { 59 | this.age = age; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /cache-server/src/main/resources/config/sqlmap/ServerGroup.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 21 | 28 | 29 | 30 | 34 | 35 | 36 | 37 | 42 | 43 | 44 | 45 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /avatar-cache-remote/src/main/java/com/dianping/remote/cache/dto/SingleCacheRemoveDTO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: avatar-cache-remote 3 | * 4 | * File Created at 2010-10-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.remote.cache.dto; 17 | 18 | import com.dianping.remote.share.annotation.JmsMessageBody; 19 | 20 | /** 21 | * Local cache removing message. 22 | * 23 | * @author pengshan.zhang 24 | * 25 | */ 26 | @JmsMessageBody(innerDestination="SINGLE_CACHE_REMOVE") 27 | public class SingleCacheRemoveDTO extends CacheMessageDTO { 28 | 29 | /** 30 | * Serial Version UID 31 | */ 32 | private static final long serialVersionUID = 6746249464661690655L; 33 | 34 | private String cacheType; 35 | 36 | /** 37 | * Key type 38 | */ 39 | private String cacheKey; 40 | 41 | /** 42 | * @param msgValue the msgValue to set 43 | */ 44 | public void setCacheKey(String msgValue) { 45 | this.cacheKey = msgValue; 46 | } 47 | 48 | /** 49 | * @return the msgValue 50 | */ 51 | public String getCacheKey() { 52 | return cacheKey; 53 | } 54 | 55 | /** 56 | * @return the cacheType 57 | */ 58 | public String getCacheType() { 59 | return cacheType; 60 | } 61 | 62 | /** 63 | * @param cacheType the cacheType to set 64 | */ 65 | public void setCacheType(String cacheType) { 66 | this.cacheType = cacheType; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /cache-core/src/main/resources/ehcache-distribution.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 9 | 11 | 12 | 15 | 16 | 27 | 28 | -------------------------------------------------------------------------------- /avatar-cache-remote/src/main/java/com/dianping/remote/cache/dto/CacheMessageDTO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: avatar 3 | * 4 | * File Created at 2010-10-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.remote.cache.dto; 17 | 18 | import java.util.List; 19 | 20 | import com.dianping.remote.share.dto.AbstractDTO; 21 | 22 | /** 23 | * Cache message recived from jms or remote service 24 | * 25 | * @author pengshan.zhang 26 | * 27 | */ 28 | public abstract class CacheMessageDTO extends AbstractDTO { 29 | 30 | /** 31 | * Serial Version UID 32 | */ 33 | private static final long serialVersionUID = -8627060114802935333L; 34 | 35 | /** 36 | * Time when message is born. 37 | */ 38 | private long addTime = System.currentTimeMillis(); 39 | 40 | /** 41 | * which destinations resolve the message 42 | */ 43 | protected List destinations; 44 | 45 | /** 46 | * @param addTime 47 | * the addTime to set 48 | */ 49 | public void setAddTime(long addTime) { 50 | this.addTime = addTime; 51 | } 52 | 53 | /** 54 | * @return the addTime 55 | */ 56 | public long getAddTime() { 57 | return addTime; 58 | } 59 | 60 | public List getDestinations() { 61 | return destinations; 62 | } 63 | 64 | public void setDestinations(List destinations) { 65 | this.destinations = destinations; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /avatar-cache-remote/src/main/java/com/dianping/remote/cache/dto/CacheConfigurationsDTO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: avatar-cache-remote 3 | * 4 | * File Created at 2010-10-18 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.remote.cache.dto; 17 | 18 | import java.util.HashMap; 19 | import java.util.List; 20 | import java.util.Map; 21 | import java.util.Set; 22 | 23 | import com.dianping.remote.share.dto.AbstractDTO; 24 | 25 | /** 26 | * Cache Client Configurations 27 | * @author danson.liu 28 | * 29 | */ 30 | public class CacheConfigurationsDTO extends AbstractDTO { 31 | 32 | /** 33 | * 34 | */ 35 | private static final long serialVersionUID = 2977016286139912352L; 36 | 37 | private Map configurations = new HashMap(); 38 | 39 | public CacheConfigurationsDTO() {} 40 | 41 | public CacheConfigurationsDTO(List configurations) { 42 | for (CacheConfigurationDTO configuration : configurations) { 43 | this.configurations.put(configuration.getKey(), configuration); 44 | } 45 | } 46 | 47 | public void addConfiguration(CacheConfigurationDTO configuration) { 48 | this.configurations.put(configuration.getKey(), configuration); 49 | } 50 | 51 | public Set keys() { 52 | return configurations.keySet(); 53 | } 54 | 55 | public CacheConfigurationDTO getConfiguration(String cacheKey) { 56 | return this.configurations.get(cacheKey); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/service/CacheKeyConfigurationService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-server 3 | * 4 | * File Created at 2010-10-15 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.service; 17 | 18 | import java.util.List; 19 | 20 | import org.springframework.transaction.annotation.Transactional; 21 | 22 | import com.dianping.avatar.exception.DuplicatedIdentityException; 23 | import com.dianping.cache.entity.CacheKeyConfiguration; 24 | import com.dianping.cache.service.condition.CacheKeyConfigSearchCondition; 25 | import com.dianping.core.type.PageModel; 26 | 27 | /** 28 | * CacheKeyConfigurationService 29 | * @author danson.liu 30 | * 31 | */ 32 | @Transactional 33 | public interface CacheKeyConfigurationService { 34 | 35 | /** 36 | * retrieve all configurations 37 | * @return 38 | */ 39 | List findAll(); 40 | 41 | PageModel paginate(PageModel paginater, CacheKeyConfigSearchCondition searchCondition); 42 | 43 | CacheKeyConfiguration find(String category); 44 | 45 | /** 46 | * inc version and get version 47 | */ 48 | String incAndRetriveVersion(String keyType); 49 | 50 | /** 51 | * @param config 52 | */ 53 | CacheKeyConfiguration create(CacheKeyConfiguration config) throws DuplicatedIdentityException; 54 | 55 | /** 56 | * @param config 57 | */ 58 | CacheKeyConfiguration update(CacheKeyConfiguration config); 59 | 60 | void delete(String category); 61 | 62 | } 63 | -------------------------------------------------------------------------------- /cache-server/src/test/java/com/dianping/cache/jms/NotifyMessageProducer.java: -------------------------------------------------------------------------------- 1 | package com.dianping.cache.jms; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import javax.jms.Destination; 7 | 8 | import org.springframework.jms.core.JmsTemplate; 9 | 10 | public class NotifyMessageProducer { 11 | 12 | private JmsTemplate jmsTemplate; 13 | private Destination notifyQueue; 14 | private Destination notifyTopic; 15 | 16 | private void sendMessage(String username, String email, Destination destination) { 17 | Map map = new HashMap(); 18 | map.put("userName", username); 19 | map.put("email", email); 20 | 21 | jmsTemplate.convertAndSend(destination, map); 22 | } 23 | 24 | public void sendQueue(String username, String email) { 25 | sendMessage(username, email,notifyQueue); 26 | } 27 | 28 | 29 | public void sendTopic(String username, String email) { 30 | sendMessage(username, email, notifyTopic); 31 | } 32 | 33 | public void setJmsTemplate(JmsTemplate jmsTemplate) { 34 | this.jmsTemplate = jmsTemplate; 35 | } 36 | 37 | public void setNotifyQueue(Destination notifyQueue) { 38 | this.notifyQueue = notifyQueue; 39 | } 40 | 41 | public void setNotifyTopic(Destination nodifyTopic) { 42 | this.notifyTopic = nodifyTopic; 43 | } 44 | 45 | /** 46 | * @return the jmsTemplate 47 | */ 48 | public JmsTemplate getJmsTemplate() { 49 | return jmsTemplate; 50 | } 51 | 52 | /** 53 | * @return the notifyQueue 54 | */ 55 | public Destination getNotifyQueue() { 56 | return notifyQueue; 57 | } 58 | 59 | /** 60 | * @return the notifyTopic 61 | */ 62 | public Destination getNotifyTopic() { 63 | return notifyTopic; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /avatar-cache-remote/src/main/java/com/dianping/remote/cache/dto/MemcachedConfigDetailDTO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: avatar-cache-remote 3 | * 4 | * File Created at 2010-10-18 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.remote.cache.dto; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | /** 22 | * Memcached Config Detail DTO 23 | * @author danson.liu 24 | * 25 | */ 26 | public class MemcachedConfigDetailDTO extends CacheConfigDetailDTO { 27 | 28 | /** 29 | * 30 | */ 31 | private static final long serialVersionUID = 5119818771060964933L; 32 | 33 | /** 34 | * 35 | */ 36 | private static final String DEFAULT_TRANSCODER_CLASS = "com.dianping.cache.memcached.HessianTranscoder"; 37 | 38 | /** 39 | * e.g. 10.10.1.1:8081 40 | */ 41 | private List serverList = new ArrayList(); 42 | 43 | private String transcoderClazz = DEFAULT_TRANSCODER_CLASS; 44 | 45 | /** 46 | * 47 | */ 48 | public MemcachedConfigDetailDTO() { 49 | this.clientClazz = "com.dianping.cache.memcached.MemcachedClientImpl"; 50 | } 51 | 52 | public List getServerList() { 53 | return serverList; 54 | } 55 | 56 | public void setServerList(List serverList) { 57 | this.serverList = serverList; 58 | } 59 | 60 | public String getTranscoderClazz() { 61 | return transcoderClazz; 62 | } 63 | 64 | public void setTranscoderClazz(String transcoderClazz) { 65 | this.transcoderClazz = transcoderClazz; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /avatar-cache/src/main/java/com/dianping/avatar/cache/CacheKey.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: avatar 3 | * 4 | * File Created at 2010-7-14 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; 17 | 18 | import java.io.Serializable; 19 | import java.util.Arrays; 20 | import java.util.Collections; 21 | import java.util.List; 22 | 23 | import org.apache.commons.lang.ArrayUtils; 24 | 25 | /** 26 | * Cache key object 27 | * 28 | * @author danson.liu 29 | * 30 | */ 31 | public class CacheKey implements Serializable { 32 | 33 | /** 34 | * Serial Version UID 35 | */ 36 | private static final long serialVersionUID = -1099870460150967658L; 37 | 38 | /** 39 | * Item category 40 | */ 41 | private String category; 42 | 43 | /** 44 | * Parameters 45 | */ 46 | private Object[] params; 47 | 48 | /** 49 | * Constructor 50 | */ 51 | public CacheKey(String category, Object... params) { 52 | this.category = category; 53 | this.params = params; 54 | } 55 | 56 | public String getCategory() { 57 | return category; 58 | } 59 | 60 | /** 61 | * @return the params 62 | */ 63 | public Object[] getParams() { 64 | return params; 65 | } 66 | 67 | public List getParamsAsList() { 68 | if (params == null) { 69 | return Collections.emptyList(); 70 | } 71 | return Arrays.asList(params); 72 | } 73 | 74 | @Override 75 | public String toString() { 76 | return "CacheKey[category:" + category + ", indexParams:" + ArrayUtils.toString(params) + "]"; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /cache-server/src/main/resources/config/spring/appcontext-server.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /avatar-cache/src/main/java/com/dianping/avatar/cache/configuration/EnhancedCacheItemConfigManager.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: avatar-cache 3 | * 4 | * File Created at 2011-9-13 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.avatar.cache.configuration; 17 | 18 | import java.util.concurrent.ConcurrentHashMap; 19 | import java.util.concurrent.ConcurrentMap; 20 | 21 | import com.dianping.avatar.cache.util.CacheMonitorUtil; 22 | 23 | /** 24 | * Enhanced CacheItemConfigManager, 用于对未配置正确的cache category进行容错和告警 25 | * @author danson.liu 26 | * 27 | */ 28 | public class EnhancedCacheItemConfigManager implements CacheItemConfigManager { 29 | 30 | private CacheItemConfigManager itemConfigManager; 31 | 32 | private static ConcurrentMap DEFAULT_CACHE_KEY_TYPES = new ConcurrentHashMap(); 33 | 34 | public EnhancedCacheItemConfigManager(CacheItemConfigManager itemConfigManager) { 35 | this.itemConfigManager = itemConfigManager; 36 | } 37 | 38 | @Override 39 | public CacheKeyType getCacheKeyType(String category) { 40 | CacheKeyType cacheKeyType = itemConfigManager.getCacheKeyType(category); 41 | if (cacheKeyType != null) { 42 | return cacheKeyType; 43 | } 44 | CacheMonitorUtil.logConfigNotFound(category); 45 | CacheKeyType defaultCacheKeyType = DEFAULT_CACHE_KEY_TYPES.get(category); 46 | if (defaultCacheKeyType != null) { 47 | return defaultCacheKeyType; 48 | } 49 | defaultCacheKeyType = new DefaultCacheKeyType(category); 50 | DEFAULT_CACHE_KEY_TYPES.put(category, defaultCacheKeyType); 51 | return defaultCacheKeyType; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /avatar-cache/src/main/java/com/dianping/avatar/cache/listener/CacheConfigurationUpdateListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: com.dianping.avatar-cache-2.0.0-SNAPSHOT 3 | * 4 | * File Created at 2011-2-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.avatar.cache.listener; 17 | 18 | import com.dianping.avatar.cache.client.RemoteCacheClientFactory; 19 | import com.dianping.avatar.log.AvatarLogger; 20 | import com.dianping.avatar.log.AvatarLoggerFactory; 21 | import com.dianping.remote.cache.dto.CacheConfigurationDTO; 22 | 23 | /** 24 | * Cache Configuration Update Listener 25 | * @author danson.liu 26 | * 27 | */ 28 | public class CacheConfigurationUpdateListener { 29 | 30 | private final AvatarLogger logger = AvatarLoggerFactory.getLogger(CacheConfigurationUpdateListener.class); 31 | 32 | private RemoteCacheClientFactory cacheClientFactory; 33 | 34 | public void handleMessage(CacheConfigurationDTO configurationDTO) { 35 | if (configurationDTO != null) { 36 | try { 37 | if (cacheClientFactory != null) { 38 | cacheClientFactory.updateCache(configurationDTO); 39 | logger.info("Cache[" + configurationDTO.getKey() + "]'s config update succeed."); 40 | } 41 | } catch (Exception e) { 42 | logger.error("Cache[" + configurationDTO.getKey() + "]'s config update failed.", e); 43 | } 44 | } 45 | } 46 | 47 | /** 48 | * @param cacheClientFactory the cacheClientFactory to set 49 | */ 50 | public void setCacheClientFactory(RemoteCacheClientFactory cacheClientFactory) { 51 | this.cacheClientFactory = cacheClientFactory; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /cache-server/src/main/resources/config/sqlmap/CacheConfiguration.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 21 | 28 | 29 | 30 | 34 | 35 | 36 | 37 | 42 | 43 | 44 | 45 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/modules/spring/flex/CustomizedMessageInterceptor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-server 3 | * 4 | * File Created at 2011-9-21 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.modules.spring.flex; 17 | 18 | import java.util.Map; 19 | 20 | import org.springframework.flex.core.MessageInterceptor; 21 | import org.springframework.flex.core.MessageProcessingContext; 22 | import org.springframework.security.Authentication; 23 | import org.springframework.security.context.SecurityContextHolder; 24 | 25 | import flex.messaging.messages.CommandMessage; 26 | import flex.messaging.messages.Message; 27 | 28 | /** 29 | * TODO Comment of CustomizedMessageInterceptor 30 | * @author danson.liu 31 | * 32 | */ 33 | public class CustomizedMessageInterceptor implements MessageInterceptor { 34 | 35 | @SuppressWarnings({ "unchecked", "rawtypes" }) 36 | @Override 37 | public Message postProcess(MessageProcessingContext context, Message inputMessage, Message outputMessage) { 38 | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); 39 | if (inputMessage instanceof CommandMessage && ((CommandMessage) inputMessage).getOperation() == CommandMessage.LOGIN_OPERATION) { 40 | Object body = outputMessage.getBody(); 41 | if (body instanceof Map) { 42 | ((Map) body).put("details", authentication.getDetails()); 43 | } 44 | } 45 | return outputMessage; 46 | } 47 | 48 | @Override 49 | public Message preProcess(MessageProcessingContext context, Message inputMessage) { 50 | return inputMessage; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/entity/OperationLog.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-server 3 | * 4 | * File Created at 2011-9-18 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.entity; 17 | 18 | import java.io.Serializable; 19 | import java.util.Date; 20 | 21 | /** 22 | * @author danson.liu 23 | * 24 | */ 25 | public class OperationLog implements Serializable { 26 | 27 | private static final long serialVersionUID = -4650264528786877392L; 28 | 29 | private long id; 30 | 31 | private String operator; 32 | 33 | private Date operateTime; 34 | 35 | private String content; 36 | 37 | private boolean succeed; 38 | 39 | private boolean critical; 40 | 41 | public long getId() { 42 | return id; 43 | } 44 | 45 | public void setId(long id) { 46 | this.id = id; 47 | } 48 | 49 | public String getOperator() { 50 | return operator; 51 | } 52 | 53 | public void setOperator(String operator) { 54 | this.operator = operator; 55 | } 56 | 57 | public Date getOperateTime() { 58 | return operateTime; 59 | } 60 | 61 | public void setOperateTime(Date operateTime) { 62 | this.operateTime = operateTime; 63 | } 64 | 65 | public String getContent() { 66 | return content; 67 | } 68 | 69 | public void setContent(String content) { 70 | this.content = content; 71 | } 72 | 73 | public boolean isCritical() { 74 | return critical; 75 | } 76 | 77 | public void setCritical(boolean critical) { 78 | this.critical = critical; 79 | } 80 | 81 | public boolean isSucceed() { 82 | return succeed; 83 | } 84 | 85 | public void setSucceed(boolean succeed) { 86 | this.succeed = succeed; 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/dao/CacheConfigurationDao.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-server 3 | * 4 | * File Created at 2010-10-15 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.dao; 17 | 18 | import java.util.List; 19 | 20 | import com.dianping.avatar.dao.GenericDao; 21 | import com.dianping.avatar.dao.annotation.DAOAction; 22 | import com.dianping.avatar.dao.annotation.DAOActionType; 23 | import com.dianping.avatar.dao.annotation.DAOParam; 24 | import com.dianping.avatar.dao.annotation.DAOParamType; 25 | import com.dianping.cache.entity.CacheConfiguration; 26 | 27 | /** 28 | * CacheKeyConfiguration data access object 29 | * @author danson.liu 30 | * 31 | */ 32 | public interface CacheConfigurationDao extends GenericDao { 33 | 34 | /** 35 | * retrieve all configurations 36 | * @return 37 | */ 38 | @DAOAction 39 | List findAll(); 40 | 41 | /** 42 | * @param key 43 | * @return 44 | */ 45 | @DAOAction(action = DAOActionType.LOAD) 46 | CacheConfiguration find(@DAOParam("key") String key); 47 | 48 | /** 49 | * @param config 50 | * @return 51 | */ 52 | @DAOAction(action = DAOActionType.INSERT) 53 | void create(@DAOParam(type = DAOParamType.ENTITY) CacheConfiguration config); 54 | 55 | /** 56 | * @param config 57 | */ 58 | @DAOAction(action = DAOActionType.UPDATE) 59 | void update(@DAOParam(type = DAOParamType.ENTITY) CacheConfiguration config); 60 | 61 | /** 62 | * @param key 63 | */ 64 | @DAOAction(action = DAOActionType.DELETE) 65 | void delete(@DAOParam("key") String key); 66 | 67 | } 68 | -------------------------------------------------------------------------------- /avatar-cache-remote/src/main/java/com/dianping/remote/cache/dto/CacheKeyTypeVersionUpdateDTO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: avatar 3 | * 4 | * File Created at 2010-10-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.remote.cache.dto; 17 | 18 | import com.dianping.remote.share.annotation.JmsMessageBody; 19 | 20 | /** 21 | * Cache message recived from jms to update key type version. 22 | * 23 | * @author pengshan.zhang 24 | * 25 | */ 26 | @JmsMessageBody(innerDestination="KEYTYPE_VERSION_UPDATE") 27 | public class CacheKeyTypeVersionUpdateDTO extends CacheMessageDTO { 28 | 29 | /** 30 | * Serial Version UID 31 | */ 32 | private static final long serialVersionUID = 903598456694367471L; 33 | 34 | /** 35 | * Key type 36 | */ 37 | private String msgValue; 38 | 39 | /** 40 | * Version is used to update 41 | */ 42 | private String version; 43 | 44 | /** 45 | * @param version 46 | * the version to set 47 | */ 48 | public void setVersion(String version) { 49 | this.version = version; 50 | } 51 | 52 | /** 53 | * @return the version 54 | */ 55 | public String getVersion() { 56 | return version; 57 | } 58 | 59 | /** 60 | * @param msgValue 61 | * the msgValue to set 62 | */ 63 | public void setMsgValue(String msgValue) { 64 | this.msgValue = msgValue; 65 | } 66 | 67 | /** 68 | * @return the msgValue 69 | */ 70 | public String getMsgValue() { 71 | return msgValue; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /avatar-cache/src/main/java/com/dianping/avatar/cache/listener/CacheKeyConfigUpdateListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: com.dianping.avatar-cache-2.0.0-SNAPSHOT 3 | * 4 | * File Created at 2011-2-20 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.avatar.cache.listener; 17 | 18 | import com.dianping.avatar.cache.configuration.RemoteCacheItemConfigManager; 19 | import com.dianping.avatar.log.AvatarLogger; 20 | import com.dianping.avatar.log.AvatarLoggerFactory; 21 | import com.dianping.remote.cache.dto.CacheKeyConfigurationDTO; 22 | 23 | /** 24 | * Cache Key Configuration Update Listener 25 | * @author danson.liu 26 | * 27 | */ 28 | public class CacheKeyConfigUpdateListener { 29 | 30 | private final AvatarLogger logger = AvatarLoggerFactory.getLogger(CacheKeyConfigUpdateListener.class); 31 | 32 | private RemoteCacheItemConfigManager cacheItemConfigManager; 33 | 34 | public void handleMessage(CacheKeyConfigurationDTO configurationDTO) { 35 | if (configurationDTO != null) { 36 | try { 37 | if (cacheItemConfigManager != null) { 38 | cacheItemConfigManager.updateConfig(configurationDTO); 39 | logger.info("CacheItem[" + configurationDTO.getCacheType() + "]'s config update succeed."); 40 | } 41 | } catch (Exception e) { 42 | logger.error("CacheItem[" + configurationDTO.getCacheType() + "]'s config update failed.", e); 43 | } 44 | } 45 | } 46 | 47 | /** 48 | * @param cacheItemConfigManager the cacheItemConfigManager to set 49 | */ 50 | public void setCacheItemConfigManager(RemoteCacheItemConfigManager cacheItemConfigManager) { 51 | this.cacheItemConfigManager = cacheItemConfigManager; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /cache-core/src/main/java/com/dianping/cache/ehcache/EhcacheConfiguration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-core 3 | * 4 | * File Created at 2010-9-2 $Id$ 5 | * 6 | * Copyright 2010 dianping.com Corporation Limited. All rights reserved. 7 | * 8 | * This software is the confidential and proprietary information of Dianping 9 | * Company. ("Confidential Information"). You shall not disclose such 10 | * Confidential Information and shall use it only in accordance with the terms 11 | * of the license agreement you entered into with dianping.com. 12 | */ 13 | package com.dianping.cache.ehcache; 14 | 15 | import java.net.URL; 16 | 17 | import net.sf.ehcache.CacheManager; 18 | 19 | import com.dianping.cache.core.CacheClientConfiguration; 20 | 21 | /** 22 | * The configuration for ehcache client implementation 23 | * 24 | * @author pengshan.zhang 25 | * 26 | */ 27 | public class EhcacheConfiguration implements CacheClientConfiguration { 28 | 29 | /** 30 | * Default ehcache configuration file 31 | */ 32 | private static final String EHCACHE_FILE_URL = "/ehcache.xml"; 33 | 34 | private static final String CUSTOM_EHCACHE_FILE_URL = "/config/ehcache-cust.xml"; 35 | 36 | private String xmlFile = EHCACHE_FILE_URL; 37 | 38 | /** 39 | * @return the xmlFile 40 | */ 41 | public String getXmlFile() { 42 | return xmlFile; 43 | } 44 | 45 | /** 46 | * @param xmlFile 47 | * the xmlFile to set 48 | */ 49 | public void setXmlFile(String xmlFile) { 50 | this.xmlFile = xmlFile; 51 | } 52 | 53 | /** 54 | * Create ehcache CacheManager instance from configuration file 55 | */ 56 | public CacheManager buildEhcacheManager() { 57 | if (getClass().getResource(CUSTOM_EHCACHE_FILE_URL) != null) { 58 | xmlFile = CUSTOM_EHCACHE_FILE_URL; 59 | } 60 | URL url = getClass().getResource(xmlFile); 61 | return new CacheManager(url); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /cache-core/src/main/java/com/dianping/cache/memcached/KvdbTranscoder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-core 3 | * 4 | * File Created at 2010-7-26 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.io.InputStream; 19 | import java.io.UnsupportedEncodingException; 20 | 21 | import net.spy.memcached.CachedData; 22 | import net.spy.memcached.compat.SpyObject; 23 | import net.spy.memcached.transcoders.Transcoder; 24 | 25 | /** 26 | * Decode the {@link InputStream} to String 27 | * 28 | * @author guoqing.chen 29 | * @author danson.liu 30 | * 31 | */ 32 | public class KvdbTranscoder extends SpyObject implements Transcoder { 33 | 34 | /** 35 | * Decode bytes with UTF-8, if error using default charset 36 | */ 37 | @Override 38 | public Object decode(CachedData data) { 39 | try { 40 | return new String(data.getData(), "UTF-8"); 41 | } catch (UnsupportedEncodingException e) { 42 | return new String(data.getData()); 43 | } 44 | } 45 | 46 | @Override 47 | public CachedData encode(Object str) { 48 | if (str == null) { 49 | return null; 50 | } 51 | 52 | String strVal = (String) str; 53 | byte[] data; 54 | try { 55 | data = strVal.getBytes("UTF-8"); 56 | } catch (UnsupportedEncodingException e) { 57 | data = strVal.getBytes(); 58 | } 59 | 60 | return new CachedData(0, data, getMaxSize()); 61 | } 62 | 63 | @Override 64 | public boolean asyncDecode(CachedData d) { 65 | return false; 66 | } 67 | 68 | @Override 69 | public int getMaxSize() { 70 | //KVDB's value not exceed 1M generally 71 | return CachedData.MAX_SIZE; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /cache-server/src/test/java/com/dianping/cache/jms/JmsSenderTest.java: -------------------------------------------------------------------------------- 1 | package com.dianping.cache.jms; 2 | 3 | 4 | import java.io.BufferedReader; 5 | import java.io.InputStreamReader; 6 | 7 | import org.junit.Ignore; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.context.support.ClassPathXmlApplicationContext; 12 | import org.springframework.test.context.ContextConfiguration; 13 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 14 | 15 | @RunWith(SpringJUnit4ClassRunner.class) 16 | @ContextConfiguration(locations = "classpath:/config/spring/applicationContext-jms-sender-test.xml") 17 | @Ignore 18 | public class JmsSenderTest { 19 | 20 | @Autowired 21 | private NotifyMessageProducer notifyMessageProducer; 22 | 23 | @Test 24 | public void queueMessage() { 25 | notifyMessageProducer.sendQueue("zhangsan", "zhangsan@dianping.com"); 26 | } 27 | 28 | @Test 29 | public void topicMessage() { 30 | notifyMessageProducer.sendTopic("lisi", "lisi@dianping.com"); 31 | } 32 | 33 | public static void main(String[] args) { 34 | ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:/config/spring/applicationContext-jms-sender-test.xml"); 35 | NotifyMessageProducer producer = (NotifyMessageProducer) context.getBean("notifyMessageProducer"); 36 | BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); 37 | while (true) { 38 | try { 39 | System.out.print(">"); 40 | String line = reader.readLine().toLowerCase(); 41 | if (line.startsWith("quit") || line.startsWith("exit")) { 42 | break; 43 | } 44 | try { 45 | producer.sendTopic("lisi", line); 46 | } catch (Exception e) { 47 | System.err.println("Error happend: " + e.getMessage()); 48 | } 49 | System.out.println(); 50 | System.out.println("A message has been sent."); 51 | } catch (Exception e) { 52 | e.printStackTrace(); 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/entity/User.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-server 3 | * 4 | * File Created at 2011-9-22 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.entity; 17 | 18 | import java.io.Serializable; 19 | import java.util.List; 20 | 21 | /** 22 | * @author danson.liu 23 | * 24 | */ 25 | public class User implements Serializable { 26 | 27 | /** 28 | * 29 | */ 30 | private static final long serialVersionUID = -5959458780477391005L; 31 | 32 | private int id; 33 | private String name; 34 | private String password; 35 | private String email; 36 | private String phone; 37 | private String realName; 38 | private List roleList; 39 | 40 | public int getId() { 41 | return id; 42 | } 43 | 44 | public void setId(int id) { 45 | this.id = id; 46 | } 47 | 48 | public String getName() { 49 | return name; 50 | } 51 | 52 | public void setName(String name) { 53 | this.name = name; 54 | } 55 | 56 | public String getPassword() { 57 | return password; 58 | } 59 | 60 | public void setPassword(String password) { 61 | this.password = password; 62 | } 63 | 64 | public String getEmail() { 65 | return email; 66 | } 67 | 68 | public void setEmail(String email) { 69 | this.email = email; 70 | } 71 | 72 | public String getPhone() { 73 | return phone; 74 | } 75 | 76 | public void setPhone(String phone) { 77 | this.phone = phone; 78 | } 79 | 80 | public String getRealName() { 81 | return realName; 82 | } 83 | 84 | public void setRealName(String realName) { 85 | this.realName = realName; 86 | } 87 | 88 | public List getRoleList() { 89 | return roleList; 90 | } 91 | 92 | public void setRoleList(List roleList) { 93 | this.roleList = roleList; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /cache-core/src/test/java/com/dianping/cache/core/ketama/MockKetamaNodeLocator.java: -------------------------------------------------------------------------------- 1 | package com.dianping.cache.core.ketama; 2 | 3 | import java.util.Collection; 4 | import java.util.List; 5 | import java.util.SortedMap; 6 | import java.util.TreeMap; 7 | 8 | import net.spy.memcached.HashAlgorithm; 9 | 10 | public class MockKetamaNodeLocator { 11 | // 12 | // final Collection allNodes; 13 | // final SortedMap ketamaNodes; 14 | // final MockKetamaNodeLocatorConfiguration config; 15 | // 16 | // public MockKetamaNodeLocator(List nodes) { 17 | //// allNodes = nodes; 18 | //// ketamaNodes=new TreeMap(); 19 | //// config = new MockKetamaNodeLocatorConfiguration(); 20 | //// 21 | //// int numReps= config.getNodeRepetitions(); 22 | //// for(String node : nodes) { 23 | //// // Ketama does some special work with md5 where it reuses chunks. 24 | //// for(int i=0; i 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 transcoder; 42 | 43 | /** 44 | * Add memcached server and prot 45 | */ 46 | public void addServer(String server, int port) { 47 | addServer(server + ":" + port); 48 | } 49 | 50 | public void addServer(String address) { 51 | servers.add(address); 52 | } 53 | 54 | public void setServers(List servers) { 55 | this.servers = servers; 56 | } 57 | 58 | public String getServers() { 59 | 60 | StringBuffer sb = new StringBuffer(); 61 | 62 | for (String server : servers) { 63 | sb.append(server.trim()); 64 | sb.append(" "); 65 | } 66 | 67 | return sb.toString().trim(); 68 | } 69 | 70 | /** 71 | * @return the transcoder 72 | */ 73 | public Transcoder getTranscoder() { 74 | return transcoder; 75 | } 76 | 77 | /** 78 | * @param transcoder 79 | * the transcoder to set 80 | */ 81 | public void setTranscoder(Transcoder transcoder) { 82 | this.transcoder = transcoder; 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /cache-server/src/main/webapp/WEB-INF/flex-application-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 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 | -------------------------------------------------------------------------------- /avatar-cache-remote/src/main/java/com/dianping/remote/cache/CacheManageWebService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: com.dianping.avatar-cache-remote-2.0.0-SNAPSHOT 3 | * 4 | * File Created at 2011-2-15 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.remote.cache; 17 | 18 | import com.dianping.remote.cache.dto.CacheClearDTO; 19 | import com.dianping.remote.cache.dto.CacheKeyConfigurationDTO; 20 | import com.dianping.remote.cache.dto.GenericCacheConfigurationDTO; 21 | 22 | /** 23 | * Cache Manage Web Service 24 | * @author danson.liu 25 | * 26 | */ 27 | public interface CacheManageWebService { 28 | 29 | /** 30 | * 清除指定类别的所有缓存项 31 | * @param category 32 | * @see CacheManageWebService#clearByKey(CacheClearDTO)方法的"注意"项,相同 33 | */ 34 | void clearByCategory(String category); 35 | 36 | /** 37 | * 清除指定缓存服务下指定key的缓存项 38 | * @param key 39 | * @deprecated 为了兼容老版本的avatar-cache,全部升级后移除 40 | * @see CacheManageWebService#clearByKey(CacheClearDTO)方法的"注意"项,相同 41 | */ 42 | @Deprecated 43 | void clearByKey(String cacheType, String key); 44 | 45 | /** 46 | * 注意,在调用该接口时,需要在调用端异步调用,因为目前还需要发送消息到activemq,而activemq很无稳定 47 | * 不在该接口实现中做异步,因为调用端可能会关心清空是否成功的结果 48 | * @param cacheClear 49 | */ 50 | void clearByKey(CacheClearDTO cacheClear); 51 | 52 | void createConfiguration(GenericCacheConfigurationDTO configuration); 53 | 54 | void updateConfiguration(GenericCacheConfigurationDTO configuration); 55 | 56 | void createCacheKeyConfig(CacheKeyConfigurationDTO config); 57 | 58 | void updateCacheKeyConfig(CacheKeyConfigurationDTO config); 59 | 60 | /** 61 | * @param category 62 | * @param serverOrGroup 63 | */ 64 | void clearByCategory(String category, String serverOrGroup); 65 | 66 | void incVersion(String category); 67 | 68 | void pushCategoryConfig(String category, String serverOrGroup); 69 | 70 | } 71 | -------------------------------------------------------------------------------- /cache-core/src/main/java/com/dianping/cache/memcached/HessianSerializer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-core 3 | * 4 | * File Created at 2010-8-23 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.io.ByteArrayInputStream; 19 | import java.io.ByteArrayOutputStream; 20 | import java.io.IOException; 21 | 22 | import net.spy.memcached.compat.SpyObject; 23 | 24 | import com.caucho.hessian.io.Hessian2Input; 25 | import com.caucho.hessian.io.Hessian2Output; 26 | 27 | /** 28 | * HessianSerializer for serialize and deserialize serializable object 29 | * @author danson.liu 30 | * 31 | */ 32 | public class HessianSerializer extends SpyObject { 33 | 34 | /** 35 | * @param o 36 | * @return 37 | */ 38 | public byte[] serialize(Object o) { 39 | try { 40 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 41 | Hessian2Output hessian2Output = new Hessian2Output(baos); 42 | hessian2Output.writeObject(o); 43 | //place here not finally block, because byte array stream is not required to be closed 44 | hessian2Output.close(); 45 | return baos.toByteArray(); 46 | } catch (IOException e) { 47 | throw new IllegalArgumentException("Non-serializable object", e); 48 | } 49 | } 50 | 51 | /** 52 | * @param data 53 | * @return 54 | */ 55 | public Object deserialize(byte[] data) { 56 | Object rv=null; 57 | try { 58 | ByteArrayInputStream bais = new ByteArrayInputStream(data); 59 | Hessian2Input hessian2Input = new Hessian2Input(bais); 60 | rv = hessian2Input.readObject(); 61 | //place here not finally block, because byte array stream is not required to be closed 62 | hessian2Input.close(); 63 | } catch(IOException e) { 64 | getLogger().warn("Caught IOException decoding %d bytes of data", data.length, e); 65 | } 66 | return rv; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/entity/SupportedSpecification.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-server 3 | * 4 | * File Created at 2010-10-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.entity; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | /** 22 | * Supported Cache Specification 23 | * @author danson.liu 24 | * 25 | */ 26 | public class SupportedSpecification { 27 | 28 | /** 29 | * Supported Cache Clients 30 | * @author danson.liu 31 | * 32 | */ 33 | public static class SupportedCacheClients { 34 | 35 | /** 36 | * supported cache client classes 37 | */ 38 | private static List supportedClazzes = new ArrayList(); 39 | 40 | public static final String EHCACHE_CLIENT_CLAZZ = "com.dianping.cache.ehcache.EhcacheClientImpl"; 41 | public static final String MEMCACHED_CLIENT_CLAZZ = "com.dianping.cache.memcached.MemcachedClientImpl"; 42 | 43 | static { 44 | supportedClazzes.add(MEMCACHED_CLIENT_CLAZZ); 45 | supportedClazzes.add(EHCACHE_CLIENT_CLAZZ); 46 | } 47 | 48 | public static List getSupportedClazzes() { 49 | return supportedClazzes; 50 | } 51 | 52 | } 53 | 54 | /** 55 | * Supported Memcached Transcoders 56 | * @author danson.liu 57 | * 58 | */ 59 | public static class SupportedMemcachedTranscoders { 60 | 61 | /** 62 | * supported memcached transcoders 63 | */ 64 | private static List supportedTranscoders = new ArrayList(); 65 | 66 | static { 67 | supportedTranscoders.add("com.dianping.cache.memcached.HessianTranscoder"); 68 | supportedTranscoders.add("net.spy.memcached.transcoders.SerializingTranscoder"); 69 | } 70 | 71 | public static List getSupportedTranscoders() { 72 | return supportedTranscoders; 73 | } 74 | 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | 7 | com.dianping 8 | dianping-parent 9 | 2.0.0 10 | 11 | avatar-cache-parent 12 | 2.4.2 13 | pom 14 | avatar-cache-parent 15 | http://maven.apache.org 16 | 17 | 18 | 19 | 20 | ${project.groupId} 21 | cache-core 22 | ${project.version} 23 | 24 | 25 | ${project.groupId} 26 | cache-builder 27 | ${project.version} 28 | 29 | 30 | ${project.groupId} 31 | avatar-cache-remote 32 | ${project.version} 33 | 34 | 35 | com.dianping 36 | avatar-common-remote 37 | 2.0.3 38 | 39 | 40 | com.dianping 41 | avatar-logger 42 | 2.2.4 43 | 44 | 45 | com.dianping 46 | avatar-tracker 47 | 2.2.4 48 | 49 | 50 | 51 | 52 | 53 | 54 | junit 55 | junit 56 | 57 | 58 | net.spy 59 | spymemcached 60 | 2.9.1 61 | 62 | 63 | 64 | cache-core 65 | cache-builder 66 | cache-server 67 | avatar-cache 68 | avatar-cache-remote 69 | 70 | 71 | -------------------------------------------------------------------------------- /cache-server/src/main/resources/config/spring/appcontext-sms.xml: -------------------------------------------------------------------------------- 1 | 2 | 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 | -------------------------------------------------------------------------------- /cache-server/src/test/resources/config/spring/applicationContext-jms-sender-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 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 | -------------------------------------------------------------------------------- /avatar-cache/src/main/java/com/dianping/avatar/cache/client/CacheClientConfigurationHelper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: avatar 3 | * 4 | * File Created at 2010-10-18 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.client; 17 | 18 | import java.util.Map; 19 | import java.util.concurrent.ConcurrentHashMap; 20 | 21 | import com.dianping.cache.core.CacheClient; 22 | import com.dianping.cache.core.CacheClientConfiguration; 23 | import com.dianping.cache.ehcache.EhcacheClientImpl; 24 | import com.dianping.cache.kvdb.KvdbClientImpl; 25 | import com.dianping.cache.memcached.MemcachedClientImpl; 26 | import com.dianping.remote.cache.dto.CacheConfigDetailDTO; 27 | 28 | /** 29 | * CacheClientConfiguration parse helper class 30 | * 31 | * @author danson.liu 32 | * 33 | */ 34 | public class CacheClientConfigurationHelper { 35 | 36 | private static Map, CacheClientConfigurationParser> parserMap = 37 | new ConcurrentHashMap, CacheClientConfigurationParser>(); 38 | 39 | static { 40 | register(MemcachedClientImpl.class, new MemcachedClientConfigurationParser()); 41 | register(KvdbClientImpl.class, new MemcachedClientConfigurationParser()); 42 | register(EhcacheClientImpl.class, new EhcacheClientConfigurationParser()); 43 | } 44 | 45 | public static void register(Class clientClazz, CacheClientConfigurationParser parser) { 46 | parserMap.put(clientClazz, parser); 47 | } 48 | 49 | /** 50 | * @param detail 51 | * @return 52 | */ 53 | @SuppressWarnings("unchecked") 54 | public static CacheClientConfiguration parse(CacheConfigDetailDTO detail) { 55 | try { 56 | Class clientClazz = Class.forName(detail.getClientClazz()); 57 | return parserMap.get(clientClazz).parse(detail); 58 | } catch (ClassNotFoundException e) { 59 | throw new RuntimeException("Parser not found with cache client[" + detail.getClientClazz() + "]."); 60 | } 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /avatar-cache-remote/src/main/java/com/dianping/remote/cache/dto/GenericCacheConfigurationDTO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: com.dianping.avatar-cache-remote-2.0.0-SNAPSHOT 3 | * 4 | * File Created at 2011-2-18 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.remote.cache.dto; 17 | 18 | import com.dianping.remote.share.dto.AbstractDTO; 19 | 20 | /** 21 | * TODO Comment of GenericCacheConfigurationDTO 22 | * @author danson.liu 23 | * 24 | */ 25 | public class GenericCacheConfigurationDTO extends AbstractDTO { 26 | 27 | /** 28 | * 29 | */ 30 | private static final long serialVersionUID = 6009866894577345358L; 31 | 32 | private String cacheKey; 33 | 34 | private String clientClazz; 35 | 36 | private String servers; 37 | 38 | private String transcoderClazz; 39 | 40 | /** 41 | * @return the cacheKey 42 | */ 43 | public String getCacheKey() { 44 | return cacheKey; 45 | } 46 | 47 | /** 48 | * @param cacheKey the cacheKey to set 49 | */ 50 | public void setCacheKey(String cacheKey) { 51 | this.cacheKey = cacheKey; 52 | } 53 | 54 | /** 55 | * @return the clientClazz 56 | */ 57 | public String getClientClazz() { 58 | return clientClazz; 59 | } 60 | 61 | /** 62 | * @param clientClazz the clientClazz to set 63 | */ 64 | public void setClientClazz(String clientClazz) { 65 | this.clientClazz = clientClazz; 66 | } 67 | 68 | /** 69 | * @return the servers 70 | */ 71 | public String getServers() { 72 | return servers; 73 | } 74 | 75 | /** 76 | * @param servers the servers to set 77 | */ 78 | public void setServers(String servers) { 79 | this.servers = servers; 80 | } 81 | 82 | /** 83 | * @return the transcoderClazz 84 | */ 85 | public String getTranscoderClazz() { 86 | return transcoderClazz; 87 | } 88 | 89 | /** 90 | * @param transcoderClazz the transcoderClazz to set 91 | */ 92 | public void setTranscoderClazz(String transcoderClazz) { 93 | this.transcoderClazz = transcoderClazz; 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /avatar-cache/src/main/java/com/dianping/avatar/cache/client/MemcachedClientConfigurationParser.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: avatar 3 | * 4 | * File Created at 2010-10-18 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.client; 17 | 18 | import java.util.List; 19 | 20 | import net.spy.memcached.transcoders.Transcoder; 21 | 22 | import org.apache.commons.lang.ClassUtils; 23 | 24 | import com.dianping.cache.core.CacheClientConfiguration; 25 | import com.dianping.cache.memcached.MemcachedClientConfiguration; 26 | import com.dianping.remote.cache.dto.CacheConfigDetailDTO; 27 | import com.dianping.remote.cache.dto.MemcachedConfigDetailDTO; 28 | 29 | /** 30 | * TODO Comment of MemcachedClientConfigurationParser 31 | * @author danson.liu 32 | * 33 | */ 34 | public class MemcachedClientConfigurationParser implements CacheClientConfigurationParser { 35 | 36 | @SuppressWarnings("unchecked") 37 | @Override 38 | public CacheClientConfiguration parse(CacheConfigDetailDTO detail) { 39 | assert detail instanceof MemcachedConfigDetailDTO; 40 | MemcachedClientConfiguration config = new MemcachedClientConfiguration(); 41 | 42 | MemcachedConfigDetailDTO memcachedDetail = (MemcachedConfigDetailDTO) detail; 43 | String transcoderClass = memcachedDetail.getTranscoderClazz(); 44 | 45 | if (transcoderClass != null && !transcoderClass.trim().isEmpty()) { 46 | try { 47 | Class cz = ClassUtils.getClass(transcoderClass.trim()); 48 | Transcoder transcoder = (Transcoder) cz.newInstance(); 49 | config.setTranscoder(transcoder); 50 | } catch (Exception ex) { 51 | throw new RuntimeException("Failed to set memcached's transcoder.", ex); 52 | } 53 | } 54 | 55 | List serverList = memcachedDetail.getServerList(); 56 | if (serverList == null || serverList.size() == 0) { 57 | throw new RuntimeException("Memcached config's server list must not be empty."); 58 | } 59 | config.setServers(serverList); 60 | return config; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/entity/CacheConfiguration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-server 3 | * 4 | * File Created at 2010-10-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.entity; 17 | 18 | import java.io.Serializable; 19 | import java.util.Arrays; 20 | import java.util.List; 21 | 22 | import org.apache.commons.lang.StringUtils; 23 | 24 | /** 25 | * Cache client configuration 26 | * @author danson.liu 27 | * 28 | */ 29 | public class CacheConfiguration implements Serializable { 30 | 31 | /** 32 | * 33 | */ 34 | private static final long serialVersionUID = -6623912955403363194L; 35 | 36 | private static final String LIST_SEPARATOR = ";~;"; 37 | 38 | private String cacheKey; 39 | 40 | private String clientClazz; 41 | 42 | private String servers; 43 | 44 | private String transcoderClazz; 45 | 46 | public String getCacheKey() { 47 | return cacheKey; 48 | } 49 | 50 | public void setCacheKey(String cacheKey) { 51 | this.cacheKey = cacheKey; 52 | } 53 | 54 | public String getClientClazz() { 55 | return clientClazz; 56 | } 57 | 58 | public void setClientClazz(String clientClazz) { 59 | this.clientClazz = clientClazz; 60 | } 61 | 62 | public String getServers() { 63 | return servers; 64 | } 65 | 66 | public List getServerList() { 67 | if (servers == null) { 68 | return null; 69 | } 70 | return Arrays.asList(servers.split(LIST_SEPARATOR)); 71 | } 72 | 73 | public void setServers(String servers) { 74 | this.servers = servers; 75 | } 76 | 77 | public void setServerList(List serverList) { 78 | String servers = null; 79 | if (serverList != null && !serverList.isEmpty()) { 80 | servers = StringUtils.join(serverList, LIST_SEPARATOR); 81 | } 82 | setServers(servers); 83 | } 84 | 85 | public String getTranscoderClazz() { 86 | return transcoderClazz; 87 | } 88 | 89 | public void setTranscoderClazz(String transcoderClazz) { 90 | this.transcoderClazz = transcoderClazz; 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /cache-core/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | 7 | com.dianping 8 | avatar-cache-parent 9 | 2.4.2 10 | 11 | cache-core 12 | jar 13 | 14 | cache-core 15 | http://maven.apache.org 16 | 17 | 18 | 19 | com.caucho 20 | hessian 21 | 22 | 23 | net.sf.ehcache 24 | ehcache-core 25 | 2.5.2 26 | 27 | 28 | org.slf4j 29 | jcl-over-slf4j 30 | test 31 | 32 | 33 | org.slf4j 34 | slf4j-log4j12 35 | test 36 | 37 | 38 | com.dianping.lion 39 | lion-client 40 | 0.3.2 41 | provided 42 | 43 | 44 | 45 | 46 | 47 | maven-compiler-plugin 48 | 3.1 49 | 50 | 51 | default-compile 52 | compile 53 | 54 | compile 55 | 56 | 57 | 1.6 58 | 1.6 59 | UTF-8 60 | 61 | 62 | 63 | default-testCompile 64 | test-compile 65 | 66 | testCompile 67 | 68 | 69 | 1.6 70 | 1.6 71 | UTF-8 72 | 73 | 74 | 75 | 76 | 1.6 77 | 1.6 78 | UTF-8 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /cache-server/src/main/resources/config/sqlmap/User.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 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 | 40 | 46 | 52 | 53 | -------------------------------------------------------------------------------- /cache-server/src/main/resources/config/sqlmap/OperationLog.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 24 | 25 | 26 | Operator LIKE CONCAT('%', #operator#, '%') 27 | 28 | 29 | = #operateStart#]]> 30 | 31 | 32 | 33 | 34 | 35 | Succeed = #succeed# 36 | 37 | 38 | Content LIKE CONCAT('%', #content#, '%') 39 | 40 | 41 | IsCritical = 1 42 | 43 | 44 | 45 | 46 | 52 | 53 | 58 | 59 | 60 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/remote/sms/CacheCleanFromDotNetConsumer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dianping.cache.remote.sms; 5 | 6 | import org.apache.commons.lang.ArrayUtils; 7 | import org.apache.commons.lang.StringUtils; 8 | 9 | import com.dianping.cache.entity.CacheKeyConfiguration; 10 | import com.dianping.cache.service.CacheConfigurationService; 11 | import com.dianping.cache.service.CacheKeyConfigurationService; 12 | import com.dianping.queue.listener.MessageListener; 13 | import com.dianping.queue.message.Message; 14 | import com.dianping.queue.message.TextMessage; 15 | 16 | /** 17 | * @author jian.liu 18 | * 19 | */ 20 | public class CacheCleanFromDotNetConsumer implements MessageListener { 21 | 22 | private CacheKeyConfigurationService cacheKeyConfigurationService; 23 | 24 | private CacheConfigurationService cacheConfigurationService; 25 | 26 | @Override 27 | public void onMessage(Message message) { 28 | System.out.println("Receive message[" + message + "]."); 29 | TextMessage textMsg = (TextMessage) message; 30 | String content = textMsg.getContent(); 31 | if (content.startsWith("*")) { 32 | //clear by category 33 | String category = content.substring(1); 34 | cacheConfigurationService.clearByCategory(category); 35 | } else { 36 | //clear specified cache item 37 | String[] splits = StringUtils.split(content, '|'); 38 | String category = splits[0]; 39 | CacheKeyConfiguration configuration = cacheKeyConfigurationService.find(category); 40 | String[] params = (String[]) ArrayUtils.subarray(splits, 1, splits.length); 41 | cacheConfigurationService.clearByKey(configuration.getCacheType(), generateKey(configuration, params)); 42 | } 43 | } 44 | 45 | private String generateKey(CacheKeyConfiguration configuration, String[] params) { 46 | String accessKey = configuration.getCategory() + "." + configuration.getIndexTemplate() 47 | + "_" + configuration.getVersion(); 48 | for (int i = 0; i < params.length; i++) { 49 | accessKey = accessKey.replace("{" + i + "}", params[i].toString()); 50 | } 51 | return accessKey; 52 | } 53 | 54 | public void setCacheConfigurationService(CacheConfigurationService cacheConfigurationService) { 55 | this.cacheConfigurationService = cacheConfigurationService; 56 | } 57 | 58 | public void setCacheKeyConfigurationService(CacheKeyConfigurationService cacheKeyConfigurationService) { 59 | this.cacheKeyConfigurationService = cacheKeyConfigurationService; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/service/CacheConfigurationService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-server 3 | * 4 | * File Created at 2010-10-15 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.service; 17 | 18 | import java.util.List; 19 | 20 | import org.springframework.transaction.annotation.Propagation; 21 | import org.springframework.transaction.annotation.Transactional; 22 | 23 | import com.dianping.avatar.exception.DuplicatedIdentityException; 24 | import com.dianping.cache.entity.CacheConfiguration; 25 | 26 | /** 27 | * CacheKeyConfigurationService 28 | * @author danson.liu 29 | * 30 | */ 31 | @Transactional 32 | public interface CacheConfigurationService { 33 | 34 | /** 35 | * retrieve all configurations 36 | * @return 37 | */ 38 | List findAll(); 39 | 40 | CacheConfiguration find(String key); 41 | 42 | /** 43 | * 批量清除,仅清除Java端 44 | * @param category 45 | */ 46 | void clearByCategory(String category); 47 | 48 | /** 49 | * 批量清除指定机器或组的缓存,仅清除Java端 50 | * @param category 51 | * @param serverOrGroup 52 | */ 53 | void clearByCategory(String category, String serverOrGroup); 54 | 55 | /** 56 | * 批量清除,同时通知到.net系统 57 | * @param category 58 | */ 59 | void clearByCategoryBothSide(String category); 60 | 61 | /** 62 | * 仅在JAVA端清除缓存(可调整为同时清除.net缓存,但尚无需求,可在.net后台管理系统操作) 63 | * @param cacheType 64 | * @param key 65 | */ 66 | void clearByKey(String cacheType, String key); 67 | 68 | /** 69 | * 前台APP调用,可同时发送消息通知.net清除相应缓存(category+params) 70 | * @param cacheType 71 | * @param key 72 | * @param category 73 | * @param params 74 | */ 75 | @Transactional(propagation=Propagation.SUPPORTS) 76 | void clearByKeyBothSide(String cacheType, String key, String category, List params); 77 | 78 | CacheConfiguration create(CacheConfiguration config) throws DuplicatedIdentityException; 79 | 80 | CacheConfiguration update(CacheConfiguration config); 81 | 82 | void delete(String key); 83 | 84 | void incVersion(String category); 85 | 86 | void pushCategoryConfig(String category, String serverOrGroup); 87 | 88 | } 89 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/modules/spring/flex/SecurityHelper.java: -------------------------------------------------------------------------------- 1 | package com.dianping.modules.spring.flex; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.springframework.security.Authentication; 7 | import org.springframework.security.context.SecurityContextHolder; 8 | 9 | /** 10 | * Created by IntelliJ IDEA. 11 | * User: danson 12 | * Date: 2010-3-10 13 | * Time: 23:17:44 14 | * To change this template use File | Settings | File Templates. 15 | */ 16 | public class SecurityHelper { 17 | 18 | public static final String EMBED_PRINCIPAL_SUFFIX = "@!@"; 19 | 20 | public static Map getAuthentication() { 21 | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); 22 | if (authentication == null) { 23 | return null; 24 | } 25 | Map authenticationResult = new HashMap(); 26 | authenticationResult.put("name", authentication.getName()); 27 | String[] authorities = new String[authentication.getAuthorities().length]; 28 | for (int i = 0; i < authorities.length; i++) { 29 | authorities[i] = authentication.getAuthorities()[i].getAuthority(); 30 | } 31 | authenticationResult.put("authorities", authorities); 32 | authenticationResult.put("details", authentication.getDetails()); 33 | return authenticationResult; 34 | } 35 | 36 | @SuppressWarnings("unchecked") 37 | public static String getPrincipal() { 38 | Map authentication = getAuthentication(); 39 | if (authentication == null) { 40 | return null; 41 | } 42 | 43 | Object detailsObj = authentication.get("details"); 44 | 45 | if(!(detailsObj instanceof Map)) { 46 | return null; 47 | } 48 | 49 | Map details = (Map) detailsObj; 50 | String realName = null; 51 | if (details != null) { 52 | realName = (String) details.get("realName"); 53 | } 54 | return (String) authentication.get("name") + (realName != null ? "(" + realName + ")" : ""); 55 | } 56 | 57 | public static boolean isEmbededPrincipal(String principal) { 58 | return principal != null && principal.endsWith(EMBED_PRINCIPAL_SUFFIX); 59 | } 60 | 61 | public static String getPrincipalWithEmbeded(String principal) { 62 | if (isEmbededPrincipal(principal)) { 63 | return principal.substring(0, principal.length() - EMBED_PRINCIPAL_SUFFIX.length()); 64 | } 65 | return principal; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /cache-server/src/test/resources/config/spring/applicationContext-jms-sender-test-amq.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 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 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /cache-core/src/test/java/com/dianping/cache/core/TestHessian.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-core 3 | * 4 | * File Created at 2010-8-24 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.core; 17 | 18 | import java.io.ByteArrayOutputStream; 19 | import java.io.ObjectOutputStream; 20 | import java.io.Serializable; 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | import org.junit.Test; 25 | 26 | import com.caucho.hessian.io.Hessian2Output; 27 | 28 | /** 29 | * Test hessian serialize 30 | * 31 | * @author guoqing.chen 32 | * 33 | */ 34 | public class TestHessian { 35 | 36 | @Test 37 | public void testHessian() throws Exception { 38 | 39 | ByteArrayOutputStream bout = new ByteArrayOutputStream(); 40 | Hessian2Output output = new Hessian2Output(bout); 41 | 42 | long t1 = System.currentTimeMillis(); 43 | 44 | for (int i = 0; i < 100000; i++) { 45 | User user = new User(100, "dianping.com" + i); 46 | user.mobiles.add("mobile" + i); 47 | user.mobiles.add("mobile2" + (i + 1)); 48 | output.writeObject(user); 49 | } 50 | 51 | long interval1 = System.currentTimeMillis() - t1; 52 | 53 | ByteArrayOutputStream bout2 = new ByteArrayOutputStream(); 54 | ObjectOutputStream oOutput = new ObjectOutputStream(bout2); 55 | 56 | long t2 = System.currentTimeMillis(); 57 | 58 | for (int i = 0; i < 100000; i++) { 59 | User user = new User(100, "dianping.com" + i); 60 | user.mobiles.add("mobile" + i); 61 | user.mobiles.add("mobile2" + (i + 1)); 62 | 63 | oOutput.writeObject(user); 64 | } 65 | 66 | long interval2 = System.currentTimeMillis() - t2; 67 | 68 | System.out.printf("Hessian (%d,%d), RMI:(%d,%d)", bout.size(), interval1, bout2.size(), interval2); 69 | } 70 | 71 | public static class User implements Serializable { 72 | /** 73 | * serial version uid 74 | */ 75 | private static final long serialVersionUID = -4754574594493166572L; 76 | 77 | public final int id; 78 | public final String name; 79 | 80 | public final List mobiles = new ArrayList(); 81 | 82 | /** 83 | * @param id 84 | * @param name 85 | */ 86 | public User(int id, String name) { 87 | super(); 88 | this.id = id; 89 | this.name = name; 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /avatar-cache/src/test/java/com/dianping/avatar/cache/spring/CacheBeanDefinitionParserTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: avatar-cache 3 | * 4 | * File Created at 2011-9-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.avatar.cache.spring; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | 20 | import org.junit.Ignore; 21 | import org.junit.Test; 22 | import org.springframework.beans.factory.support.BeanDefinitionRegistry; 23 | import org.springframework.beans.factory.xml.XmlBeanFactory; 24 | import org.springframework.core.io.ClassPathResource; 25 | 26 | /** 27 | * CacheBeanDefinitionParserTest 28 | * @author youngphy.yang 29 | * 30 | */ 31 | @Ignore 32 | public class CacheBeanDefinitionParserTest{ 33 | /** 34 | * Test whether the interceptor takes effect or not 35 | */ 36 | @Test 37 | public void testRegisterStatisticsCacheInterceptor() { 38 | ClassPathResource resource = new ClassPathResource("AOPDemo.xml"); 39 | XmlBeanFactory beanFactory = new XmlBeanFactory(resource); 40 | BeanDefinitionRegistry beanDefinitionRegistry = beanFactory; 41 | 42 | CacheBeanDefinitionParser cacheBeanDefinitionParser = new CacheBeanDefinitionParser() { 43 | protected Class getStatisticsCacheInterceptor() { 44 | return com.dianping.avatar.cache.spring.DemoInterceptor.class; 45 | } 46 | }; 47 | cacheBeanDefinitionParser.registerStatisticsCacheInterceptor(null, beanDefinitionRegistry); 48 | cacheBeanDefinitionParser.registerCacheProxyBean(null, beanDefinitionRegistry, null); 49 | BusinessInterface businessBean = (BusinessInterface)beanFactory.getBean("cacheService"); 50 | assertEquals(200, businessBean.bye()); 51 | 52 | beanFactory = new XmlBeanFactory(resource); 53 | beanDefinitionRegistry = beanFactory; 54 | cacheBeanDefinitionParser = new CacheBeanDefinitionParser() { 55 | protected Class getStatisticsCacheInterceptor() { 56 | return com.dianping.avatar.cache.spring.DemoInterceptor2.class; 57 | } 58 | }; 59 | cacheBeanDefinitionParser.registerStatisticsCacheInterceptor(null, beanDefinitionRegistry); 60 | cacheBeanDefinitionParser.registerCacheProxyBean(null, beanDefinitionRegistry, null); 61 | businessBean = (BusinessInterface)beanFactory.getBean("cacheService"); 62 | assertEquals(100, businessBean.bye()); 63 | 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /cache-server/src/main/java/com/dianping/cache/entity/CacheKeyConfiguration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project: cache-server 3 | * 4 | * File Created at 2010-10-15 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.entity; 17 | 18 | import java.io.Serializable; 19 | 20 | /** 21 | * CacheKey Configuration persistent object 22 | * @author danson.liu 23 | * 24 | */ 25 | public class CacheKeyConfiguration implements Serializable { 26 | 27 | private static final long serialVersionUID = 2481840480409511748L; 28 | 29 | private String category; 30 | 31 | private String duration; 32 | 33 | private String indexTemplate; 34 | 35 | private String indexDesc; 36 | 37 | private String cacheType; 38 | 39 | private int version; 40 | 41 | private boolean sync2Dnet; 42 | 43 | private boolean hot; 44 | 45 | public String getCategory() { 46 | return category; 47 | } 48 | 49 | public void setCategory(String category) { 50 | this.category = category; 51 | } 52 | 53 | public String getDuration() { 54 | return duration; 55 | } 56 | 57 | public void setDuration(String duration) { 58 | this.duration = duration; 59 | } 60 | 61 | public String getIndexTemplate() { 62 | return indexTemplate; 63 | } 64 | 65 | public void setIndexTemplate(String indexTemplate) { 66 | this.indexTemplate = indexTemplate; 67 | } 68 | 69 | public String getIndexDesc() { 70 | return indexDesc; 71 | } 72 | 73 | public void setIndexDesc(String indexDesc) { 74 | this.indexDesc = indexDesc; 75 | } 76 | 77 | public String getCacheType() { 78 | return cacheType; 79 | } 80 | 81 | public void setCacheType(String cacheType) { 82 | this.cacheType = cacheType; 83 | } 84 | 85 | public int getVersion() { 86 | return version; 87 | } 88 | 89 | public void setVersion(int version) { 90 | this.version = version; 91 | } 92 | 93 | public boolean isSync2Dnet() { 94 | return sync2Dnet; 95 | } 96 | 97 | public void setSync2Dnet(boolean sync2Dnet) { 98 | this.sync2Dnet = sync2Dnet; 99 | } 100 | 101 | public boolean isHot() { 102 | return hot; 103 | } 104 | 105 | public void setHot(boolean hot) { 106 | this.hot = hot; 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /cache-core/src/main/java/com/dianping/cache/core/CacheException.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.core; 17 | 18 | /** 19 | * A runtime cache exception 20 | * wrap the concrete cache implement's original exception 21 | * @author danson.liu 22 | * 23 | */ 24 | public class CacheException extends RuntimeException { 25 | 26 | /** 27 | * 28 | */ 29 | private static final long serialVersionUID = -270209742367889082L; 30 | 31 | /** 32 | * Construct a CacheException with the specified detail message 33 | * @param msg the detail message 34 | */ 35 | public CacheException(String msg) { 36 | super(msg); 37 | } 38 | 39 | /** 40 | * Construct a CacheException with the specified detail message 41 | * and nested exception. 42 | * @param msg the detail message 43 | * @param cause the nested exception 44 | */ 45 | public CacheException(String msg, Throwable cause) { 46 | super(msg, cause); 47 | } 48 | 49 | /** 50 | * Retrieve the innermost cause of this exception, if any 51 | * @return the innermost exception, or null if none 52 | */ 53 | public Throwable getRootCause() { 54 | Throwable rootCause = null; 55 | Throwable cause = getCause(); 56 | while (cause != null && cause != rootCause) { 57 | rootCause = cause; 58 | cause = cause.getCause(); 59 | } 60 | return rootCause; 61 | } 62 | 63 | /** 64 | * Retrieve the most specific cause of this exception, that is, 65 | * either the innermost cause (root cause) or this exception itself 66 | * @return the most specific cause (never null) 67 | */ 68 | public Throwable getMostSpecificCause() { 69 | Throwable rootCause = getRootCause(); 70 | return (rootCause != null ? rootCause : this); 71 | } 72 | 73 | @Override 74 | public String getMessage() { 75 | String message = super.getMessage(); 76 | Throwable cause = super.getCause(); 77 | if (cause != null) { 78 | StringBuffer buf = new StringBuffer(); 79 | if (message != null) { 80 | buf.append(message).append("; "); 81 | } 82 | buf.append("nested exception is ").append(cause); 83 | return buf.toString(); 84 | } 85 | else { 86 | return message; 87 | } 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /cache-core/src/main/java/com/dianping/cache/ehcache/LooseBlockingCache.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dianping.cache.ehcache; 5 | 6 | import net.sf.ehcache.CacheException; 7 | import net.sf.ehcache.Ehcache; 8 | import net.sf.ehcache.Element; 9 | import net.sf.ehcache.concurrent.LockType; 10 | import net.sf.ehcache.concurrent.Sync; 11 | import net.sf.ehcache.constructs.blocking.BlockingCache; 12 | import net.sf.ehcache.constructs.blocking.LockTimeoutException; 13 | 14 | /** 15 | * 在已有的cache api的情形下,对blockingcache进行的折中,BlockingCache本身要求如下编程模型(对并发的更精细的控制,避免重复的缓存重建): 16 | * Element ele = null; 17 | * try { 18 | * ele = blockingCache.get(key); 19 | * } catch (RuntimeException e) { 20 | * blockingCache.put(new Element(key, null)); 21 | * } 22 | * if (ele == null) { 23 | * Object item = null; 24 | * try { 25 | * item = retrieveAndBuildItemFromDataSource(); 26 | * } catch (Exception e) { 27 | * blockingCache.releaseWriteLockOnKey(key); 28 | * throw e; 29 | * } 30 | * try { 31 | * blockingCache.put(new Element(key, item)); 32 | * } finally { 33 | * return item; 34 | * } 35 | * } 36 | * return ele.getVal(); 37 | * 38 | * @author danson.liu 39 | * 40 | */ 41 | public class LooseBlockingCache extends BlockingCache { 42 | 43 | public LooseBlockingCache(Ehcache cache) throws CacheException { 44 | super(cache); 45 | } 46 | 47 | public LooseBlockingCache(final Ehcache cache, int numberOfStripes) { 48 | super(cache, numberOfStripes); 49 | } 50 | 51 | @Override 52 | public Element get(Object key) throws RuntimeException { 53 | Sync lock = getLockForKey(key); 54 | acquiredLockForKey(key, lock, LockType.READ); 55 | try { 56 | return underlyingCache.get(key); 57 | } finally { 58 | lock.unlock(LockType.READ); 59 | } 60 | } 61 | 62 | private void acquiredLockForKey(final Object key, final Sync lock, final LockType lockType) { 63 | if (timeoutMillis > 0) { 64 | try { 65 | boolean acquired = lock.tryLock(lockType, timeoutMillis); 66 | if (!acquired) { 67 | StringBuilder message = new StringBuilder("Lock timeout. Waited more than ") 68 | .append(timeoutMillis) 69 | .append("ms to acquire lock for key ") 70 | .append(key).append(" on blocking cache ").append(underlyingCache.getName()); 71 | throw new LockTimeoutException(message.toString()); 72 | } 73 | } catch (InterruptedException e) { 74 | throw new LockTimeoutException("Got interrupted while trying to acquire lock for key " + key, e); 75 | } 76 | } else { 77 | lock.lock(lockType); 78 | } 79 | } 80 | 81 | } 82 | --------------------------------------------------------------------------------