If some logic e.g. in a grails service should be invoked asynchronous, in Grails 2 the spring annotation @Async can be used. For that the spring annotation driven task support must be activated in the spring configuration. To activate the task support, the task namespace should be added to the spring configuration. Here a sample spring configuration ("resources.groovy").
Now the spring annotation can be used to mark e.g. service logic which should be invoked asynchronous.
Here a sample to send mails asynchronous (for sending the mails the grails mail plugin is used).
For more details see also the spring framework documentation:
http://static.springsource.org/spring/docs/current/spring-framework-reference/html/scheduling.html#scheduling-annotation-support-async
Sonntag, 20. Mai 2012
Montag, 5. März 2012
Start buggy lazy Bundles
Yesterday I push to github a simple bundle, which I use in bnd and bndtools to activate buggy lazy bundles.
What is a buggy lazy Bundle?
Sometimes I have bundles with a Bundle-ActivationPolicy header, which is set to lazy. But no other bundle in the application loads classes from this bundle or use a service e.g. via DS from this bundle. In some cases the lazy bundle didn’t export anything.
When you like to use such lazy bundles, then this bundle must be start by hand. Examples are the Eclipse ECF bundles. To use the ECF bundles (see also ticket ID-373475) some of the bundles must be start by hand because of the Bundle-ActivationPolicy header lazy. I think these are buggy bundles and the Bundle-ActivationPolicy header should be removed from the manifests.
When you use lazy bundles then this bundles should automatically started by the OSGi framework, when some other bundle in the application need the functionally of the lazy bundle. Think about before you use the Bundle-ActivationPolicy lazy. Only use lazy bundles when the OSGi framework could detect that some other bundle would like to use functionally which the lazy bundle provides.
Examples use lazy bundles when the bundle exports packages with classes and only when some other bundle loads a class from these exported packages the bundle should be in state active. Or when the bundle provides an OSGi service via DS and the bundle should only be in state active when some other bundle would like to use this service. So be careful with using the Bundle-ActivationPolicy header.
More about lazy activation bundle see the OSGi Alliance web site here.
Handling buggy lazy Bundles in Bnd
When you like to use a buggy lazy bundle with bnd or bndtools the bundle must be started by hand. For this I create a simple bundle, which I call “Start lazy Bundles”. The bundle implements an extender pattern which watch for starting bundles. When the starting bundle has a Bundle-ActivationPolicy lazy and the bundle symbolic name is set in a system property the “Start lazy Bundles” bundle try’s to start the bundle.
More details see the Github project:
https://github.com/tux2323/Start-lazy-Bundles
What is a buggy lazy Bundle?
Sometimes I have bundles with a Bundle-ActivationPolicy header, which is set to lazy. But no other bundle in the application loads classes from this bundle or use a service e.g. via DS from this bundle. In some cases the lazy bundle didn’t export anything.
When you like to use such lazy bundles, then this bundle must be start by hand. Examples are the Eclipse ECF bundles. To use the ECF bundles (see also ticket ID-373475) some of the bundles must be start by hand because of the Bundle-ActivationPolicy header lazy. I think these are buggy bundles and the Bundle-ActivationPolicy header should be removed from the manifests.
When you use lazy bundles then this bundles should automatically started by the OSGi framework, when some other bundle in the application need the functionally of the lazy bundle. Think about before you use the Bundle-ActivationPolicy lazy. Only use lazy bundles when the OSGi framework could detect that some other bundle would like to use functionally which the lazy bundle provides.
Examples use lazy bundles when the bundle exports packages with classes and only when some other bundle loads a class from these exported packages the bundle should be in state active. Or when the bundle provides an OSGi service via DS and the bundle should only be in state active when some other bundle would like to use this service. So be careful with using the Bundle-ActivationPolicy header.
More about lazy activation bundle see the OSGi Alliance web site here.
Handling buggy lazy Bundles in Bnd
When you like to use a buggy lazy bundle with bnd or bndtools the bundle must be started by hand. For this I create a simple bundle, which I call “Start lazy Bundles”. The bundle implements an extender pattern which watch for starting bundles. When the starting bundle has a Bundle-ActivationPolicy lazy and the bundle symbolic name is set in a system property the “Start lazy Bundles” bundle try’s to start the bundle.
More details see the Github project:
https://github.com/tux2323/Start-lazy-Bundles
Freitag, 17. Februar 2012
Lambdaj Closure in Java
Yesterday we played around with the Lambdaj project. The project provides a fancy way to simulate closure in Java. Here some simple examples based on the lambda4j documentation code.
And here a second example with "delayedClosure", which shows how to read a file line by line with lambda4j.
More details about lambda4j please have a look at the project website:
http://code.google.com/p/lambdaj/
And here a second example with "delayedClosure", which shows how to read a file line by line with lambda4j.
More details about lambda4j please have a look at the project website:
http://code.google.com/p/lambdaj/
Montag, 23. Januar 2012
Eclipse Equinox ECF Unpack *pack.gz
If you downloading Eclipse ECF as a ZIP file, the plugins folder in the ZIP contains pack200 compressed JAR files. The pack200 compressed files ends with *.pack.gz. The ECF ZIP distribution contains the same content like a normal Eclipse P2 update site.
If you like to use Eclipse Equinix ECF bundles without P2 or Eclipse you must unpack the pack200 OSGi bundels. For that eclipse provides a tool called "org.eclipse.equinox.p2.jarprocessor". Here a small bash script to show how to extract the OSGi bundles from the pack200 files.
Links
If you like to use Eclipse Equinix ECF bundles without P2 or Eclipse you must unpack the pack200 OSGi bundels. For that eclipse provides a tool called "org.eclipse.equinox.p2.jarprocessor". Here a small bash script to show how to extract the OSGi bundles from the pack200 files.
Links
- Eclipse Pack200 Documentation - http://wiki.eclipse.org/Pack200
- Eclipse ECF Download Page - http://www.eclipse.org/ecf/downloads.php
Samstag, 10. Dezember 2011
Mockito the Java Standard Mocking Framework?
I used a long time JMock and I really love it, I also used a lot EasyMock because of the answer and capture feature. About a year ago I found the mocking framework mockito. After that I was able to inspire a few work colleagues to use mockito in their projets. I play around with it again and my conclusion is: Mockito is at the moment the best mocking framework for Java and I'm not alone.
"We decided during the main conference that we should use JUnit 4 and Mockito because we think they are the future of TDD and mocking in Java" - Dan North, the originator of BDD
Mockito has a clean syntax and the patterns and ideas behind mockito make tests more maintainable. Mockito has the power of EasyMock but a smarter syntax. Today I build for my self a simple JUnit test as mockito cheat sheet. So you convince yourself with Mockito and the smart API see the demo test bellow.
Links
"We decided during the main conference that we should use JUnit 4 and Mockito because we think they are the future of TDD and mocking in Java" - Dan North, the originator of BDD
Mockito has a clean syntax and the patterns and ideas behind mockito make tests more maintainable. Mockito has the power of EasyMock but a smarter syntax. Today I build for my self a simple JUnit test as mockito cheat sheet. So you convince yourself with Mockito and the smart API see the demo test bellow.
Links
- Mockito Project Site
http://code.google.com/p/mockito/ - Documentation Mockito
http://docs.mockito.googlecode.com/hg/latest/org/mockito/Mockito.html - GitHub Project with the Cheat Sheet Test
https://github.com/tux2323/mockito-cheat-sheet
Abonnieren
Posts (Atom)
