April 2008

Science Fiction and Life Extension

So while I was on vacation last week, I finished my latest non-fiction, vaguely work related book (Nerve Center: Inside the White House Situation Room by Michael Bohn, not worth it, BTW) and started reading fiction again. I’ve been carrying around my kindle since I got it, but I have been reading so many non-fiction books, which don’t have a PDF or amazon kindle equivalent (and my company’s procurement system doesn’t have a means to buy digital books for my kindle), that it has seen little use in the past month or two.

So I turned it on and started reading.

I started with Old Man’s War by Scalzi, which starts with the premise that at the age of 75, you can join the colonial army, and become young again (intentionally not saying any more, since the details are the book’s first book reveal). Life extension is owned by the colonial army, which is powerful enough to keep it for themselves, and every knows they have it.

Once I finished that, I started reading Down and Out in the Magic Kingdom by Doctrow. Its premise is that life extension is so cheap and easy that everyone can do it, even on a whim. Much of the book concentrates on the socioeconomic ramifications of such capability.

Finally, I’m reading Old Twentieth by Haldeman. Its concept is that there is a massively expensive pill that offers unlimited life (freedom from disease, old age, etc), which triggers a war between the people that can afford the pill, and those that cannot.

So, three books, all of which have been on my to-read pile for a while, and all I have this same key technology hook as the “how does this world work different than ours” piece. Not that there is any great point here, I just find the congruence of themes interesting.

Geek

Comments (3)

Permalink

Persistence hell, pt 4: Persistance Wins, I Lose

I give up. For whatever stupid reason, my JPATranscodedObject won’t serialize (SerializationException from JPA). That only happens when the JPATranscodedObject is included in the BasisObject map.

So, I want to get something working while I try to figure it out, so I put in a pretty simple hack. The BasisObject is stored and a JPATranscodedObject is created. The JPATranscodedObject is XML serialized, and the XML string is put into the BasisObject.

On decoding, as we step through the basis object, we pull out the XML string, turn it back into a JPATranscodedObject, and then decode the BasisObject from the resulting transcoded object.

It is more expensive computationally, but it works. It ensures that contained / embedded objects are stored independently. It doesn’t do anything about solving the whole cyclic object problem, though.

Technology

Comments (0)

Permalink

Persistence hell, pt 3

So I have most of a persistence solution, with one minor issue.

The basic algorithm is going to work like this:

BasisObject implements IPersistantObject

JPATranscodedObject implements IPersistantTranscodedObject

// returns an IPersistantObjectProxy that just has an id field populated

IPersistantTranscodedObject transcode(IPersistantObject)

// from a proxy, return the object into a real object

IPersistantObject decode()

So to transcode:

transcode(a) ->

foreach object o in a

if o instanceof IPersistantObject

replace o with the result of transcode(o)

and to decode:

decode(a) ->

foreach object o in a

if o instanceof IPersistantObject

replace o with the result of decode(o.type, o)

the issue, which I don’t have a good solution for, is what happens in the case of a cycle? a includes b, b includes a.

Options? If I detect a cycle, I could create a temporary placeholder object, serialize all objects in the cycle, and then go back and update with the correct ids. That would be pretty ugly, but I’m not sure there is a better solution.

Technology

Comments (0)

Permalink

Persistence hell, pt 2

So, here’s the plan.

Given a class A and instances A1, A2, A3, and A4, that looks like:

A1 = {x = “string”, y = “other string”, z = A2, {t = A3, u = A4}}

(i.e., a map of multiple levels, with some values as strings and others as instances of class A)

I want to persist it via JPA such that a new object of class A, B1, which includes the existing object A2:

B1 = {x = A2}

The A2 contained in B1 is the same instance as that included in A1. i.e., an update A2 propagates via the persistence layer.

So, the question becomes how do we take objects A1 and B1 and turn them into properly persisted blobs.

Proposal:

When building the object A1, do not directly include other objects of class A, but include wrapper objects instead. These wrapper objects are embeddable (as per JPA definition). They contain two fields, the JPA ID of the object (if it has already been serialized) and the actual object of class A.

When we serialize a class A, we clone the object and go through the object and extract any of the wrapper objects. Update or persist the object that are contained, insert the id if it does not exist and remove the object in the wrapper.

By the time we’ve finished with the original object, it contains a set of objects and wrappers that now only have JPA ids.

Deserializing the object follows a similar pattern.

Persist those (using the same rules), and replace them with a simple embed

and make simple embeddable objects.

Given a map, transform it via the following rules:

  1. Extract the contained map
  2. turn the top level of the map into a collection of values
  3. for each value,
    1. if it is a collection or map, recurse to 2
    2. if it is an instance of A, recurse to 1
    3. otherwise, do nothing
  4. if there are no remaining items in the value and we’re working on a
  5. sdf

Technology

Comments (0)

Permalink

Persistence hell

So I have a class A that contains a hashmap. The hashmap may contain any object, including instances of A. JPA throws a “can’t serialize” exception, in that case.

Ideally, this should just work. It may be that the “generic” map is too generic for JPA to deal with, which would suck.

The other issue is that two identical instances of class A should be linked, somehow. i.e., two objects that represent a user should refer to the same db table, regardless of what container object they may be serialized from.

It may be that my JPA annotations and/or persistence logic is just too simplistic. Ultimately, the question is how do you persist a complex graph.

Technology

Comments (0)

Permalink

Distributing Java Applications / Libraries

So I am writing a Java library. Like many java libraries, it depends on a dozen or so third party libraries. What’s worse is that, like many java libraries, it depends on specific versions of those libraries.

(IMO, this is a huge issue with Java, there are very few meaningful java libraries that won’t depend on a foundation of a dozen or so other libraries. The answer is not to extend the language, but to come up with some meaningful distribution model, like CPAN)

So, until someone writes the CPAN equivalent in java, how does one distribute a core library and have some reasonable assurance that it will work?

A few options:

  1. When writing THYME (my grad school framework), my build scripts unjar’d the contents of /lib into /classes and jar’d the whole mess into one ginormous jar file. It worked, it dealt with versioning issues, it was a nasty hack.
  2. Create two jar files, one core jar and one dependencies jar, with the dependencies jar file containing the unjar’d contents of all the dependencies. A little bit less of a hack, but still doesn’t make me happy.
  3. Make an “installation” script that somehow ensures that the dependencies are put into the classpath. Bleh. So much for self-contained libraries.
  4. Write a classloader that deals with a jar of jar files? There are some of these floating around, but I’m not sure how well they work or how to make such a class loader load by default.

My current best guess is (2), until I figure out how to make something better work.

Geek

Comments (5)

Permalink

Killer App

[EDIT: I don't know why the text didn't publish]

I want an application that will take a fully qualified java class (x.y.z.Stuff) and provide a link to (a) the JAR file that contains this class and (b) the JavaDocs that describe this jar.

I think I spent at least two hours trying to track down jsr173_api.jar last week.

Geek

Comments (3)

Permalink

The Great Media Organization Effort, pt 2

Through the O’s. 830 albums

Geek

Comments (0)

Permalink

I hate computers: the router saga

I am reworking my home network after one of my routers stopped routing. As part of this rebuild, I want to take advantage of all my incoming capacity. Specifically, I maintain two incoming network pipes, since my and my wife’s jobs depend on us having internet access all the time.

So, incoming to the house I have a fast cable modem, which blocks every useful outgoing port you can think of and a DSL line, which isn’t as fast, but has two static IP addresses.

My goals are:

  1. Fail over (not load balancing) between the cable modem and DSL
  2. DSL IP1, port 80 forwards to my mac mini port 80 (running apache)
  3. DSL IP2, port 80 forwards to my mac mini port 81 (running tomcat)

You’d think this would be easy. My initial thought was:

DSL -> hub1 -> two cheap routers (CR1 and CR2) -> hub2

hub2 -> dual WAN router (DWR)

cable -> DWR

DWR -> my network

CR1 would forward port 80 to DWR:80, which would forward to mini:80

CR2 would forward port 80 to DWR:81, which would forward to mini:81

Of course that didn’t work. No port forwarding worked successfully here. I’m still not sure why.

I tried moving the mini to hub2, and set one of the routers as the gateway. Which ever router was the gateway could forward back and forth to it, without an issue. The other one would not work. One of the routers exposes a useful syslog, and informed me it wouldn’t route that traffic, since incoming and outgoing routes were different.

I tried giving the mini a second virtual ethernet interface, and setting it to gateway through the second router. Still no luck.

My next attempt is to put an airport express on CR2 and use wifi. I’m not hopeful.

I could dig up a linux box to put as the second machine, but I’d rather not have to maintain a linux box if I can avoid it.

If I could get the tomcat connector working for apache, it would solve the problem, but I haven’t had any luck with that.

Technology

Comments (4)

Permalink

The Great Media Organization Effort

Slowly going through my itunes library, getting rid of obvious duplicates, updating album art, and entering any missing albums (i.e., those acquired from itunes, amazon, or “other”) into delicious library.

I am currently through the N’s. Current stats:

number of albums in DL: 815

total items in itunes: 17678

total playing time: 49 days, 17 hours, 16 minutes, 20 seconds

total size: 105 GB

Of course this list doesn’t include audiobooks (another 50 or so days of listening) or video (all my DVDs are slowly being ripped to my media drive).

Geek

Comments (0)

Permalink