├── README.md ├── cscache ├── .gitignore ├── src │ ├── main │ │ ├── resources │ │ │ ├── META-INF │ │ │ │ └── services │ │ │ │ │ └── javax.cache.spi.CachingProvider │ │ │ └── log4j2.xml │ │ └── java │ │ │ └── org │ │ │ └── cachestudy │ │ │ └── writeitbyself │ │ │ ├── store │ │ │ ├── ValueHolder.java │ │ │ ├── impl │ │ │ │ ├── BasicValueHolder.java │ │ │ │ ├── WeakValueHolder.java │ │ │ │ ├── BasicDataStore.java │ │ │ │ ├── WeakValueDataStore.java │ │ │ │ ├── LRUEntry.java │ │ │ │ └── LRUDataStore.java │ │ │ ├── DataStore.java │ │ │ └── StoreAccessException.java │ │ │ ├── CsCache.java │ │ │ └── jsr107 │ │ │ ├── CsCaching107Provider.java │ │ │ ├── CsCache107.java │ │ │ └── CsCache107Manager.java │ └── test │ │ └── java │ │ └── org │ │ └── cachestudy │ │ └── writeitbyself │ │ ├── bean │ │ └── User.java │ │ ├── CsCache107Test.java │ │ └── CsCacheTest.java ├── .settings │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.core.resources.prefs │ └── org.eclipse.jdt.core.prefs ├── .project ├── .classpath └── pom.xml ├── .gitignore └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # demo_cache -------------------------------------------------------------------------------- /cscache/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /cscache/src/main/resources/META-INF/services/javax.cache.spi.CachingProvider: -------------------------------------------------------------------------------- 1 | org.cachestudy.writeitbyself.jsr107.CsCaching107Provider 2 | -------------------------------------------------------------------------------- /cscache/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /cscache/src/main/java/org/cachestudy/writeitbyself/store/ValueHolder.java: -------------------------------------------------------------------------------- 1 | package org.cachestudy.writeitbyself.store; 2 | 3 | public interface ValueHolder { 4 | V value(); 5 | } 6 | -------------------------------------------------------------------------------- /cscache/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | *.war 9 | *.ear 10 | 11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 12 | hs_err_pid* 13 | -------------------------------------------------------------------------------- /cscache/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 3 | org.eclipse.jdt.core.compiler.compliance=1.7 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.7 6 | -------------------------------------------------------------------------------- /cscache/src/test/java/org/cachestudy/writeitbyself/bean/User.java: -------------------------------------------------------------------------------- 1 | package org.cachestudy.writeitbyself.bean; 2 | 3 | public class User { 4 | String name; 5 | 6 | public String getName() { 7 | return name; 8 | } 9 | 10 | public void setName(String name) { 11 | this.name = name; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /cscache/src/main/java/org/cachestudy/writeitbyself/store/impl/BasicValueHolder.java: -------------------------------------------------------------------------------- 1 | package org.cachestudy.writeitbyself.store.impl; 2 | 3 | import org.cachestudy.writeitbyself.store.ValueHolder; 4 | 5 | public class BasicValueHolder implements ValueHolder { 6 | private final V refValue; 7 | 8 | public BasicValueHolder(final V value) { 9 | refValue = value; 10 | } 11 | 12 | public V value() { 13 | return refValue; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /cscache/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /cscache/src/main/java/org/cachestudy/writeitbyself/store/impl/WeakValueHolder.java: -------------------------------------------------------------------------------- 1 | package org.cachestudy.writeitbyself.store.impl; 2 | 3 | import java.lang.ref.WeakReference; 4 | 5 | import org.cachestudy.writeitbyself.store.ValueHolder; 6 | 7 | public class WeakValueHolder implements ValueHolder { 8 | 9 | public WeakValueHolder(V value) { 10 | super(); 11 | if (null == value) { 12 | return; 13 | } 14 | this.v = new WeakReference(value); 15 | } 16 | 17 | private WeakReference v; 18 | 19 | @Override 20 | public V value() { 21 | return this.v.get(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /cscache/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | cscache 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /cscache/src/main/java/org/cachestudy/writeitbyself/store/DataStore.java: -------------------------------------------------------------------------------- 1 | package org.cachestudy.writeitbyself.store; 2 | 3 | public interface DataStore { 4 | ValueHolder get(K key) throws StoreAccessException; 5 | 6 | PutStatus put(K key, V value) throws StoreAccessException; 7 | 8 | ValueHolder remove(K key) throws StoreAccessException; 9 | 10 | void clear() throws StoreAccessException; 11 | 12 | enum PutStatus { 13 | /** 14 | * New value was put 15 | */ 16 | PUT, 17 | /** 18 | * New value was put and replace old value 19 | */ 20 | UPDATE, 21 | /** 22 | * New value was dropped 23 | */ 24 | NOOP 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /cscache/src/test/java/org/cachestudy/writeitbyself/CsCache107Test.java: -------------------------------------------------------------------------------- 1 | package org.cachestudy.writeitbyself; 2 | 3 | import javax.cache.Cache; 4 | import javax.cache.CacheManager; 5 | import javax.cache.Caching; 6 | import javax.cache.configuration.Configuration; 7 | import javax.cache.configuration.MutableConfiguration; 8 | import javax.cache.spi.CachingProvider; 9 | 10 | import org.cachestudy.writeitbyself.bean.User; 11 | import org.junit.Test; 12 | 13 | public class CsCache107Test { 14 | @Test 15 | public void test01() { 16 | CachingProvider cachingProvider = Caching.getCachingProvider(); 17 | CacheManager manager = cachingProvider.getCacheManager(); 18 | Cache cache = (Cache) manager 19 | .> createCache("Test", 20 | new MutableConfiguration()); 21 | String key = "leo"; 22 | User user = new User(); 23 | user.setName("leo"); 24 | cache.put(key, user); 25 | System.out.println("Hello " + cache.get(key).getName()); 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /cscache/src/main/java/org/cachestudy/writeitbyself/store/impl/BasicDataStore.java: -------------------------------------------------------------------------------- 1 | package org.cachestudy.writeitbyself.store.impl; 2 | 3 | import java.util.concurrent.ConcurrentHashMap; 4 | 5 | import org.cachestudy.writeitbyself.store.DataStore; 6 | import org.cachestudy.writeitbyself.store.StoreAccessException; 7 | import org.cachestudy.writeitbyself.store.ValueHolder; 8 | 9 | public class BasicDataStore implements DataStore { 10 | 11 | ConcurrentHashMap> map = new ConcurrentHashMap>(); 12 | 13 | public ValueHolder get(K key) throws StoreAccessException { 14 | return map.get(key); 15 | } 16 | 17 | public PutStatus put(K key, V value) throws StoreAccessException { 18 | ValueHolder v = new BasicValueHolder(value); 19 | map.put(key, v); 20 | return PutStatus.PUT; 21 | } 22 | 23 | public ValueHolder remove(K key) throws StoreAccessException { 24 | return map.remove(key); 25 | } 26 | 27 | public void clear() throws StoreAccessException { 28 | map.clear(); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /cscache/src/main/java/org/cachestudy/writeitbyself/store/StoreAccessException.java: -------------------------------------------------------------------------------- 1 | package org.cachestudy.writeitbyself.store; 2 | 3 | public class StoreAccessException extends Exception { 4 | 5 | private static final long serialVersionUID = -3962141124378773527L; 6 | 7 | /** 8 | * Creates a new exception wrapping the {@link Throwable cause} passed in. 9 | * 10 | * @param cause the cause of this exception 11 | */ 12 | public StoreAccessException(Throwable cause) { 13 | super(cause); 14 | } 15 | 16 | /** 17 | * Creates a new exception wrapping the {@link Throwable cause} passed in and with the provided message. 18 | * 19 | * @param message information about the exception 20 | * @param cause the cause of this exception 21 | */ 22 | public StoreAccessException(String message, Throwable cause) { 23 | super(message, cause); 24 | } 25 | 26 | /** 27 | * Creates a new exception with the provided message. 28 | * 29 | * @param message information about the exception 30 | */ 31 | public StoreAccessException(String message) { 32 | super(message); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /cscache/src/main/java/org/cachestudy/writeitbyself/store/impl/WeakValueDataStore.java: -------------------------------------------------------------------------------- 1 | package org.cachestudy.writeitbyself.store.impl; 2 | 3 | import java.util.concurrent.ConcurrentHashMap; 4 | 5 | import org.cachestudy.writeitbyself.store.DataStore; 6 | import org.cachestudy.writeitbyself.store.StoreAccessException; 7 | import org.cachestudy.writeitbyself.store.ValueHolder; 8 | 9 | public class WeakValueDataStore implements DataStore { 10 | 11 | ConcurrentHashMap> map = new ConcurrentHashMap>(); 12 | 13 | @Override 14 | public ValueHolder get(K key) throws StoreAccessException { 15 | return map.get(key); 16 | } 17 | 18 | @Override 19 | public PutStatus put(K key, V value) throws StoreAccessException { 20 | ValueHolder v = new WeakValueHolder(value); 21 | map.put(key, v); 22 | return PutStatus.PUT; 23 | } 24 | 25 | @Override 26 | public ValueHolder remove(K key) throws StoreAccessException { 27 | return map.remove(key); 28 | } 29 | 30 | @Override 31 | public void clear() throws StoreAccessException { 32 | map.clear(); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /cscache/src/main/java/org/cachestudy/writeitbyself/store/impl/LRUEntry.java: -------------------------------------------------------------------------------- 1 | package org.cachestudy.writeitbyself.store.impl; 2 | 3 | import java.util.Map.Entry; 4 | 5 | import org.cachestudy.writeitbyself.store.ValueHolder; 6 | 7 | public class LRUEntry> implements Entry> { 8 | 9 | final K key; // non-null 10 | ValueHolder v; // non-null 11 | 12 | LRUEntry> pre; 13 | LRUEntry> next; 14 | 15 | public LRUEntry> getPre() { 16 | return pre; 17 | } 18 | 19 | public void setPre(LRUEntry> pre) { 20 | this.pre = pre; 21 | } 22 | 23 | public LRUEntry> getNext() { 24 | return next; 25 | } 26 | 27 | public void setNext(LRUEntry> next) { 28 | this.next = next; 29 | } 30 | 31 | public LRUEntry(K key, V value) { 32 | super(); 33 | 34 | this.key = key; 35 | this.v = value; 36 | } 37 | 38 | @Override 39 | public K getKey() { 40 | return key; 41 | } 42 | 43 | @Override 44 | public ValueHolder getValue() { 45 | return this.v; 46 | } 47 | 48 | @Override 49 | public ValueHolder setValue(ValueHolder value) { 50 | ValueHolder oldValue = this.v; 51 | this.v = value; 52 | return oldValue; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /cscache/.classpath: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /cscache/src/main/java/org/cachestudy/writeitbyself/CsCache.java: -------------------------------------------------------------------------------- 1 | package org.cachestudy.writeitbyself; 2 | 3 | import org.cachestudy.writeitbyself.store.DataStore; 4 | import org.cachestudy.writeitbyself.store.StoreAccessException; 5 | import org.cachestudy.writeitbyself.store.ValueHolder; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | public class CsCache { 10 | private final DataStore store; 11 | private static Logger logger = LoggerFactory.getLogger(CsCache.class); 12 | 13 | public CsCache(final DataStore dataStore) { 14 | store = dataStore; 15 | } 16 | 17 | public V get(final K key) { 18 | try { 19 | ValueHolder value = store.get(key); 20 | if (null == value) { 21 | return null; 22 | } 23 | return value.value(); 24 | } catch (StoreAccessException e) { 25 | logger.error("store access error : ", e.getMessage()); 26 | logger.error(e.getStackTrace().toString()); 27 | return null; 28 | } 29 | } 30 | 31 | public void put(final K key, final V value) { 32 | try { 33 | store.put(key, value); 34 | } catch (StoreAccessException e) { 35 | logger.error("store access error : ", e.getMessage()); 36 | logger.error(e.getStackTrace().toString()); 37 | } 38 | } 39 | 40 | public V remove(K key) { 41 | try { 42 | ValueHolder value = store.remove(key); 43 | return value != null ? value.value() : null; 44 | } catch (StoreAccessException e) { 45 | logger.error("store access error : ", e.getMessage()); 46 | logger.error(e.getStackTrace().toString()); 47 | return null; 48 | } 49 | } 50 | 51 | public void clear() { 52 | try { 53 | store.clear(); 54 | } catch (StoreAccessException e) { 55 | logger.error("store access error : ", e.getMessage()); 56 | logger.error(e.getStackTrace().toString()); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /cscache/src/test/java/org/cachestudy/writeitbyself/CsCacheTest.java: -------------------------------------------------------------------------------- 1 | package org.cachestudy.writeitbyself; 2 | 3 | import org.cachestudy.writeitbyself.bean.User; 4 | import org.cachestudy.writeitbyself.store.impl.BasicDataStore; 5 | import org.cachestudy.writeitbyself.store.impl.LRUDataStore; 6 | import org.cachestudy.writeitbyself.store.impl.WeakValueDataStore; 7 | import org.junit.Assert; 8 | import org.junit.Test; 9 | 10 | public class CsCacheTest { 11 | @Test 12 | public void TestHelloWorld() { 13 | CsCache cache = new CsCache(new BasicDataStore()); 14 | String key = "Hello"; 15 | cache.put(key, "World!"); 16 | System.out.println(key + " " + cache.get(key)); 17 | } 18 | 19 | @Test 20 | public void TestWeakValue() throws InterruptedException { 21 | CsCache cache = new CsCache(new WeakValueDataStore()); 22 | String key = "leo"; 23 | User user = new User(); 24 | user.setName("leo"); 25 | cache.put(key, user); 26 | user = null; 27 | System.out.println("Hello " + cache.get(key).getName()); 28 | System.gc(); 29 | Thread.sleep(1000); 30 | System.out.println("Hello " + cache.get(key)); 31 | } 32 | 33 | @Test 34 | public void TestLRU() { 35 | CsCache cache = new CsCache(new LRUDataStore(2)); 36 | String key = "leo"; 37 | User user = new User(); 38 | user.setName("leo"); 39 | 40 | User oldUser = cache.remove(key); 41 | Assert.assertTrue(oldUser == null); 42 | 43 | String key1 = "liu"; 44 | User user1 = new User(); 45 | user1.setName("liu"); 46 | 47 | String key2 = "robin"; 48 | User user2 = new User(); 49 | user2.setName("robin"); 50 | 51 | cache.put(key, user); 52 | cache.put(key1, user1); 53 | cache.get(key); 54 | cache.put(key2, user2); 55 | 56 | if (cache.get(key) != null) { 57 | System.out.println("Hello " + cache.get(key).getName()); 58 | } 59 | if (cache.get(key1) != null) { 60 | System.out.println("Hello " + cache.get(key1).getName()); 61 | } 62 | if (cache.get(key2) != null) { 63 | System.out.println("Hello " + cache.get(key2).getName()); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /cscache/src/main/java/org/cachestudy/writeitbyself/store/impl/LRUDataStore.java: -------------------------------------------------------------------------------- 1 | package org.cachestudy.writeitbyself.store.impl; 2 | 3 | import java.util.concurrent.ConcurrentHashMap; 4 | 5 | import org.cachestudy.writeitbyself.store.DataStore; 6 | import org.cachestudy.writeitbyself.store.StoreAccessException; 7 | import org.cachestudy.writeitbyself.store.ValueHolder; 8 | 9 | public class LRUDataStore implements DataStore { 10 | 11 | public LRUDataStore(int maxSize) { 12 | super(); 13 | this.maxSize = maxSize; 14 | } 15 | 16 | private final int maxSize; 17 | 18 | ConcurrentHashMap>> map = new ConcurrentHashMap>>(); 19 | 20 | private LRUEntry> first; 21 | private LRUEntry> last; 22 | 23 | @SuppressWarnings("unchecked") 24 | @Override 25 | public ValueHolder get(K key) throws StoreAccessException { 26 | LRUEntry> entry = (LRUEntry>) getEntry(key); 27 | if (entry == null) { 28 | return null; 29 | } 30 | moveToFirst(entry); 31 | return (ValueHolder) entry.getValue(); 32 | 33 | } 34 | 35 | @Override 36 | public PutStatus put(K key, V value) throws StoreAccessException { 37 | LRUEntry> entry = (LRUEntry>) getEntry(key); 38 | PutStatus status = PutStatus.NOOP; 39 | if (entry == null) { 40 | if (map.size() >= maxSize) { 41 | map.remove(last.getKey()); 42 | removeLast(); 43 | } 44 | entry = new LRUEntry>(key, new BasicValueHolder(value)); 45 | status = PutStatus.PUT; 46 | } else { 47 | entry.setValue(new BasicValueHolder(value)); 48 | status = PutStatus.UPDATE; 49 | } 50 | moveToFirst(entry); 51 | map.put(key, entry); 52 | return status; 53 | } 54 | 55 | @SuppressWarnings("unchecked") 56 | @Override 57 | public ValueHolder remove(K key) throws StoreAccessException { 58 | LRUEntry> entry = getEntry(key); 59 | if (entry == null) { 60 | return null; 61 | } else { 62 | if (entry.getPre() != null) 63 | entry.getPre().setNext(entry.getNext()); 64 | if (entry.getNext() != null) 65 | entry.getNext().setPre(entry.getPre()); 66 | if (entry == first) 67 | first = entry.getNext(); 68 | if (entry == last) 69 | last = entry.getPre(); 70 | } 71 | LRUEntry> oldValue = map.remove(key); 72 | return (ValueHolder) oldValue.getValue(); 73 | } 74 | 75 | @Override 76 | public void clear() throws StoreAccessException { 77 | this.map.clear(); 78 | this.first = this.last = null; 79 | } 80 | 81 | private void moveToFirst(LRUEntry> entry) { 82 | if (entry == first) 83 | return; 84 | if (entry.getPre() != null) 85 | entry.getPre().setNext(entry.getNext()); 86 | if (entry.getNext() != null) 87 | entry.getNext().setPre(entry.getPre()); 88 | if (entry == last) 89 | last = last.getPre(); 90 | 91 | if (first == null || last == null) { 92 | first = last = entry; 93 | return; 94 | } 95 | 96 | entry.setNext(first); 97 | first.setPre(entry); 98 | first = entry; 99 | entry.setPre(null); 100 | } 101 | 102 | private void removeLast() { 103 | if (last != null) { 104 | last = last.getPre(); 105 | if (last == null) 106 | first = null; 107 | else 108 | last.next = null; 109 | } 110 | } 111 | 112 | private LRUEntry> getEntry(K key) { 113 | return map.get(key); 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /cscache/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | org.cachestudy.writeitbyself 6 | cscache 7 | 0.0.1-SNAPSHOT 8 | jar 9 | 10 | cscache 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | 20 | org.apache.logging.log4j 21 | log4j-api 22 | 2.5 23 | 24 | 25 | org.apache.logging.log4j 26 | log4j-core 27 | 2.5 28 | 29 | 30 | org.apache.logging.log4j 31 | log4j-slf4j-impl 32 | 2.5 33 | 34 | 35 | com.lmax 36 | disruptor 37 | 3.3.2 38 | 39 | 40 | 41 | 42 | org.slf4j 43 | slf4j-api 44 | 1.7.21 45 | 46 | 47 | 48 | org.apache.commons 49 | commons-lang3 50 | 3.0 51 | 52 | 53 | javax.cache 54 | cache-api 55 | 1.0.0 56 | 57 | 58 | junit 59 | junit 60 | 4.12 61 | 62 | 63 | 64 | 65 | 66 | org.apache.commons 67 | commons-lang3 68 | 3.0 69 | 70 | 71 | 72 | 73 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | org.apache.maven.plugins 85 | maven-compiler-plugin 86 | 87 | 1.7 88 | 1.7 89 | UTF8 90 | 91 | 92 | 93 | org.apache.maven.plugins 94 | maven-assembly-plugin 95 | 2.3 96 | 97 | false 98 | 99 | jar-with-dependencies 100 | 101 | 102 | 103 | org.cachestudy.writeitbyself.App 104 | 105 | 106 | 107 | 108 | 109 | make-assembly 110 | package 111 | 112 | assembly 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /cscache/src/main/java/org/cachestudy/writeitbyself/jsr107/CsCaching107Provider.java: -------------------------------------------------------------------------------- 1 | package org.cachestudy.writeitbyself.jsr107; 2 | 3 | import java.net.URI; 4 | import java.net.URISyntaxException; 5 | import java.util.Map; 6 | import java.util.Properties; 7 | import java.util.WeakHashMap; 8 | import java.util.concurrent.ConcurrentHashMap; 9 | import java.util.concurrent.ConcurrentMap; 10 | 11 | import javax.cache.CacheManager; 12 | import javax.cache.configuration.OptionalFeature; 13 | import javax.cache.spi.CachingProvider; 14 | 15 | public class CsCaching107Provider implements CachingProvider { 16 | private static final String DEFAULT_URI_STRING = "urn:X-cscache:jsr107-default-config"; 17 | 18 | private static final URI URI_DEFAULT; 19 | 20 | private final Map> cacheManagers = new WeakHashMap>(); 21 | 22 | static { 23 | try { 24 | URI_DEFAULT = new URI(DEFAULT_URI_STRING); 25 | } catch (URISyntaxException e) { 26 | throw new javax.cache.CacheException(e); 27 | } 28 | } 29 | 30 | @Override 31 | public void close() { 32 | // TODO Auto-generated method stub 33 | 34 | } 35 | 36 | @Override 37 | public void close(ClassLoader arg0) { 38 | // TODO Auto-generated method stub 39 | 40 | } 41 | 42 | @Override 43 | public void close(URI arg0, ClassLoader arg1) { 44 | // TODO Auto-generated method stub 45 | 46 | } 47 | 48 | @Override 49 | public CacheManager getCacheManager() { 50 | return getCacheManager(getDefaultURI(), getDefaultClassLoader(), null); 51 | } 52 | 53 | @Override 54 | public CacheManager getCacheManager(URI uri, ClassLoader classLoader) { 55 | return getCacheManager(uri, classLoader, getDefaultProperties()); 56 | } 57 | 58 | @Override 59 | public CacheManager getCacheManager(URI uri, ClassLoader classLoader, Properties properties) { 60 | uri = uri == null ? getDefaultURI() : uri; 61 | classLoader = classLoader == null ? getDefaultClassLoader() : classLoader; 62 | properties = properties == null ? new Properties() : cloneProperties(properties); 63 | 64 | ConcurrentMap cacheManagersByURI = cacheManagers.get(classLoader); 65 | 66 | if (cacheManagersByURI == null) { 67 | cacheManagersByURI = new ConcurrentHashMap(); 68 | } 69 | 70 | CacheManager cacheManager = cacheManagersByURI.get(uri); 71 | 72 | if (cacheManager == null) { 73 | cacheManager = new CsCache107Manager(this, properties, classLoader, uri); 74 | 75 | cacheManagersByURI.put(uri, cacheManager); 76 | } 77 | 78 | if (!cacheManagers.containsKey(classLoader)) { 79 | cacheManagers.put(classLoader, cacheManagersByURI); 80 | } 81 | return cacheManager; 82 | } 83 | 84 | private static Properties cloneProperties(Properties properties) { 85 | Properties clone = new Properties(); 86 | for (Map.Entry entry : properties.entrySet()) { 87 | clone.put(entry.getKey(), entry.getValue()); 88 | } 89 | return clone; 90 | } 91 | 92 | @Override 93 | public ClassLoader getDefaultClassLoader() { 94 | return getClass().getClassLoader(); 95 | } 96 | 97 | @Override 98 | public Properties getDefaultProperties() { 99 | return new Properties(); 100 | } 101 | 102 | @Override 103 | public URI getDefaultURI() { 104 | return URI_DEFAULT; 105 | } 106 | 107 | @Override 108 | public boolean isSupported(OptionalFeature arg0) { 109 | // TODO Auto-generated method stub 110 | return false; 111 | } 112 | 113 | public void releaseCacheManager(URI uri, ClassLoader classLoader) { 114 | if (uri == null || classLoader == null) { 115 | throw new NullPointerException("uri or classLoader should not be null"); 116 | } 117 | 118 | ConcurrentMap cacheManagersByURI = cacheManagers.get(classLoader); 119 | if (cacheManagersByURI != null) { 120 | cacheManagersByURI.remove(uri); 121 | 122 | if (cacheManagersByURI.size() == 0) { 123 | cacheManagers.remove(classLoader); 124 | } 125 | } 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /cscache/src/main/java/org/cachestudy/writeitbyself/jsr107/CsCache107.java: -------------------------------------------------------------------------------- 1 | package org.cachestudy.writeitbyself.jsr107; 2 | 3 | import java.util.Iterator; 4 | import java.util.Map; 5 | import java.util.Set; 6 | 7 | import javax.cache.Cache; 8 | import javax.cache.CacheManager; 9 | import javax.cache.configuration.CacheEntryListenerConfiguration; 10 | import javax.cache.configuration.Configuration; 11 | import javax.cache.integration.CompletionListener; 12 | import javax.cache.processor.EntryProcessor; 13 | import javax.cache.processor.EntryProcessorException; 14 | import javax.cache.processor.EntryProcessorResult; 15 | 16 | import org.cachestudy.writeitbyself.CsCache; 17 | import org.cachestudy.writeitbyself.store.impl.BasicDataStore; 18 | 19 | public class CsCache107 implements Cache { 20 | 21 | private CsCache csCache = new CsCache(new BasicDataStore());; 22 | private volatile boolean isClosed; 23 | 24 | private String cacheName; 25 | 26 | private CsCache107Manager cacheManager; 27 | 28 | private Configuration configuration; 29 | 30 | public CsCache107(CsCache107Manager cacheManager, String cacheName, Configuration configuration) { 31 | this.cacheManager = cacheManager; 32 | this.cacheName = cacheName; 33 | 34 | this.configuration = configuration; 35 | 36 | this.isClosed = false; 37 | } 38 | 39 | @Override 40 | public void clear() { 41 | csCache.clear(); 42 | } 43 | 44 | @Override 45 | synchronized public void close() { 46 | if (!isClosed) { 47 | isClosed = true; 48 | 49 | if (cacheManager != null) 50 | cacheManager.releaseCache(cacheName); 51 | csCache.clear(); 52 | } 53 | } 54 | 55 | @Override 56 | public boolean containsKey(K arg0) { 57 | // TODO Auto-generated method stub 58 | return false; 59 | } 60 | 61 | @Override 62 | public void deregisterCacheEntryListener(CacheEntryListenerConfiguration arg0) { 63 | // TODO Auto-generated method stub 64 | 65 | } 66 | 67 | @Override 68 | public V get(K key) { 69 | return csCache.get(key); 70 | } 71 | 72 | @Override 73 | public Map getAll(Set arg0) { 74 | // TODO Auto-generated method stub 75 | return null; 76 | } 77 | 78 | @Override 79 | public V getAndPut(K arg0, V arg1) { 80 | // TODO Auto-generated method stub 81 | return null; 82 | } 83 | 84 | @Override 85 | public V getAndRemove(K arg0) { 86 | // TODO Auto-generated method stub 87 | return null; 88 | } 89 | 90 | @Override 91 | public V getAndReplace(K arg0, V arg1) { 92 | // TODO Auto-generated method stub 93 | return null; 94 | } 95 | 96 | @Override 97 | public CacheManager getCacheManager() { 98 | return this.cacheManager; 99 | } 100 | 101 | @SuppressWarnings("unchecked") 102 | @Override 103 | public > C getConfiguration(Class arg0) { 104 | return (C) this.configuration; 105 | } 106 | 107 | @Override 108 | public String getName() { 109 | return this.cacheName; 110 | } 111 | 112 | @Override 113 | public T invoke(K arg0, EntryProcessor arg1, Object... arg2) throws EntryProcessorException { 114 | // TODO Auto-generated method stub 115 | return null; 116 | } 117 | 118 | @Override 119 | public Map> invokeAll(Set arg0, EntryProcessor arg1, 120 | Object... arg2) { 121 | // TODO Auto-generated method stub 122 | return null; 123 | } 124 | 125 | @Override 126 | public boolean isClosed() { 127 | // TODO Auto-generated method stub 128 | return false; 129 | } 130 | 131 | @Override 132 | public Iterator> iterator() { 133 | // TODO Auto-generated method stub 134 | return null; 135 | } 136 | 137 | @Override 138 | public void loadAll(Set arg0, boolean arg1, CompletionListener arg2) { 139 | // TODO Auto-generated method stub 140 | 141 | } 142 | 143 | @Override 144 | public void put(K key, V value) { 145 | this.csCache.put(key, value); 146 | 147 | } 148 | 149 | @Override 150 | public void putAll(Map arg0) { 151 | // TODO Auto-generated method stub 152 | 153 | } 154 | 155 | @Override 156 | public boolean putIfAbsent(K arg0, V arg1) { 157 | // TODO Auto-generated method stub 158 | return false; 159 | } 160 | 161 | @Override 162 | public void registerCacheEntryListener(CacheEntryListenerConfiguration arg0) { 163 | // TODO Auto-generated method stub 164 | 165 | } 166 | 167 | @Override 168 | public boolean remove(K key) { 169 | csCache.remove(key); 170 | return true; 171 | } 172 | 173 | @Override 174 | public boolean remove(K arg0, V arg1) { 175 | // TODO Auto-generated method stub 176 | return false; 177 | } 178 | 179 | @Override 180 | public void removeAll() { 181 | // TODO Auto-generated method stub 182 | 183 | } 184 | 185 | @Override 186 | public void removeAll(Set arg0) { 187 | // TODO Auto-generated method stub 188 | 189 | } 190 | 191 | @Override 192 | public boolean replace(K arg0, V arg1) { 193 | // TODO Auto-generated method stub 194 | return false; 195 | } 196 | 197 | @Override 198 | public boolean replace(K arg0, V arg1, V arg2) { 199 | // TODO Auto-generated method stub 200 | return false; 201 | } 202 | 203 | @SuppressWarnings("unchecked") 204 | @Override 205 | public T unwrap(Class clazz) { 206 | if (clazz.isAssignableFrom(csCache.getClass())) { 207 | return (T) this.csCache; 208 | } 209 | 210 | throw new IllegalArgumentException("Unwrapping to " + clazz + " is not " + "supported by this implementation"); 211 | } 212 | 213 | } 214 | -------------------------------------------------------------------------------- /cscache/src/main/java/org/cachestudy/writeitbyself/jsr107/CsCache107Manager.java: -------------------------------------------------------------------------------- 1 | package org.cachestudy.writeitbyself.jsr107; 2 | 3 | import java.net.URI; 4 | import java.util.ArrayList; 5 | import java.util.Collections; 6 | import java.util.Properties; 7 | import java.util.concurrent.ConcurrentHashMap; 8 | import java.util.concurrent.ConcurrentMap; 9 | 10 | import javax.cache.Cache; 11 | import javax.cache.CacheException; 12 | import javax.cache.CacheManager; 13 | import javax.cache.configuration.Configuration; 14 | import javax.cache.spi.CachingProvider; 15 | 16 | import org.slf4j.Logger; 17 | import org.slf4j.LoggerFactory; 18 | 19 | public class CsCache107Manager implements CacheManager { 20 | 21 | private final CsCaching107Provider cachingProvider; 22 | private final ClassLoader classLoader; 23 | private final URI uri; 24 | private final Properties props; 25 | private volatile boolean isClosed; 26 | 27 | private static Logger logger = LoggerFactory.getLogger(CacheManager.class); 28 | 29 | private final ConcurrentMap> caches = new ConcurrentHashMap>(); 30 | 31 | public CsCache107Manager(CsCaching107Provider cachingProvider, Properties props, ClassLoader classLoader, URI uri) { 32 | this.cachingProvider = cachingProvider; 33 | this.classLoader = classLoader; 34 | this.uri = uri; 35 | this.props = props; 36 | } 37 | 38 | @Override 39 | synchronized public void close() { 40 | if (!isClosed()) { 41 | cachingProvider.releaseCacheManager(getURI(), getClassLoader()); 42 | 43 | isClosed = true; 44 | 45 | ArrayList> cacheList = new ArrayList>(caches.values()); 46 | caches.clear(); 47 | 48 | for (Cache cache : cacheList) { 49 | try { 50 | cache.close(); 51 | } catch (Exception e) { 52 | logger.warn("cannot close cache : " + cache, e); 53 | } 54 | } 55 | } 56 | } 57 | 58 | @SuppressWarnings("unchecked") 59 | @Override 60 | synchronized public > Cache createCache(String cacheName, C configuration) 61 | throws IllegalArgumentException { 62 | if (isClosed()) { 63 | throw new IllegalStateException(); 64 | } 65 | 66 | checkNotNull(cacheName, "cacheName"); 67 | checkNotNull(configuration, "configuration"); 68 | 69 | CsCache107 cache = caches.get(cacheName); 70 | 71 | if (cache == null) { 72 | cache = new CsCache107(this, cacheName, configuration); 73 | caches.put(cache.getName(), cache); 74 | 75 | return (Cache) cache; 76 | } else { 77 | throw new CacheException("A cache named " + cacheName + " already exists."); 78 | } 79 | } 80 | 81 | @Override 82 | synchronized public void destroyCache(String cacheName) { 83 | if (isClosed()) { 84 | throw new IllegalStateException(); 85 | } 86 | 87 | checkNotNull(cacheName, "cacheName"); 88 | 89 | Cache cache = caches.get(cacheName); 90 | 91 | if (cache != null) { 92 | cache.close(); 93 | } 94 | } 95 | 96 | private void checkNotNull(Object object, String name) { 97 | if (object == null) { 98 | throw new NullPointerException(name + " can not be null"); 99 | } 100 | } 101 | 102 | @Override 103 | public void enableManagement(String arg0, boolean arg1) { 104 | // TODO Auto-generated method stub 105 | 106 | } 107 | 108 | @Override 109 | public void enableStatistics(String arg0, boolean arg1) { 110 | // TODO Auto-generated method stub 111 | 112 | } 113 | 114 | @SuppressWarnings("unchecked") 115 | @Override 116 | public Cache getCache(String cacheName) { 117 | return (Cache) getCache(cacheName, Object.class, Object.class); 118 | } 119 | 120 | @SuppressWarnings("unchecked") 121 | @Override 122 | public Cache getCache(String cacheName, Class keyClazz, Class valueClazz) { 123 | if (isClosed()) { 124 | throw new IllegalStateException(); 125 | } 126 | 127 | checkNotNull(keyClazz, "keyType"); 128 | checkNotNull(valueClazz, "valueType"); 129 | 130 | CsCache107 cache = (CsCache107) caches.get(cacheName); 131 | 132 | if (cache == null) { 133 | return null; 134 | } else { 135 | Configuration configuration = cache.getConfiguration(Configuration.class); 136 | 137 | if (configuration.getKeyType() != null && configuration.getKeyType().equals(keyClazz)) { 138 | if (configuration.getValueType() != null && configuration.getValueType().equals(valueClazz)) { 139 | return cache; 140 | } else { 141 | throw new ClassCastException("Incompatible cache value types specified, expected " 142 | + configuration.getValueType() + " but " + keyClazz + " was specified"); 143 | } 144 | } else { 145 | throw new ClassCastException("Incompatible cache key types specified, expected " 146 | + configuration.getKeyType() + " but " + valueClazz + " was specified"); 147 | } 148 | } 149 | } 150 | 151 | @Override 152 | public Iterable getCacheNames() { 153 | if (isClosed()) { 154 | throw new IllegalStateException(); 155 | } 156 | 157 | return Collections.unmodifiableList(new ArrayList(caches.keySet())); 158 | } 159 | 160 | @Override 161 | public CachingProvider getCachingProvider() { 162 | return cachingProvider; 163 | } 164 | 165 | @Override 166 | public ClassLoader getClassLoader() { 167 | return this.classLoader; 168 | } 169 | 170 | @Override 171 | public Properties getProperties() { 172 | return this.props; 173 | } 174 | 175 | @Override 176 | public URI getURI() { 177 | return this.uri; 178 | } 179 | 180 | @Override 181 | public boolean isClosed() { 182 | return isClosed; 183 | } 184 | 185 | @Override 186 | public T unwrap(Class clazz) { 187 | if (clazz.isAssignableFrom(getClass())) { 188 | return clazz.cast(this); 189 | } 190 | 191 | throw new IllegalArgumentException("Unwapping to " + clazz + " is not a supported by this implementation"); 192 | } 193 | 194 | synchronized public void releaseCache(String cacheName) { 195 | if (cacheName == null) { 196 | throw new NullPointerException(); 197 | } 198 | 199 | caches.remove(cacheName); 200 | } 201 | 202 | } 203 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------