Grails and Ehcache Annotations for Spring
Posted by admin - 04/11/11 at 01:11:09 amEhcache Annotations for Spring is a project that allows "declarative, aspect based caching to be added to a Spring Framework based application by simple annotation". And because Grails stands on Spring, there is no problem to do that. We are using spring xml based configuration here, but if any one know how rewrite it to Groovy DSL, please leave a comment.
1) Configure dependencies in BuildConfig.groovy.
compile('com.googlecode.ehcache-spring-annotations:ehcache-spring-annotations:1.2.0'){ excludes 'ehcache-core', 'slf4j-api' }
2) Configure spring resources.xml. We are using proxy-target-class="true" option to avoid JdkDynamicAopProxy ClassCastException problem.
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd"> <ehcache:annotation-driven proxy-target-class="true" /> <ehcache:config cache-manager="cacheManager"> <ehcache:evict-expired-elements interval="60" /> </ehcache:config> <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"/> </beans>
3) Configure Ehcache in ehcache.xml.
<?xml version="1.0" encoding="UTF-8"?> <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd"> <diskStore path="java.io.tmpdir"/> <defaultCache maxElementsInMemory="10000" eternal="false" overflowToDisk="false" timeToIdleSeconds="300" timeToLiveSeconds="300" diskPersistent="false" diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" /> <cache name="cacheableService" maxElementsInMemory="30000" eternal="false" overflowToDisk="false" diskPersistent="false" timeToLiveSeconds="86400" timeToIdleSeconds="0" /> </ehcache>
4) Use annotations in code:
class CacheableService { @Cacheable(cacheName="cacheableService") public MyData getData() { ... return myData } @Transactional @TriggersRemove(cacheName="cacheableService", removeAll=true) public void updateData() { ... } }
Grails Gmock partial mock example
Posted by admin - 21/10/11 at 01:10:52 pmclass Foo { def methodFoo(String param){ return "methodFoo" } } ... class Bar { def foo def methodBar(String param){ return foo.methodFoo(param) + methodBarSecond(param); } def methodBarSecond(String param){ return "methodBarSecond" } } ... import static org.hamcrest.Matchers.any @WithGmock class BarTests { @Test public void checkMethodBar(){ def result = "my other result" def mockFoo = mock(Foo) mockFoo.testMethod(any(String)).returns(result) Bar bar = new Bar() bar.foo = mockFoo mock(bar).methodBarSecond(any(String)).returns(result) play { assertEquals (result * 2, bar.methodBar()) } } }
Grails bean factory + method with parameters
Posted by admin - 20/10/11 at 11:10:14 pmclass MyObjectFactory { static final int TYPE_ONE = 1 static final int TYPE_TWO = 2 def produce(int type){ if (type == TYPE_ONE){ return ... // type one } if (type == TYPE_TWO){ return ... // type two } throw new IllegalArgumentException() } } ... beans { myObjectFactoryBean(MyObjectFactory) myObjectBean(myObjectFactoryBean:'produce'){bean-> bean.constructorArgs = [MyObjectFactory.TYPE_ONE ] } }
After DevMeeting
Posted by admin - 22/05/11 at 11:05:25 pmDevMeeting is after us, and only thing I can say after it is "more". Meeting started at 9 a.m. and we worked with short breaks till 9 p.m. Whole meeting was leaded by David de Rosier and I must say that I have been under deep impression how big and broad knowledge he has.
We started with JavaScript refreshing - quick review of JavaScript magick. As a exercise we got task to implement elements of Aspect Programming in JavaScript.
Next we jumped to NodeJS and I must say that this was the most interesting part of whole meeting. His callback approach provide really powerful way for creating server-side code. After theoretical part we started implementation of chat - part of online code editor that was ours goal on this meeting. It was rally amazing to see that the same library (Socket.IO) is used on client and server side, JSON is transparent for both sides and all was running in less than 15 minutes.
As last element we explore RingoJS - MVC Server framework. It wasn't impressive - yet another framework. Only interesting thing in it is possibility of Java libraries usage. But there is no "magic" that NodeJS is offering and there is a lot of much better frameworks around in any other language.
Whole meeting was really successful, it has given me wider look on server side JavaScript, and I am definitely recommending it any one who want to learn something interesting.
Pre DevMeeting
Posted by admin - 27/04/11 at 11:04:00 pmOn 14 May in Poznan there will be interesting meeting (with I hope to take part) about RingoJS, V8cgi and NodeJS. I am still confused with "server side JavaScript" concept and I hope to clarify my point of view after this meeting. Meanwhile I strongly recommend two videos where Ryan Dahl is explaining why he has created NodeJS, it general architecture and for what and where NodeJS can be used.
GAE as free Java hosting? Not really.
Posted by admin - 25/02/11 at 04:02:00 pm
If you plan to deploy your new, shiny, low traffic application on Google App Engine, because you think that you can get it for free - don't bother. That was my idea recently - to took Play framework (nice integration with GAE and Siena through modules) build simple (but not trivial) low traffic application, and deploy it on GAE. Quota that is assigned to free GAE option was more than enough for my requirements.
After quick warm-up with framework and GAE infrastructure I have created first snapshot of my application. All was smooth and easy. The only problem was with page response time: it was taking even ~5s to get response. In logs I found this information:
This request caused a new process to be started for your application, and thus caused your application code to be loaded for the first time. This request may thus take longer and use more CPU than a typical request for your application.
Quick search through a mailing lists and I found information that GAE will utilize your instances, if they are not used (with in case of low traffic application is more than sure). There is solution to prevent that: you can buy Always On option, but at this moment it costs 9$/month. Its not much as for Java hosting solution, but well - its still more than PHP.
AndEngine in action
Posted by admin - 03/01/11 at 10:01:49 pmAny one interested in making games on Android platform, should definitely check AndEngine. This framework will help with creating 2D OpenGL games. It is easy, quick and powerful. Extension allows to create games based on physic or even multiplayer games. Below you can find video that shows what can be done in just two evenings.
JavaScriptMVC and Skylinetrooper.net
Posted by admin - 23/12/10 at 06:12:05 pm
My another friend has asked my to update his portfolio. And again I have chosen JavaScriptMVC as client side framework. I think that final effect is more than good. If you want to check it, visit www.skylinetrooper.net. I strongly recommend to check also Piotr private gallery under www.skylinesleep.net.
Madness? This is ImpactJS!
Posted by admin - 20/09/10 at 10:09:06 pmAnother great JS gaming engine is in the way. Just check out this awesome presentation where you can find some info about engine and editor (!):
You can play in Biolab disaster to check how cool it is. I am over deep impression about it.
Bye Google Wave
Posted by admin - 09/08/10 at 10:08:24 pmToday I have back from vacations, and I found bad news from Google: they will close Google Wave at the end of the year.
But despite these wins, and numerous loyal fans, Wave has not seen the user adoption we would have liked.
For me its quite strange: in my company we use Wave and it works very well and for sure there is lots of companies that are in the same position. Why they can keep it online like other closed products (like Google Notebook)? Did Google think that it will be competition for Twitter? What it mean "user adoption" for Google?
Lots of questions but there is on sure - for Novel Pulse it's good news.
Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds.
Valid XHTML and CSS.