Life Codecs Ruminations. Reflections. Refractions. Code.

April 28, 2009

Bad Browser Haiku

Filed under: poetry — Tags: , , — Kamal Advani @ 01:53

Yes, I have nothing better to do. Enjoy the following haiku, which is potentially a pseudo-ku (not to be confused with Sudoku – gosh I am funny :P!), though I tried to stick to the rules and spirit of it.

1
2
3
Fox on fire, why, how.
Script gone rogue, Face... book, so cold.
Kill... the tab. Okay.

Yes, poetry is like code, and vice versa ;-).

April 26, 2009

Spring 2.5 + EJB 3 Integration

Filed under: software dev — Tags: , , — Kamal Advani @ 01:49

Yes, yet another post on the topic so talked about on the Web (like a year ago or so anyway!). This is mostly for my benefit and summary though – haven’t even written code to test it myself, but here goes. Spent a few hours exploring integration alternatives just now, basically EJB 3 DI is great, but a glaring thing that’s missing is injecting POJOs into it, which Spring does quite well – sure in both cases the “POJOs” are managed by containers, but hey, nothing’s perfect, yet. To summarise, here are the 2 major integration scenarios and solutions:

  1. To inject Spring Beans into EJBs (and bootstrap Spring app context(s) from within EJBs!) is simple enough, we use:

    Spring Docs, Chapter 18, EJB 3 Integration

    This actually handles bootstrapping (read up the doc on how it does it), which is tricky in EJB modules, since there’s no standard EJB context listener mechanism as there is for web containers. Many app server vendors do have EJB module lifecycle hooks/interfaces you can implement – but obviously they’re proprietary and make your app less portable, so I’d rather avoid them if I can, I still don’t see why this feature isn’t part of the spec… clearly there are use cases, and clearly since there are non-standard implementations, it’s feasible to do and define behavior for.

  2. The other way around is a bit tricky, i.e. we now need EJB container-managed objects (e.g. entity managers, EBJs, resources, etc.) injected into Spring Beans in the XML file. In this case those resources need to be registered in the JNDI ENC (still figuring out EJB context vs. global) and in the Spring XML a JNDI lookup is done for the name it was registered with, and then injected to the relevant bean via a bean-ref. A ‘lookup-then-inject’ Spring XML config example can be seen here (note dataSource JNDI look-up and inject):

    Spring and JNDI (Tomcat or Jetty)

    Registering the container-managed objects in the JNDI can be done via EJB 3 interceptors, for example, a use case is having Spring-managed DAO beans, but EJB-managed Entities/Persistence Units: let the interceptor have an annotation

    @PersistenceUnit(unitName="bar", name=”barEntityManagerFactory”)

    – which receives the container-injected persistence unit and then registers it into the JNDI registry keyed by the name “barEntityManagerFactory”. The Spring XML config will need a bean created through a JNDI look-up of “barEntityManager”, and inject that in to the DAO Spring-managed bean.

    Lots of repetition up there! (Note I said it was for my benefit :P).

Now I can finally watch some Naruto!

April 25, 2009

Humorous Comments on Adobe’s PSD Format

Filed under: software dev — Tags: , , — Kamal Advani @ 06:02

Travis (of Cute Peas fame) sent me this link. That’s what you call a first-class rant :-).

JBoss 5.0.x (and 5.1 Beta?) and JPA Persistence Units

Filed under: software dev — Tags: , , — Kamal Advani @ 05:50

After much messing around, I finally have my sample EJB 3 app working, but on Glassfish!! I started off with JBoss, and may still go back to it once they decide on better handling of persistence units, and not reload/load it regardless! Too complicated for me to explain, check out these links which summarise it in depth (they speak about Seam, but refer to the same issue I’m babbling about):

http://relation.to/Bloggers/JBossAS5AndGlassFishSupportAddedToSeamgen
http://code.google.com/p/seaminaction/wiki/DeployingToJBossAS5

Basically I have a common domain-model jar which I wish to treat as a persistence unit used by both my EJB and WAR in the same EAR.

And after hours of tweaking and messing, this is my successful test output:

1
2
3
4
5
6
7
8
9
10
Creating...
Data Value=JustCreated!!

Retrieving...
Data Value=JustCreated!!

Updating...
Updated Data Value=JustUpdated!!

Deleting...

Ah, the joys of development. Actually that’s a pretty decent test case, it’s a servlet that’s got an EJB3 instance injected, which in turn has an EntityManager instance obtained via the JNDI name of a configured JTA XA MySQL datasource injected. What a mouthful!

“Do that to me one more time”, Captain and Tennille

Filed under: arts — Tags: — Kamal Advani @ 05:32

Chill out song – very girly – but still decent enough :P. Captain and Tennille, Do that to me one more time.

April 23, 2009

A Failed Interview!

Filed under: general,software dev — Tags: , — Kamal Advani @ 12:54

I had an interview yesterday – which I thought went quite well, except for 2 questions below (interview was around 30 minutes I think), which it seems were significant to the interviewer.

Disclaimer: I didn’t get the job – so there’s obviously some bias in what I have to say. If anything, just add these questions to your list of things to look out for when looking for a Java WebApp job. I did not have a full job description when I went in (it was not provided), all I knew was it involved Hibernate, and that they were a team following an Agile methodology.

The Questions of Doom were:

  1. What’s a Hibernate Session?
  2. In a WSDL, what’s the difference between port and binding?

Question 1, something I probably should’ve been able to give a quick answer for. I started with the Session being a non-threadsafe object, which allows you to do CRUD operations with entities. The interviewer brought up the relationship between a Session and a database connection, and this is where I fumbled – eventually saying that a session uses one connection. It’s tricky because a Hibernate Session performs many functions (the docs say so too – “The Session is also many other things”!! I wonder if that violates the SRP :P – though it’s probably more a logical Facade). When you learn it mostly on project where most things are set up when you get there, you tend to skip exact details, so reading about it formally: it’s a unit of work, it also maintains the persistence cache – a map of objects in the persistence context to ensure identity, it is a handle to load and store objects, it’s a list of SQL statements to be executed, and finally it obtains a connection from a connection pool. Many things eh. I knew all of this from experience, I just could not put it elegantly into words. I also obviously knew having too many sessions open at the same time could exhaust your connections!

I also now know that you can reconnect a session – but the API deprecates the no-param reconnect() method, and you have to supply a connection reconnect(Connection)… any ideas on what the use case for this generally is? Extended sessions? Hmm…

Question 2, now I have done a fair bit of Web Services work, debugged quite a few issues too – but I’ve generally been a downstream client, so we get WSDLs from the upstream services, run a tool like Axis over it, voila a nicer Java view of the whole thing, so I didn’t have to tweak or look at the WSDL much – hence my knowledge of WSDLs themselves is fairly informal – I do know it’s basically a contract/webservice interface document and defines types, messages, and operations. When I did have to mess with WSDLs – it had to do with the operations and I/O parameters – the actual messages being passed around. So this question took me under 10 minutes to find resources for and get a fairly clear idea about the difference – a portType is like a module of available functions, and their parameters. A binding links these operations (and defines message formats) to a transport (which is usually just SOAP over HTTP anyway!). While I appreciate that it shows a crucial concept that WSDL separates messages from the transport – it’s hardly something that takes days to understand, certainly not rocket science (actually talking about SOAP itself, it very well could be).

In this interview, if I were to apply meaning to the whole incident, I would be left feeling a bit discontented – but I won’t do that because I know my abilities better than that – I so uberly-rock *cough* :P. In the end I just did not meet their expectations, but it is their expectations, and that is all. As for me, I’ll prepare better for notions or concepts that I take for granted because I use them everyday – must be like a fish-in-the-water-not-knowing-about-the-water-syndrome (that’s a long syndrome name…).

April 5, 2009

BKC Demonstration

Filed under: martial arts — Tags: , — Kamal Advani @ 22:58

I initially posted this video on Facebook (doesn’t look like I can point to my status and it’s comments from here?), and received some comments to which I needed to reply in some detail. However, Facebook restricts the amount I can type in a comment box, so reproducing it here.

See post comments. FYI it’s a demonstration by my grandmaster, founder of BKC.

Powered by WordPress