Hidden Iterator in Collections toString()
The toString() method in the Java Collection invokes the toString() method of each item using Iterator.
In a multi-threaded environment a call to toString() should be synchronized to prevent ConcurrentModificationException.
Sunday, March 23, 2008 | 0 Comments
Deploying BIRT to J2EE Server
Eclipse BIRT report viewer can be deployed on a J2EE Server
In order to use a JDBC driver in the BIRT viewer, the driver jar file needs to be in the viewer drivers directory. On BIRT 2.2.2 it is:
/WEB-INF/platform/plugins/org.eclipse.birt.report.data.oda.jdbc_2.2.2.r22x_v20071206/drivers
On BIRT 2.3 it is:
/WEB-INF/platform/plugins/org.eclipse.birt.report.data.oda.jdbc_2.3.0.v20080610/drivers
If you are using Firefox 3 you might have noticed the Version Mismatch error. In this case you will need to use a different browser or to upgrade your BIRT version to 2.3
Thursday, March 20, 2008 | 0 Comments
TPTP Agent Controller on Ubuntu 7.10
Prerequisites:
The Eclipse tptp Agent Controller is compiled using libstdc++-libc6.2-2.so.3. If we don't have it under /usr/lib, then we need to install it:
sudo apt-get install libstdc++2.10-glibc2.2
Using Ubuntu Hardy 8.04? take a look here on how to install libstdc++2.10-glibc2.2
Agent Controller Installation:
$ sudo mkdir /opt/agntctrl.linux_ia32-TPTP-4.4.1
$ sudo ln -s /opt/agntctrl.linux_ia32-TPTP-4.4.1 /opt/tptpAC
$ cd /opt/tptpAC/
$ sudo unzip /home/shimi/agntctrl.linux_ia32-TPTP-4.4.1.zip
Run the configuration script. The script will create the Eclipse tptp Agent Controller configuration file /opt/tptpAC/config/serviceconfig.xml
$ cd bin
$ sudo SetConfig.sh
Add the following lines to ~/.bashrc
PATH=$PATH:/opt/tptpAC/bin
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/tptpAC/lib
TEMP=/tmp
Change the first line in the scripts ACStart.sh and ACStop.sh from#!/bin/sh
to#!/bin/bash
Thursday, March 13, 2008 | 1 Comments
How to share objects between different classloaders on Terracotta
Object identity in Terracotta is based on a combination of classloader name and object reference. When using Terracotta to share an object between different applications where the object class is loaded by classloaders with different names, exception is thrown. In my case I shared an object between deployed ear application on JBoss (app-ee.ear) and a console application.
Exception in thread "Thread-10" com.tc.exception.TCClassNotFoundException: java.lang.ClassNotFoundException: No registered loader for description: JBoss.UnifiedClassLoader3:deploy/app-ee.ear, trying to load org.terracotta.datagrid.workmanager.routing.RoutableWorkItem
at com.tc.object.bytecode.ManagerUtil.lookupObject(ManagerUtil.java:335)
at java.util.concurrent.LinkedBlockingQueue$Node.getItem(LinkedBlockingQueue.java:65)
at java.util.concurrent.LinkedBlockingQueue.extract(LinkedBlockingQueue.java:139)
at java.util.concurrent.LinkedBlockingQueue.poll(LinkedBlockingQueue.java:386)
at org.terracotta.datagrid.workmanager.routing.RoutingAwareWorker.start(RoutingAwareWorker.java:46)
at com.shimi.example.StartRoutingWorker$1.run(StartRoutingWorker.java:20)
Caused by: java.lang.ClassNotFoundException: No registered loader for description: JBoss.UnifiedClassLoader3:deploy/app-ee.ear, trying to load org.terracotta.datagrid.workmanager.routing.RoutableWorkItem
at com.tc.object.loaders.StandardClassProvider.getClassFor(StandardClassProvider.java:43)
at com.tc.object.ClientObjectManagerImpl.lookup(ClientObjectManagerImpl.java:522)
at com.tc.object.ClientObjectManagerImpl.lookupObject(ClientObjectManagerImpl.java:423)
at com.tc.object.ClientObjectManagerImpl.lookupObject(ClientObjectManagerImpl.java:412)
at com.tc.object.bytecode.ManagerImpl.lookupObject(ManagerImpl.java:651)
at com.tc.object.bytecode.ManagerUtil.lookupObject(ManagerUtil.java:333)
... 5 more
In order to solve the problem, all the VMs which are synchronized by Terracotta needs to load the shared class with the same classloader name. Since the name of the classloader which loaded the class on JBoss was JBoss.UnifiedClassLoader3:deploy/app-ee.ear, I needed to load the class on the console application using a classloader with the same name. I used a wrapper main class around the application main class. The wrapper class rename the system classloader using Terracotta NamedClassLoader and start the application.
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import com."com/caucho/loader/EnvironmentClassLoader"tc.object.bytecode.hook.impl.ClassProcessorHelper;
import com.tc.object.loaders.NamedClassLoader;
public class CustomLoader {
// usage: java CustomLoader com.example.MyRealMainClass [arg1] [arg2]
public static void main(String[] args) throws Exception {
URL[] systemURLs = ((URLClassLoader) ClassLoader.getSystemClassLoader()).getURLs();
ClassLoader loader = new URLClassLoader(systemURLs, ClassLoader
.getSystemClassLoader().getParent());
// here is the custom classloader name
((NamedClassLoader) loader).__tc_setClassLoaderName("JBoss.UnifiedClassLoader3:deploy/app-ee.ear");
ClassProcessorHelper.registerGlobalLoader((NamedClassLoader) loader);
Thread.currentThread().setContextClassLoader(loader);
Class mainClass = loader.loadClass(args[0]);
Method main = mainClass.getMethod("main", new Class[] { args.getClass() });
String[] nextArgs = new String[args.length - 1];
System.arraycopy(args, 0, nextArgs, 0, nextArgs.length);
main.invoke(null, new Object[] { nextArgs });
}
}
Tuesday, March 11, 2008 | 1 Comments
How to configure Firefox with Java
In order to configure Firefox with installed JRE, a link needs to be created in the browser plugins directory to the JRE plugin directory
cd ~/.mozilla/plugins/
ln -s /usr/lib/jvm/java-6-sun/jre/plugin/i386/ns7/libjavaplugin_oji.so
Monday, March 10, 2008 | 0 Comments
JMX remote connection failure to Java application running on Ubuntu
I have been trying to remote monitoring my application which was running on Ubuntu server using Jconsole and I kept on getting connection failure.
When I run the same application on my Ubuntu desktop I did managed to connect to it using Jconsole.
I wrote a small program to help me investigate the problem:
public class JmxTest {
public static void main(String[] args) {
try {
Thread.sleep(Integer.MAX_VALUE);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
and I ran it with the following properties on my Ubuntu desktop:
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9004 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false
I have tried to connect to it using JConsole from a different machine on my network and I got the same error. I have tried to connect to the application using MX4J and I got the following exception:
java.rmi.ConnectException: Connection refused to host: 127.0.1.1; nested exception is:
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:574)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:94)
at javax.management.remote.rmi.RMIServerImpl_Stub.newClient(Unknown Source)
at javax.management.remote.rmi.RMIConnector.getConnection(RMIConnector.java:2239)
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:271)
at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248)
at org.mc4j.console.connection.JSR160ConnectionNode.connect(JSR160ConnectionNode.java:132)
at org.mc4j.console.connection.ReconnectAction.performAction(ReconnectAction.java:47)
at org.openide.util.actions.NodeAction$3.run(NodeAction.java:440)
at org.openide.util.actions.CallableSystemAction$ActionRunnable.actionPerformed(CallableSystemAction.java:247)
at org.netbeans.core.ModuleActions.invokeAction(ModuleActions.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.openide.util.actions.CallableSystemAction.invokeAction(CallableSystemAction.java:179)
at org.openide.util.actions.CallableSystemAction.access$000(CallableSystemAction.java:31)
at org.openide.util.actions.CallableSystemAction$ActionRunnable.doRun(CallableSystemAction.java:241)
at org.openide.util.actions.CallableSystemAction$2.run(CallableSystemAction.java:111)
at org.openide.util.Task.run(Task.java:136)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:330)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:686)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:520)
at java.net.Socket.connect(Socket.java:470)
at java.net.Socket.<init>(Socket.java:367)
at java.net.Socket.<init>(Socket.java:180)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:569)
[catch] ... 23 more
I have noticed the
127.0.0.1 localhost
127.0.1.1 ubuntu-desktop
I removed the 127.0.1.1 line and I moved the host name to the end of the first line:
127.0.0.1 localhost ubuntu-desktop
After that I tried again to connect to my application using MX4J. This time I got the same exception but instead of 127.0.1.1 I got 127.0.0.1
java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is: java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:574)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:94)
at javax.management.remote.rmi.RMIServerImpl_Stub.newClient(Unknown Source)
at javax.management.remote.rmi.RMIConnector.getConnection(RMIConnector.java:2239)
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:271)
at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248)
at org.mc4j.console.connection.JSR160ConnectionNode.connect(JSR160ConnectionNode.java:132)
at org.mc4j.console.connection.ReconnectAction.performAction(ReconnectAction.java:47)
at org.openide.util.actions.NodeAction$3.run(NodeAction.java:440)
at org.openide.util.actions.CallableSystemAction$ActionRunnable.actionPerformed(CallableSystemAction.java:247)
at org.netbeans.core.ModuleActions.invokeAction(ModuleActions.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.openide.util.actions.CallableSystemAction.invokeAction(CallableSystemAction.java:179)
at org.openide.util.actions.CallableSystemAction.access$000(CallableSystemAction.java:31)
at org.openide.util.actions.CallableSystemAction$ActionRunnable.doRun(CallableSystemAction.java:241)
at org.openide.util.actions.CallableSystemAction$2.run(CallableSystemAction.java:111)
at org.openide.util.Task.run(Task.java:136)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:330)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:686)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:520)
at java.net.Socket.connect(Socket.java:470)
at java.net.Socket.<init>(Socket.java:367)
at java.net.Socket.<init>(Socket.java:180)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:569)
[catch] ... 23 more
After that I removed the host name from the file and I tried again, this time everything worked.
I have found this Blog entry about troubleshooting connection problems in jconsole. In my case the problem was different but it might be helpful to others .
Sunday, March 09, 2008 | 2 Comments
How to Add Command Line Properties to JMeter
Command line properties are very helpful when running JMeter in non-gui mode.
Passing a property value to the test plan:
-J[prop name]=[value]
Accessing the property value from the test plan:
${__P(prop name,default-value)}
The first value is the property name. The second value is the default value if the test was started without passing a value to the property.
For example, if we want to configure the host name and port number of the server that we want to test, we can write ${__P(server.host,localhost)} in the server name and ${__P(server.port,80)} in the port number of the test plan HTTP Request Defaults config element.
The command line will look like this:
./jmeter -t testplan.jmx -n -Jserver.host=differenthostname -Jserver.port=8080
Wednesday, March 05, 2008 | 0 Comments
How to Disable Hadoop File System Permissions
HDFS permissions is a new feature in Hadoop 0.16.0
The default value for the HDFS permissions in hadoop 0.16.0 is true. In order to disable it you need to add the following block to your Hadoop configuration file (hadoop-site.xml):
<property>
<name>dfs.permissions</name>
<value>false</value>
</property>
Tuesday, March 04, 2008 | 0 Comments
How to enable JMX on a Java Application
To enable Java with JMX Agent we need to add the following line to the application VM arguments:-Dcom.sun.management.jmxremote
This will enable only local monitoring. To enable remote JMX connection we need to specify the port which the JMX server will listen for remote connection.-Dcom.sun.management.jmxremote.port=9004 (or any other port number)
The JMX remote connection is secured by default. To disable the authentication or the SSL in the JMX remote connection:-Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false
much more information about monitoring and management using JMX can be found here
Tuesday, March 04, 2008 | 0 Comments