Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding new TLP as per INFRA-5163

  • Loading branch information...
commit 316ba3203ae7649ce941df88a2237d66d00d1556 0 parents
Tony Stevenson authored
Showing with 55,707 additions and 0 deletions.
  1. +8 −0 .gitignore
  2. +10 −0 DISCLAIMER
  3. +247 −0 LICENSE
  4. +11 −0 NOTICE
  5. +13 −0 README
  6. +15 −0 directmemory-cache/bench.bat
  7. +16 −0 directmemory-cache/bench.sh
  8. +132 −0 directmemory-cache/pom.xml
  9. +196 −0 directmemory-cache/src/main/aspect/org/apache/directmemory/monitoring/Performance.aj
  10. +180 −0 directmemory-cache/src/main/java/org/apache/directmemory/DirectMemory.java
  11. +154 −0 directmemory-cache/src/main/java/org/apache/directmemory/cache/Cache.java
  12. +93 −0 directmemory-cache/src/main/java/org/apache/directmemory/cache/CacheService.java
  13. +357 −0 directmemory-cache/src/main/java/org/apache/directmemory/cache/CacheServiceImpl.java
  14. +23 −0 directmemory-cache/src/main/java/org/apache/directmemory/cache/package-info.java
  15. +31 −0 directmemory-cache/src/main/java/org/apache/directmemory/measures/Every.java
  16. +40 −0 directmemory-cache/src/main/java/org/apache/directmemory/measures/Expires.java
  17. +31 −0 directmemory-cache/src/main/java/org/apache/directmemory/measures/For.java
  18. +26 −0 directmemory-cache/src/main/java/org/apache/directmemory/measures/Heap.java
  19. +92 −0 directmemory-cache/src/main/java/org/apache/directmemory/measures/In.java
  20. +26 −0 directmemory-cache/src/main/java/org/apache/directmemory/measures/Memory.java
  21. +118 −0 directmemory-cache/src/main/java/org/apache/directmemory/measures/Monitor.java
  22. +58 −0 directmemory-cache/src/main/java/org/apache/directmemory/measures/MonitorService.java
  23. +158 −0 directmemory-cache/src/main/java/org/apache/directmemory/measures/MonitorServiceImpl.java
  24. +26 −0 directmemory-cache/src/main/java/org/apache/directmemory/measures/Ram.java
  25. +64 −0 directmemory-cache/src/main/java/org/apache/directmemory/measures/Sizing.java
  26. +26 −0 directmemory-cache/src/main/java/org/apache/directmemory/measures/Space.java
  27. +23 −0 directmemory-cache/src/main/java/org/apache/directmemory/measures/package-info.java
  28. +59 −0 directmemory-cache/src/main/java/org/apache/directmemory/memory/AllocationPolicy.java
  29. +90 −0 directmemory-cache/src/main/java/org/apache/directmemory/memory/MemoryManager.java
  30. +88 −0 directmemory-cache/src/main/java/org/apache/directmemory/memory/MemoryManagerService.java
  31. +387 −0 directmemory-cache/src/main/java/org/apache/directmemory/memory/MemoryManagerServiceImpl.java
  32. +67 −0 directmemory-cache/src/main/java/org/apache/directmemory/memory/Pointer.java
  33. +199 −0 directmemory-cache/src/main/java/org/apache/directmemory/memory/PointerImpl.java
  34. +107 −0 directmemory-cache/src/main/java/org/apache/directmemory/memory/RoundRobinAllocationPolicy.java
  35. +70 −0 directmemory-cache/src/main/java/org/apache/directmemory/memory/allocator/AbstractByteBufferAllocator.java
  36. +63 −0 directmemory-cache/src/main/java/org/apache/directmemory/memory/allocator/ByteBufferAllocator.java
  37. +61 −0 directmemory-cache/src/main/java/org/apache/directmemory/memory/allocator/DirectByteBufferUtils.java
  38. +221 −0 ...ctmemory-cache/src/main/java/org/apache/directmemory/memory/allocator/FixedSizeByteBufferAllocatorImpl.java
  39. +431 −0 directmemory-cache/src/main/java/org/apache/directmemory/memory/allocator/MergingByteBufferAllocatorImpl.java
  40. +215 −0 directmemory-cache/src/main/java/org/apache/directmemory/memory/allocator/SlabByteBufferAllocatorImpl.java
  41. +23 −0 directmemory-cache/src/main/java/org/apache/directmemory/memory/package-info.java
  42. +23 −0 directmemory-cache/src/main/java/org/apache/directmemory/package-info.java
  43. +33 −0 directmemory-cache/src/main/java/org/apache/directmemory/serialization/Serializer.java
  44. +122 −0 directmemory-cache/src/main/java/org/apache/directmemory/serialization/SerializerFactory.java
  45. +43 −0 directmemory-cache/src/main/java/org/apache/directmemory/serialization/SerializerNotFoundException.java
  46. +75 −0 directmemory-cache/src/main/java/org/apache/directmemory/serialization/StandardSerializer.java
  47. +23 −0 directmemory-cache/src/main/java/org/apache/directmemory/serialization/package-info.java
  48. +18 −0 directmemory-cache/src/main/resources/META-INF/services/org.apache.directmemory.serialization.Serializer
  49. +257 −0 directmemory-cache/src/test/java/org/apache/directmemory/cache/CacheConcurrentTest.java
  50. +268 −0 directmemory-cache/src/test/java/org/apache/directmemory/cache/CacheLightConcurrentTest.java
  51. +125 −0 directmemory-cache/src/test/java/org/apache/directmemory/cache/CacheServiceImplTest.java
  52. +77 −0 directmemory-cache/src/test/java/org/apache/directmemory/cache/TestCachePlusSerialization.java
  53. +407 −0 directmemory-cache/src/test/java/org/apache/directmemory/memory/AbstractMemoryManagerServiceTest.java
  54. +237 −0 directmemory-cache/src/test/java/org/apache/directmemory/memory/BaseTest.java
  55. +240 −0 directmemory-cache/src/test/java/org/apache/directmemory/memory/Concurrent2Test.java
  56. +266 −0 directmemory-cache/src/test/java/org/apache/directmemory/memory/Concurrent3Test.java
  57. +239 −0 directmemory-cache/src/test/java/org/apache/directmemory/memory/ConcurrentTest.java
  58. +34 −0 directmemory-cache/src/test/java/org/apache/directmemory/memory/DefaultMemoryManagerServiceTest.java
  59. +199 −0 directmemory-cache/src/test/java/org/apache/directmemory/memory/MallocTest.java
  60. +202 −0 directmemory-cache/src/test/java/org/apache/directmemory/memory/MemoryManagerServiceImplTest.java
  61. +106 −0 directmemory-cache/src/test/java/org/apache/directmemory/memory/MemoryManagerTest.java
  62. +41 −0 directmemory-cache/src/test/java/org/apache/directmemory/memory/MemoryTestUtils.java
  63. +89 −0 directmemory-cache/src/test/java/org/apache/directmemory/memory/NIOTest.java
  64. +152 −0 directmemory-cache/src/test/java/org/apache/directmemory/memory/RoundRobinAllocationPolicyTest.java
  65. +79 −0 directmemory-cache/src/test/java/org/apache/directmemory/memory/SlabMemoryManagerServiceTest.java
  66. +132 −0 directmemory-cache/src/test/java/org/apache/directmemory/memory/Starter.java
  67. +130 −0 ...mory-cache/src/test/java/org/apache/directmemory/memory/allocator/FixedSizeByteBufferAllocatorImplTest.java
  68. +188 −0 ...memory-cache/src/test/java/org/apache/directmemory/memory/allocator/MergingByteBufferAllocatorImplTest.java
  69. +76 −0 directmemory-cache/src/test/java/org/apache/directmemory/memory/allocator/SlabByteBufferAllocatorImplTest.java
  70. +50 −0 directmemory-cache/src/test/java/org/apache/directmemory/misc/DummyPojo.java
  71. +211 −0 directmemory-cache/src/test/java/org/apache/directmemory/preliminary/MicroBenchmark.java
  72. +236 −0 directmemory-cache/src/test/java/org/apache/directmemory/preliminary/PreliminarBenchmark.java
  73. +69 −0 directmemory-cache/src/test/java/org/apache/directmemory/serialization/DummyPojoSerializer.java
  74. +41 −0 directmemory-cache/src/test/java/org/apache/directmemory/serialization/SerializerFactoryTestCase.java
  75. +85 −0 directmemory-cache/src/test/java/org/apache/directmemory/serialization/SerializerTest.java
  76. +215 −0 directmemory-cache/src/test/java/org/apache/directmemory/serialization/StandardSerializerTest.java
  77. +49 −0 directmemory-cache/src/test/resources/logback-test.xml
  78. +48 −0 directmemory-tests/pom.xml
  79. +73 −0 directmemory-tests/src/main/java/org/apache/directmemory/test/AbstractSerializerTest.java
  80. +64 −0 directmemory-tests/src/main/java/org/apache/directmemory/test/Wine.java
  81. +34 −0 directmemory-tests/src/test/java/org/apache/directmemory/test/StandardSerializerTest.java
  82. +39 −0 examples/pom.xml
  83. +83 −0 examples/server-example/pom.xml
  84. +41 −0 examples/server-example/src/main/resources/log4j.xml
  85. +37 −0 examples/server-example/src/main/webapp/WEB-INF/web.xml
  86. +4,983 −0 examples/server-example/src/main/webapp/css/bootstrap.2.0.4.css
  87. +137 −0 examples/server-example/src/main/webapp/index.html
  88. +1,825 −0 examples/server-example/src/main/webapp/js/bootstrap.2.0.4.js
  89. +9,404 −0 examples/server-example/src/main/webapp/js/jquery-1.7.2.js
  90. +484 −0 examples/server-example/src/main/webapp/js/jquery-tmpl.js
  91. +193 −0 examples/server-example/src/main/webapp/js/jquery.json-2.3.js
  92. +155 −0 examples/server-example/src/main/webapp/js/sample.js
  93. +18 −0 init-git-svn.sh
  94. +80 −0 integrations/ehcache/pom.xml
  95. +120 −0 integrations/ehcache/src/main/java/net/sf/ehcache/store/offheap/OffHeapStore.java
  96. +177 −0 integrations/ehcache/src/main/java/org/apache/directmemory/ehcache/DirectMemoryCache.java
  97. +600 −0 integrations/ehcache/src/main/java/org/apache/directmemory/ehcache/DirectMemoryStore.java
  98. +73 −0 integrations/ehcache/src/main/java/org/apache/directmemory/ehcache/NotifyingDirectMemoryStore.java
  99. +103 −0 integrations/ehcache/src/test/java/org/apache/directmemory/ehcache/EHCacheTest.java
  100. +31 −0 integrations/ehcache/src/test/resources/ehcache.xml
  101. +54 −0 integrations/ehcache/src/test/resources/logback-test.xml
  102. +55 −0 integrations/guice/pom.xml
  103. +67 −0 integrations/guice/src/main/java/org/apache/directmemory/guice/CacheServiceProvider.java
  104. +42 −0 integrations/guice/src/main/java/org/apache/directmemory/guice/DirectMemoryModule.java
  105. +54 −0 integrations/pom.xml
  106. +103 −0 integrations/solr/pom.xml
  107. +320 −0 integrations/solr/src/main/java/org/apache/directmemory/solr/SolrOffHeapCache.java
  108. +23 −0 integrations/solr/src/main/java/org/apache/directmemory/solr/package-info.java
  109. +102 −0 integrations/solr/src/test/java/org/apache/directmemory/solr/SolrOffHeapCacheTest.java
  110. +92 −0 integrations/solr/src/test/java/org/apache/directmemory/solr/SolrOffHeapIntegrationTest.java
  111. +34 −0 integrations/solr/src/test/resources/logback-test.xml
  112. +31 −0 integrations/solr/src/test/resources/solr/conf/admin-extra.html
  113. +38 −0 integrations/solr/src/test/resources/solr/conf/elevate.xml
  114. +246 −0 integrations/solr/src/test/resources/solr/conf/mapping-ISOLatin1Accent.txt
  115. +21 −0 integrations/solr/src/test/resources/solr/conf/protwords.txt
  116. +581 −0 integrations/solr/src/test/resources/solr/conf/schema.xml
  117. +24 −0 integrations/solr/src/test/resources/solr/conf/scripts.conf
  118. +671 −0 integrations/solr/src/test/resources/solr/conf/solrconfig.xml
  119. +58 −0 integrations/solr/src/test/resources/solr/conf/stopwords.txt
  120. +31 −0 integrations/solr/src/test/resources/solr/conf/synonyms.txt
  121. +143 −0 integrations/solr/src/test/resources/solr/conf/xslt/example.xsl
  122. +74 −0 integrations/solr/src/test/resources/solr/conf/xslt/example_atom.xsl
  123. +70 −0 integrations/solr/src/test/resources/solr/conf/xslt/example_rss.xsl
  124. +382 −0 integrations/solr/src/test/resources/solr/conf/xslt/luke.xsl
  125. +21 −0 integrations/solr/src/test/resources/solr/protwords.txt
  126. +58 −0 integrations/solr/src/test/resources/solr/stopwords.txt
  127. +31 −0 integrations/solr/src/test/resources/solr/synonyms.txt
  128. +111 −0 itests/osgi/pom.xml
  129. +213 −0 itests/osgi/src/test/java/org/apache/directmemory/tests/osgi/DirectMemoryOsgiTestSupport.java
  130. +65 −0 itests/osgi/src/test/java/org/apache/directmemory/tests/osgi/cache/CacheServiceExportingActivator.java
  131. +127 −0 itests/osgi/src/test/java/org/apache/directmemory/tests/osgi/cache/CacheServiceTest.java
  132. +115 −0 itests/osgi/src/test/java/org/apache/directmemory/tests/osgi/cache/CacheTest.java
  133. +88 −0 itests/osgi/src/test/java/org/apache/directmemory/tests/osgi/cache/SimpleObject.java
  134. +143 −0 itests/osgi/src/test/java/org/apache/directmemory/tests/osgi/ehcache/EhCacheTest.java
  135. +31 −0 itests/osgi/src/test/resources/ehcache.xml
  136. +37 −0 itests/pom.xml
  137. +115 −0 platforms/karaf/pom.xml
  138. +67 −0 platforms/karaf/src/main/resources/features.xml
  139. +39 −0 platforms/pom.xml
  140. +929 −0 pom.xml
  141. +77 −0 serializers/msgpack/pom.xml
  142. +80 −0 serializers/msgpack/src/main/java/org/apache/directmemory/serialization/msgpack/MessagePackSerializer.java
  143. +23 −0 serializers/msgpack/src/main/java/org/apache/directmemory/serialization/msgpack/package-info.java
  144. +18 −0 serializers/msgpack/src/main/resources/META-INF/services/org.apache.directmemory.serialization.Serializer
  145. +34 −0 serializers/msgpack/src/test/java/org/apache/directmemory/serialization/msgpack/MessagePackSerializerTest.java
  146. +54 −0 serializers/pom.xml
  147. +81 −0 serializers/protobuf/pom.xml
  148. +107 −0 serializers/protobuf/src/main/java/org/apache/directmemory/serialization/protobuf/ProtobufSerializer.java
  149. +23 −0 serializers/protobuf/src/main/java/org/apache/directmemory/serialization/protobuf/package-info.java
  150. +18 −0 serializers/protobuf/src/main/resources/META-INF/services/org.apache.directmemory.serialization.Serializer
  151. +88 −0 serializers/protostuff/pom.xml
  152. +78 −0 ...izers/protostuff/src/main/java/org/apache/directmemory/serialization/protostuff/ProtoStuffSerializerV1.java
  153. +117 −0 ...ff/src/main/java/org/apache/directmemory/serialization/protostuff/ProtoStuffWithLinkedBufferSerializer.java
  154. +23 −0 serializers/protostuff/src/main/java/org/apache/directmemory/serialization/protostuff/package-info.java
  155. +19 −0 serializers/protostuff/src/main/resources/META-INF/services/org.apache.directmemory.serialization.Serializer
  156. +52 −0 serializers/protostuff/src/test/java/org/apache/directmemory/serialization/protostuff/DummyPojo.java
  157. +35 −0 ...zers/protostuff/src/test/java/org/apache/directmemory/serialization/protostuff/ProtostufSerializerTest.java
  158. +78 −0 serializers/protostuff/src/test/java/org/apache/directmemory/serialization/protostuff/ProtostuffTestCase.java
  159. +69 −0 server/directmemory-server-archetype/pom.xml
  160. +52 −0 server/directmemory-server-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
  161. +6 −0 server/directmemory-server-archetype/src/main/resources/archetype-resources/README
  162. +96 −0 server/directmemory-server-archetype/src/main/resources/archetype-resources/pom.xml
  163. +44 −0 server/directmemory-server-archetype/src/main/resources/archetype-resources/src/main/resources/log4j.xml
  164. +40 −0 server/directmemory-server-archetype/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
  165. +4,067 −0 ...irectmemory-server-archetype/src/main/resources/archetype-resources/src/main/webapp/css/bootstrap.2.0.1.css
  166. +140 −0 server/directmemory-server-archetype/src/main/resources/archetype-resources/src/main/webapp/index.html
  167. +1,729 −0 .../directmemory-server-archetype/src/main/resources/archetype-resources/src/main/webapp/js/bootstrap.2.0.1.js
  168. +9,266 −0 server/directmemory-server-archetype/src/main/resources/archetype-resources/src/main/webapp/js/jquery-1.7.1.js
  169. +484 −0 server/directmemory-server-archetype/src/main/resources/archetype-resources/src/main/webapp/js/jquery-tmpl.js
  170. +193 −0 .../directmemory-server-archetype/src/main/resources/archetype-resources/src/main/webapp/js/jquery.json-2.3.js
  171. +149 −0 server/directmemory-server-archetype/src/main/resources/archetype-resources/src/main/webapp/js/sample.js
  172. +5 −0 server/directmemory-server-archetype/src/test/resources/projects/basic/archetype.properties
  173. 0  server/directmemory-server-archetype/src/test/resources/projects/basic/goal.txt
  174. +80 −0 server/directmemory-server-client/pom.xml
  175. +156 −0 ...emory-server-client/src/main/java/org/apache/directmemory/server/client/AbstractDirectMemoryHttpClient.java
  176. +122 −0 ...rectmemory-server-client/src/main/java/org/apache/directmemory/server/client/DefaultDirectMemoryClient.java
  177. +83 −0 server/directmemory-server-client/src/main/java/org/apache/directmemory/server/client/DirectMemoryClient.java
  178. +159 −0 ...rectmemory-server-client/src/main/java/org/apache/directmemory/server/client/DirectMemoryClientBuilder.java
  179. +222 −0 ...mory-server-client/src/main/java/org/apache/directmemory/server/client/DirectMemoryClientConfiguration.java
  180. +53 −0 .../directmemory-server-client/src/main/java/org/apache/directmemory/server/client/DirectMemoryHttpClient.java
  181. +242 −0 .../org/apache/directmemory/server/client/providers/asynchttpclient/AsyncHttpClientDirectMemoryHttpClient.java
  182. +53 −0 ...rc/main/java/org/apache/directmemory/server/client/providers/asynchttpclient/DirectMemoryDeleteHandler.java
  183. +64 −0 ...t/src/main/java/org/apache/directmemory/server/client/providers/asynchttpclient/DirectMemoryGetHandler.java
  184. +61 −0 ...t/src/main/java/org/apache/directmemory/server/client/providers/asynchttpclient/DirectMemoryPutHandler.java
  185. +241 −0 .../main/java/org/apache/directmemory/server/client/providers/httpclient/HttpClientDirectMemoryHttpClient.java
  186. +97 −0 server/directmemory-server-commons/pom.xml
  187. +80 −0 ...emory-server-commons/src/main/java/org/apache/directmemory/server/commons/AbstractDirectMemoryExchange.java
  188. +44 −0 ...directmemory-server-commons/src/main/java/org/apache/directmemory/server/commons/DirectMemoryConstants.java
  189. +37 −0 ...directmemory-server-commons/src/main/java/org/apache/directmemory/server/commons/DirectMemoryException.java
  190. +39 −0 ...ctmemory-server-commons/src/main/java/org/apache/directmemory/server/commons/DirectMemoryHttpConstants.java
  191. +142 −0 ...er/directmemory-server-commons/src/main/java/org/apache/directmemory/server/commons/DirectMemoryParser.java
  192. +155 −0 ...r/directmemory-server-commons/src/main/java/org/apache/directmemory/server/commons/DirectMemoryRequest.java
  193. +112 −0 .../directmemory-server-commons/src/main/java/org/apache/directmemory/server/commons/DirectMemoryResponse.java
  194. +133 −0 ...er/directmemory-server-commons/src/main/java/org/apache/directmemory/server/commons/DirectMemoryWriter.java
  195. +60 −0 server/directmemory-server-commons/src/main/java/org/apache/directmemory/server/commons/ExchangeType.java
  196. +72 −0 ...irectmemory-server-commons/src/test/java/org/apache/directmemory/server/commons/DirectMemoryParserTest.java
  197. +105 −0 ...irectmemory-server-commons/src/test/java/org/apache/directmemory/server/commons/DirectMemoryWriterTest.java
  198. +3 −0  server/directmemory-server-commons/src/test/resources/cache-rq.json
  199. +1 −0  server/directmemory-server-commons/src/test/resources/cache-rs.json
  200. +33 −0 server/directmemory-server-commons/src/test/resources/logback-test.xml
  201. +159 −0 server/directmemory-server/pom.xml
  202. +40 −0 server/directmemory-server/src/main/java/org/apache/directmemory/server/services/ContentTypeHandler.java
  203. +271 −0 server/directmemory-server/src/main/java/org/apache/directmemory/server/services/DirectMemoryServlet.java
  204. +61 −0 ...ctmemory-server/src/main/java/org/apache/directmemory/server/services/JavaSerializedContentTypeHandler.java
  205. +66 −0 server/directmemory-server/src/main/java/org/apache/directmemory/server/services/JsonContentTypeHandler.java
  206. +112 −0 .../directmemory-server/src/main/java/org/apache/directmemory/server/services/TextPlainContentTypeHandler.java
  207. +241 −0 ...irectmemory-server/src/test/java/org/apache/directmemory/server/services/AbstractServletWithClientTest.java
  208. +63 −0 server/directmemory-server/src/test/java/org/apache/directmemory/server/services/AsyncHttpClientTest.java
  209. +295 −0 server/directmemory-server/src/test/java/org/apache/directmemory/server/services/DirectMemoryServletTest.java
  210. +49 −0 server/directmemory-server/src/test/java/org/apache/directmemory/server/services/ExtractKeyFromPathTest.java
  211. +41 −0 ...ectmemory-server/src/test/java/org/apache/directmemory/server/services/ServletWithClientBinaryTypeTest.java
  212. +34 −0 ...irectmemory-server/src/test/java/org/apache/directmemory/server/services/ServletWithClientJsonTypeTest.java
  213. +112 −0 ...memory-server/src/test/java/org/apache/directmemory/server/services/ServletWithClientTextPlainTypeTest.java
  214. +34 −0 server/directmemory-server/src/test/resources/logback-test.xml
  215. +73 −0 server/pom.xml
  216. +76 −0 src/main/assembly/source-release.xml
  217. +66 −0 src/site/apt/committer-environment.apt
  218. +63 −0 src/site/apt/ehcache-integration.apt.vm
  219. +54 −0 src/site/apt/javascript-caching.apt
  220. +55 −0 src/site/apt/privacy-policy.apt
  221. +168 −0 src/site/apt/releases/release-notes-0.1-incubating.apt
  222. +97 −0 src/site/apt/server-instance.apt.vm
  223. +65 −0 src/site/apt/simple-usage.apt.vm
  224. +18 −0 src/site/resources/css/site.css
Sorry, we could not display the entire diff because it was too big.
8 .gitignore
@@ -0,0 +1,8 @@
+target
+*.iml
+.idea
+.classpath
+.project
+.settings
+.DS_Store
+out
10 DISCLAIMER
@@ -0,0 +1,10 @@
+Apache DirectMemory is an effort undergoing incubation at the Apache Software
+Foundation (ASF), sponsored by the Apache Incubator PMC.
+
+Incubation is required of all newly accepted projects until a further review
+indicates that the infrastructure, communications, and decision making process
+have stabilized in a manner consistent with other successful ASF projects.
+
+While incubation status is not necessarily a reflection of the completeness
+or stability of the code, it does indicate that the project has yet to be
+fully endorsed by the ASF.
247 LICENSE
@@ -0,0 +1,247 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+APPENDIX II: Licenses for Incorporated Works.
+
+------
+jQuery, Jquery tmpl, jQuery JSON Plugin
+
+Copyright (c) 2011 John Resig, http://jquery.com/
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+------
+Bootstrap
+
+Copyright 2012 Twitter, Inc.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
11 NOTICE
@@ -0,0 +1,11 @@
+Apache DirectMemory
+Copyright 2001-2012 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
+This product includes software (bootstrap) developed by
+Twitter (http://twitter.github.com/bootstrap/).
+
+This product includes software (jquery) developed by
+Jquery (http://jquery.org/).
13 README
@@ -0,0 +1,13 @@
+Apache DirectMemory is a multi layered cache implementation featuring off-heap memory storage (a-la BigMemory)
+to enable caching of java objects without degrading jvm performance.
+Its main purpose is to act as a second level cache (after a heap based one)
+to collect large amounts of data without filling up the java heap and thus avoiding long garbage collection cycles.
+Included in the box is a small set of utility classes to easily handle off-heap memory buffers.
+
+------------
+Build
+------------
+You need Apache Maven to build the project. Just use: mvn clean install (you will have jars installed locally in your
+local Maven repository.
+
+NOTE: the buildnumber maven plugin which add a maven property with the current svn revision has been configured to work with svn 1.7
15 directmemory-cache/bench.bat
@@ -0,0 +1,15 @@
+rem Licensed to the Apache Software Foundation (ASF) under one or more
+rem contributor license agreements. See the NOTICE file distributed with
+rem this work for additional information regarding copyright ownership.
+rem The ASF licenses this file to You under the Apache License, Version 2.0
+rem (the "License"); you may not use this file except in compliance with
+rem the License. You may obtain a copy of the License at
+rem
+rem http://www.apache.org/licenses/LICENSE-2.0
+rem
+rem Unless required by applicable law or agreed to in writing, software
+rem distributed under the License is distributed on an "AS IS" BASIS,
+rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+rem See the License for the specific language governing permissions and
+rem limitations under the License.
+mvn test -Dtest=SerializerTest -Djub.customkey=%1 -Djub.consumers=CONSOLE,XML,H2 -Djub.db.file=data/benchmarks/database -Djub.xml.file=data/benchmarks/benchmarks.xml -Djub.charts.dir=data/benchmarks/graphs
16 directmemory-cache/bench.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+mvn test -Djub.customkey=$1 -Dtest=MicroBenchmarks -Djub.consumers=CONSOLE,XML,H2 -Djub.db.file=target/benchmarks/database -Djub.xml.file=target/logs/benchmarks.xml -Djub.charts.dir=target/data/benchmarks/graphs
132 directmemory-cache/pom.xml
@@ -0,0 +1,132 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.directmemory</groupId>
+ <artifactId>directmemory</artifactId>
+ <version>0.1-incubating</version>
+ <relativePath>../</relativePath>
+ </parent>
+
+ <artifactId>directmemory-cache</artifactId>
+ <name>Apache DirectMemory :: Cache</name>
+ <packaging>bundle</packaging>
+ <description>DirectMemory Cache is a multi layered cache implementation featuring off-heap memory management (a-la
+ BigMemory) to enable efficient handling of a large number of java objects without affecting jvm garbage collection
+ performance
+ </description>
+
+ <properties>
+ <osgi.import>
+ !org.apache.directmemory*,
+ com.google.common.collect;version="[9.0,11)",
+ com.google.common.base;version="[9.0,11)",
+ org.aspectj*;version="[1.6,2)",
+ org.slf4j*
+ </osgi.import>
+ <osgi.export>org.apache.directmemory*;version="${project.version}</osgi.export>
+ </properties>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-clean-plugin</artifactId>
+ <configuration>
+ <filesets>
+ <fileset>
+ <directory>logs</directory>
+ <followSymlinks>false</followSymlinks>
+ </fileset>
+ </filesets>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>aspectj-maven-plugin</artifactId>
+ <version>1.4</version>
+ <configuration>
+ <source>${maven.compile.source}</source>
+ <target>${maven.compile.target}</target>
+ <complianceLevel>${java.version}</complianceLevel>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>compile</goal>
+ <!-- use this goal to weave all your main classes -->
+ <goal>test-compile</goal>
+ <!-- use this goal to weave all your test classes -->
+ </goals>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjtools</artifactId>
+ <version>${aspectj.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjrt</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.carrotsearch</groupId>
+ <artifactId>junit-benchmarks</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
196 directmemory-cache/src/main/aspect/org/apache/directmemory/monitoring/Performance.aj
@@ -0,0 +1,196 @@
+package org.apache.directmemory.monitoring;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static java.lang.String.format;
+
+import org.apache.directmemory.cache.Cache;
+import org.apache.directmemory.measures.Monitor;
+import org.apache.directmemory.measures.MonitorService;
+import org.apache.directmemory.memory.Pointer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public aspect Performance
+{
+
+ public static final String cache_prefix = "cache";
+
+ public static final String cache_putByteArray = cache_prefix + ".putByteArray";
+
+ public static final String cache_retrieveByteArray = cache_prefix + ".retrieveByteArray";
+
+ public static final String cache_getPointer = cache_prefix + ".getPointer";
+
+ public static final String cache_putObject = cache_prefix + ".put";
+
+ public static final String cache_retrieveObject = cache_prefix + ".get";
+
+ public static final String cache_collectLFU = cache_prefix + ".collectLFU";
+
+ public static final String cache_collectExpired = cache_prefix + ".collectExpired";
+
+ public static final String cache_serialize = cache_prefix + ".serializer.serialize";
+
+ public static final String cache_deserialize = cache_prefix + ".serializer.deserialize";
+
+ private static Logger logger = LoggerFactory.getLogger( Cache.class );
+
+ pointcut putByteArrayPointcut( String key, byte[] payload ):
+ execution(Pointer org.apache.directmemory.cache.Cache.putByteArray(java.lang.String, byte[])) &&
+ args(key, payload);
+
+ pointcut putObjectPointcut( String key, Object object, int expiresIn ):
+ execution(Pointer org.apache.directmemory.cache.Cache.put(java.lang.String, java.lang.Object, int)) &&
+ args(key, object, expiresIn);
+
+ pointcut retrieveByteArrayPointcut( String key ):
+ execution(byte[] org.apache.directmemory.cache.Cache.retrieveByteArray(java.lang.String)) &&
+ args(key);
+
+ pointcut retrieveObjectPointcut( String key ):
+ execution(java.lang.Object org.apache.directmemory.cache.Cache.retrieve(java.lang.String)) &&
+ args(key);
+
+ pointcut getPointcut( String key ):
+ execution(Pointer org.apache.directmemory.cache.Cache.getPointer(java.lang.String)) &&
+ args(key);
+
+ pointcut collectLFUPointcut():
+ execution(void org.apache.directmemory.cache.Cache.collectLFU());
+
+ pointcut collectExpiredPointcut():
+ execution(void org.apache.directmemory.cache.Cache.collectExpired());
+
+ pointcut serializePointcut( Object obj, @SuppressWarnings( "rawtypes" ) Class clazz ):
+ execution(byte[] org.apache.directmemory.serialization.ProtoStuffSerializerV1.serialize(java.lang.Object, java.lang.Class)) &&
+ args(obj, clazz);
+
+ pointcut deserializePointcut( byte[] source, @SuppressWarnings( "rawtypes" ) Class clazz ):
+ execution(java.lang.Object org.apache.directmemory.serialization.ProtoStuffSerializerV1.deserialize(byte[], java.lang.Class)) &&
+ args(source, clazz);
+
+ Pointer around( String key, byte[] payload ): putByteArrayPointcut(key, payload) {
+ MonitorService mon = Monitor.get( cache_putByteArray );
+ final long startedAt = mon.start();
+ Pointer entry = proceed( key, payload );
+ if ( logger.isDebugEnabled() )
+ {
+ logger.debug( format( "put: [%s] %d bytes", key, payload.length ) );
+ }
+ mon.stop( startedAt );
+ return entry;
+ }
+
+ Pointer around( String key, Object object, int expiresIn ): putObjectPointcut(key, object, expiresIn) {
+ MonitorService mon = Monitor.get( cache_putObject );
+ final long startedAt = mon.start();
+ Pointer entry = proceed( key, object, expiresIn );
+ if ( logger.isDebugEnabled() )
+ {
+ logger.debug( format( "put object: [%s]", key ) );
+ }
+ mon.stop( startedAt );
+ return entry;
+ }
+
+ byte[] around( String key ): retrieveByteArrayPointcut(key) {
+ MonitorService mon = Monitor.get( cache_retrieveByteArray );
+ final long startedAt = mon.start();
+ byte[] payload = proceed( key );
+ if ( logger.isDebugEnabled() )
+ {
+ logger.debug( format( "retrieve: [%s]", key ) );
+ }
+ mon.stop( startedAt );
+ return payload;
+ }
+
+ Object around( String key ): retrieveObjectPointcut(key) {
+ MonitorService mon = Monitor.get( cache_retrieveObject );
+ final long startedAt = mon.start();
+ Object payload = proceed( key );
+ if ( logger.isDebugEnabled() )
+ {
+ logger.debug( format( "retrieve object: [%s]", key ) );
+ }
+ mon.stop( startedAt );
+ return payload;
+ }
+
+ Pointer around( String key ): getPointcut(key) {
+ MonitorService mon = Monitor.get( cache_getPointer );
+ final long startedAt = mon.start();
+ Pointer pointer = proceed( key );
+ if ( logger.isDebugEnabled() )
+ {
+ logger.debug( format( "get: [%s]", key ) );
+ }
+ mon.stop( startedAt );
+ return pointer;
+ }
+
+ void around(): collectLFUPointcut() {
+ MonitorService mon = Monitor.get( cache_collectLFU );
+ final long startedAt = mon.start();
+ proceed();
+ if ( logger.isDebugEnabled() )
+ {
+ logger.debug( "collect LFU" );
+ }
+ mon.stop( startedAt );
+ }
+
+ void around(): collectExpiredPointcut() {
+ MonitorService mon = Monitor.get( cache_collectExpired );
+ final long startedAt = mon.start();
+ proceed();
+ if ( logger.isDebugEnabled() )
+ {
+ logger.debug( "collect expired" );
+ }
+ mon.stop( startedAt );
+ }
+
+ byte[] around( Object obj, @SuppressWarnings( "rawtypes" ) Class clazz ): serializePointcut(obj, clazz) {
+ MonitorService mon = Monitor.get( cache_serialize );
+ final long startedAt = mon.start();
+ byte[] payload = proceed( obj, clazz );
+ if ( logger.isDebugEnabled() )
+ {
+ logger.debug( format( "serialize: [%s]", clazz.getSimpleName() ) );
+ }
+ mon.stop( startedAt );
+ return payload;
+ }
+
+ Object around( byte[] source, @SuppressWarnings( "rawtypes" ) Class clazz ): deserializePointcut(source, clazz) {
+ MonitorService mon = Monitor.get( cache_deserialize );
+ final long startedAt = mon.start();
+ Object obj = proceed( source, clazz );
+ if ( logger.isDebugEnabled() )
+ {
+ logger.debug( format( "deserialize: [%s]", clazz.getSimpleName() ) );
+ }
+ mon.stop( startedAt );
+ return obj;
+ }
+
+}
180 directmemory-cache/src/main/java/org/apache/directmemory/DirectMemory.java
@@ -0,0 +1,180 @@
+package org.apache.directmemory;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.lang.String.format;
+import static org.apache.directmemory.measures.In.seconds;
+import static org.apache.directmemory.serialization.SerializerFactory.createNewSerializer;
+
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.directmemory.cache.CacheService;
+import org.apache.directmemory.cache.CacheServiceImpl;
+import org.apache.directmemory.measures.Ram;
+import org.apache.directmemory.memory.MemoryManagerService;
+import org.apache.directmemory.memory.MemoryManagerServiceImpl;
+import org.apache.directmemory.memory.Pointer;
+import org.apache.directmemory.serialization.Serializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.MapMaker;
+
+public final class DirectMemory<K, V>
+{
+
+ public static final int DEFAULT_CONCURRENCY_LEVEL = 4;
+
+ public static final int DEFAULT_INITIAL_CAPACITY = 100000;
+
+ public static final int DEFAULT_DISPOSAL_TIME = 10; // seconds
+
+ private final Logger logger = LoggerFactory.getLogger( getClass() );
+
+ private int numberOfBuffers;
+
+ private int size;
+
+ private int initialCapacity = DEFAULT_INITIAL_CAPACITY;
+
+ private int concurrencyLevel = DEFAULT_CONCURRENCY_LEVEL;
+
+ private long disposalTime = seconds( DEFAULT_DISPOSAL_TIME );
+
+ private ConcurrentMap<K, Pointer<V>> map;
+
+ private Serializer serializer;
+
+ private MemoryManagerService<V> memoryManager;
+
+ public DirectMemory()
+ {
+ // does nothing
+ }
+
+ public DirectMemory( DirectMemory<K, V> prototype )
+ {
+ checkArgument( prototype != null, "Impossible to create a DirectMemory instance from a null prototype" );
+
+ numberOfBuffers = prototype.numberOfBuffers;
+ size = prototype.size;
+ initialCapacity = prototype.initialCapacity;
+ concurrencyLevel = prototype.concurrencyLevel;
+ disposalTime = prototype.disposalTime;
+
+ map = prototype.map;
+ serializer = prototype.serializer;
+ memoryManager = prototype.memoryManager;
+ }
+
+ public DirectMemory<K, V> setNumberOfBuffers( int numberOfBuffers )
+ {
+ checkArgument( numberOfBuffers > 0, "Impossible to create a CacheService with a number of buffers lesser than 1" );
+ this.numberOfBuffers = numberOfBuffers;
+ return this;
+ }
+
+ public DirectMemory<K, V> setSize( int size )
+ {
+ checkArgument( size > 0, "Impossible to create a CacheService with a size lesser than 1" );
+ this.size = size;
+ return this;
+ }
+
+ public DirectMemory<K, V> setInitialCapacity( int initialCapacity )
+ {
+ checkArgument( initialCapacity > 0, "Impossible to create a CacheService with an initialCapacity lesser than 1" );
+ this.initialCapacity = initialCapacity;
+ return this;
+ }
+
+ public DirectMemory<K, V> setConcurrencyLevel( int concurrencyLevel )
+ {
+ checkArgument( concurrencyLevel > 0, "Impossible to create a CacheService with a concurrencyLevel lesser than 1" );
+ this.concurrencyLevel = concurrencyLevel;
+ return this;
+ }
+
+ public DirectMemory<K, V> setDisposalTime( long disposalTime )
+ {
+ checkArgument( disposalTime > 0, "Impossible to create a CacheService with a disposalTime lesser than 1" );
+ this.disposalTime = disposalTime;
+ return this;
+ }
+
+ public DirectMemory<K, V> setMap( ConcurrentMap<K, Pointer<V>> map )
+ {
+ checkArgument( map != null, "Impossible to create a CacheService with a null map" );
+ this.map = map;
+ return this;
+ }
+
+ public DirectMemory<K, V> setSerializer( Serializer serializer )
+ {
+ checkArgument( serializer != null, "Impossible to create a CacheService with a null serializer" );
+ this.serializer = serializer;
+ return this;
+ }
+
+ public DirectMemory<K, V> setMemoryManager( MemoryManagerService<V> memoryManager )
+ {
+ checkArgument( memoryManager != null, "Impossible to create a CacheService with a null memoryManager" );
+ this.memoryManager = memoryManager;
+ return this;
+ }
+
+ public CacheService<K, V> newCacheService()
+ {
+ if ( map == null )
+ {
+ map = new MapMaker().concurrencyLevel( concurrencyLevel ).initialCapacity( initialCapacity ).makeMap();
+ }
+ if ( memoryManager == null )
+ {
+ memoryManager = new MemoryManagerServiceImpl<V>();
+ }
+ if ( serializer == null )
+ {
+ serializer = createNewSerializer();
+ }
+
+ logger.info( "******************************** initializing *******************************" );
+ logger.info( " ____ _ __ __ ___" );
+ logger.info( " / __ \\(_)________ _____/ /_/ |/ /___ ____ ___ ____ _______ __" );
+ logger.info( " / / / / // ___/ _ \\/ ___/ __/ /|_/ // _ \\/ __ `__ \\/ __ \\/ ___/ / / /" );
+ logger.info( " / /_/ / // / / __/ /__/ /_/ / / // __/ / / / / / /_/ / / / /_/ / " );
+ logger.info( " /_____/_//_/ \\___/\\___/\\__/_/ /_/ \\___/_/ /_/ /_/\\____/_/ \\__, /" );
+ logger.info( " /____/ " );
+ logger.info( "********************************************************************************" );
+
+ memoryManager.init( numberOfBuffers, size );
+
+ logger.info( "initialized" );
+ logger.info( format( "number of buffer(s): \t%1d with %2s each", numberOfBuffers, Ram.inMb( size ) ) );
+ logger.info( format( "initial capacity: \t%1d", initialCapacity ) );
+ logger.info( format( "concurrency level: \t%1d", concurrencyLevel ) );
+
+ CacheService<K, V> cacheService = new CacheServiceImpl<K, V>( map, memoryManager, serializer );
+ cacheService.scheduleDisposalEvery( disposalTime );
+ return cacheService;
+ }
+
+}
154 directmemory-cache/src/main/java/org/apache/directmemory/cache/Cache.java
@@ -0,0 +1,154 @@
+package org.apache.directmemory.cache;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import org.apache.directmemory.DirectMemory;
+import org.apache.directmemory.memory.MemoryManagerService;
+import org.apache.directmemory.memory.Pointer;
+import org.apache.directmemory.serialization.Serializer;
+
+public class Cache
+{
+
+ private static final DirectMemory<String, Object> builder = new DirectMemory<String, Object>();
+
+ private static CacheService<String, Object> cacheService = builder.newCacheService();
+
+ // olamy chicken and eggs isssue
+ // private static CacheService cacheService = new CacheServiceImpl( getMemoryManager());
+
+ private Cache()
+ {
+ // not instantiable
+ }
+
+ public static void scheduleDisposalEvery( long l )
+ {
+ // store to builder
+ builder.setDisposalTime( l );
+
+ cacheService.scheduleDisposalEvery( l );
+ }
+
+ public static void init( int numberOfBuffers, int size, int initialCapacity, int concurrencyLevel )
+ {
+ cacheService =
+ builder.setNumberOfBuffers( numberOfBuffers ).setInitialCapacity( initialCapacity ).setConcurrencyLevel(
+ concurrencyLevel ).setSize( size ).newCacheService();
+ }
+
+ public static void init( int numberOfBuffers, int size )
+ {
+ init( numberOfBuffers, size, DirectMemory.DEFAULT_INITIAL_CAPACITY, DirectMemory.DEFAULT_CONCURRENCY_LEVEL );
+ }
+
+ public static Pointer<Object> putByteArray( String key, byte[] payload, int expiresIn )
+ {
+ return cacheService.putByteArray( key, payload, expiresIn );
+ }
+
+ public static Pointer<Object> putByteArray( String key, byte[] payload )
+ {
+ return cacheService.putByteArray( key, payload );
+ }
+
+ public static Pointer<Object> put( String key, Object object )
+ {
+ return cacheService.put( key, object );
+ }
+
+ public static Pointer<Object> put( String key, Object object, int expiresIn )
+ {
+ return cacheService.put( key, object, expiresIn );
+ }
+
+ public static byte[] retrieveByteArray( String key )
+ {
+ return cacheService.retrieveByteArray( key );
+ }
+
+ public static Object retrieve( String key )
+ {
+ return cacheService.retrieve( key );
+ }
+
+ public static Pointer<Object> getPointer( String key )
+ {
+ return cacheService.getPointer( key );
+ }
+
+ public static void free( String key )
+ {
+ cacheService.free( key );
+ }
+
+ public static void free( Pointer<Object> pointer )
+ {
+ cacheService.free( pointer );
+ }
+
+ public static void collectExpired()
+ {
+ cacheService.collectExpired();
+ }
+
+ public static void collectLFU()
+ {
+ cacheService.collectLFU();
+ }
+
+ public static void collectAll()
+ {
+ cacheService.collectAll();
+ }
+
+
+ public static void clear()
+ {
+ cacheService.clear();
+ }
+
+ public static long entries()
+ {
+ return cacheService.entries();
+ }
+
+ public static void dump()
+ {
+ cacheService.dump();
+ }
+
+ public static Serializer getSerializer()
+ {
+ return cacheService.getSerializer();
+ }
+
+ public static MemoryManagerService<Object> getMemoryManager()
+ {
+ return cacheService.getMemoryManager();
+ }
+
+ public static Pointer<Object> allocate( String key, int size )
+ {
+ return cacheService.allocate( key, Object.class, size );
+ }
+
+}
93 directmemory-cache/src/main/java/org/apache/directmemory/cache/CacheService.java
@@ -0,0 +1,93 @@
+package org.apache.directmemory.cache;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import org.apache.directmemory.memory.MemoryManagerService;
+import org.apache.directmemory.memory.Pointer;
+import org.apache.directmemory.serialization.Serializer;
+
+import java.util.concurrent.ConcurrentMap;
+
+public interface CacheService<K, V>
+{
+
+ void scheduleDisposalEvery( long l );
+
+ /**
+ *
+ * @param key
+ * @param payload
+ * @param expiresIn in ms
+ * @return
+ */
+ Pointer<V> putByteArray( K key, byte[] payload, int expiresIn );
+
+ Pointer<V> putByteArray( K key, byte[] payload );
+
+ Pointer<V> put( K key, V value );
+
+ /**
+ *
+ * @param key
+ * @param value
+ * @param expiresIn in ms
+ * @return
+ */
+ Pointer<V> put( K key, V value, int expiresIn );
+
+ byte[] retrieveByteArray( K key );
+
+ V retrieve( K key );
+
+ Pointer<V> getPointer( K key );
+
+ void free( K key );
+
+ void free( Pointer<V> pointer );
+
+ void collectExpired();
+
+ void collectLFU();
+
+ void collectAll();
+
+
+ void clear();
+
+ long entries();
+
+ void dump();
+
+ ConcurrentMap<K, Pointer<V>> getMap();
+
+ void setMap( ConcurrentMap<K, Pointer<V>> map );
+
+ Serializer getSerializer();
+
+ MemoryManagerService<V> getMemoryManager();
+
+ void setMemoryManager( MemoryManagerService<V> memoryManager );
+
+ void setSerializer( Serializer serializer );
+
+ <T extends V> Pointer<V> allocate( K key, Class<T> type, int size );
+
+}
357 directmemory-cache/src/main/java/org/apache/directmemory/cache/CacheServiceImpl.java
@@ -0,0 +1,357 @@
+package org.apache.directmemory.cache;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.directmemory.measures.Ram;
+import org.apache.directmemory.memory.MemoryManagerService;
+import org.apache.directmemory.memory.Pointer;
+import org.apache.directmemory.serialization.Serializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.ConcurrentMap;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.lang.String.format;
+
+public class CacheServiceImpl<K, V>
+ implements CacheService<K, V>
+{
+
+ private static Logger logger = LoggerFactory.getLogger( CacheServiceImpl.class );
+
+ private ConcurrentMap<K, Pointer<V>> map;
+
+ private Serializer serializer;
+
+ private MemoryManagerService<V> memoryManager;
+
+ private final Timer timer = new Timer();
+
+ /**
+ * Constructor
+ */
+ public CacheServiceImpl( ConcurrentMap<K, Pointer<V>> map, MemoryManagerService<V> memoryManager,
+ Serializer serializer )
+ {
+ checkArgument( map != null, "Impossible to initialize the CacheService with a null map" );
+ checkArgument( memoryManager != null, "Impossible to initialize the CacheService with a null memoryManager" );
+ checkArgument( serializer != null, "Impossible to initialize the CacheService with a null serializer" );
+
+ this.map = map;
+ this.memoryManager = memoryManager;
+ this.serializer = serializer;
+ }
+
+ @Override
+ public void scheduleDisposalEvery( long l )
+ {
+ timer.schedule( new TimerTask()
+ {
+ public void run()
+ {
+ logger.info( "begin scheduled disposal" );
+
+ collectExpired();
+ collectLFU();
+
+ logger.info( "scheduled disposal complete" );
+ }
+ }, l, l );
+
+ logger.info( "disposal scheduled every {} milliseconds", l );
+ }
+
+ @Override
+ public Pointer<V> putByteArray( K key, byte[] payload )
+ {
+ return store( key, payload, 0 );
+ }
+
+ @Override
+ public Pointer<V> putByteArray( K key, byte[] payload, int expiresIn )
+ {
+ return store( key, payload, expiresIn );
+ }
+
+ @Override
+ public Pointer<V> put( K key, V value )
+ {
+ return put( key, value, 0 );
+ }
+
+ @Override
+ public Pointer<V> put( K key, V value, int expiresIn )
+ {
+ try
+ {
+ byte[] payload = serializer.serialize( value );
+ Pointer<V> ptr = store( key, payload, expiresIn );
+ if ( ptr != null )
+ {
+ @SuppressWarnings( "unchecked" ) // type driven by the compiler
+ Class<? extends V> clazz = (Class<? extends V>) value.getClass();
+
+ ptr.setClazz( clazz );
+ }
+ return ptr;
+ }
+ catch ( IOException e )
+ {
+
+ if ( logger.isDebugEnabled() )
+ {
+ logger.debug( "IOException put object in cache:{}", e.getMessage(), e );
+ }
+ else
+ {
+ logger.error( "IOException put object in cache:{}", e.getMessage() );
+ }
+ return null;
+ }
+ }
+
+ private Pointer<V> store( K key, byte[] payload, int expiresIn )
+ {
+ Pointer<V> pointer = map.get( key );
+ if ( pointer != null )
+ {
+ return memoryManager.update( pointer, payload );
+ }
+ else
+ {
+ pointer = memoryManager.store( payload, expiresIn );
+ if ( pointer != null )
+ {
+ map.put( key, pointer );
+ }
+ return pointer;
+ }
+ }
+
+ @Override
+ public byte[] retrieveByteArray( K key )
+ {
+ Pointer<V> ptr = getPointer( key );
+ if ( ptr == null )
+ {
+ return null;
+ }
+ if ( ptr.isExpired() || ptr.isFree() )
+ {
+ map.remove( key );
+ if ( !ptr.isFree() )
+ {
+ memoryManager.free( ptr );
+ }
+ return null;
+ }
+ else
+ {
+ return memoryManager.retrieve( ptr );
+ }
+ }
+
+ @Override
+ public V retrieve( K key )
+ {
+ Pointer<V> ptr = getPointer( key );
+ if ( ptr == null )
+ {
+ return null;
+ }
+ if ( ptr.isExpired() || ptr.isFree() )
+ {
+ map.remove( key );
+ if ( !ptr.isFree() )
+ {
+ memoryManager.free( ptr );
+ }
+ return null;
+ }
+ else
+ {
+ try
+ {
+ return serializer.deserialize( memoryManager.retrieve( ptr ), ptr.getClazz() );
+ }
+ catch ( EOFException e )
+ {
+ logger.error( e.getMessage() );
+ }
+ catch ( IOException e )
+ {
+ logger.error( e.getMessage() );
+ }
+ catch ( ClassNotFoundException e )
+ {
+ logger.error( e.getMessage() );
+ }
+ catch ( InstantiationException e )
+ {
+ logger.error( e.getMessage() );
+ }
+ catch ( IllegalAccessException e )
+ {
+ logger.error( e.getMessage() );
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Pointer<V> getPointer( K key )
+ {
+ return map.get( key );
+ }
+
+ @Override
+ public void free( K key )
+ {
+ Pointer<V> p = map.remove( key );
+ if ( p != null )
+ {
+ memoryManager.free( p );
+ }
+ }
+
+ @Override
+ public void free( Pointer<V> pointer )
+ {
+ memoryManager.free( pointer );
+ }
+
+ @Override
+ public void collectExpired()
+ {
+ memoryManager.collectExpired();
+ // still have to look for orphan (storing references to freed pointers) map entries
+ }
+
+ @Override
+ public void collectLFU()
+ {
+ memoryManager.collectLFU();
+ // can possibly clear one whole buffer if it's too fragmented - investigate
+ }
+
+ @Override
+ public void collectAll()
+ {
+ Thread thread = new Thread()
+ {
+ public void run()
+ {
+ logger.info( "begin disposal" );
+ collectExpired();
+ collectLFU();
+ logger.info( "disposal complete" );
+ }
+ };
+ thread.start();
+ }
+
+
+ @Override
+ public void clear()
+ {
+ map.clear();
+ memoryManager.clear();
+ logger.info( "Cache cleared" );
+ }
+
+ @Override
+ public long entries()
+ {
+ return map.size();
+ }
+
+ public void dump( MemoryManagerService<V> mms )
+ {
+ logger.info( format( "off-heap - allocated: \t%1s", Ram.inMb( mms.capacity() ) ) );
+ logger.info( format( "off-heap - used: \t%1s", Ram.inMb( mms.used() ) ) );
+ logger.info( format( "heap - max: \t%1s", Ram.inMb( Runtime.getRuntime().maxMemory() ) ) );
+ logger.info( format( "heap - allocated: \t%1s", Ram.inMb( Runtime.getRuntime().totalMemory() ) ) );
+ logger.info( format( "heap - free : \t%1s", Ram.inMb( Runtime.getRuntime().freeMemory() ) ) );
+ logger.info( "************************************************" );
+ }
+
+ @Override
+ public void dump()
+ {
+ if ( !logger.isInfoEnabled() )
+ {
+ return;
+ }
+
+ logger.info( "*** DirectMemory statistics ********************" );
+
+ dump( memoryManager );
+ }
+
+ @Override
+ public ConcurrentMap<K, Pointer<V>> getMap()
+ {
+ return map;
+ }
+
+ @Override
+ public void setMap( ConcurrentMap<K, Pointer<V>> map )
+ {
+ this.map = map;
+ }
+
+ @Override
+ public Serializer getSerializer()
+ {
+ return serializer;
+ }
+
+ @Override
+ public void setSerializer( Serializer serializer )
+ {
+ this.serializer = serializer;
+ }
+
+ @Override
+ public MemoryManagerService<V> getMemoryManager()
+ {
+ return memoryManager;
+ }
+
+ @Override
+ public void setMemoryManager( MemoryManagerService<V> memoryManager )
+ {
+ this.memoryManager = memoryManager;
+ }
+
+ @Override
+ public <T extends V> Pointer<V> allocate( K key, Class<T> type, int size )
+ {
+ Pointer<V> ptr = memoryManager.allocate( type, size, -1, -1 );
+ map.put( key, ptr );
+ ptr.setClazz( type );
+ return ptr;
+ }
+}
23 directmemory-cache/src/main/java/org/apache/directmemory/cache/package-info.java
@@ -0,0 +1,23 @@
+/**
+ * Apache DirectMemory cache APIs.
+ */
+package org.apache.directmemory.cache;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
31 directmemory-cache/src/main/java/org/apache/directmemory/measures/Every.java
@@ -0,0 +1,31 @@
+package org.apache.directmemory.measures;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+public class Every
+ extends In
+{
+
+ public Every( double measure )
+ {
+ super( measure );
+ }
+
+}
40 directmemory-cache/src/main/java/org/apache/directmemory/measures/Expires.java
@@ -0,0 +1,40 @@
+package org.apache.directmemory.measures;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+public class Expires
+ extends In
+{
+
+ public Expires( double measure )
+ {
+ super( measure );
+ }
+
+ public static In in( double measure )
+ {
+ return new In( measure );
+ }
+
+ public static long never()
+ {
+ return -1L;
+ }
+}
31 directmemory-cache/src/main/java/org/apache/directmemory/measures/For.java
@@ -0,0 +1,31 @@
+package org.apache.directmemory.measures;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+public class For
+ extends In
+{
+
+ public For( double measure )
+ {
+ super( measure );
+ }
+
+}
26 directmemory-cache/src/main/java/org/apache/directmemory/measures/Heap.java
@@ -0,0 +1,26 @@
+package org.apache.directmemory.measures;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+public class Heap
+ extends Sizing
+{
+
+}
92 directmemory-cache/src/main/java/org/apache/directmemory/measures/In.java
@@ -0,0 +1,92 @@
+package org.apache.directmemory.measures;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+public class In
+{
+
+ private static final int MILLISECONDS_IN_SECOND = 1000;
+
+ private static final int SECONDS_IN_MINUTE_OR_MINUTES_IN_HOUR = 60;
+
+ private static final int HOUR_IN_DAY = 24;
+
+ private double measure;
+
+ public In( double measure )
+ {
+ this.measure = measure;
+ }
+
+ public long seconds()
+ {
+ return seconds( measure );
+ }
+
+ public long minutes()
+ {
+ return minutes( measure );
+ }
+
+ public long hours()
+ {
+ return hours( measure );
+ }
+
+ public long days()
+ {
+ return days( measure );
+ }
+
+ public static long seconds( double seconds )
+ {
+ return (long) seconds * MILLISECONDS_IN_SECOND;
+ }
+
+ public static long minutes( double minutes )
+ {
+ return seconds( minutes * SECONDS_IN_MINUTE_OR_MINUTES_IN_HOUR );
+ }
+
+ public static long hours( double hours )
+ {
+ return minutes( hours * SECONDS_IN_MINUTE_OR_MINUTES_IN_HOUR );
+ }
+
+ public static long days( double days )
+ {
+ return hours( days * HOUR_IN_DAY );
+ }
+
+ public static In just( double measure )
+ {
+ return new In( measure );
+ }
+
+ public static In exactly( double measure )
+ {
+ return new In( measure );
+ }
+
+ public static In only( double measure )
+ {
+ return new In( measure );
+ }
+}
26 directmemory-cache/src/main/java/org/apache/directmemory/measures/Memory.java
@@ -0,0 +1,26 @@
+package org.apache.directmemory.measures;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+public class Memory
+ extends Sizing
+{
+
+}
118 directmemory-cache/src/main/java/org/apache/directmemory/measures/Monitor.java
@@ -0,0 +1,118 @@
+package org.apache.directmemory.measures;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static java.lang.String.format;
+
+import java.text.DecimalFormat;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Monitor
+{
+
+ private static final Logger LOG = LoggerFactory.getLogger( Monitor.class );
+
+ //TODO: MONITORS looks like a good candidate to become a private field
+ public static final Map<String, MonitorService> MONITORS = new HashMap<String, MonitorService>();
+
+ private MonitorService monitorService;
+
+ public static MonitorService get( String key )
+ {
+ MonitorService mon = MONITORS.get( key );
+ if ( mon == null )
+ {
+ mon = new MonitorServiceImpl( key );
+ MONITORS.put( key, mon );
+ }
+ return mon;
+ }
+
+ public Monitor( String name )
+ {
+ this.monitorService = new MonitorServiceImpl( name );
+ MONITORS.put( name, monitorService );
+ }
+
+ public long start()
+ {
+ return System.nanoTime();
+ }
+
+ public long stop( long begunAt )
+ {
+ monitorService.getHits().incrementAndGet();
+ final long lastAccessed = System.nanoTime();
+ final long elapsed = lastAccessed - begunAt;
+ monitorService.addToTotalTime( elapsed );
+ if ( elapsed > monitorService.getMax() && monitorService.getHits().get() > 0 )
+ {
+ monitorService.setMax( elapsed );
+ }
+ if ( elapsed < monitorService.getMin() && monitorService.getHits().get() > 0 )
+ {
+ monitorService.setMin( elapsed );
+ }
+ return elapsed;
+ }
+
+ public long hits()
+ {
+ return monitorService.getHits().get();
+ }
+
+ public long totalTime()
+ {
+ return monitorService.totalTime();
+ }
+
+ public long average()
+ {
+ return monitorService.getHits().get() > 0 ? monitorService.getTotalTime() / monitorService.getHits().get() : 0;
+ }
+
+ public String toString()
+ {
+ return format( "%1$s hits: %2$d, avg: %3$s ms, tot: %4$s seconds", monitorService.getName(),
+ monitorService.getHits().get(),
+ new DecimalFormat( "####.###" ).format( (double) average() / 1000000 ),
+ new DecimalFormat( "####.###" ).format( (double) monitorService.getTotalTime() / 1000000000 ) );
+ }
+
+ public static void dump( String prefix )
+ {
+ for ( MonitorService monitor : MONITORS.values() )
+ {
+ if ( monitor.getName().startsWith( prefix ) )
+ {
+ LOG.info( monitor.toString() );
+ }
+ }
+ }
+
+ public static void dump()
+ {
+ dump( "" );
+ }
+}
58 directmemory-cache/src/main/java/org/apache/directmemory/measures/MonitorService.java
@@ -0,0 +1,58 @@
+package org.apache.directmemory.measures;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import java.util.concurrent.atomic.AtomicLong;
+
+public interface MonitorService
+{
+
+ long start();
+
+ long stop( long begunAt );
+
+ long hits();
+
+ long totalTime();
+
+ long average();
+
+ void dump( String prefix );
+
+ void dump();
+
+ AtomicLong getHits();
+
+ long getTotalTime();
+
+ void addToTotalTime( long time );
+
+ long getMin();
+
+ void setMin( long min );
+
+ long getMax();
+
+ void setMax( long max );
+
+ String getName();
+
+}
158 directmemory-cache/src/main/java/org/apache/directmemory/measures/MonitorServiceImpl.java
@@ -0,0 +1,158 @@
+package org.apache.directmemory.measures;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static java.lang.String.format;
+
+import java.text.DecimalFormat;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MonitorServiceImpl
+ implements MonitorService
+{
+
+ private AtomicLong hits = new AtomicLong( 0 );
+
+ private long totalTime = 0;
+
+ private long min = -1;
+
+ private long max = -1;
+
+ public String name;
+
+ private static final Logger LOG = LoggerFactory.getLogger( MonitorServiceImpl.class );
+
+ //TODO: MONITORS looks like a good candidate to become a private field
+ public static final Map<String, MonitorServiceImpl> MONITORS = new HashMap<String, MonitorServiceImpl>();
+
+ public MonitorServiceImpl( String name )
+ {
+ this.name = name;
+ }
+
+ public long start()
+ {
+ return System.nanoTime();
+ }
+
+ public long stop( long begunAt )
+ {
+ hits.incrementAndGet();
+ final long lastAccessed = System.nanoTime();
+ final long elapsed = lastAccessed - begunAt;
+ totalTime += elapsed;
+ if ( elapsed > max && hits.get() > 0 )
+ {
+ max = elapsed;
+ }
+ if ( elapsed < min && hits.get() > 0 )
+ {
+ min = elapsed;
+ }
+ return elapsed;
+ }
+
+ public long hits()
+ {
+ return hits.get();
+ }
+
+ public long totalTime()
+ {
+ return totalTime;
+ }
+
+ public long average()
+ {
+ return hits.get() > 0 ? totalTime / hits.get() : 0;
+ }
+
+ public String toString()
+ {
+ return format( "%1$s hits: %2$d, avg: %3$s ms, tot: %4$s seconds", name, hits.get(),
+ new DecimalFormat( "####.###" ).format( (double) average() / 1000000 ),
+ new DecimalFormat( "####.###" ).format( (double) totalTime / 1000000000 ) );
+ }
+
+ public void dump( String prefix )
+ {
+ for ( MonitorServiceImpl monitor : MonitorServiceImpl.MONITORS.values() )
+ {
+ if ( monitor.name.startsWith( prefix ) )
+ {
+ LOG.info( monitor.toString() );
+ }
+ }
+ }
+
+ public void dump()
+ {
+ dump( "" );
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public AtomicLong getHits()
+ {
+ return hits;
+ }
+
+ public long getTotalTime()
+ {
+ return totalTime;
+ }
+
+ @Override
+ public void addToTotalTime( long time )
+ {
+ totalTime += time;
+ }
+
+ public long getMin()
+ {
+ return min;
+ }
+
+ public void setMin( long min )
+ {
+ this.min = min;
+ }
+
+ public long getMax()
+ {
+ return max;
+ }
+
+ public void setMax( long max )
+ {
+ this.max = max;
+ }
+
+
+}
26 directmemory-cache/src/main/java/org/apache/directmemory/measures/Ram.java
@@ -0,0 +1,26 @@
+package org.apache.directmemory.measures;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+public class Ram
+ extends Sizing
+{
+
+}
64 directmemory-cache/src/main/java/org/apache/directmemory/measures/Sizing.java
@@ -0,0 +1,64 @@
+package org.apache.directmemory.measures;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static java.lang.String.format;
+
+public class Sizing
+{
+
+ private static final int KILOBYTE_UNIT = 1024;
+
+ public static int Gb( double giga )
+ {
+ return (int) giga * KILOBYTE_UNIT * KILOBYTE_UNIT * KILOBYTE_UNIT;
+ }
+
+ public static int Mb( double mega )
+ {
+ return (int) mega * KILOBYTE_UNIT * KILOBYTE_UNIT;
+ }
+
+ public static int Kb( double kilo )
+ {
+ return (int) kilo * KILOBYTE_UNIT;
+ }
+
+ public static int unlimited()
+ {
+ return -1;
+ }
+
+ public static String inKb( long bytes )
+ {
+ return format( "%(,.1fKb", (double) bytes / KILOBYTE_UNIT );
+ }
+
+ public static String inMb( long bytes )
+ {
+ return format( "%(,.1fMb", (double) bytes / KILOBYTE_UNIT / KILOBYTE_UNIT );
+ }
+
+ public static String inGb( long bytes )
+ {
+ return format( "%(,.1fGb", (double) bytes / KILOBYTE_UNIT / KILOBYTE_UNIT / KILOBYTE_UNIT );
+ }
+
+}
26 directmemory-cache/src/main/java/org/apache/directmemory/measures/Space.java
@@ -0,0 +1,26 @@
+package org.apache.directmemory.measures;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+public class Space
+ extends Sizing
+{
+
+}
23 directmemory-cache/src/main/java/org/apache/directmemory/measures/package-info.java
@@ -0,0 +1,23 @@
+/**
+ * Fluent APIs for manipulate unit measures, such as time and space memory.
+ */
+package org.apache.directmemory.measures;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
<