[
https://issues.apache.org/jira/browse/DIRECTMEMORY-62?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13216603#comment-13216603
]
Hudson commented on DIRECTMEMORY-62:
------------------------------------
Integrated in directmemory-trunk #136 (See
[https://builds.apache.org/job/directmemory-trunk/136/])
dropped DIRECTMEMORY-62 stuff - when binding components I am reinventing
the wheel and it is not needed (Revision 1293731)
Result = SUCCESS
simonetripodi :
Files :
*
/incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/AbstractCacheConfiguration.java
*
/incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/AbstractChainedBuilder.java
*
/incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/CacheConfiguration.java
*
/incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/CacheConfigurator.java
*
/incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/CacheConfiguratorImpl.java
*
/incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/DefaultMemoryUnitDimensionBuilder.java
*
/incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/DefaultScheduleDisposalBuilder.java
*
/incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/DefaultTimeMeasureBuilder.java
*
/incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/DirectMemory.java
*
/incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/DirectMemoryConfigurationException.java
*
/incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/ErrorMessage.java
*
/incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/MemoryUnitDimensionBuilder.java
*
/incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/ScheduleDisposalBuilder.java
*
/incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/SizeBuilder.java
*
/incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/TimeMeasureBuilder.java
*
/incubator/directmemory/trunk/directmemory-cache/src/main/java/org/apache/directmemory/package-info.java
*
/incubator/directmemory/trunk/directmemory-cache/src/test/java/org/apache/directmemory/BootstrapTestCase.java
> Adopt fluent APIs for bootstrapping the Cache (and optionally manage stored
> objects)
> ------------------------------------------------------------------------------------
>
> Key: DIRECTMEMORY-62
> URL: https://issues.apache.org/jira/browse/DIRECTMEMORY-62
> Project: Apache DirectMemory
> Issue Type: New Feature
> Affects Versions: 0.6.0
> Reporter: Simone Tripodi
> Assignee: Simone Tripodi
> Fix For: 0.6.0
>
> Attachments: edsl-prototype.patch
>
>
> Hi all guys,
> as discussed some days ago, I started prototyping an EDSL embedded in DM to
> make Cache APIs more "sexy" :)
> So, influenced by the past experience with Commons Digester - influenced by
> Google Guice - I tried to identify the 2 phases in the Cache lifecycle
> * the "bootstrap" phase - where settings are used to instantiate the Cache;
> * the object store management.
> Current codebase has a mix of both and users have to be aware of correct
> sequence of operations call, I mean, calling {{Cache.retrieve( "aaa" )}}
> without having previously called {{Cache.init( 1, Ram.Mb( 100 ) )}} at the
> beginning of the program, would cause an error. That is why I recurred to a
> kind of "configuration" pattern to make sure Cache instance have to be
> configured first and then can be used:
> {code}
> /* Basic configuration APIs */
> Cache cache = DirectMemory.createNewInstance( new CacheConfiguration()
> {
> @Override
> public void configure( CacheConfigurator cacheConfigurator )
> {
> cacheConfigurator.numberOfBuffers().ofSize( 1 );
> cacheConfigurator.allocateMemoryOfSize( 128 ).Mb();
> cacheConfigurator.scheduleDisposalEvery( 10 ).hours();
> cacheConfigurator.bindConcurrentMap().withJVMConcurrentMap();
>
> cacheConfigurator.bindMemoryManagerService().withDefaultImplamentation();
>
> cacheConfigurator.bindSerializer().fromServiceProviderInterface();
> }
> } );
> {code}
> Hoping that the code itself is clear enough, the {{DirectMemory}} class
> accepts a {{CacheConfiguration}}, users have to override the {{ configure(
> CacheConfigurator )}} method, where describing the basic Cache behavior, and
> will return a Cache instance.
> According to the DRY (Don't Repeat Yourself) principle, repeating
> "cacheConfigurator" over and over for each binding can get a little tedious,
> so there is an abstract support class:
> {code}
> cache = DirectMemory.createNewInstance( new
> AbstractCacheConfiguration()
> {
> @Override
> protected void configure()
> {
> numberOfBuffers().ofSize( 1 );
> allocateMemoryOfSize( 128 ).Mb();
> scheduleDisposalEvery( 10 ).hours();
> bindConcurrentMap().withJVMConcurrentMap();
> bindMemoryManagerService().withDefaultImplamentation();
> bindSerializer().fromServiceProviderInterface();
> }
> } );
> {code}
> Once obtained the Cache instance, users can now start storing objects:
> {code}
> Pointer a = cache.allocatePointer( 1 ).Gb().identifiedBy( "Simo" );
> Pointer b = cache.put( "Strored!" ).identifiedBy( "Raf"
> ).thatNeverExpires();
> Pointer c = cache.putByteArray( new byte[0] ).identifiedBy( "Izio"
> ).thatExpiresIn( 1 ).days();
> Pointer d = cache.update( new Object() ).identifiedBy( "Olivier" );
> Pointer e = cache.updateByteArray( new byte[0] ).identifiedBy(
> "TomNaso" );
> {code}
> WDYT?
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira