Archive for July, 2009

Something to Really Like in Java – VarArgs and Arrays

Friday, July 31st, 2009

java-logo-thumb.png

I've been so jaded about Java that the last few years I really haven't worked to keep up with all the syntactical candy that has been added. The new for loops are a great example - as are templates: things that are in other languages that reduce typing a bit but don't really add to the power of the language.

So imagine my surprise when I started digging into varArgs in Java. First, I could see how they were used by a method:

  public void printAll(Object... things) {
    for (Object thing : things) {
      System.out.println(thing + ", ");
    }
  }

that's a pretty standard take on the C/C++ varArgs, and I'll admit, it's really nice to have. Makes the signatures of a lot of classes a lot simpler. But I needed to be able to call something with varArgs based on a stack.

For example, I have a parser that calls my code with all the arguments on a stack. I need to pop off the values - LIFO order, and then call the String.format() method with the fmt and then a bunch of Object values. But how to do that?

Thankfully, the Java guys really extended the language here. I'm really glad. They made the idea of Object... synonymous with the array: Object[]. This means that I can put all the values in an Object[] and then call the method, like this:

  /**
   * Get the format and all the args and then generate the string
   */
  public void run(Stack aStack) throws ParseException
  {
    // Check if stack is null
    if (aStack == null) {
      throw new ParseException("Stack argument null");
    }
    // see if we have a reasonable number of arguments
    if (curNumberOfParameters < 1) {
      throw new ParseException("You need at least a string format for "
            + "this call.");
    }
 
    // create an array of the proper size to hold all the args
    Object[]  varArgs = new Object[curNumberOfParameters - 1];
    if (varArgs == null) {
      throw new ParseException("I was unable to create an array to hold "
            + "the arguments. Check on it.");
    }
    // get the parameter from the stack
    for (int i = (curNumberOfParameters - 2); i >= 0; --i) {
      varArgs[i] = aStack.pop();
    }
    // finally, get the string format to use with these args
    String    fmt = (String) aStack.pop();
    // now we need to do the work... it will auto-convert the array
    aStack.push(String.format(fmt, varArgs));
  }

Needless to say, this is making the method within the parser very powerful. I now have the complete printf-like formatting available to my expressions, and while my original code worked (assuming a maximum size), this is far more flexible, and a far far better solution.

So I'm going to lighten up on Java for a while. Someone is still working on it in good ways that are just syntactic sugar.

VLC 1.0.1 is Out

Friday, July 31st, 2009

VLC.jpg

This morning I saw that VLC 1.0.1 is out, but interestingly enough, it wasn't available from the "Check for Updates" within VLC 1.0. Odd, but maybe they think this is a minor update and they didn't create a package to be downloaded/updated the other way. Seems reasonable, but I still wish they had release notes, or at least made them easier to find. I just couldn't find them on the site. Very odd for an Open Source project.

Anyway, got it so that I can keep ripping DVDs when I want to see them on my iPhone.

CoRD – a Cocoa Remote Resktop Client

Thursday, July 30th, 2009

CoRD.jpg

I'm currently working in a tri-OS world. Lots of developers are using Mac laptops, linux workstations and Windows workstations. Things run on all these, and we need to be able to get to one from another. We have Cisco VPN, but I use Shimo for VPN control as it's so much nicer. But one of the things I've been concerned about is the ability to use RemoteDesktop into my Windows boxes (I need to monitor/control about 11 every day) from my Mac.

Enter CoRD 0.5.0.

It's an Open Source project on Sourceforge that places a Cocoa client to the Windows RemoteDesktop API and gives me the ability to show windows displays back on my Mac. That's something really nice. I can't wait to try it out.

Back in the Saddle (Again)

Thursday, July 30th, 2009

OK, things are looking a lot smoother this morning. I've been able to get everything I needed from TimeMachine, the laptop is running well, it's got another 180GB of storage (up to 500GB from 320GB) which is always helpful, and things are coming back into a comfortable swing.

In this experience, I have to say the surprising moments were these:

  • The Apple Store had no drives. Why on earth not?
  • The drive was only $129 at Fry's. Again, so inexpensive, why not have a few on hand, Apple?
  • The replacement of the drive was easy. Thanks, Apple. It could have been a lot worse.
  • The original drive was a lemon because it didn't even last a year. Sad, but it happens.

So things are kicking right along. I've got a lot of little things to watch today and it should be a nice, easy day.

It's good to be back in the saddle.

Updated WordPress at HostMonster to 2.8.2

Thursday, July 30th, 2009

wordpress.gif

When I was rebuilding my laptop, I started Firefox, like I always do, to open up a set of pages to HostMonster so that I can see what is going on there with all the sites I host there. Well... I noticed that WordPress 2.8.2 was out, and so I went to the SimpleScripts console at HostMonster and upgraded all my installs to 2.8.2.

The SimpleScripts install really is just about as easy as it can be. There's never a problem with the updates, everything is saved, they are fast, close to the release dates of the packages. Really, it's far better than the other package installer I used at HostMonster. Nice.

Growl 1.1.6 is Out

Thursday, July 30th, 2009

growlicon.png

During the rebuild of my laptop this morning I got another update notification - this one was from Growl for 1.1.6. This one even had release notes! This is the messaging system that a lot of Mac software uses, and I have to say, when I first saw it I thought "Why?", but now that I'm using my Mac as everything, it makes a lot of sense. Get the notifications you want to see as you want to see them. Nice.

Anyway, the fixes look like they will help, and with Snow Leopard on the way, it's nice to see these packages getting updated.

Perian 1.1.4 is Out

Thursday, July 30th, 2009

Perian.jpg

This morning, as I was finishing the re-build of my laptop, I got a notice from Perian that 1.1.4 was out, and so I updated that right away. Perian is the QuickTime plug-in that allows it to play a ton of additional file types, and since I still get a lot of media from family and friends that was created on PCs, this is a really nice thing to have.

Super nice thing to have.

My Drive is Dead – Long Live My Drive

Wednesday, July 29th, 2009

MacBookPro17.jpg

This morning I had a horrible feeling as my MacBook Pro had that annoying little "chirping" sound again. About every second for 10 or 20 seconds a little "chirp" came from the left-hand side of the laptop. Not good. This has happened on and off for a while now, and I just figured it was some odd software state, and when it didn't stop, and the apps stopped being responsive, I decided to reboot and clear it up.

Not bloody likely.

It wouldn't reboot. Not at all. Nothing. The machine would startup, and the "checking disk" would spin, but I'd never get the login screen, and I knew then that the culprit was the drive. At that point, it was clear that my drive was on the edge of death, if not already over the edge. So I shut the box off and let it sit for a while. I had a lot of work to do today, so I needed to get to it.

After about 30 mins., I tried again. It appeared to boot, and I thought "Holy Cow! What a lucky break!" But after only a few minutes, it was clear that it wasn't OK, in fact, it was really in trouble. Bad news. Thankfully, I had TimeMachine, and that was going to cover all the data I had on the box. Good to have that backup.

No, the problem was How to get a new drive? I called the Apple Store in Oak Brook, the closest one to my house, and asked them "Hey, let's say my drive is dead, do you have one in stock to replace it with?" - they diverted my to Apple Care. I can understand that, so I was patient and dealt with that guy, who agreed that it was a drive, and to have me get to an Apple Store.

So I called back the Apple Store in Oak Brook, and told them of my conversation with Apple Care. Again, the "best" they could do is to say I had to bring it in and then they can tell me if they have what is needed in stock. Arrgh. OK, I can see the logic here, most people aren't going to be able to ask a question, and then that makes Apple look bad when they say they have the part, and that's not the part that's needed. OK, not good, but OK.

So I make a Genius Bar appointment and go to the Oak Brook Apple Store.

The Genius there agreed on the assessment, and said that if they had the drive in stock they could replace it right then. So back into the "bowels" of the Store she went.

I waited.

She returned to say that no, they didn't have a drive to put in my laptop. She could order one and it'd take two days to get a replacement.

WHAT!?

I asked her to check the other stores in the area - maybe one of them had a drive. SHe called one store - no good. Didn't call any others. Clearly, I'm guessing that she wasn't able to get this level of information from anyone. She did say, however, that the Unibody MacBook Pros were designed to have user-serviceable drives. I asked her how, and she explained that by removing the screws on the bottom, the drive is easily accessible.

I decided to try a new drive myself. I got directions from Liza for how to get to Fry's from Oak Brook, and she helped out a lot. I got a Seagate 500GB 7200rpm drive - the same drive that is in the new 17-inch MacBook Pros, and went home to install it.

The screws are small, that's for sure, but they are almost all just small phillips-head screws. The exception to this are the "posts" on the side of the drive to hold it in place once in the machine. These look like very small torx drives. But since they were posts, a pair of pliers worked very nicely.

I got the drive in, had to use the restore disks for 10.5.6 as the 10.5 disks didn't have the hardware support that was needed for this "Early 2009" machine. Still, after about 30 mins I had OS X installed and was pulling in the accounts and files from the TimeMachine drive. I had to let it run overnight as it was time to get some sleep, but I had a good feeling that in the morning I'd be able to finish it all up and be back at work with a functioning laptop.

Adding Transactions to a Servlet-Based System

Wednesday, July 29th, 2009

WebDevel.jpg

Today I had the difficult task of trying to add in transactional integrity to a web system where the data is coming in as posts to the web server. If each post was a transaction, that wouldn't be so bad, but if I needed to have transactional integrity over multiple posts, then we get into a lot of trouble. Face it, web servers aren't noted for their state-maintenance - that's something you add on top of the web server in order to create the illusion of saved state for the user.

But in this case, we had one program feeding another. The sender wasn't passing in real markers for the beginning and end of a transaction, and that was the first thing that needed to change. We then needed to do something with this information, so I added that in. Now I had a place to handle the meat of starting and ending a transaction - but I needed to know what to put there.

The next problem I attacked was a little simpler, the market data service wasn't handling the blocks of data in a unit. Rather, as it was parsing data, it was sending it to it's cache. This would allow for inconsistent data as the instrument prices move but the greeks were in a buffer until the entire block was read. Also, the market data cache had no locking on it. So I added the locking and the buffering so that the market data was "clean" for each block.

But that still didn't solve the real problem - how to put multiple blocks in a transaction?

After thinking about all the alternatives, I came to realize that the only good way to do this is to have the sender "mark" each block of a transaction - including the BEGIN and END, so that the receiver can buffer the data by transactionID, and then release all that data and update the reports on the END. So I needed to figure out a way to get these transactionIDs.

From the UUID work I've done in the past, the IP address turned into a long was a good start. I didn't need to add in the time, as I wanted to have a transactionID per sequence, and not per transaction. So no need for the time. I did add in a simple three-digit sequence number on top of the IP address, and that should do it just fine.

Now the transactions needed to be tagged with this number. That meant modifying the payload format. Not something I was fond of doing, but it could not be helped. Did that, and decoded it on the receiver (web) side. Then I had to modify the buffering of the market data and the greeks to buffer by transactionID. I had to thread the transactionID into the code - passing it from the decoding through all the method calls all the way to the market data methods and greek cache methods. It wasn't more than three levels, but it required a ton of changes to the unit tests.

I then had the transactionID to the right places. I added that to the buffering in the market data and greeks cache, and then was ready to update the way the update events were sent. Previously, after each update of a block, the values would be recalculated. This almost guarantee problems with updates as the values would be recalculated within a "transaction". Bad. So I changed all that to only update if there was no transaction active - or at the end of a transaction.

The results are really impressive, but I want to do more testing tomorrow. It was really pretty simple once I had decided the best approach.

VelaClock 2.1.14 is Out

Monday, July 27th, 2009

VelaClock.gif

This morning I noticed that VelaClock 2.1.14 was released and the sum total of the release notes for this guy was:

  • Version 2.1.14: Updated Daylight Saving Time rules for Bangladesh.

and while I don't have a lot of need for knowing the time in Bangladesh, it's nice to know that should the need arise, I've got the tool to help me know the time.

Honestly, it's an invaluable tool for looking at the time in a lot of timezones. It's been very helpful more times than I can remember.