<?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>Blog of Adam Warski</title>
	<atom:link href="http://www.warski.org/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.warski.org/blog</link>
	<description>Java and JBoss related stuff</description>
	<lastBuildDate>Tue, 17 Apr 2012 06:04:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Frameworks vs Libraries as Inheritance vs Composition?</title>
		<link>http://www.warski.org/blog/2012/04/frameworks-vs-libraries-as-inheritance-vs-composition/</link>
		<comments>http://www.warski.org/blog/2012/04/frameworks-vs-libraries-as-inheritance-vs-composition/#comments</comments>
		<pubDate>Tue, 17 Apr 2012 06:04:21 +0000</pubDate>
		<dc:creator>Adam Warski</dc:creator>
				<category><![CDATA[Framework]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[Library]]></category>
		<category><![CDATA[Methodology]]></category>
		<category><![CDATA[Modularity]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.warski.org/blog/?p=570</guid>
		<description><![CDATA[For quite some time inheritance was the dominant model of structuring programs in OO languages like Java. Very often it was used as a mechanism for reusing code &#8211; &#8220;common&#8221; functions where placed in an abstract class, so that subclasses can use them. However, this often proves to be very limiting, as you can only [...]]]></description>
			<content:encoded><![CDATA[<p>For quite some time inheritance was the dominant model of structuring programs in OO languages like Java. Very often it was used as a mechanism for reusing code &#8211; &#8220;common&#8221; functions where placed in an abstract class, so that subclasses can use them.</p>
<p>However, this often proves to be very limiting, as you can only inherit from a single class. The code becomes constrained and tied to one particular framework-specific class. Not to mention testing &#8211; such base classes often depend on outside state, making tests hard to setup.</p>
<p>That&#8217;s why nowadays time and again you can hear that you should prefer composition over inheritance (see for example <a href="http://stackoverflow.com/questions/49002/prefer-composition-over-inheritance">this StackOverflow question</a>). When using composition, you can leverage multiple re-usable chunks of code, and combine them in an arbitrary way. Also using IoC/Dependency Injection strongly favors composition.</p>
<p>I think the above inheritance-composition opposition strongly resembles the framework-library distinction. When using a framework, you are forced into a specific structure, where you must model your code in one specific way. Quite obviously it&#8217;s often hard or impossible to use two frameworks in one layer/module. That&#8217;s how hacks, ugly workarounds, reflection madness, etc. is born.</p>
<p>Libraries on the other hand (unless they are deliberately wrongly written), can be freely combined. Just like composition of classes, you can compose usage of many libraries in one module. Your code can be kept clean and only use the library functionality it really requires.</p>
<p>I&#8217;m not saying that frameworks are bad &#8211; just like inheritance, they may be very useful if used in the correct places. However, next time you put your code into a framework, maybe it&#8217;s better to think twice: can this functionality be implemented using composition, with the help of a library? Won&#8217;t this make my code cleaner and more maintainable?</p>
<p>Adam</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warski.org/blog/2012/04/frameworks-vs-libraries-as-inheritance-vs-composition/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>ElasticMQ 0.4: message replication</title>
		<link>http://www.warski.org/blog/2012/03/elasticmq-0-4-message-replication/</link>
		<comments>http://www.warski.org/blog/2012/03/elasticmq-0-4-message-replication/#comments</comments>
		<pubDate>Wed, 28 Mar 2012 05:52:47 +0000</pubDate>
		<dc:creator>Adam Warski</dc:creator>
				<category><![CDATA[Clustering]]></category>
		<category><![CDATA[Distributed]]></category>
		<category><![CDATA[ElasticMQ]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JBoss]]></category>
		<category><![CDATA[JGroups]]></category>
		<category><![CDATA[Library]]></category>
		<category><![CDATA[Replication]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[SQS]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.warski.org/blog/?p=574</guid>
		<description><![CDATA[ElasticMQ is a message queue system, with Java, Scala and an Amazon SQS-compatible REST interface. The 0.4 release brings a new major feature: data replication. You can now setup a cluster of ElasticMQ nodes, and have each queue and message replicated across this cluster. Each node can use either the in-memory storage, or the DB-backed [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.elasticmq.org">ElasticMQ</a> is a message queue system, with Java, Scala and an Amazon SQS-compatible REST interface.</p>
<p><a href="http://tools.softwaremill.pl/nexus/content/repositories/releases/org/elasticmq/">The 0.4 release</a> brings a new major feature: data replication. You can now setup a cluster of ElasticMQ nodes, and have each queue and message replicated across this cluster. Each node can use either the in-memory storage, or the DB-backed storage. This enables a wide range of deployment scenarios, e.g.:</p>
<ul>
<li>in-memory storage, single node: ideal for testing (ElasticMQ is easily embeddable and can be used to test applications which use Amazon SQS in production)</li>
<li>db storage, multiple nodes, single shared database</li>
<li>in-memory storage, multiple nodes, replication: good if at least one node is always alive</li>
<li>local db storage, multiple nodes, replication: each node has its own persistance. Data safety without the need to setup a clustered database</li>
</ul>
<p>Depending on how safe you want to be from loosing a message, there&#8217;s a variety of replication modes to choose from:</p>
<ul>
<li>fire-and-forget: data replication is done in the background</li>
<li>wait for at least one cluster member to acknowledge that it received the message</li>
<li>wait for a majority of members</li>
<li>wait for all members</li>
</ul>
<p>See the <a href="https://github.com/adamw/elasticmq/blob/master/README.md">README</a> for more details. Starting to use ElasticMQ is really simple!</p>
<p>Clustering is implemented using <a href="http://www.jgroups.org">JGroups</a> (thanks to Bela for the help on the forums!). The cluster can be configured using a standard JGroups configuration file, which means you can either use the UDP stack with multicast discovery, TCP stack with a list of initial node IPs, AWS discovery, and so on. ElasticMQ doesn&#8217;t require any particular JGroups configuration so you are free to use whatever suites your deployment best.</p>
<p>Please note that the replication feature is still at an experimental stage, so bugs (as always) may happen :).</p>
<p>Feedback welcome!</p>
<p>Adam</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warski.org/blog/2012/03/elasticmq-0-4-message-replication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ElasticMQ 0.3: new API, new in-memory storage</title>
		<link>http://www.warski.org/blog/2012/02/elasticmq-0-3-new-api-new-in-memory-storage/</link>
		<comments>http://www.warski.org/blog/2012/02/elasticmq-0-3-new-api-new-in-memory-storage/#comments</comments>
		<pubDate>Mon, 06 Feb 2012 20:52:35 +0000</pubDate>
		<dc:creator>Adam Warski</dc:creator>
				<category><![CDATA[AWS]]></category>
		<category><![CDATA[ElasticMQ]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[SQS]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.warski.org/blog/?p=563</guid>
		<description><![CDATA[ElasticMQ 0.3 just got released! ElasticMQ is a simple message queue system, which exposes both a native and an Amazon SQS-compatible interface. There are two major changes in this release. Firstly, there&#8217;s a new all-Scala/Java in-memory message storage, significantly faster than the previous one, which simply used an in-memory H2 instance; currently the implementation is [...]]]></description>
			<content:encoded><![CDATA[<p><a href="https://github.com/adamw/elasticmq">ElasticMQ</a> 0.3 just got released! ElasticMQ is a simple message queue system, which exposes both a native and an Amazon SQS-compatible interface. There are two major changes in this release.</p>
<p>Firstly, there&#8217;s a new all-Scala/Java in-memory message storage, significantly faster than the previous one, which simply used an  in-memory H2 instance; currently the implementation is based on Java concurrent queues. The usage is still very simple, to create an ElasticMQ instance with in-memory storage just execute:</p>
<pre class="brush: scala; title: ; notranslate">
  val node = NodeBuilder.withInMemoryStorage().build()
  val server = SQSRestServerFactory.start(node.nativeClient,
    8888, &quot;http://localhost:8888&quot;)
</pre>
<p>To show some numbers, here are a couple of runs of the <a href="https://github.com/adamw/elasticmq/blob/master/core/src/test/scala/org/elasticmq/performance/MultiThreadPerformanceTest.scala">MultiThreadPerformanceTest</a> test on my MBP (2.4GHz Core2Duo, 8GB ram; all operations executed using the native API, without the http overhead):</p>
<pre>
    Storage: InMemory, number of threads: 5, number of messages: 50000
    Send took: 3 (3140), ops: 250000, ops per second: 83333
    Receive took: 5 (5057), ops: 250000, ops per second: 50000

    Storage: MySQL, number of threads: 5, number of messages: 2000
    Send took: 5 (5500), ops: 10000, ops per second: 2000
    Receive took: 74 (74269), ops: 10000, ops per second: 135

    Storage: H2, number of threads: 5, number of messages: 2000
    Send took: 0 (841), ops: 10000, ops per second: 10000
    Receive took: 30 (30388), ops: 10000, ops per second: 333
</pre>
<p>I think the difference is pretty clear.</p>
<p>Secondly, the native API has seen a major rewrite. It has a much nicer, object-oriented feel, for example (all classes are thread-safe):</p>
<pre class="brush: scala; title: ; notranslate">
  val node = NodeBuilder.withInMemoryStorage().build()
  val client = node.nativeClient
  val queue = client.createOrLookupQueue(&quot;queue1&quot;);
  queue.sendMessage(&quot;msg1&quot;)
  queue.sendMessage(MessageBuilder(&quot;msg2&quot;).withNextDelivery(tomorrow))
  queue.receiveMessage().map(message =&gt; {
    println(message.content)
    message.delete()
  })
</pre>
<p>See the <a href="https://github.com/adamw/elasticmq/blob/master/api/src/main/scala/org/elasticmq/Client.scala">Client</a>, <a href="https://github.com/adamw/elasticmq/blob/master/api/src/main/scala/org/elasticmq/Queue.scala">Queue</a>, <a href="https://github.com/adamw/elasticmq/blob/master/api/src/main/scala/org/elasticmq/QueueOperations.scala">QueueOperations</a>, <a href="https://github.com/adamw/elasticmq/blob/master/api/src/main/scala/org/elasticmq/Message.scala">Message</a> and <a href="https://github.com/adamw/elasticmq/blob/master/api/src/main/scala/org/elasticmq/MessageOperations.scala">MessageOperations</a> traits for details.</p>
<p>I also created a <a href="https://groups.google.com/forum/?fromgroups#!forum/elasticmq">Google Group</a> in case you have any questions, ideas or problems with ElasticMQ (feedback is very welcome!). </p>
<p>See the <a href="https://github.com/adamw/elasticmq">README</a> for details on how to download and use ElasticMQ in your SBT/Maven project.</p>
<p>Adam</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warski.org/blog/2012/02/elasticmq-0-3-new-api-new-in-memory-storage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ElasticMQ 0.2 &#8211; support for delayed queues and messages</title>
		<link>http://www.warski.org/blog/2012/01/elasticmq-0-2-support-for-delayed-queues-and-messages/</link>
		<comments>http://www.warski.org/blog/2012/01/elasticmq-0-2-support-for-delayed-queues-and-messages/#comments</comments>
		<pubDate>Thu, 12 Jan 2012 16:52:54 +0000</pubDate>
		<dc:creator>Adam Warski</dc:creator>
				<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Distributed]]></category>
		<category><![CDATA[ElasticMQ]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[SQS]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.warski.org/blog/?p=555</guid>
		<description><![CDATA[Time to start blogging in 2012 :) I just released version 0.2 of ElasticMQ &#8211; a simple message queue system, which implements the Amazon SQS interface. Ideal if you want to test a service which uses SQS, or create a system which can leverage either the AWS infrastructure or run stand-alone. The new version brings [...]]]></description>
			<content:encoded><![CDATA[<p>Time to start blogging in 2012 :)</p>
<p>I just released version 0.2 of <a href="https://github.com/adamw/elasticmq">ElasticMQ</a> &#8211; a simple message queue system, which implements the <a href="http://aws.amazon.com/sqs/">Amazon SQS</a> interface. Ideal if you want to test a service which uses SQS, or create a system which can leverage either the AWS infrastructure or run stand-alone.</p>
<p>The new version brings support for some new Amazon SQS features: delayed messages and queues. See the <a href="http://aws.typepad.com/aws/2011/10/amazon-simple-queue-service-batch-operations-delay-queue-and-message-timers.html">Amazon Blog</a> for details.</p>
<p>Also, I changed the testsuite to use <a href="http://aws.amazon.com/sdkforjava/">Amazon&#8217;s Java SDK</a>. So you can be pretty sure that ElasticMQ works with SQS clients :). As an example, here&#8217;s the required code (in Scala, Java equivalent would be obviously a bit longer ;) ) to start an ElasticMQ node, send &#038; receive a message using Amazon Java SDK and shutdown the server.</p>
<pre class="brush: scala; title: ; notranslate">
// First we need to create a Node
val node = NodeBuilder.withInMemoryStorage().build()
// Then we can expose the native client using the SQS REST interface
val server = SQSRestServerFactory.start(node.nativeClient, 8888,
      &quot;http://localhost:8888&quot;)

// Now we need to create the sqs client
client = new AmazonSQSClient(new BasicAWSCredentials(&quot;x&quot;, &quot;x&quot;))
client.setEndpoint(&quot;http://localhost:8888&quot;)

// Using the client is quite straightforward
val queueUrl = client.createQueue(new CreateQueueRequest(&quot;queue1&quot;))
      .getQueueUrl
client.sendMessage(new SendMessageRequest(queueUrl, &quot;message1&quot;))

client.shutdown()

// Finally we need to stop the server and the node
server.stop()
node.shutdown()
</pre>
<p>For more information about ElasticMQ, information on SBT and Maven dependencies, see the <a href="https://github.com/adamw/elasticmq">webpage</a>.</p>
<p>Stay tuned,<br />
Adam</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warski.org/blog/2012/01/elasticmq-0-2-support-for-delayed-queues-and-messages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ElasticMQ 0.1 released!</title>
		<link>http://www.warski.org/blog/2011/10/elasticmq-0-1-released/</link>
		<comments>http://www.warski.org/blog/2011/10/elasticmq-0-1-released/#comments</comments>
		<pubDate>Wed, 12 Oct 2011 10:04:08 +0000</pubDate>
		<dc:creator>Adam Warski</dc:creator>
				<category><![CDATA[AWS]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Distributed]]></category>
		<category><![CDATA[ElasticMQ]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JBoss]]></category>
		<category><![CDATA[Netty]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[SQS]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.warski.org/blog/?p=547</guid>
		<description><![CDATA[ElasticMQ is a simple messaging system, exposing an SQS-compatible REST interface. It can run using an in-memory H2 database (ideal for testing), or backed by a normal database (e.g. MySQL). Using ElasticMQ can&#8217;t get much simpler, just include the dependency and: (the code below is Scala, but it is just as easy to use from [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://elasticmq.org">ElasticMQ</a> is a simple messaging system, exposing an <a href="http://aws.amazon.com/sqs/">SQS</a>-compatible REST interface. It can run using an in-memory H2 database (ideal for testing), or backed by a normal database (e.g. MySQL).</p>
<p>Using ElasticMQ can&#8217;t get much simpler, just include the dependency and: (the code below is Scala, but it is just as easy to use from Java)</p>
<pre class="brush: scala; title: ; notranslate">
// First we need to create a Node
val node = NodeBuilder.withInMemoryStorage().build()
// Then we can expose the native client using the SQS REST interface
val server = SQSRestServerFactory.start(node.nativeClient,
                   8888,
                   &quot;http://localhost:8888&quot;)

// ... use: http://localhost:8888 exposes the full SQS interface ...

// Finally we need to stop the server and the node
server.stop()
node.shutdown()
</pre>
<p>ElasticMQ is written entirely in <a href="http://scala-lang.org">Scala</a>, leveraging the <a href="http://squeryl.org/">Squeryl</a> library for ORM and <a href="http://www.jboss.org/netty">Netty</a> for implementing the REST server.</p>
<p>The 0.1 release contains support for all SQS actions, providing a fully-functional SQS replacement. A tiny fraction message attributes is still not supported (e.g. <code>SenderId</code>).</p>
<p>Moreover, ElasticMQ will soon see its first production usage, serving as the messaging system behind one of the services we develop. The service used to be deployed on US-based servers, and it then successfully used the US-East SQS service. However, after moving the servers to Australia, as there&#8217;s no local AWS center, the communication delays with US and Singapore SQS servers became unacceptable; hence the need for a local SQS installation.</p>
<p>Adam</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warski.org/blog/2011/10/elasticmq-0-1-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Envers bundled with JBoss AS 7.0.2!</title>
		<link>http://www.warski.org/blog/2011/09/envers-bundled-with-jboss-as-7-0-2/</link>
		<comments>http://www.warski.org/blog/2011/09/envers-bundled-with-jboss-as-7-0-2/#comments</comments>
		<pubDate>Wed, 28 Sep 2011 20:05:03 +0000</pubDate>
		<dc:creator>Adam Warski</dc:creator>
				<category><![CDATA[Envers]]></category>
		<category><![CDATA[Forge]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JBoss]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.warski.org/blog/?p=532</guid>
		<description><![CDATA[Using Envers is now even easier! Since version 7.0.2, Envers comes bundled with JBoss Application Server. To showcase how easy the integration is, I created a small JSF/CDI application, which uses Envers and can be deployed straight to AS7. To build the application I decided to try out JBoss Forge, which turned out to be [...]]]></description>
			<content:encoded><![CDATA[<p>Using <a href="http://jboss.org/envers">Envers</a> is now even easier! Since <a href="http://jboss.org/jbossas/downloads">version 7.0.2</a>, Envers comes bundled with JBoss Application Server.</p>
<p>To showcase how easy the integration is, I <a href="https://github.com/adamw/envers-as7-demo">created a small JSF/CDI application</a>, which uses Envers and can be deployed straight to AS7. To build the application I decided to try out <a href="http://jboss.org/forge">JBoss Forge</a>, which turned out to be very easy to use and provided me with a simple one-entity CRUD in no time. Just a few changes made it possible to track changes made to the entity, and view its history.</p>
<p>So if you are using AS 7.0.2, to add Envers to your app you just need to:</p>
<ol>
<li>Add <code>hibernate-envers</code> to the <code>pom.xml</code> using the <code>provided</code> scope</li>
<li>Add <code>@Audited</code> to the entities that you want to audit</li>
</ol>
<p>To view all the changes necessary in detail, just <a href="https://github.com/adamw/envers-as7-demo/commit/ccad766bc834b6211d57391bed04f76904a64456">take a look at this commit</a> (note that the <code>MANIFEST.MF</code> file is not required, as I initially mistakenly thought).</p>
<p>Apart from storing the changes, you may also want to view the history of an entity. That&#8217;s also pretty straightforward. All we need is to create a new JSF view and a CDI bean with a method running a simple history query. Again, <a href="https://github.com/adamw/envers-as7-demo/commit/be08646bf3bca842004cdd5374c218bbdfbf820c">this commit</a> shows all the changes needed.</p>
<p><img src="http://www.warski.org/blog/wp-content/uploads/2011/09/envers_as7_demo_screenshot.png" alt="" width="75%" /></p>
<p>You can deploy the application in two ways:</p>
<ol>
<li>Run <code>mvn clean install</code>, and copy the resulting <code>.war</code> to <code>jboss/standalone/deployments</code></li>
<li>If you are using Forge, run <code>forge</code> from the checkout directory, and invoke: <code>build</code>, then: <code>as7 deploy</code></li>
</ol>
<p>After deployment, you should be able to access the application using <code>http://localhost:8080/envers-as7-demo</code>. Click on the <code>Person</code> link on the left to add, edit, list and view history of the entity.</p>
<p>By default, the application uses an example datasource, but if you wish to explore the additional schema generated by Envers you can easily change it to another database by modifying <code>persistence.xml</code> and creating a new datasource in the AS administration console.</p>
<p>As always I invite you to submit feedback on the <a href="http://community.jboss.org/en/hibernate/envers?view=discussions">Envers forum</a>. Have fun!</p>
<p>Adam</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warski.org/blog/2011/09/envers-bundled-with-jboss-as-7-0-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to handle inheritance and @Audited?</title>
		<link>http://www.warski.org/blog/2011/09/how-to-handle-inheritance-and-audited/</link>
		<comments>http://www.warski.org/blog/2011/09/how-to-handle-inheritance-and-audited/#comments</comments>
		<pubDate>Thu, 08 Sep 2011 12:13:05 +0000</pubDate>
		<dc:creator>Adam Warski</dc:creator>
				<category><![CDATA[Envers]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JBoss]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.warski.org/blog/?p=528</guid>
		<description><![CDATA[Some Envers uses had problems because of the limited flexibility in specifying which fields from superclasses (especially those annotated with @MappedSuperclass) should be audited or not. We improved a bit in the latest release, by being able to explicitly enumerate the superclasses to audit. But still this is not fully flexible. That&#8217;s why Łukasz Antoniak [...]]]></description>
			<content:encoded><![CDATA[<p>Some <a href="http://jboss.org/envers">Envers</a> uses had problems because of the limited flexibility in specifying which fields from superclasses (especially those annotated with <code>@MappedSuperclass</code>) should be audited or not. We improved a bit in the latest release, by being able to explicitly enumerate the superclasses to audit.</p>
<p>But still this is not fully flexible. That&#8217;s why <a href="http://lukaszantoniak.wordpress.com/">Łukasz Antoniak</a> started a discussion on the Envers forum (<a href="http://community.jboss.org/message/624057#624057">http://community.jboss.org/message/624057#624057</a>) to gather remarks and use-cases on how people use Envers with inheritance. Your opinion will be very valuable to us, so please share!</p>
<p>Adam</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warski.org/blog/2011/09/how-to-handle-inheritance-and-audited/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Blending Ruby (on Rails) and CDI on OpenBlend 2011</title>
		<link>http://www.warski.org/blog/2011/09/blending-ruby-on-rails-and-cdi-on-openblend-2011/</link>
		<comments>http://www.warski.org/blog/2011/09/blending-ruby-on-rails-and-cdi-on-openblend-2011/#comments</comments>
		<pubDate>Thu, 08 Sep 2011 08:56:57 +0000</pubDate>
		<dc:creator>Adam Warski</dc:creator>
				<category><![CDATA[CDI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JBoss]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[OpenBlend]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[TorqueBox]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Weld]]></category>

		<guid isPermaLink="false">http://www.warski.org/blog/?p=523</guid>
		<description><![CDATA[I will have the pleasure to speak on OpenBlend 2011, in exactly a week: 15th September 2011, which will take place in Ljubljana, Slovenia. Apart from many other interesting presentations, I will be demoing Torquebox &#038; CDI integration. Torquebox is an enhanced JBoss AS, which besides being the regular JEE container everybody knows lets you [...]]]></description>
			<content:encoded><![CDATA[<p>I will have the pleasure to speak on <a href="http://www.openblend.org/en/home">OpenBlend 2011</a>, in exactly a week: 15th September 2011, which will take place in <a href="http://en.wikipedia.org/wiki/Ljubljana">Ljubljana, Slovenia</a>.</p>
<p>Apart from many other interesting presentations, I will be demoing <a href="http://torquebox.org/">Torquebox</a> &#038; CDI integration. Torquebox is an enhanced JBoss AS, which besides being the regular JEE container everybody knows lets you deploy Ruby applications and provides Ruby integration for various AS components (like clustering or caching). This also includes applications written in Ruby on Rails.</p>
<p>Moreover, you can deploy mixed Ruby and Java applications. And that&#8217;s exactly what we will do: deploy an application which has a Ruby-on-Rails frontend (which will provide us with instance code changes) and a CDI/Weld backend (with all the goodies coming from a DI framework, typesafety and Java).</p>
<p>Additionally, everything will run on the brand-new and lightning-fast <a href="http://jboss.org/jbossas">JBoss AS 7</a>, which is the base for Torquebox 2.0.</p>
<p>See you there!<br />
Adam</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warski.org/blog/2011/09/blending-ruby-on-rails-and-cdi-on-openblend-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Modules, modules, modules &#8230;</title>
		<link>http://www.warski.org/blog/2011/08/modules-modules-modules/</link>
		<comments>http://www.warski.org/blog/2011/08/modules-modules-modules/#comments</comments>
		<pubDate>Tue, 30 Aug 2011 18:34:39 +0000</pubDate>
		<dc:creator>Adam Warski</dc:creator>
				<category><![CDATA[CDI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JBoss]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[Modularity]]></category>
		<category><![CDATA[OSGi]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.warski.org/blog/?p=499</guid>
		<description><![CDATA[I think everybody will agree that writing modular applications and modularity in general is a good thing. But how does support for modularity look like, both from the Java and Scala languages and various Java/Scala frameworks? There&#8217;s a lot of different approaches! Let&#8217;s look at some of them. Below &#8220;protection&#8221; means how well modules are [...]]]></description>
			<content:encoded><![CDATA[<p>I think everybody will agree that writing modular applications and modularity in general is a <em>good thing</em>. </p>
<p>But how does support for modularity look like, both from the Java and Scala languages and various Java/Scala frameworks? There&#8217;s a lot of different approaches! Let&#8217;s look at some of them. Below &#8220;protection&#8221; means how well modules are separated either at compile-time or run-time.</p>
<h4>Packages</h4>
<p>First of all we&#8217;ve got <strong>Java (or Scala) packages</strong>. The concept is very useful when it comes to organizing the source code. However it doesn&#8217;t offer compile-time or run-time (except for the package-protected visibility, which isn&#8217;t used too widely) protection, so it&#8217;s rather hard to say that packages are any help in modularizing the code. Also, there&#8217;s a lot of naming problems and hence conventions: if for example we have two implementations of a data reader, one using a database, the second using the filesystem, should the associated classes go to <code>database</code> and <code>filesystem</code> subpackages, or stay in the same top-level package? Should the class names be prefixed with <code>Database</code> and <code>Filesystem</code>, even if they are inside the dedicated packages?</p>
<h4>Build subprojects</h4>
<p>Secondly, there&#8217;s <strong>Maven/SBT modules/subprojects</strong>. They offer compile-time protection, which is a very nice thing: we can now statically make sure that our code only references classes from the explicitly specified dependencies. However, then comes the obvious question: when is a functionality &#8220;big enough&#8221; to make it a separate Maven module? Is it ok to have many Maven modules, each containing only several classes (which can be a PITA, having to define a separate pom, directory structure for each), or should they be bigger? What about naming conventions, should the package name correspond to the module name? If so, we&#8217;re clearly violating <a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY</a> here ;)!</p>
<p>Imagine we decide to put our database and filesystem data readers into separate packages, maven modules and name them appropriately. So we have a <code>DatabaseReader</code> (plus 10 helper classes) in a <code>foo.bar.database</code> package in the <code>myapp-database</code> Maven module. Now a simple refactoring: renaming &#8220;database&#8221; to &#8220;db&#8221; becomes a really complex task, most certainly ending up in using various terms in various places.</p>
<h4>OSGi</h4>
<p>The next step of the evolution would be <a href="http://www.google.pl/url?sa=t&#038;source=web&#038;cd=2&#038;ved=0CDQQFjAB&#038;url=http%3A%2F%2Fwww.osgi.org%2F&#038;ei=Jt1HTrKdAcWZOpSCpfMD&#038;usg=AFQjCNGL-pQ2Iv69bMfSqJx-r9JSJhmWZA&#038;sig2=4ts3qWb8xeebWC80x4Kefw">OSGi bundles</a> (or, equivalently, a module in <a href="https://docs.jboss.org/author/display/MODULES/Home">JBoss Modules</a> or in <a href="http://openjdk.java.net/projects/jigsaw/">Project Jigsaw</a>). One such bundle is typically a product of one (or more) Maven module, but it also offers run-time protection by appropriately scoping class-loaders. All of the problems from Maven modules are inherited &#8230; with the additional need to name the bundle!</p>
<h4>Nested classes/cake pattern</h4>
<p>Another possibility of scoping your code is using <strong>nested classes</strong>, or even to go further and use the <a href="http://www.warski.org/blog/2010/12/di-in-scala-cake-pattern/">Cake pattern in Scala</a>. Apart from the old problems: what package to use and how to name the module class, we&#8217;ve got a couple new ones. Firstly, the whole source code of the module is now in one file. This can mean really long files! However maybe that&#8217;s more of an IDE problem: nobody said that a file needs to be edited all at once; the editor could show only one module class/method (like in the Smalltalk IDE). Cake pattern is also <a href="http://www.warski.org/blog/2011/04/di-in-scala-cake-pattern-pros-cons/">not free of problems</a>. And, what about nested modules?</p>
<h4>DI frameworks</h4>
<p>Finally, we&#8217;ve got various <strong>DI frameworks</strong> (like Guice, Spring or CDI), where, if we look from an appropriate perspective, we define small modules (classes) which can depend on other modules (injected by the container). Separating the module interface (java interface) from the module implementation (java class), and only injecting the interface is also very common. But again, the only way to partially statically prevent injecting the implementation we have to resort to creating separate <code>-api</code> and <code>-impl</code> Maven modules.</p>
<p>In fact, if we take the approach of nested classes, a DI framework may be very well suited for resolving inter-module dependencies and doing all of the wiring for us (which can be very useful if we want to be protected from situations where a module has a new dependency, and each use-site must be now amended).</p>
<h4>Next?</h4>
<p>To sum up, I think that the various approaches to supporting modularity could use some unification. And, unfortunately, this would probably mean totally departing from what we know today from Java/Scala: a new package system, a new build system, a new runtime system. Unfortunately the outcrop of new programming languages doesn&#8217;t offer much in that area.</p>
<p>Do you think there should be one module system, usable both in the small (single classes) and in the large (sets of classes)? After all, what a <strong>DI container</strong> does to resolve the dependencies and instantiate classes isn&#8217;t so much different from what <strong>Maven</strong> or an <strong>OSGi</strong> runtime does when booting!</p>
<p>Or maybe modules inherently have several types, small ones (class-level) and big ones (maven module/osgi bundle-level)?</p>
<p>Lastly, maybe there are some other non-JVM based languages, which solve the modularity problem (still being usable) in a nicer way?</p>
<p>Adam</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warski.org/blog/2011/08/modules-modules-modules/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Introducing ElasticMQ: Scala SQS alternative</title>
		<link>http://www.warski.org/blog/2011/08/introducing-elasticmq-scala-sqs-alternative/</link>
		<comments>http://www.warski.org/blog/2011/08/introducing-elasticmq-scala-sqs-alternative/#comments</comments>
		<pubDate>Tue, 16 Aug 2011 05:22:48 +0000</pubDate>
		<dc:creator>Adam Warski</dc:creator>
				<category><![CDATA[AWS]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Distributed]]></category>
		<category><![CDATA[DSL]]></category>
		<category><![CDATA[ElasticMQ]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Netty]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[SQS]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.warski.org/blog/?p=482</guid>
		<description><![CDATA[Wanting to explore Scala and some new Scala/Java libraries I started writing ElasticMQ. It is a simple message queueing system, following closely Amazon SQS semantics and exposing a REST SQS-like interface. Currently only the basic operations are implemented. ElasticMQ can be useful as an SQS replacement, e.g. for for testing SQS applications. My aim was [...]]]></description>
			<content:encoded><![CDATA[<p>Wanting to explore Scala and some new Scala/Java libraries I started writing <a href="https://github.com/adamw/elasticmq">ElasticMQ</a>. It is a simple message queueing system, following closely <a href="http://aws.amazon.com/sqs/">Amazon SQS</a> semantics and exposing a REST SQS-like interface. Currently only the basic operations are implemented. ElasticMQ can be useful as an SQS replacement, e.g. for for testing SQS applications.</p>
<p>My aim was to make the usage as simple as possible, that&#8217;s why to create a new node and expose the REST interface all you need to do is:</p>
<pre class="brush: java; title: ; notranslate">
val node = NodeBuilder.createNode
val server = SQSRestServerFactory.start(node.nativeClient, 8888,
                 &quot;http://localhost:8888&quot;)
</pre>
<p>Now simply point your SQS client to <code>http://localhost:8888</code> and you should be able to create/delete queues, change the visibility timeout, send and receive messages.<br />
When you are done using ElasticMQ, you can shutdown the node and the server:</p>
<pre class="brush: java; title: ; notranslate">
server.stop()
node.shutdown()
</pre>
<p>All of the source code is available on <a href="https://github.com/adamw/elasticmq">GitHub</a>. See the readme for instructions on how to add ElasticMQ as a dependency to your Maven or SBT project.</p>
<p>On the technical side, ElasticMQ uses a number of interesting things.</p>
<p>Firstly, there&#8217;s <a href="http://www.jboss.org/netty">Netty</a>, an asynchronous, event-driven java NIO framework. I used Netty to implement the REST server. All of the requests are processed in a non-blocking way.</p>
<p>The messages are currently stored in an in-memory H2 database (but this can be easily changed to point e.g. to a MySQL or PostgreSQL DB), and managed using the <a href="http://squeryl.org/">Squeryl</a> Scala library. Squeryl lets you write SQL queries as typesafe Scala code, e.g.:</p>
<pre class="brush: java; title: ; notranslate">
update(messages)(m =&gt;
  where(m.id === message.id and m.lastDelivered === message.lastDelivered)
    set(m.lastDelivered := lastDelivered))
</pre>
<p>For integration testing I am using the <a href="http://code.google.com/p/typica/">Typica</a> library.</p>
<p>On the Scala side, I created a simple internal DSL for defining rest handlers. The server (which uses Netty) is generic and can be provided with any number of &#8220;rest handlers&#8221;, to which requests are dispatched. Each rest handler specifies what is the path it will respond to, what are the required parameters and what should be run in response to a request. For example:</p>
<pre class="brush: java; title: ; notranslate">
val handler1 = (createHandler
   forMethod GET
   forPath (root / &quot;products&quot; / %(&quot;name&quot;) / &quot;price&quot;)
   requiringParameters List(&quot;currency&quot;, &quot;quantity&quot;)
   requiringParameterValues Map(&quot;department&quot;-&gt;&quot;electronics&quot;)
   running electronicsPriceRequestLogic)

val server = RestServer.start(handler1 :: handler2 :: … :: Nil, 8888)
</pre>
<p>See the <a href="https://github.com/adamw/elasticmq/blob/master/rest/rest-core/src/main/scala/org/elasticmq/rest/RequestHandlerLogic.scala">RequestHandlerLogic</a> file for the implementation and <a href="https://github.com/adamw/elasticmq/blob/master/rest/rest-core/src/test/scala/org/elasticmq/rest/RequestHandlerBuilderTestSuite.scala">RequestHandlerBuilderTestSuite</a> for example usage.</p>
<p>In fact there&#8217;s another small DSL for defining paths. For example <code>(root / "a" / "b" / "c")</code> will only match <code>a/b/c</code>, but <code>(root / "a" / %("p1") / "c")</code> will match <code>a/anything/c</code>, with the middle component being assigned to the <code>p1</code> parameter. You can also use regex, e.g. <code>(root /  "a" / """[a-z0-9]+""".r / "c")</code> for matching path components. See the RestPath <a href="https://github.com/adamw/elasticmq/blob/master/rest/rest-core/src/main/scala/org/elasticmq/rest/RestPath.scala">class</a> and <a href="https://github.com/adamw/elasticmq/blob/master/rest/rest-core/src/test/scala/org/elasticmq/rest/RestPathTestSuite.scala">test</a> for details.</p>
<p>Not sure where ElasticMQ will go in the future, but I can image lots of interesting possibilities. So stay tuned :).</p>
<p>Comments about the code, Scala style, Netty/Squeryl usage are very welcome! As well as any other ideas, improvement suggestions etc.</p>
<p>Adam</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warski.org/blog/2011/08/introducing-elasticmq-scala-sqs-alternative/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

