// shall I write some keywords here to boost search engine ranking?

Showing posts with label dirty trick. Show all posts
Showing posts with label dirty trick. Show all posts

Sunday, September 21, 2008

ActiveMQ Failover with Async Send

Apche ActiveMQ is a popular open source JMS Message Broker. As in version 5.0, it support failover transport, and async send. But not both at the same time.

Both connection string below will NOT work:

failover:(tcp://remotehost:61616,tcp://localhost:61616)?jms.useAsyncSend=true
failover:(tcp://remotehost:61616?jms.useAsyncSend=true,tcp://localhost:61616?jms.useAsyncSend=true)

So the dirty trick I use is to write my own ContextFactory that override 'org.apache.activemq.jndi.ActiveMQInitialContextFactory'


package org.apache.activemq.jndi;

import java.net.URISyntaxException;
import java.util.Hashtable;

import org.apache.activemq.ActiveMQConnectionFactory;

public class ActiveMQOptimisedSendInitialContextFactory extends ActiveMQInitialContextFactory{

@Override
protected ActiveMQConnectionFactory createConnectionFactory(
Hashtable environment
) throws URISyntaxException {
ActiveMQConnectionFactory connFactory = super.createConnectionFactory(environment);

connFactory.setUseAsyncSend(true);

return connFactory;

}

@Override
protected ActiveMQConnectionFactory createConnectionFactory(
String name,
Hashtable environment
) throws URISyntaxException {
ActiveMQConnectionFactory connFactory = super.createConnectionFactory(name, environment);

connFactory.setUseAsyncSend(true);

return connFactory;
}

}


Using this class as JNDI's 'java.naming.factory.initial', then the connection will be using async send by default, inlude failover transport.

Saturday, August 09, 2008

MySQL: continue auto increment number from deleted record

The behavior of auto increment number in MySQL is keep increasing even the existing record had been removed. For example, let say your auto increment had reach 10, and you delete the record of 9, 10. The next record inserted is will still be 11.

Sometime you will just want it to be continue with 9 instead of 11. It can be done with an ALTER TABLE statement:


ALTER TABLE tablename AUTO_INCREMENT = 1;

Thursday, December 13, 2007

Enable Right Click

For some reasons, some websites will disable the right click of users. And for some reasons, you want to re-enable right click on such website.

This is not difficult, especially if you are reading my blog :P

Type this Javascript in you browser address bar and press Enter. Done.

javascript:void(document.oncontextmenu=null)
You may want to keep this as something like bookmarklet. Drag and drop this link to your bookmark toolbar: Enable Right Click [Developer's Philosophy]

Monday, October 01, 2007

Error: no 'server' JVM at '...'

Some workstation or server will not come with server JVM after you install JDK on it. When you run server JVM by 'java -server MyApp', you will get the error such as:

Error: no `server' JVM at `C:\Program Files\Java\jre1.6.0\bin\server\jvm.dll'.
There is a little trick to get the server JVM up and running:
  1. Copy 'server' folder from the JDK's JRE's bin folder (example: C:\Program Files\Java\jdk1.6.0\jre\bin\server)
  2. Paste the 'server' folder to JRE's bin folder(example: C:\Program Files\Java\jre1.6.0\bin)
  3. Done

Friday, September 21, 2007

Solution to MySQL Replication Problems: CREATE USER failed

After setup replication, I start to create a few database login. And the next day, I found that the database replication is stopped. The error code is 1396 which indicate the failure of create user.

However, when i checked into the database, the database login is created successfully. I restart the slave a few time but replication still failed to start.

Then I google and found this solution.

The workaround is add the following line into my.cnf, then restart the slave database:

slave_skip_errors=1396

Tuesday, March 13, 2007

Cross Platform File Path in Java

Recently come across some a Java program that have problem to work on Linux due the the program used "\" for directory.



It remind me of a dirty trick I used last time. Just used "/" in the code, it will work in both Windows and Linux.



Java as a cross platform language, already provide simple way to solve this with a static variable File.seperator . A much better alternative to my dirty trick.



Sunday, August 21, 2005

Dirty Trick with Servlet Filter

As the name imply, Servlet Filter is a filter that can modify request before it is process by Servlet and modify response generated by Servlet before serve to client. As you might guess, it is implementing the Decorator pattern.

I had once struggle with the combination of JSP + Crystal Report + MS SQL Server. The details can be found in the Question I have post in the Expert Exchange. The moral behind this story is: Never use View as Crystal Report's Data Source!!!

But as in the question, there is still one more problem can't be resolve, the last page do not work. After a few head crashing trial and error, error and trial......I still cant fixed it.

Then a genius idea popup in my mind >> Servlet Filter. Both my 6th sense and logical thinking tell me that it can solve my problem. And I have post another quesion on Expert Exchange to get help.

And finally successfully hide the first page and last page button from the report generated. It is by using a Servlet Filter to remove all HTML code of these button that is generated by Crystal Report.

Basically, it do not solve my last page problem, but if the problem is not realise by end user, it means no problem. (Or at least, not my problem......)