(new BigDecimal("1.00")).stripTrailingZeros().toPlainString(); // "1"
(new BigDecimal("0.00")).stripTrailingZeros().toPlainString(); // "0.00"
Pages
Monday, June 29, 2009
Thursday, May 14, 2009
ActiveMQ, Ruby, STOMP Transport
ActiveMQ is a popular Enterprise Messaging and Integration Patterns provider. ActiveMQ is designed to communicate over a number of protocols (such as Stomp), and it also supports plenty of cross language clients.
And so here we have a stomp client for ruby, which I found quite easy to use, however quite a few information is available for it.
What you do to use Apache ActiveMQ and the stomp client for ruby?
1, download and install Apache ActiveMQ.
2, download and install rubygems.
3, configure stomp transport in Apache ActiveMQ. In fact, in conf/activemq.xml of your ActiveMQ installation you can see that stomp transport is already configured:

4, writing a message sender using the stomp client for ruby.
5, writing a message listener using the stomp client for ruby.
And so this is it! Just start the ActiveMQ message broker, start the listener (ruby listener.rb), start the sender (ruby sender.rb) and the "Hello World!" message will be transported via ActiveMQ's stomp transport.
And so here we have a stomp client for ruby, which I found quite easy to use, however quite a few information is available for it.
What you do to use Apache ActiveMQ and the stomp client for ruby?
1, download and install Apache ActiveMQ.
2, download and install rubygems.
3, configure stomp transport in Apache ActiveMQ. In fact, in conf/activemq.xml of your ActiveMQ installation you can see that stomp transport is already configured:

4, writing a message sender using the stomp client for ruby.
#sender.rb
require 'rubygems'
require 'stomp'
client = Stomp::Client.open "stomp://localhost:61613"
client.send('/queue/myqueue',"Hello World!")
client.close
5, writing a message listener using the stomp client for ruby.
#listener.rb
require 'rubygems'
require 'stomp'
client = Stomp::Client.open "stomp://localhost:61613"
client.subscribe "/queue/myqueue" do |message|
puts "received: #{message.body} on #{message.headers['destination']}"
end
client.join
client.close
And so this is it! Just start the ActiveMQ message broker, start the listener (ruby listener.rb), start the sender (ruby sender.rb) and the "Hello World!" message will be transported via ActiveMQ's stomp transport.
Friday, May 8, 2009
Oracle 10g JDBC and Java 5
In addition to the previous bug with Oracle 10g JDBC driver v10.1.0.4 and Java 5, when instead of a very small number a very large number gets inserted, we encountered another bug, which was kind of the opposite. This time the exact version of Oracle driver is 10.1.0.5.
Here's a sample code:
inserted 1.03+7 but the result is 10
We cannot rewrite the application, as it already has a lot of Java 5 features in it. One option could be to use retrotranslator and run the application with Java 4. But the problem is that we already use some frameworks that make use of Java 5 API and we cannot overcome the problem just by translating the bytecodes to the older JVM.
Here's the solution I discovered:
When using the scientific notation for instantiating BigDecimal, calling a toString() method will be:
But changing the scale will produce something different:
That's it! You just can set scale for the BigDecimal that you are about to insert into Oracle database :) So far we're good with this solution, although it looks like a crap.
Here's a sample code:
BigDecimal decimal = new BigDecimal("1.03+7"); PreparedStatement stmt = .... stmt.setBigDecimal(decimal); stmt.update("...some sql...");After the transaction is commited, and we do a query for the result we get .... 10 (!)
We cannot rewrite the application, as it already has a lot of Java 5 features in it. One option could be to use retrotranslator and run the application with Java 4. But the problem is that we already use some frameworks that make use of Java 5 API and we cannot overcome the problem just by translating the bytecodes to the older JVM.
Here's the solution I discovered:
When using the scientific notation for instantiating BigDecimal, calling a toString() method will be:
BigDecimal decimal = new BigDecimal("1.03+7"); System.out.println(decimal);>> 1.03+7
But changing the scale will produce something different:
BigDecimal decimal = new BigDecimal("1.03+7"); System.out.println(decimal.setScale(2));>> 10300000.00
That's it! You just can set scale for the BigDecimal that you are about to insert into Oracle database :) So far we're good with this solution, although it looks like a crap.
Saturday, May 2, 2009
Erlybird: the Erlang plug-in for Netbeans
Erlybird looks very fine while working in Netbeans. Unfortunately Erlide (the Erlang plug-in for eclipse) wasn't that smooth.

The strange thing about the plug-in settings is that it shows itself like if it would be a JRuby plug-in:

What could be done better, I think, is when I run a script, instead of the erl interpreter I could choose a function to be used to start the script. So it could look like any other program I'm running in IDE.

The strange thing about the plug-in settings is that it shows itself like if it would be a JRuby plug-in:

What could be done better, I think, is when I run a script, instead of the erl interpreter I could choose a function to be used to start the script. So it could look like any other program I'm running in IDE.
Friday, May 1, 2009
FIX is digging the ESB world
After Apache Synapse got its FIX integration and Apache Camel followed with the FIX endpoint, we can see now same integration done for Mule ESB. It is interesting, that all the products use QuickFIX/J to implement the integration.
What is it? Is it a hype for the ESB world, to include FIX - there must be a trigger for this kind of features. Do the OMS really demand FIX more and more?
What is it? Is it a hype for the ESB world, to include FIX - there must be a trigger for this kind of features. Do the OMS really demand FIX more and more?
Labels:
apache camel,
apache synapse,
esb,
fix,
mule,
quickfixj
Sunday, April 12, 2009
Sun Tech Days 2009 in St. Petersburg
So I visited Pt.Petersburg in order to take part in Sun Tech Days 2009. Unfortunately the quality of the sessions was twofold, some were missing a lot of technical details. But still it was a good opportunity to visit St. Petersburg - an astonishing city.

The first session I attended was OpenSSO, delivered by Sang Shin
OpenSSO looks very promising. A very modular design of the framework allows to use virtually any authentication scheme.
Next, I attended a session about DTrace, quite a powerful tool for monitoring your applications.
Also, JSR-290 looks very promising!
I also attended the superb talk by Yakov Sirotkin, about organizing the asynchronous jobs using the Oracle AQ.
Also, VirtualBox have been advertised quite heavily.

The first session I attended was OpenSSO, delivered by Sang Shin
![]() |
OpenSSO looks very promising. A very modular design of the framework allows to use virtually any authentication scheme.
Next, I attended a session about DTrace, quite a powerful tool for monitoring your applications.
![]() |
![]() |
Also, JSR-290 looks very promising!
![]() |
I also attended the superb talk by Yakov Sirotkin, about organizing the asynchronous jobs using the Oracle AQ.
![]() |
Also, VirtualBox have been advertised quite heavily.
![]() |
Wednesday, March 11, 2009
camel-quickfix update: Simple Acceptor Usage Scenario
The simplest usage scenario of a Quickfix/J Acceptor in Apache Camel would be as follows:
The bean will receive a class instance derived from quickfix.Message and the user can do what ever he wants with this model. However, very often you may want to map the FIX representation onto your own object model. For this purpose camel-bindy is a nice tool, where you can describe how the FIX string should be mapped onto the object model.
So now we have a bit improved version of the scenario:
So, now the target bean will receive the message which is defined in your own object model.
This is the simplest scenario, but there's more to come.
from("quickfix-server:server.cfg").
to("bean:someBean");
The bean will receive a class instance derived from quickfix.Message and the user can do what ever he wants with this model. However, very often you may want to map the FIX representation onto your own object model. For this purpose camel-bindy is a nice tool, where you can describe how the FIX string should be mapped onto the object model.
So now we have a bit improved version of the scenario:
DataFormat bindy = ...
from("quickfix-server:server.cfg")
.unmarshall(bindy)
.to("bean:someBean");
So, now the target bean will receive the message which is defined in your own object model.
This is the simplest scenario, but there's more to come.
Tuesday, February 24, 2009
camel-quickfix: Working with FIX messages using Apache Camel
Apache Camel
Apache Camel is a powerful open source integration framework based on known Enterprise Integration Patterns. The very nice feature in Camel is that it provides many out-of-the-box components to be reused for any kind of data sources or services.
FIX (Financial Information eXchange)
FIX is an open specification intended to streamline electronic communications in the financial industry. FIX is governed by fixprotocol.org. FIX messages are constructed with name value pairs that contains a standard header (which contains a message type property), a body and a trailer.
Here's a sample FIX message: Buy 1000 DELL @ MKT
Thousands of small investment firms use FIX protocol and benefit from it as its specification is open and free. FIX supports derivatives like equity, options, FOREX (Foreign Exchange) and fixed incomes, like bonds.
Apache Camel and FIX
For the enterprise version of Apache Camel, the FUSE mediation router, there exists a component that should enable integration via FIX protocol using Camel. The current implementation depends on the Artix Data Services, which is not open-sourced, and also there are some requests for enhancements. There is also a JIRA issue: #CAMEL-1350.
Currently, we also have a project which requires integration with NASDAQ INET platform using FIX protocol, and Apache Camel would be a great tool for that, if it only had a FIX component without Artix DS dependency. For this purpose I have a small project at Google Project site: camel-quickfix.
There's a TODO list at the moment, which includes message normalization and component orchestration issues. But also there's a number of scenarios that are required to be supported in that component (or with its aid). For instance, if our application is an initiator, then in Camel DSL we write:
But, in FIX communication, the acceptor side is responding with ExecutionReport message. So, we have an issue here, how should it be supported? Either to request some sort a callback mechanism into Camel DSL, or force the QuickfixApplication to reuse the Camel context to route the response message back. This issue will go to another post.
Apache Camel is a powerful open source integration framework based on known Enterprise Integration Patterns. The very nice feature in Camel is that it provides many out-of-the-box components to be reused for any kind of data sources or services.
FIX (Financial Information eXchange)
FIX is an open specification intended to streamline electronic communications in the financial industry. FIX is governed by fixprotocol.org. FIX messages are constructed with name value pairs that contains a standard header (which contains a message type property), a body and a trailer.
Here's a sample FIX message: Buy 1000 DELL @ MKT
8=FIX.4.0#9=105#35=D#34=2#49=BANZAI#52=20080711-06:42:26#56=SYNAPSE#11=1215758546278#21=1#38=1000#40=1#54=1#55=DELL#59=0#10=253
Thousands of small investment firms use FIX protocol and benefit from it as its specification is open and free. FIX supports derivatives like equity, options, FOREX (Foreign Exchange) and fixed incomes, like bonds.
Apache Camel and FIX
For the enterprise version of Apache Camel, the FUSE mediation router, there exists a component that should enable integration via FIX protocol using Camel. The current implementation depends on the Artix Data Services, which is not open-sourced, and also there are some requests for enhancements. There is also a JIRA issue: #CAMEL-1350.
Currently, we also have a project which requires integration with NASDAQ INET platform using FIX protocol, and Apache Camel would be a great tool for that, if it only had a FIX component without Artix DS dependency. For this purpose I have a small project at Google Project site: camel-quickfix.
There's a TODO list at the moment, which includes message normalization and component orchestration issues. But also there's a number of scenarios that are required to be supported in that component (or with its aid). For instance, if our application is an initiator, then in Camel DSL we write:
...to("camel-initiator:config.cfg[?params]
But, in FIX communication, the acceptor side is responding with ExecutionReport message. So, we have an issue here, how should it be supported? Either to request some sort a callback mechanism into Camel DSL, or force the QuickfixApplication to reuse the Camel context to route the response message back. This issue will go to another post.
Friday, January 16, 2009
JBoss Drools: Reasoning on QuickFIX-J data model
I just tried to make a simple JBoss Drools example which could probably handle QuickFIX-J messages. So I created the simplest rule flow, including one RuleSet node, mapped onto a ruleflow-group in a DRL file.

same in textual form:
Next describe to rule in a DRL file:
What looks a little strange to me is the when part:
I spent just quite a few minutes to figure out why my first version of the rule didn't work as I expected. It seemed to me that it would be more natural to make it just in one line, something like this:
With a Java code from the Drools examples (which may also are generated when you create a Drools Project with the Drools eclipse plug-in), I run the example and it works fine.
This example just shows that with Drools one may handle even quite complex data model, such as QuickFIX-J's one. Next, it would have real value if I'm able to make do the same via Guvnor.
same in textual form:
<?xml version="1.0" encoding="UTF-8"?>
<process xmlns="http://drools.org/drools-5.0/process"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/drools-5.0/process drools-processes-5.0.xsd"
type="RuleFlow" name="oms" id="my.oms" package-name="my.oms" >
<header>
</header>
<nodes>
<start id="1" name="Start" x="16" y="16" width="80" height="40" />
<actionNode id="2" name="Action" x="128" y="16" width="80" height="40" >
<action type="expression" dialect="java" >System.out.println("Action Start");</action>
</actionNode>
<ruleSet id="3" name="RuleSet" x="240" y="16" width="80" height="40" ruleFlowGroup="my-oms" />
<actionNode id="4" name="Action" x="352" y="16" width="80" height="40" >
<action type="expression" dialect="java" >System.out.println("Action End");</action>
</actionNode>
<end id="5" name="End" x="464" y="16" width="80" height="40" />
</nodes>
<connections>
<connection from="1" to="2" />
<connection from="2" to="3" />
<connection from="3" to="4" />
<connection from="4" to="5" />
</connections>
</process>
Next describe to rule in a DRL file:
package my.oms
import quickfix.fix44.NewOrderSingle
import quickfix.field.MinQty
rule "reset minqty"
dialect "mvel"
ruleflow-group "my-oms"
when
$order : NewOrderSingle($qty : minQty)
MinQty(value == 1.0 || value > 100.0) from $qty
then
System.out.println("reset order: " + $order);
modify($order){
$order.set(new MinQty(20));
}
end
What looks a little strange to me is the when part:
$order : NewOrderSingle($qty : minQty)
MinQty(value == 1.0 || value > 100.0) from $qty
I spent just quite a few minutes to figure out why my first version of the rule didn't work as I expected. It seemed to me that it would be more natural to make it just in one line, something like this:
NewOrderSingle(MinQty(value == 1.0 || value > 100.0))
With a Java code from the Drools examples (which may also are generated when you create a Drools Project with the Drools eclipse plug-in), I run the example and it works fine.
package my.oms;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.*;
import org.drools.io.ResourceFactory;
import org.drools.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.runtime.StatefulKnowledgeSession;
import quickfix.field.MinQty;
import quickfix.fix44.NewOrderSingle;
public class MyOms {
public static final void main(String[] args) {
try {
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
// go !
NewOrderSingle order = new NewOrderSingle();
order.set(new MinQty(1.0));
NewOrderSingle order1 = new NewOrderSingle();
order1.set(new MinQty(111.0));
NewOrderSingle order2 = new NewOrderSingle();
order2.set(new MinQty(222.0));
ksession.insert(order);
ksession.insert(order1);
ksession.insert(order2);
ksession.startProcess("my.oms");
ksession.fireAllRules();
logger.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("oms.drl"), ResourceType.DRL);
kbuilder.add(ResourceFactory.newClassPathResource("oms.rf"), ResourceType.DRF);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error: errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge.");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
return kbase;
}
}
This example just shows that with Drools one may handle even quite complex data model, such as QuickFIX-J's one. Next, it would have real value if I'm able to make do the same via Guvnor.
Sunday, January 11, 2009
Comparing Strings in C: Wii hack
I've just read an article about game console hacking: Console Hacking 2008: Wii Fail.
One interesting code fragment that was acquired in binary decompilation process:
SHA1_sig, SHA1_in are actually binaries, but are compared like strings, and if both of them start with \0 the strncmp will say that they are equal even if everything else is different.
(As I'm not a C expert to believe it right away) I made a simple code fragment to see it myself:
So the result will be:
So ... happy hacking! :)
One interesting code fragment that was acquired in binary decompilation process:
strncmp(SHA1_sig, SHA1_in, 20);
SHA1_sig, SHA1_in are actually binaries, but are compared like strings, and if both of them start with \0 the strncmp will say that they are equal even if everything else is different.
(As I'm not a C expert to believe it right away) I made a simple code fragment to see it myself:
#include
#include
int main(){
char* x;
char* y;
int res;
x = "\0hello";
y = "\0bye";
res = strncmp(x, y, 20);
printf("The C strings %s and %s are ", x, y);
if (res == 0){
printf("equal\n");
} else {
printf("not equal\n");
}
return 0;
}
So the result will be:
$> ant@ubuntu:~$ gcc test.c ; ./a.out
The C strings and are equal
So ... happy hacking! :)
Subscribe to:
Posts (Atom)