Arsenalist

The Toronto Raptors Blog with an Arsenal touch

Archive for the 'tech' Category


Tech part of this blog moved

Posted by Arsenalist on April 18, 2008

Somehow talking about how Axis is shit and how bad Jason Kapono’s defense is while presenting Arsenal highlights never really meshed. So I thought it better to move the techy portion of the blog over to somewhere else. It’ll also give me a chance to post more without fear of cluttering stuff up. So without further ado, I present:

http://depressedprogrammer.wordpress.com

If you got the WordPress RSS feed, you might want to switch it over to the Feedburner one if you haven’t already. If you already got that one, no worries, the bullshit will be supplied directly to your reader without you taking any further action.

Posted in java, tech | Tagged: | 1 Comment »

Performing a LEFT OUTER JOIN using JPQL and JPA

Posted by Arsenalist on November 20, 2007

Posted in java, tech | Tagged: , , , , , , , , , , | 9 Comments »

IIS messes with the application lifecycle in a way Tomcat wouldn’t dare

Posted by Arsenalist on November 6, 2007

How would you dig it if someone randomly restarted your application every few minutes or so for absolutely no reason? Would you be upset, angry or plain confused on why an application server would bother recycling an application at seemingly random intervals without being prompted. See, just like the Servlet specification defines the ServletContextListener interface, it’s .NET counterpart happens to be Global.asax which defines application lifecycle methods like Application_End, Application_Start and such. A pretty sensible idea when you look at the surface of things but what’s horribly, horribly wrong is that .NET applications shut themselves down every 20 minutes if they detect that no requests have been made to IIS. This is all done in the hopes of preserving IIS resources which makes me wonder just exactly how resource intensive running an IIS app really is.

Now think about this, this means that any context loading or application initialization that you do on startup might be happening a few times an hour just because traffic to your application might be slow. Any static variables that you declare get dumped, any kron processes you’re running get killed, database connection pools get emptied, application scope data is erased, worker threads are stopped, everything is gone! If you’re running a plain old website which doesn’t do much, this might be borderline acceptable, but if you perchance happen to do some medium to heavy initialization, you’re bound to run into big time trouble that will leave you scratching your head and adjusting your crotch. And no, it doesn’t matter what you change in Web.config, nothing can save you.

If this isn’t appalling enough, try checking out some of the work-arounds to this problem. If you’re running a kron job in your application, you’ll realize that you’ll be doing some serious work just to keep it running. One of the arguments you hear is that since it’s a kron job, it really doesn’t belong in a .NET application and that you should really be writing a windows service to do the job for you. Now that’s just plain see-through bullshit, you can’t suggest writing a desktop application and call running a kron job in a web application a bad design The .NET gurus also suggest simulating a call to the web server to keep your application alive, something like the following:


void Application_End(Object sender, EventArgs e) {
   WebRequest request = WebRequest.Create ("http://myapp.com/SomePage.aspx");
   HttpWebResponse response = (HttpWebResponse)request.GetResponse ();
   log.Info("Status: " + response.StatusDescription);
   response.Close ();
}        

So pretty much, resuscitate it just before it’s about to croak. Truly a pathetic, pathetic piece of code which only exists because of a deep flaw in .NET”s application lifecycle philosophy. Compare this with the old and sturdy ServletContextListener which wouldn’t have the cahones to call contextDestroyed() even if the app was running for 10 years straight.

Another similar problem in .NET is the tendency for threads to store data in the HttpContext.Current object (kinda like ThreadLocal in Java), except that HttpContext is dependent on the Request object actually existing. If the Request is gone away (which only make sense since it’s an atomic event), any variables tied to it are also gone. I never comprehended why simple static space isn’t used instead.

Now someone might argue that you might be able to tweak settings in Machine.config or go to IIS Manager and drill down to Application Pools (new in IIS 6) and change your DefaultAppPool properties to alter the behavior of worker processes, which might do the trick. But the problem is that the default behavior of ALL IIS hosting companies is to leave this crucial setting at it’s default value and the worst part is that it can’t be altered at an application level but only in IIS. Something which just flat out sucks.

Posted in .net, java, tech | Tagged: , , , , , , , | 7 Comments »

Logging abstraction is utterly pointless

Posted by Arsenalist on September 12, 2007

I had always thought so but in the last week I’ve concluded with dynamite determination that logging abstraction is completely pointless. No. Benefit. Whatsoever. Could I be mistaken? No, if anything you’re probably still hanging on to Commons Logging because somebody told you how great it was, I don’t think anyone in their right mind would, after taking a step back and looking at the circumstances say, Hmmm, I really need to be careful and not commit myself to Log4J because God knows when Mark Womack and his team might pack it in and leave me hangin’. The same people who name their first born after Commons Logging classes commit themselves to products like IText, JFreeChart and GodKnowsWhat without ever thinking about abstraction. Raise your hand if you’re ever used IText and considered what happens if you want to switch your PDF generation tool? Nobody? So why the hell do we care so much about logging?

Luckily the answer is as simple as it is stupid: making a logging tool is so freaking easy that everybody’s got a homegrown one which they swear by and would never ditch even if they were offered ass in return (this just in, Logger just won the most used classname ever, it beat out Tester). So instead they use Commons Logging which gives them the feeling of not being such a big idiot with the added bonus of sleeping well at night knowing that they could eaaaasily switch to Log4J if they wanted to. What these poor saps don’t know is that switching between logging tools isn’t even that easy regardless of the abstraction, you still have to worry about configuring your tool which is a major pain in the ass if you want to actually stick to the proper log levels. Besides, nobody’s switching to anything, once you pick a logging framework you stick with it until the application is dead. Period. No exceptions. And if you happen to be switching your logging implementation so frequently that you need abstraction you suck at design and product evaluation.

Do you really care which of the two following imports you’d rather have shit on your code: org.apache.commons.logging or org.apache.log4j. Unless you have a thing for using commons packages (and some people do) you probably don’t give a rats ass. So with that in mind why don’t we save ourselves some trouble and just use Log4J, and as a bonus I’ll throw in the pro of Tomcat not barfing every time it sees two commons logging jars in its classpath, God forbid if they’re two different versions because then it starts giving you errors that make you regret ever even getting into Java.

The only way to beat Log4J is to have something out of the ever so trustworthy java.* packages do the logging for you. Luckily there’s JULI which is really great but unfortunately it’s documented about as poorly as Guice and isn’t marketed nearly as aggressively as that retard Duke (I really hate that son of a bitch, looks like a tooth with a big cavity). Besides, anytime anyone asks you to modify something in the JAVA_HOME directory to configure something red flags go up. Somebody please document how to load a config file from your classpath without specifying a -D option in JAVA_OPTS. I mean I’m configuring logging, not optimizing my garbage collection, yeeeesh.

Subscribe to Arsenalist's tech feed

This post has moved to here.

Posted in Technology, java, log4j, tech | 24 Comments »

On hiatus

Posted by Arsenalist on August 21, 2007

Due to a family emergency, I’ll be on hiatus till at least August 30th.

Posted in Raptors, arsenal, tech, tfc, toronotfc | 6 Comments »

Career not going anywhere? Just change your title

Posted by Arsenalist on August 21, 2007

So you’ve been working away at your development job for God knows how long and there’s no end in sight to your misery. There’s no chance of moving up in the company and although your bosses like you, they don’t think much of you. They’re happy with what you’re doing as long as you do it quietly, deliver in the whereabouts of your deadlines, show up to the company picnic and stay out of any real decision making. You’re taking up more and more responsibilities over the years but your pay is only being raised by a paltry 2% while the cost of living is going up by 5. You know you’re being fucked but are too lazy or incapable of doing anything. So what do you do? You change your title of course.

Read the rest of this entry »

Posted in Technology, java, tech | 5 Comments »

Indian outsourcing is killing IT

Posted by Arsenalist on August 14, 2007

The mailing lists were never easy to read through but if a man put his mind to it and used the delete button swiftly enough you could actually get something out of them and maybe even find a reason to stay on. But ever since everybody in North America cheaped out and started sending all the work to India the mailing lists of every major product have been polluted with the Sanjays and Prashants of this world asking questions that make me wonder why the hell we’re sending out our prized projects to these seemingly incompetent people.

Granted they come cheap but even so judging from their posts and having worked with them on a couple projects I still haven’t found a singular reason why I should trust them to write a simple POJO. Their unaccountability on their mailing list is appalling, I wouldn’t want my company being represented by some dude who’s asking the struts-user list questions like these and putting their company name and his title at the bottom. This just tells me you’re an idiot and have no clue what you’re doing.

I realize that I’m generalizing and that there are always exceptions, but if you Nabble through the Maven, IBatis, Struts etc user lists you’ll encounter posts which make it apparent that the author has the most rudimentary knowledge of the product and of software design and is just hoping to get by. This theme is prevalent across most mailing lists leading me to believe that this is a widespread disease which effects the outsourcing industry. Given the apparently skill level of the people working on these projects, one can only surmise that the quality of work being done in those countries is subpar. Also, posting your resumes and asking for H1 visas on peoples blogs does not help your credibility nor does it showcase your skills. Again, it just makes you look like an idiot.

Here’s an exercise: try posting an ad for a development project on Craiglist and ask for a quote. What you’ll end up getting is tin-canned emails from India that list Gupta Inc. as knowing EVERY SINGLE LANGUAGE AND DATABASE PLATFORM EVER MADE. Then follow up with a random one and actually talk to their “Project Manager” and you’ll notice that the email was just a bunch of bullshit and you’re dealing with a two-man operation run out of a basement on a Pentium II.

Lately I’ve met an increasing number of people who are “managing a team in India” and work for a company with an accent in it’s name. These are the new managers the IT industry is producing, usually they’re in their mid-20’s and consider their new “manager” role a promotion. But when you’re managing narrow-minded developers getting paid the minimum wage and communicating 95% of the time over MSN, the work that’ll get done will reflect the circumstances and talent of the people involved. Software development is an industry where geographic location hardly seems to matter but when we’re communicating requirements, design and expectations entirely over chat, things are bound to get lost in translation. My point? You can’t oversee a project if you’re thousands of miles away, especially if you’re dealing with a guy who’s trying to scrape by. This whole system is flawed and annoying, both from the manager’s and developer’s perspective.

As long as you can tolerate their nerdiness and smell you can generally have a conversation with another North American developer and talk about a wide range of languages and tools without too many awkward moments. Not the case with slave labor. I visited India a couple years ago and had a chance to speak with some developers working at India’s second richest bank. The first think you notice about these people is how specialized they are. If they have a Java job, that’s all they know. Nothing more. Java. Java. Java. If they have a Perl job, it’s all about Perl and they’ll write everything in Perl and not even consider anything else for any reason. The mentality seems to be to get the job done as the lowest price and as fast as possible, nothing else matters. Fair enough, but I just don’t see the price of the work making up for the lack of quality and the general fuckedupness of the process.

And yes, I’m an Indian.

 Get the feed

This post has moved here.

Posted in Technology, india, java, outsourcing, tech | 127 Comments »

CXF WS-Security using JSR 181 + Interceptor Annotations (XFire Migration)

Posted by Arsenalist on July 31, 2007

Posted in cxf, java, maven, spring, tech, web services, xfire | 22 Comments »

Spring’s AOP support can’t be ignored

Posted by Arsenalist on July 2, 2007

You see I’ve never actually written many (any?) AOP classes but there’s enough talk about it splashed all over the internet that even though it might be a worthless concept that you’ve never used or cared about, you’re bound to encounter it at some point. A fellow GO Train rider once told me it was the thing to know if you want to have a Java job in five years. That made me read the AspectJ in Action book which makes you feel guilty about not using AOP. I don’t talk to that guy anymore. Then there’s Adrian Colyer who will have you believe that AOP is the glue that ties every enterprise application together and without it you might be writing code that is hanging on by threads.

Now I realize for some of you this might bring flashbacks to 2004 but bear with me. A few days ago I had to catch an Exception in the DAO layer and translate it to something else, now normally this very simple problem is solved by 95% of the monkeys by using a try/catch on the Exception and throwing something more worthy of being bubbled up. But if the same DAO method is being executed in different places in your application you might have to do separate try/catch blocks for each, something which is totally acceptable, clear, concise and happening for ages. There’s nothing wrong with it.

But there is an AOP way of doing this outlined pretty clearly in the docs where you write a pointcut and provide advice on the execution of the event. No try/catch blocks, the client code is devoid of any knowledge about exceptions. Spring’s AOP support makes doing this the AOP way very easy, but is it overkill? I don’t know, I guess it depends on your style of development.

So to replace the generic try/catch mechanism with the AOP way, first declare a pointcut:


package com.arsenalist.aop;   

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;   

@Aspect
public class SystemArchitecture {   

    @Pointcut("execution(* com.arsenalist.dao.*.*(..))")
    public void daoOperation() {}
}

Once we’ve specified what methods to monitor using pointcuts, give advice on what should happen when the pointcut is executed.


package com.arsenalist.aop;   

import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;   

@Aspect
public class DaoExceptionTranslator {   

    @AfterThrowing(
      pointcut="com.arsenalist.aop.SystemArchitecture.daoOperation()",
      throwing="ex")
    public void translateException(Exception ex) {
        throw new RuntimeException("Generic message");
    }
}

With the above setup any method executed in the com.arsenalist.dao.*.* packages will be translated into a RuntimeException. I’m assuming that the interfaces reside in com.arsenalist.dao package and the implementations in a package underneath that. Here’s the Spring configuration needed:

<bean id="daoExceptionTranslator" class="com.arsenalist.aop.DaoExceptionTranslator"/>
<bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator" />

Most importanly the Maven POM should look something like this:

<dependency>
    <groupId>aspectj</groupId>
    <artifactId>aspectjweaver</artifactId>
    <version>1.5.3</version>
</dependency>
<dependency>
    <groupId>aspectj</groupId>
    <artifactId>aspectjrt</artifactId>
    <version>1.5.3</version>
</dependency>
<dependency>
    <groupId>cglib</groupId>
    <artifactId>cglib-nodep</artifactId>
    <version>2.1_3</version>
</dependency>
<dependency>
    <groupId>asm</groupId>
    <artifactId>asm-all</artifactId>
    <version>2.2</version>
</dependency>

Although there is a newer version of ASM available, it doesn’t seem to be compatible with Spring AOP.

There can be many arguments against this setup, the main one being that you’re unable to handle the same Exception differently depending on where it’s being called from. To do that you’d have to specify another pointcut and another advice on how to handle it. You also lose all call-context information because you’re assuming that everthing you need to handle the exception is in the Exception object.

But in the general sense it does seem to be an improved method of executing baseline operations when a particular event occurs. The docs get you thinking about other places where you can use AOP proxies instead of the “normal” way of doing things and it’s pretty easy to get sucked into “convert everything to AOP mode”.

If you’re afraid of proxies, this is not for you. Every call to the DAO layer happens via a proxy which is necessary to achieve the intended effect. I’m not sure what the performance penalites of using proxys on every single call to the DAO layer are but if you go this route, CGLIB proxies are apparently much faster than their JDK counterparts. Either way, if you haven’t tried out AOP but are sick of hearing the sound of it, give Spring AOP a shot. It’s probably worth it.

Posted in aop, java, maven, spring, tech | 3 Comments »

Unit Testing Struts 2 Actions wired with Spring using JUnit

Posted by Arsenalist on June 18, 2007

Posted in java, junit, spring, struts, tech, testing | 86 Comments »