Wednesday, December 29, 2010

Homebrew now has an improved sbt launcher script

In my latest adventures with Scala, I've gone all in, and have been using sbt as my build tool of choice. And, given that I hate installing things myself, I installed using the world most awesome package manager for Mac, Homebrew.

Lately, though, I've been having trouble with sbt running out of permgen space. Rather than just making some local mods to my launcher script, I patched Homebrew's launcher script, which adamv quickly accepted. (Thanks!)

If you used Homebrew to install sbt on your Mac, the next time you update you'll find the launcher more configurable.

Create a file in your home directory named .sbtconfig. In that file, you can define the environment variable SBT_OPTS to be to extra options passed to Java when launching sbt. You can set -Xmx, -XX:MaxPermSize, or any other tuning you might find necessary, (such as -XX:+CMSClassUnloadingEnabled). My file looks like this:
SBT_OPTS="-XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m"
I hope running out of permgen is now a thing of the past. We'll see!

Enjoy!

Wednesday, July 14, 2010

Scala 2.8.0

Anyone else who's a language enthusiast would be glad to know that Scala 2.8.0 is stabilized and officially released.

For those who don't know, Scala (stands for scalable-language) is a hybrid functions/OO language. It runs on the JVM and is fully compatible with existing Java code.
Now we just need Lift 2.1, and some really exciting things can begin!

Friday, June 4, 2010

Maven Versioning

Managing version numbers in Maven has always been an extreme hassle. Especially when it comes time to upgrade components.

I don't know why I've never found it before, but the Maven Versions Plugin can deal with much of that for you. Check it out!

Friday, April 9, 2010

Type Coercion failed no more

We recently upgrade from Flex 3.2 to Flex 3.5, and ran into a slew of mysterious type coercion errors.
Type Coercion failed: cannot convert Object@... to com.mycompany.myapp.MyDto
Executive summary: if you have a loadable module that gets loaded, unloaded, reloaded, and you use RemoteClass for annotating DTO's for BlazeDS or LDS, then you're going to have some Type Coercion issues after the reload. In the preinitialize method of your module, you need to manually register your classes using registerClassAlias.

A bit of context about our application. First we load a generalized shell of a console, which can then loads within it one of many Modules that runs different applications. Depending on what the user does, different modules get loaded and unloaded at run-time.

Our module makes heavy use of BlazeDS for communication with the back-end Java server. The objects we were getting the type conversion errors on were always our DTO objects, which were marked with the RemoteClass metadata tag for serializing to/from the server with BlazeDS. And the error always seemed to happen during de-serialization.

Things always worked fine the first time the module was loaded. But if it got unloaded and re-loaded, then the Type Coercion errors would start happening.

Googling about the problem usually led us down the path of people having problems with multi-version applications, and the solutions were usually to put the definitions of your remote classes into the main .swf. We don't have a multi-version application (we load, unload, reload the same .swf), and we can't modify the main .swf (it's owned by another team. Anyways, it runs lots of apps and can't reasonably pull in our app specific classes).

So I got to thinking about the problem. We knew that when the module gets reloaded, it gets loaded into a new ApplicationDomain. For whatever reason, when messages get returned from the server back to the client, our best guess was that it was still building objects using the classes from the ApplicationDomain from the first load. The profile confirmed that the old classes were still loaded, and weren't being garbage collected, in spite of our best efforts.

RemoteClass was a bit mystical and magical, but StackOverflow has deeper magic. Discovering that all RemoteClass does is invoke registerClassAlias for you, it was reasonable to think that it wasn't working properly on the subsequent loads.

So a quick trial using registerClassAlias instead of RemoteClass, and the Type Coercion errors go away. Voila!

Friday, March 5, 2010

Collatz

After seeing the xkcd on the Collatz Conjecture, I had to write an example in Scala.
def collatz(n:BigInt):Stream[BigInt] =
if (n == 1) {
Stream(1);
} else {
def next(n:BigInt):BigInt = if ((n % 2) == 0) (n / 2) else (n * 3 + 1);
Stream.cons(n, collatz(next(n)));
}
That was a fun little diversion!

Friday, February 5, 2010

A little less noise, please.

If you work in big corporate America, like I somehow find myself these days, then the server hosting your Git depot has a really annoying /etc/issue file, which you see every time you clone/push/pull/fetch. In my case, it's 20+ lines of noise.

Finally found the magic to suppress the issue. Put the following lines in your ~/ssh/config file.
Host git-depot-server
LogLevel ERROR
Enjoy :-)

Monday, February 1, 2010

IDEA + git, without the passwords

Git is my new favorite in source control. IntelliJ IDEA has long been my favorite IDE.

A nuisance lately has been IDEA prompting me for my SSH key password every time I Commit and Push. Since forever, Ubuntu has added my key to ssh-agent every time I login, giving me both good security and password-less pushing from the command line.

I finally found the config tweak to push from IntelliJ without the prompt.
Settings-->Version Control-->VCSs-->Git
SSH Executable: Native


By using the native SSH client, you take advantage of native key management, like ssh-agent.