<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Transient Technology &#187; gigaspaces</title>
	<atom:link href="http://martinaharris.com/tag/gigaspaces/feed/" rel="self" type="application/rss+xml" />
	<link>http://martinaharris.com</link>
	<description>Next time you look it might be gone</description>
	<lastBuildDate>Tue, 24 Jan 2012 18:14:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Unit Testing with a GigaSpaceFactoryBean</title>
		<link>http://martinaharris.com/2010/05/unit-testing-gigaspacefactorybean/</link>
		<comments>http://martinaharris.com/2010/05/unit-testing-gigaspacefactorybean/#comments</comments>
		<pubDate>Mon, 24 May 2010 10:29:26 +0000</pubDate>
		<dc:creator>Martin Harris</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[gigaspacefactorybean]]></category>
		<category><![CDATA[gigaspaces]]></category>
		<category><![CDATA[junit]]></category>

		<guid isPermaLink="false">http://martinaharris.com/?p=976</guid>
		<description><![CDATA[I was talking to Shay Banon (Gigaspace Software Architect) he mentioned using GigaSpaceFactoryBean for writing gigaspace unit tests. I could find no examples on their site, although I concede it may be there somewhere. This shows post shows a simple &#8230; <a href="http://martinaharris.com/2010/05/unit-testing-gigaspacefactorybean/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was talking to <span class="conn-name">Shay </span><span class="conn-name">Banon</span> (Gigaspace Software Architect) he mentioned using GigaSpaceFactoryBean for writing gigaspace unit tests.  I could find no examples on their site, although I concede it may be there somewhere.  This shows post shows a simple example.</p>
<p>He also mentioned using the admin api to do full end to end integration testing.  The admin api has huge potential as its able to control gigaspace containers, deploy into them and collect statistics.  Its a powerful api.</p>
<p>This is documented on their site: <a title="GS Admin API" href="http://www.gigaspaces.com/wiki/display/XAP7/Administration+and+Monitoring+API" target="_blank">http://www.gigaspaces.com/wiki/display/XAP7/Administration+and+Monitoring+API</a><br />
<span id="more-976"></span></p>
<h2>Example unit test using GigaSpaceFactoryBean</h2>
<p>The GigaSpaceFactoryBean does have javadoc: <a title="GIgaSpaceFactoryBean API" href="http://www.gigaspaces.com/docs/JavaDoc7.1/index.html" target="_blank">http://www.gigaspaces.com/docs/JavaDoc7.1/index.html</a>.  It can be used to provide a unit test with a gigaspace implementation for the duration of the test.</p>
<h3>Step 1 Provide a spring definition of the GigaSpaceFactoryBean</h3>
<pre class="brush: xml; gutter: false">&lt;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:os-core="http://www.openspaces.org/schema/core"
xmlns:os-events="http://www.openspaces.org/schema/events"
xmlns:os-remoting="http://www.openspaces.org/schema/remoting"
xmlns:os-sla="http://www.openspaces.org/schema/sla"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://www.openspaces.org/schema/core http://www.openspaces.org/schema/core/openspaces-core.xsd
http://www.openspaces.org/schema/events http://www.openspaces.org/schema/events/openspaces-events.xsd
http://www.openspaces.org/schema/remoting http://www.openspaces.org/schema/remoting/openspaces-remoting.xsd
http://www.openspaces.org/schema/sla http://www.openspaces.org/schema/sla/openspaces-sla.xsd"&gt;

&lt;os-core:local-tx-manager id="gs.transactionManager" space="testGigaSpace" default-timeout="1000" /&gt;
&lt;os-core:space id="testGigaSpace" url="/./my-test-pu" /&gt;

&lt;bean id="gigaSpace"&gt;
&lt;property name="space" ref="testGigaSpace" /&gt;
&lt;property name="transactionManager" ref="gs.transactionManager" /&gt;
&lt;/bean&gt;</pre>
<p>Follow with other beans needed by the test.  I.e service beans and their dependencies.  Note that the space defined here will also need to be injected into services that need it.  So you will need to use the same bean id.  Careful separation of the spring files means you will be able to substitute a test space for the real one during testing.</p>
<h3>Step 2 Write a unit test</h3>
<pre class="brush: java; gutter: false; wrap-lines: false">@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:/somewhere/sometest-pu.xml")
public class SomeGigaspaceTest {

    @Resource
	private ServiceUnderTest myservice;

    @Resource
    private GigaSpace gigaSpace;

    @Before
    public void setUp() {

        // Setup anything you may wish to be
        // in the space before the test starts.
        this.gigaSpace.write(stuff);

    }

    @Test
    public void testSomething() throws InterruptedException {

        ImmutableSet dataFromGS = this.myservice.getStuff();
        assertFalse(dataFromGS.isEmpty());
        assertThat(dataFromGS.size(), is(100));

    }</pre>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funit-testing-gigaspacefactorybean%2F&amp;title=Unit+Testing+with+a+GigaSpaceFactoryBean" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funit-testing-gigaspacefactorybean%2F&amp;title=Unit+Testing+with+a+GigaSpaceFactoryBean" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funit-testing-gigaspacefactorybean%2F&amp;title=Unit+Testing+with+a+GigaSpaceFactoryBean" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funit-testing-gigaspacefactorybean%2F&amp;headline=Unit+Testing+with+a+GigaSpaceFactoryBean" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Unit+Testing+with+a+GigaSpaceFactoryBean&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funit-testing-gigaspacefactorybean%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Unit+Testing+with+a+GigaSpaceFactoryBean&amp;u=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funit-testing-gigaspacefactorybean%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Unit+Testing+with+a+GigaSpaceFactoryBean&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funit-testing-gigaspacefactorybean%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Unit+Testing+with+a+GigaSpaceFactoryBean&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funit-testing-gigaspacefactorybean%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Unit+Testing+with+a+GigaSpaceFactoryBean&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funit-testing-gigaspacefactorybean%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funit-testing-gigaspacefactorybean%2F&amp;title=Unit+Testing+with+a+GigaSpaceFactoryBean&amp;summary=&amp;source=" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funit-testing-gigaspacefactorybean%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funit-testing-gigaspacefactorybean%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funit-testing-gigaspacefactorybean%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div><div class="dzone_button" style="float: right; margin-left: 5px;">
<script type="text/javascript">
var dzone_url = 'http://martinaharris.com/2010/05/unit-testing-gigaspacefactorybean/';
var dzone_title = 'Unit Testing with a GigaSpaceFactoryBean';
var dzone_blurb = '';
var dzone_style = '2';
</script>
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>
</div>]]></content:encoded>
			<wfw:commentRss>http://martinaharris.com/2010/05/unit-testing-gigaspacefactorybean/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gigaspace API design &#8211; the GigaSpace write method</title>
		<link>http://martinaharris.com/2010/01/gigaspace-api-design-the-gigaspace-write-method/</link>
		<comments>http://martinaharris.com/2010/01/gigaspace-api-design-the-gigaspace-write-method/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 05:00:00 +0000</pubDate>
		<dc:creator>Martin Harris</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[gigaspaces]]></category>

		<guid isPermaLink="false">http://martinaharris.com/?p=609</guid>
		<description><![CDATA[Gigaspaces is an excellent product.  Supplying a flexible cache, the ability to run processes, underpinned with spring, good desktop space management tools and some well thought out configurable and scalable architectures.  The documentation and programmers api design could do with some effort though.  Lets take a look at the GigaSpace interface and the design of the write method as a small example where improvement is much needed. <a href="http://martinaharris.com/2010/01/gigaspace-api-design-the-gigaspace-write-method/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Now don&#8217;t get me wrong, I like gigaspaces and I am not into bashing someones API for the sake of it.  Take a look at the GigaSpace interface documented in javadoc: <a title="Gigaspace JavaDoc" href="http://www.gigaspaces.com/docs/JavaDoc7.1/org/openspaces/core/GigaSpace.html" target="_blank">http://www.gigaspaces.com/docs/JavaDoc7.1/org/openspaces/core/GigaSpace.html</a> Its time the API was cleaned up.  Take the write method for instance:</p>
<pre>&lt;T&gt; <a title="interface in com.j_spaces.core" href="http://www.gigaspaces.com/docs/JavaDoc7.1/com/j_spaces/core/LeaseContext.html" target="_blank">LeaseContext</a>&lt;T&gt; <strong>write</strong>(T entry,
                          long lease,
                          long timeout,
                          int modifiers)
                      throws <a title="class or interface in org.springframework.dao" href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/dao/DataAccessException.html" target="_blank">DataAccessException</a></pre>
<p>These are the things I dislike about it:<br />
<span id="more-609"></span></p>
<ul>
<li>The long timeout and lease don&#8217;t have units declared.  See my previous blog where <a title="How to supply a duration to an api" href="/2010/01/timeunit-its-brill/" target="_blank">I show a good way to supply durations</a>.</li>
<li>The documentation is terrible, it does not mention what units the timeout are in, I had to navigate to LeaseContext to understand the lease, and find  Lease.FOREVER.  As I write this I still do not know how to set a maximum or minimum timeout.  Perhaps 0, null?  Not sure.  What happens if you set a minus value?</li>
<li>The method has a mode in the form of modifiers.  Modifiers is a bad name but I would rather delete it than change the name.  The mode is not a great way to communicate what your method does, but this one is particularly bad because it can effect what might be returned and possibly the types of exception that might get thrown.</li>
<p style="padding-left: 60px;"><a href="http://www.gigaspaces.com/docs/JavaDoc7.1/com/j_spaces/core/client/UpdateModifiers.html#UPDATE_OR_WRITE"><code>UpdateModifiers.UPDATE_OR_WRITE</code></a> .  If your very lucky you might get a lease back.  If you have successfully written (a new object or object with no id.) you get null.  If you update the lease contains the previous value.  But hang on there is a flag!  I hate flags.  The NoWriteLease if set causes the method to return null in all situations.  I wonder how you set that, the documentation has no link.</p>
<p style="padding-left: 60px;"><a href="http://www.gigaspaces.com/docs/JavaDoc7.1/com/j_spaces/core/client/UpdateModifiers.html#WRITE_ONLY"><code>UpdateModifiers.WRITE_ONLY<br />
</code></a> Could throw EntryAlreadyInSpaceException for objects that have an id and your writing a duplicate.</p>
<p style="padding-left: 60px;">So as you can see, if I call this method changing the mode might mean I have to change the post execution traps, null handling etc.  Very easy to introduce a bug inadvertently.</p>
<p>If anyone from GigaSpace or OpenSpace is reading, sorry but its been a long day and I had to walk 4 miles through the snow to get home!  While you amending the API onto an otherwise excellent product, could you update your more general documentaiton.  Its very use case based.  This is great when my use case matches your documentation, but most of the time this is not the case.  So it becomes a nightmare picking pieces from here and there hoping its all going to work.  I drive everything from tests but it gets a bit tedious when my tests fail because my assumptions are wrong.</p>
<li>UpdateModifiers is also not an enum but a constants class.  As such the evil modifier is not even type or boundary safe.</li>
</ul>
<p>Anyway before this blog turns into a rant.  It may already be too late, sorry.  <img src='http://martinaharris.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<h2>For discussion &#8211; Suggestion for a new API</h2>
<pre class="brush: java; gutter: false; wrap-lines: false">write(T entry
    , long lease, TimeUnit leaseUnit
    , long timeout, TimeUnit timeoutUnit)

writeOrUpdate(T entry
    , long lease, TimeUnit leaseUnit
    , long timeout, TimeUnit timeoutUnit)

update(T entry
    , long lease, TimeUnit leaseUnit
    , long timeout, TimeUnit timeoutUnit)

partialUpdate(T entry
    , long lease, TimeUnit leaseUnit
    , long timeout, TimeUnit timeoutUnit)</pre>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F01%2Fgigaspace-api-design-the-gigaspace-write-method%2F&amp;title=Gigaspace+API+design+-+the+GigaSpace+write+method" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F01%2Fgigaspace-api-design-the-gigaspace-write-method%2F&amp;title=Gigaspace+API+design+-+the+GigaSpace+write+method" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F01%2Fgigaspace-api-design-the-gigaspace-write-method%2F&amp;title=Gigaspace+API+design+-+the+GigaSpace+write+method" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fmartinaharris.com%2F2010%2F01%2Fgigaspace-api-design-the-gigaspace-write-method%2F&amp;headline=Gigaspace+API+design+-+the+GigaSpace+write+method" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Gigaspace+API+design+-+the+GigaSpace+write+method&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F01%2Fgigaspace-api-design-the-gigaspace-write-method%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Gigaspace+API+design+-+the+GigaSpace+write+method&amp;u=http%3A%2F%2Fmartinaharris.com%2F2010%2F01%2Fgigaspace-api-design-the-gigaspace-write-method%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Gigaspace+API+design+-+the+GigaSpace+write+method&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F01%2Fgigaspace-api-design-the-gigaspace-write-method%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Gigaspace+API+design+-+the+GigaSpace+write+method&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F01%2Fgigaspace-api-design-the-gigaspace-write-method%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Gigaspace+API+design+-+the+GigaSpace+write+method&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F01%2Fgigaspace-api-design-the-gigaspace-write-method%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F01%2Fgigaspace-api-design-the-gigaspace-write-method%2F&amp;title=Gigaspace+API+design+-+the+GigaSpace+write+method&amp;summary=&amp;source=" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fmartinaharris.com%2F2010%2F01%2Fgigaspace-api-design-the-gigaspace-write-method%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fmartinaharris.com%2F2010%2F01%2Fgigaspace-api-design-the-gigaspace-write-method%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F01%2Fgigaspace-api-design-the-gigaspace-write-method%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div><div class="dzone_button" style="float: right; margin-left: 5px;">
<script type="text/javascript">
var dzone_url = 'http://martinaharris.com/2010/01/gigaspace-api-design-the-gigaspace-write-method/';
var dzone_title = 'Gigaspace API design &#8211; the GigaSpace write method';
var dzone_blurb = '';
var dzone_style = '2';
</script>
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>
</div>]]></content:encoded>
			<wfw:commentRss>http://martinaharris.com/2010/01/gigaspace-api-design-the-gigaspace-write-method/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Untangling a Gigaspace Pojo</title>
		<link>http://martinaharris.com/2009/12/untangling-a-gigaspace-pojo/</link>
		<comments>http://martinaharris.com/2009/12/untangling-a-gigaspace-pojo/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 05:00:02 +0000</pubDate>
		<dc:creator>Martin Harris</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[annotation]]></category>
		<category><![CDATA[composition]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[gigaspaces]]></category>
		<category><![CDATA[jaxb]]></category>
		<category><![CDATA[re-factor]]></category>
		<category><![CDATA[roo]]></category>

		<guid isPermaLink="false">http://martinaharris.com/?p=543</guid>
		<description><![CDATA[A hibernate entity class is annotated describing to hibernate how its to be persisted.  Annotate this class with JAXB for a transformation, chuck in some gigaspace annotations so we can add it to a cache and things start to get messy.  Worse still gigaspace has some tight restrictions surrounding what it requires from a pojo, hibernate has others.  Its tempting to leave the resulting class cluttered with these soft concerns.  I propose a solution using composition that allows for easier maintenance ongoing. <a href="http://martinaharris.com/2009/12/untangling-a-gigaspace-pojo/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I am going to build myself another example application.  I find these very handy for exploring ideas.  If you already have a project with hibernate, spring, gigaspaces and such setup, your much more likely to try a few ideas out, and then blog them.  So for a while this blog might be more quiet than usual.  I think I may use Roo to do it.  Roo looks like a great platform for quickly building something up for an experiment.  i.e You can throw together a new set of entities, and then build an example on top of them.  Before I begin, one last thing from my current experiments.</p>
<h2>Sometimes JPA entity classes get hijacked.</h2>
<p>Say for instance you have a need to pass entity classes to another system, via JAXB.  Its possible to use DTO objects for the transfer or you could just annotate the the entity classes.  In the example below, I wanted to fetch something from a database via JPA and write it into gigaspaces.  It soon gets messy your Entity classes start to become a hub in the middle of your application with things dipping into some of the classes and annotating them and throwing them here and there.<br />
<span id="more-543"></span></p>
<p>Lets look at a simple one from my example system.  This one is only used by gigaspaces and hibernate, it could get much messier than this if I chose to add one or two more technologies.  I am deliberately leaving the imports in the examples so you can see where it all came from.</p>
<pre class="brush: java; gutter: false; wrap-lines: false; highlight: [24,25,26,27,28,29,30,31,32]">import com.gigaspaces.annotation.pojo.SpaceClass;
import com.gigaspaces.annotation.pojo.SpaceId;
import com.gigaspaces.annotation.pojo.SpaceRouting;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name = "HOUSE")
@SpaceClass
public class MessyHouse {

    private String id;
    private String name;
    private String address;
    private String pageId;

    public MessyHouse() {
    }  

    @SpaceRouting
    @Transient
    public String getPageId() {
    return pageId;
    }

    public void setPageId(String pageId) {
    this.pageId = pageId;
    }

    @Id
    @GeneratedValue
    @Column(name = "HOUSE_ID")
    @SpaceId(autoGenerate = false)
    public String getId() {
    return id;
    }

    public void setId(String id) {
    this.id = id;
    }

    public String getAddress() {
    return address;
    }

    public void setAddress(String address) {
    this.address = address;
    }

    public String getName() {
    return name;
    }

    public void setName(String name) {
    this.name = name;
    }
}</pre>
<h2>Some things I dislike about what I have done here</h2>
<ul>
<li>See the block I have marked below SpaceRouting.  In this class I wanted to change the Gigaspace routing strategy, so I have a method that has nothing to do with the persistence.  Does adding annotations break the &#8220;A class should have only one responsibility&#8221; design goal?  No perhaps not, but adding a whole method that is a Gigaspace concern does.</li>
<li>As you add more and more annotations from different technologies things get messy very quickly.</li>
<li>I have a JPA based DAO that uses this class.  I also have a set of gigaspace processing units that use this class.  Both systems are impinging their own design requirements on the class.  At the moment they are deceptively similar.  Gigaspace insists upon a default constructor, and getters and setters for <strong>all</strong> fields you wish to persist.  Hibernate is not quite as strict.  What if Gigaspaces relaxes that rule later and allows you to annotate the fields instead?  Or perhaps added some other design restriction.  Its unclear by looking at the class what things are there for hibernates soft contract and what gigaspace is insisting upon.</li>
<li>If my gigaspace experiment gets big (not that likely!).  I might want to split off the gigaspace into its own project and use it as a component.  Ah! so what about the MessyHouse class then?  Where should that live?  Indeed its going to be in the wrong project wherever I decide to keep it.</li>
</ul>
<p>This is one solution that I put to you.  Create a class for the gigaspace fields, and compose a House class into it.  With composition we can neatly separate the concerns.  Well almost.  Gigaspace may store these objects and need to restore them at some point.  I believe to do that it creates House, and populates it.  Then it creates GsHouseWrapper and injects House into it.  To do that you need a setter for the house but at least we have a class with Gigaspace design constraints and another with Hibernate peculiarities.  Check out the classes below and let me know what you make of the design.  Are there alternatives?</p>
<p>Also, currently there is a problem with the design below.  The delegation methods fail with an exception.  i.e house.setId(id); fails when writing the object to the space.  I need to submit a ticket with the Gigaspace crew to figure out why.</p>
<h2>The refactored classes.</h2>
<pre class="brush: java; gutter: false; wrap-lines: false">package javapuzzlers.compose;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "HOUSE")
public class House {

    private String id;
    private String name;
    private String address;

    public House() {
    }

    @Id
    @GeneratedValue
    @Column(name = "HOUSE_ID")
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

package javapuzzlers.compose;

import com.gigaspaces.annotation.pojo.SpaceClass;
import com.gigaspaces.annotation.pojo.SpaceId;
import com.gigaspaces.annotation.pojo.SpaceRouting;

@SpaceClass
public class GsHouseWrapper {

    private House house;
    private String pageId;

    public GsHouseWrapper() {
    }

    public GsHouseWrapper(House house) {
      this.house = house;
    }

    @SpaceId(autoGenerate = false)
    public String getId() {
        return house.getId();
    }

    public void setId(String id) {
        house.setId(id);
    }

    @SpaceRouting
    public String getPageId() {
        return pageId;
    }

    public void setPageId(String pageId) {
        this.pageId = pageId;
    }

    public GsHouseWrapper(House house) {
        this.house = house;
    }

    public String getName() {
        return house.getName();
    }

    public String getAddress() {
        return house.getAddress();
    }
}
</pre>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2009%2F12%2Funtangling-a-gigaspace-pojo%2F&amp;title=Untangling+a+Gigaspace+Pojo" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2009%2F12%2Funtangling-a-gigaspace-pojo%2F&amp;title=Untangling+a+Gigaspace+Pojo" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2009%2F12%2Funtangling-a-gigaspace-pojo%2F&amp;title=Untangling+a+Gigaspace+Pojo" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fmartinaharris.com%2F2009%2F12%2Funtangling-a-gigaspace-pojo%2F&amp;headline=Untangling+a+Gigaspace+Pojo" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Untangling+a+Gigaspace+Pojo&amp;url=http%3A%2F%2Fmartinaharris.com%2F2009%2F12%2Funtangling-a-gigaspace-pojo%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Untangling+a+Gigaspace+Pojo&amp;u=http%3A%2F%2Fmartinaharris.com%2F2009%2F12%2Funtangling-a-gigaspace-pojo%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Untangling+a+Gigaspace+Pojo&amp;url=http%3A%2F%2Fmartinaharris.com%2F2009%2F12%2Funtangling-a-gigaspace-pojo%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Untangling+a+Gigaspace+Pojo&amp;url=http%3A%2F%2Fmartinaharris.com%2F2009%2F12%2Funtangling-a-gigaspace-pojo%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Untangling+a+Gigaspace+Pojo&amp;url=http%3A%2F%2Fmartinaharris.com%2F2009%2F12%2Funtangling-a-gigaspace-pojo%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fmartinaharris.com%2F2009%2F12%2Funtangling-a-gigaspace-pojo%2F&amp;title=Untangling+a+Gigaspace+Pojo&amp;summary=&amp;source=" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fmartinaharris.com%2F2009%2F12%2Funtangling-a-gigaspace-pojo%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fmartinaharris.com%2F2009%2F12%2Funtangling-a-gigaspace-pojo%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fmartinaharris.com%2F2009%2F12%2Funtangling-a-gigaspace-pojo%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div><div class="dzone_button" style="float: right; margin-left: 5px;">
<script type="text/javascript">
var dzone_url = 'http://martinaharris.com/2009/12/untangling-a-gigaspace-pojo/';
var dzone_title = 'Untangling a Gigaspace Pojo';
var dzone_blurb = '';
var dzone_style = '2';
</script>
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>
</div>]]></content:encoded>
			<wfw:commentRss>http://martinaharris.com/2009/12/untangling-a-gigaspace-pojo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

