Scala as a Java REPL

November 08, 2011 at 09:10 PM | categories: programming, scala | View Comments

After years of Python programming, I've been spoiled by always having a REPL available when I want to test something out. As I spend more and more time in Java, I find myself missing a REPL. Well, no more. I'm happy to report that I've finally found a REPL I like using to test out libraries when I'm working in Java: the Scala REPL.

Today I needed to send some JMS messages to ActiveMQ. Instead of firing up eclipse, creating a maven project to get the dependencies, and then writing some Java code, I used sbt and Scala to create a REPL where I could easily send JMS messages.

Create an sbt project

The first step is to create an sbt project. This is as simple as creating a directory with a build.sbt file in it. My example build.sbt file pulls in two library dependencies that I want to have available in the REPL.

name := "jmstest"

scalaVersion := "2.9.1"

libraryDependencies ++= Seq(
  "org.apache.activemq" % "activemq-core" % "5.5.1",
  "org.slf4j" % "slf4j-simple" % "1.6.4"
)

Run the REPL

Running the REPL is as simple as running sbt console from the newly created sbt project. From there, it's off to the races:

import javax.jms._
import org.apache.activemq.ActiveMQConnectionFactory

val factory = new ActiveMQConnectionFactory("tcp://localhost:61616")
val connection = factory.createConnection
val session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)
val destination = session.createTopic("jms.test")
val producer = session.createProducer(destination)

val message = session.createMapMessage
message.setString("command", "basic_setup")
message.setBoolean("do_stuff", false)
producer.send(message)

That's all there is to it. Scala, with the help of sbt, makes a great REPL for testing out Java libraries.


Astricon2011 Roundup

October 27, 2011 at 07:26 PM | categories: asterisk, conferences | View Comments

I attended Astricon for the first time this year. Getting some facetime with the Asterisk developers was great and I'm a lot more comfortable with what I'll need to do to get some of my changes upstream. Now for some highlights.

Great Presentations

  • Asterisk Architecture (part of the Introduction to Asterisk Development block) by David Vossel. While the presentation rehashed a lot of the information in the Asterisk chapter of The Architecture of Open Source Applications, the presentation made Asterisk development feel much more approachable.
  • Asterisk Webphone by Chris Mattheiu. Very impressive minimal softphone in a browser. Fun to watch someone daring enough to write code live during a presentation. The only downside was that the web phone requires a proprietary Jingle to SIP gateway.
  • IPv6 -- the (Only) Way Forward by Owen DeLong. No nonsense presentation about what it takes to start using IPv6. I appreciated the candor about what works and what doesn't. Especially enjoyable was the VOIP vendor wall of shame.
  • Clustering and Scaling Asterisk with Kamailio by Klaus Darilion. Using a proxy in front of Asterisk is a complex subject and Klaus did a great job distilling the details into a great look at what's possible. I use OpenSIPS for a similar purpose and picked up a few config items I can simplify.
  • Cooking with Asterisk by Leif Madsen. Solid examples of neat things you can do in the dialplan. The example using Originate and chan_spy to playback a recorded message to one side of the call was impressive.

Stuff I Want to Try Now

  • Adhearsion - Advanced Asterisk call control in Ruby
  • StarPy - AGI and AMI interface for Twisted
  • CMU Sphinx and PocketSphinx - Voice recognition
  • Phono - Almost pure Javascript web phone
  • Tropo - Voice, SMS, and XMPP API

The Fun Stuff

  • Overheard some "creative" methods to deal with users that want to fax during a discussion about fax support on Asterisk SCF.
  • Watching Clod Patry win all the tickets in one of the arcade games at the party.
  • Best Business Card: TechPro used cleaning cloths for glasses as business cards. Especially useful with all the snow and water I got on my classes on the way to the conference.

udiskie

June 03, 2010 at 08:55 PM | categories: archlinux, tools | View Comments

With the deprecation of HAL proceeding at full speed it's time to find a new solution for automounting disks on my Linux box. I've been happily using halevt, which does a lot more than disk mounting, but won't be of much use once HAL really goes away. udisks is the replacement that the major desktops are moving to, so I decided to write a simple automounting daemon for those of us not using a major desktop: udiskie. It's a simple udisks client that just takes care of mounting removable media right now. I run it by adding udiskie & to ~/.xinitrc. When I'm done using a removable disk, udiskie-umount will take care of the unmount. I probably can't stress enough how simplistic and undocumented this approach is, but it works for me.

And, of course, for the Archlinux users, it's already packaged in the AUR: udiskie


pm-utils and Locked Screens

April 06, 2010 at 05:54 AM | categories: tips, archlinux | View Comments

pm-utils seems to be the clear winner to userspace suspend and hibernate setup. It's a great back, but, for those of us who don't run a desktop environment with a power manager, there's one thing missing: screen locking. I'd like the screen to be locked when my computer resumes from either suspend or hibernate, and I don't want to run gnome-power-manager to get that functionality. So, 00lock-screen to the rescue. Just drop that file in /etc/pm/sleep.d and, as long as you have xscreensaver, gnome-screensaver, i3lock, or xlock setup, the screen will lock as your computer suspends or hibernates.

For the Archlinux users, it's already packaged in the AUR: pm-utils-screen-lock


OpenWRT on the D-Link DIR-615

March 10, 2010 at 06:41 AM | categories: tips | View Comments

Last night, I finally got around to installing the OpenWRT 10.03 Beta on my D-Link DIR-615. The short version: it works and works well. There were only two surprises I ran into.

The first surprise is that the wireless drivers are not included in the install image. Running opkg update; opkg install kmod-ath9k takes care of that. The drivers are left out by design at least on this router and the WRT160NL. Bonus points to OpenWRT for allowing me to file a bug without creating an account on their bug tracker.

The second surprise is that the dynamic dns client doesn't know about DNS-O-Matic. I installed the ddns-scripts package and used the following config to get it working:

config 'service' 'myddns'
    option 'ip_source' 'network'
    option 'ip_network' 'wan'
    option 'check_unit' 'minutes'
    option 'enabled' '1'
    option 'domain' 'all.dnsomatic.com'
    option 'username' 'username'
    option 'password' 'password'
    option 'update_url' 'http://[USERNAME]:[PASSWORD]@updates.dnsomatic.com/nic/update?hostname=[DOMAIN]&myip=[IP]'
    option 'check_interval' '5'
    option 'force_interval' '480'
    option 'force_unit' 'hours'

« Previous Page -- Next Page »