Return-Path: X-Original-To: apmail-incubator-directmemory-dev-archive@minotaur.apache.org Delivered-To: apmail-incubator-directmemory-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DFBD99BCC for ; Sat, 18 Feb 2012 23:08:23 +0000 (UTC) Received: (qmail 54905 invoked by uid 500); 18 Feb 2012 23:08:23 -0000 Delivered-To: apmail-incubator-directmemory-dev-archive@incubator.apache.org Received: (qmail 54875 invoked by uid 500); 18 Feb 2012 23:08:23 -0000 Mailing-List: contact directmemory-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: directmemory-dev@incubator.apache.org Delivered-To: mailing list directmemory-dev@incubator.apache.org Received: (qmail 54867 invoked by uid 99); 18 Feb 2012 23:08:23 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 18 Feb 2012 23:08:23 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 18 Feb 2012 23:08:21 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 824B01BF61C for ; Sat, 18 Feb 2012 23:07:59 +0000 (UTC) Date: Sat, 18 Feb 2012 23:07:59 +0000 (UTC) From: "Simone Tripodi (Created) (JIRA)" To: directmemory-dev@incubator.apache.org Message-ID: <1382477142.55167.1329606479535.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Created] (DIRECTMEMORY-62) Adopt fluent APIs for bootstrapping the Cache and manage stored objects MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org Adopt fluent APIs for bootstrapping the Cache and manage stored objects ----------------------------------------------------------------------- Key: DIRECTMEMORY-62 URL: https://issues.apache.org/jira/browse/DIRECTMEMORY-62 Project: Apache DirectMemory Issue Type: New Feature Reporter: Simone Tripodi Assignee: Simone Tripodi 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