Friday, December 28, 2007

Spring, Struts and Weblogic 8.1 SP6

It's hard to get these things working together in Weblogic. You will have to think about class loading issues. The main problem is Spring support action classes reference Struts action classes and this fails to work if they are located in sibling class loaders. It's a pain to find why. Weblogic doesn't come with a nice class loader debugger (or I am blind enough not to see it) and you have to write your own debugger. The only thing so far I could do to get around this is to edit Spring manifest file and add struts.jar to class path dependency so that Weblogic makes the link. I am wondering if this should be a part of spring jar file anyways. As far as I understand it is a Java fashion to do this. On top of this, I think spring jar file should be sliced up a little bit for class loading reasons. I mean the web part of it might not need to be in the same class loader its container code is. The container code has state, it loads a network of beans and it keeps the network in memory along with static scoped beans. Therefore, it makes much sense if you want to share this container with multiple modules for performance reasons. Nonetheless, you won't need to share the web helper classes. 

Saturday, December 15, 2007

Spring Experience 2007

A colleague of mine sent this picture to us, right from Spring Experience 2007. I resist not to comment on it. It's cool, hey?

 

bobble-head

Thursday, December 13, 2007

Flex is the future?

The more I read about Flex the more I am convinced Flex is the way to go. For me the bigger question is how long HTML and its descendents will last. HTML was really useful but know it is just too incapable and simply it has no memory. It's intelligence is also usually supported with scripting languages such as JavaScript which is a beast of its own kind. Look at the complexity of Java front end frameworks. There is tons of them and still neither has a neat solution to the front end puzzle. The Java front end code is usually terrible. It really takes very good developers to come up with a web based GUI in Java that is well designed and it is easy to maintain. However, this is not what we want. We want stupid programmers to be able to produce. Java front end model is suffering from HTML shortcomings. Mostly from its lack of memory. That is, a request should be sent to user for every time a data is updated and server should keep this in memory for the scope of a conversation. Think of a form that adds items incrementally and as user presses save the changes are flushed to database. This will require Java code to take care of the temporary list of Items. That is why we have request scope variable, session scope variable and application scope variables. These are all a problem when it comes to scaling. In any events, Flex seems to be the answer. At least it is a great improvement. It has memory. It is richer that HTML and it can customized the same way. Even Microsoft is pushing its SilverLite.

Wednesday, December 5, 2007

SELECT FOR INSERT

Wouldn't it be nice if we had some like SELECT FOR INSERT in SQL?  I am not even sure if we don't but I have not been able to find anything like that. The problem I am trying to address is the classic problem of two transactions trying to insert a data if it is missing. Lets say T1 reads for record X and if it doesn't find it, X gets inserted. T2 is doing the same. T1 and T2 happily start together so T1 reads and there is no X, same happens to T2. T1 inserts X and commits, T2 inserts and commit and boom, Duplicate data. In the same fashion we have SELECT FOR UPDATE, it would be nice to have SELECT FOR (POSSIBLE) INSERT in SQL. This would mean looks for this data and if you don't find it lock the table because I am going to insert it. It has a bad effect on performance though. That's probably why we don't have it.

Sunday, December 2, 2007

Why do they still lock game CDs?

Game hacks and cracks are usually out within a week or two. Sometimes they are available before games are out. I am still wondering why companies are spending money on preventing copies of their CDs. I don't know how many stupid people there are and by stupid I mean the ones that can't go on internet and do a simple google search. I am talking about a 'XYZ no cd crack'. It doesn't look very hard, does it? The downside of this is legal users have to suffer. They have to push in their CDs each time they want to play a game, and of course one day their CDs are no good because all scratching and everything.

Once I asked my manager if we needed to obfuscate our code so that nobody can hack into it. He pointed at one our colleagues and said look at him---he was decompiling a flash code---there is billions and billions of these people. The only way we can be ahead of them is to be literally ahead of them by developing faster than they can hack.

Thursday, November 29, 2007

Eidos in Montreal

Eidos officially announced they will need 350 people in Montreal by 2009. This is while their competitor, Ubisoft, mass hired a lot of people in its Montreal office which at the end resulted in a sharp salary increase for most developers. The same thing is going to happen when Eidos starts sending recruiters around. I have been studying Montreal job market for a while and apparently Montreal is running out of tech work force. Hiring a developer is going to be simply impossible. Montreal has so much opportunities now that even after Motorola's close down nobody heard of excess of work force. I have seen companies putting an ad for more than 3 weeks.

Another side of the story is that this is happening while lots of software houses are running on a low and tight budget. Guess what? Most of these companies will not be able to keep their developers by next year and they will have to close down or find other sources of financing.

Wednesday, October 24, 2007

Less code or what?

My philosophy of coding is less code is always better*. That is, less code needs less effort to maintain and in case of bugs you need to examine less code to spot where a bug lives. This is important when a legacy code is being maintained. It is usually acceptable to disable a legacy code to implement a new feature or fix an existing bug. During this process, some code usually becomes redundant and it should be thrown away. However, this is scary. I haven't seen a lot of developers that feel comfortable by deleting other people's code. I understand this to some extent. On the other hand, leaving a redundant code in place is scary too. Redundant codes confuse developers. Experienced developers usually come to this question of why the hell this code is there and they usually spend days to find out well sloth is a real sin. This is when people should throw code away. Throw your redundant code away, and by code I mean any form of code, either Java code or SQL statement.

 

 

 

 

* This excludes crazy untraceable codes that break code usage searches and, therefore, prevent refactoring tools from functioning. One example is Java Reflection API which may save few (hundred) lines of code but it lets your code live as shadows.

Monday, October 15, 2007

Free IntelliJ IDEA upgrade

Today I got my free IntelliJ IDEA license upgrade. Yet another reason to love IntelliJ IDEA.

Thursday, October 4, 2007

IntelliJ IDEA 7 - method does not exist and more

For a while I was getting annoying errors in IDEA early release distributions thorough their EAP, and this was becoming an issue as the errors were disabling basic functions like code highlight. I was quite concerned that IntelliJ quality is going down but at the same time I didn't think I was right to say it because those distributions are not really meant to be stable. However, after a few tinkering here and there I realized I was getting those error because I was extracting new releases on previous releases and apparently it was not the best thing to do. One still may keep the bin directory but it is not too bad of an idea to do a clean install each time.

In any events, IDEA 7 has a nice Spring and Hibernate support. I have been enjoying code completion for HQL queries and Spring beans. Every now and often I can see a minor false-positive error detected in my HQLs but I have a feelings these things will go away in the main release of version 7. No matter what, I still prefer to stay a customer. I can't find my way in Eclipse. Therefore, that's not really an option for me.

Tuesday, September 11, 2007

Code Quality

Seriously, you need to think twice if your class has 2800 lines of code! And please don't comment your code with obvious sentences. Having no comment is a lot better than having a stupid comment.

 

Stupid comment example 1:

// Checks if total is greater than limit.
if (total > limit) {
doScrewThePerson();
}


Stupid comment example 2:


/**
* returns the favourite person
*/
public Person getFavouritePerson() {
return this.favouritePerson;
}


Business Value

Few months ago I started working on a software that is in production now for I don't know how many years. My assignments primarily were supposed to be maintenance sort of tasks, but I somehow ran into this situation in which I didn't believe patching the code to add new features was a good idea. I skip my justification at the moment for it is not the main idea of this entry.

In any events, I started evaluating the existing code and no matter how I looked at the code, I didn't find a straight way to keep the existing code. My assessment was the back-end layer should be completely replaced, the front end should be modified to adhere to technology standards, build files should be revised throughout the system, and packaging needed a serious attention. My rough estimation of how much time I needed to do this was something around a year. This may sound stupid since no one is going to wait for me for a year to have a new system that does (I am crossing my fingers) exactly the same thing as  before plus a minor new feature! On the other hand, this is not totally stupid because after the changes are done the system is better maintainable and new features will roll in as they are needed.

Having considered the above criteria, I started to think what parameters help one think his/her way out of these situations. I mean one needs to plan what to do first, and he/she should find a way to keep everyone happy. After all, technical managers don't like setbacks and delays and product managers want to be able to make promises to customers (and possibly meet those promises). One possible guide to find what to tackle first is to determine business value of each change. Most likely many changes do not have an immediate business value; therefore, they should be given a lower priority. Changes that possibly take a long time should be broken into smaller parts that can be finished in a shorter time, even if this will make the whole thing take longer. My point here is that business people do NOT care how perfect a code is, but they seriously appreciate seeing something that works but is a little slow or doesn't have A or B. This is something that developers don't usually understand.

I will try to give an example of how I think things should be in another entry.

Monday, August 27, 2007

+1 for Java Closures

After all these years of being a successful nerd I feel like I have been the wrong kind of nerd. Read this.

Monday, July 23, 2007

EJB 3.1 - Initialize your application

EJB 3.1's spec is out for community's review. It is primarily targeted to solve EJB 3 problems but among the new specs I personally like container initialization and shutdown callbacks, asynchronous stateless session bean calls and cron-like EJB timers. It also include other (great) features like stateful web services.

Wednesday, July 18, 2007

Book

A good friend of mine recommended me to read this. I do recommend reading it for people with no so amazing negotiation skills :)

WebSphere vs JBoss

At the moment of time I am working to improve an application that suffers high memory consumption. So, my basic choice is to profile application with WebSphere (production environment), but that sucks WebSphere is slow. After a while I change to profile the application on JBoss and my life is whole easier now. However, after profiling I started observing memory allocation behavior when the application is running in JBoss against WebSphere. Result is that with a couple of clicks WebSphere allocated 1G memory. The same amount of clicks on JBoss will use 600M of memory and even pounding JBoss with more clicks does not make a huge difference. The difference might be easily the JDKs used on JBoss and WAS; JBoss was running on Sun JDK 1.4 and WAS was running on IBM JDK. I have no clue at the moment.

 

I also tried to use WebSphere Application Developer Suit to profile my application. At the end of the day, it just wrecked my installation. It must be me. No seriously, I haven't been patient enough to work with WebSphere recently. Maybe because JBoss is there :)

Thursday, July 5, 2007

JProfiler 3, WebSphere 5

JProfiler 3 wrecked WebSphere 5's installation. I still don't know what the problem is, but WAS now only starts from JProfiler. Damn! I still don't know why one should pay for WAS while there is a JBoss. Just wondering...

Monday, April 9, 2007

SQL Server 2000

May be it is the third day.... I haven't found any jdbc driver that nicely handles distributed transactions on SQL Server 2000. One says JSQLConnect is nice and expensive.

In any events, one point on jTDS: they say the XA data source is not production quality so a good driver is out of question. Another point, data direct's driver does not work with hibernate and SQL Server 2000 unless you disable hibernate's fetch identity values. On top of that our application goes crazy when I use data direct jdbc driver.  The first call to create first jms table fail because it is there and the subsequent queries fail with XAER_NOTA. jTDS does not exhibit this problem. Life sucks...

Tuesday, March 13, 2007

JBossWeb, Tomcat and Apache...

JBossWeb is said to be faster when it comes to secure connections. However, my two-days-testing didn't show any significant difference on how it handles regular http connections.

The first day was spend on testing Tomcat against 1500 http connections, and Tomcat reasonably handled the connections. JBossWeb did the same job with quite less CPU usage, which was not really impressive (around 2 percent CPU usage difference, and no significant performance gain). Both Tomcat and JBossWeb crapped out when bombarded with too many connections on the same hardware. In this test JBoss crashed with a running out of native threads errors message, and Tomcat did not throw any exception but it did not respond to any other request.

The second day was spend on configuring Apache to accept http requests, parse them into AJP1.3, and redirecting parsed requests to Tomcat. This test showed a better performance improvement, but still it was not impressive enough (around 3 percent performance gain) for us.

These tests had been run with a test client we have for our online game engine, and the results do not generally stand for a reasonable comparision of these technologies. I still need to see if I can tweak them so that I can get a better performance, in terms of CPU usage or speed, in our game engine.

Thursday, March 8, 2007

Java 7

I am nervous to see where this is going...

Wednesday, March 7, 2007

JBoss JMX and remote monitoring

Java 5 comes with a nice monitoring console, JConsole, which is able to connect localy/remotely to a Java program and tell you basic stuffs about the program. This will require an application to start with a -Dcom.sun.management.jmxremote parameter. How easy! However, this parameter forces the JVM to start an MBeanServer. Well, so far so good, but I tried to use this with JBoss and boom! The JBoss didn't start up successfully. Actually, It was our application that fell apart. Why?

Our application uses Spring to manage its in-container beans. We also use MBeanProxyFactory to get a reference to the MBeans defined within JBoss deployment descriptors. The problem here is that MBeanProxyFactory looks up in the first MBeanServer it finds and ignores the others. It's more likely that this MBeanServer is not the JBoss MBeanServer one when JBoss is started with the monitoring paramter. 

Today I dug up the whole internet for a solution, and it seriously took me a long time to find a solution. First, I started to define a server connection factory but I couldn't find the right service url for the JBoss JMX. The more I tried the less I found :( However, I happened to see a post in spring forums on a similar problem, and it turned out that JBoss has a utility class that gives you access to its MBeanServer. So, the solution for now is to use a base bean for all other proxied mbeans, and set the server:

 

<bean id="baseMBeanProxyFactory" class="org.springframework.jmx.access.MBeanProxyFactoryBean" abstract="true">
<property name="server">
<bean class="org.jboss.mx.util.MBeanServerLocator" factory-method="locateJBoss"/>
</property>
</bean>

 


This works fine, but it would be easier to specify which MBeanServer should be queried for an MBean lookup. I have requested Spring people to add a new property to the MBeanProxyFactory.


 


ps. For the ones who are still wondering what the JBoss MBeanServer is called, it is 'jboss'.

Monday, February 26, 2007

Java 7, a new Java?

Apparently serious discussions are taken on the new Java language syntaxes. To me, most changes and enhancements help with the repeating code one developes in a daily Java coding. For example, we are all used to code single-method-anonymous-classes, which in a way resemble what C method pointers do. However, it doesn't look great to have all that class code while you only need a method. FCM addresses this in its entirety.

 

More on this is happening at www.javac.info. The latest Closures for the Java Programing Language explains how new literals and syntaxes can be put together to eliminate huge piles of repeated Java codes.

 

One good side of this is that all these new literals and syntaxes are translated to the existing ones, which means they will be translated into the same binary code. Nonetheless, I am not sure how this will effect code maintainability. At the same time, one could expect all sort of magical refactoring tools with Extract to Code Template bla bla to come out.

 

My take, we will be soon experiencing a new Java.

Friday, February 23, 2007

private members, are they private?

Today I was to this Seam presentation by David Geary, and it was the first time I was actually seeing an EJB 3 code in which I pointed out Seam is magically (k, I mean using reflection) setting private members of a bean class. This was the first time I had to think if that is actually possible. Guess what? Yes it is possible.

Consider this example:

package test;

public class TestClass {

      private int a = 2;

      public void printA()
      {
            System.out.println(">> a =" + a);
      }
}

TestClass has a private in member and a method to print the private data out. My goal is to access this private memeber's value through reflection. A quick and dirty try to do so would be a code like this:

import java.lang.reflect.Field;

public class TestReflection {

      public static void main(String[] args) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {

            TestClass t = new TestClass();
            t.printA();
            Field a = t.getClass().getDeclaredField("a");

            a.setInt(t, 14);
            t.printA();
      }
}

Running this will run into a java.lang.IllegalAccessException exception, which is what you would expect. However, the trick to access a private member's value is to set its accessibility. The Field class has a setAccessible method by which you can tell the VM I want to set this field's value. So, adding a single line to the same code will do the job:

import java.lang.reflect.Field;

public class TestReflection {

      public static void main(String[] args) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {

            TestClass t = new TestClass();
            t.printA();
            Field a = t.getClass().getDeclaredField("a");

            a.setAccessible(true);

            a.setInt(t, 14);
            t.printA();
      }
}

Installing a security manager will prevent setting a field's accessiblity. However, you still have the option to let a specific code base do it. Yes, I am talking about security policy files. In other words, there is ways to get around this anyways.

In any events, I am not sure if this is only my illusion that private fields are not really private or there is a way to secure private values.