Posts

Long running Java process resource consumption monitoring , leak detection and GC tuning

For easily monitoring the JVM metrics there is no better tool than Java VisualVM or its older counterpart JConsole; These two tools comes with the Java JDK. So it is absolutely necessary that you copy a JDK version to some temp directory in which your server runs. {Make sure that you do not install the JDK / put the java executable in the path.} Before going in JVM monitoring, it is essential to understand a little about Java's memory model. Note - This article is written with  HotSpot JVM in mind,which is one of the most commonly used one ; implemented by OpenJDK and Oracle - formerly from Sun. This is not the only one , notable being JRockit and others ; and some details would change with a different JVM. When you are running a Java Process in a Server you allocate the Memory for the Java Virtual Machine. This memory is split to process heap { what you give withe the Xmx Xms command}where it is again subdivided on generational basis (Young, Old)  and the PermGen -...

JBoss AS 7.1.1 and HornetQ Clustering in two nodes

Fist follow https://docs.jboss.org/author/display/AS71/AS7+Cluster+Howto Check the  domain.xml configuration in the Master node  ( for profile - full-ha part) for the things marked yellow Code as well as the domain.xml configuration  and the ports to be open is in GitHub  https://github.com/alexcpn/jboss_hornetq_clustering (Tested with AS 7.1.1) Invocation http: // :8330/MroControllerREST/rest/sessionbean/startmro?scopename=werwerwe http: // :8330/MroControllerREST/rest/sessionbean/startmro?scopename=werwerwe Will create a message/messages and send to MROQueue ; The MROExecutorMDB will receive it and post a message to MROTopic which will be received by MROControllerMDB in both the master and slave nodes (Deploy MROController.ear and MROExecuotor.ear to only other-server-group (jboss-cli.sh , connect to master and deploy)

Exposing REST interface from a Session Bean

Here is a working example  at  https://github.com/alexcpn/rest_in_sessionbean  Tested with JBOSS AS 7.1.1. Note that a war file is needed in the ear, with a web.xml . This is using JBOSS inbuilt RESTEasy. Idea from Adam Bein's  blog -  www.adam-bien.com/roller/abien/entry/ejb_3_1_and_rest

Apache CXF and Spring

http://cxf.apache.org/docs/writing-a-service-with-spring.html http://cxf.apache.org/docs/jax-ws-configuration.html http://cxf.apache.org/docs/configuration.html And finally à http://stackoverflow.com/questions/689902/cxf-without-spring --> http://cxf.apache.org/docs/servlet-transport.html#ServletTransport-UsingtheservlettransportwithoutSpring   Follwing maven settings in   jroller http://www.jroller.com/gmazza/entry/web_service_tutorial Reading a little from Spring I understood that this is actually the applicationcontext.xml and cxf is somehow cooking its beans with Spring < bean id="cxf" class="org.apache.cxf.bus.spring.SpringBus" destroy-method="shutdown" / >             < bean id="org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor"                 class="org.apache.cxf.bus.spring.BusWiringBeanFactor...

JavaScript (Prototypal) Inheritance with new and Object.create

//--------------------------- //Inheritance in JavaScript //--------------------------- var Person = function (string){ this.name= string; //if ( !(this instanceof Person) ) //part soln to danger 1 // return new Person(name); }; Person.prototype.get_name = function(){ return this.name; }; //Danger 1 : No compile errors here if new is skipped //Also inside the function would now be the global this object, //not the new instance! The constructor would be overriding all sorts //of global variables inadvertently var manu = Person("Manu"); name; manu.get_name(); //Danger 1 :only run time error here;Crackford's reason var adi = new Person("Adi"); adi.get_name(); //Okay let us try Iheritance with new var Employee = function (name,company){ this.name = name; this.company=company; Person.call(this,name); }; Employee.prototype.get_company = function(){ return this.comany; }; //How to inherit from Person ? //Step 1 - Link the prototypes /...

Self Monitoring Processor Design for a State Machine Implementation

Self Monitoring Processor Design for a FSM Using the Runnable and Callable interface as well as the Java 6 ThreadPool classes to create a class design that not only executes a task, but can monitor the execution progress periodically Here is how the interface looks like. Note that each processor has an associated ‘State’ and each state has a status - like ex scheduled, started, awaiting_async, success , fail ,timeout etc. This is because the IProcessor class is also used to implement a state machine.I won't be going through this part in more detail here. public interface IProcessor extends Runnable, Callable { ProcessingStatus getCurrentStatus(); ProcessingState getCurrentState(); ProcessingStatus execute(); Future getTask(); void setScheduledFutureHandle(ScheduledFuture handle); Now we define an Abstract class that does the basic work public abstract class Processor implements IProcessor, Comparable { @Override //Method which does the actual work publi...

OpenLayers Advanced Clustering and Setting dynamic images for OpenLayer Styles via Ajax

Update: - Read the same at  Medium  for better readability; Blogger is not technology blogging friendly JSFiddle Source for this Tutorial Let us start with a simple OpenLayer map In the JSP or the HTML we have <head> <script src="http://openlayers.org/api/OpenLayers.js"></script> <script type="text/javascript" src="<%=request.getContextPath()%>/js/maplister.js"></script> <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.7.2.min.js"></script> <script src="http://maps.google.com/maps/api/js?v=3&amp;sensor=false"></script> </head> <body> <div id="map-id" style="height:100%;width=100%"></div> </body> And on document load AUI().ready(function(X) { resize("scMapListerportlet", "#map-id"); var iconpath ="<%=request.getContextPath()%>/...

Running Jstestdriver with PhantomJs in Windows

Image
Using JSTestDriver with PhantomJS Locally PahntomJS is command line web browser JSTestDriver can be integrated to Jenkins; it can also be used for unit testing JavaScritpt Code; Only that it needs a browser running to execute the test cases.Using PahntomJs as the browser will  remove the need for a GUI browser to be launched from the script driven CI evnironment. Steps First start JStestdriver D:\Coding\lib>java -jar JsTestDriver-1.3.5.jar  --port 9876 --captureConsole --runnerMode DEBUG Starting Phantomjs browser and using it to capture the JStestdriver Download Phantomjs Download and use the javascript that is used to capture the pahntom browser https://github.com/larrymyers/js-test-driver-phantomjs/blob/master/phantomjs-jstd.js d:\Program_Files\phantomjs-1.7.0-windows>phantomjs.exe phantomjs-jstd.js Wed Oct 31 2012 12:07:26 GMT+0530 (India Standard Time): Attempting (1) to load:   http://localhost:9876/capture Run your JStestdiver...

JAX-RS with GSON and Jersy

Following from the excellent tutorial from Vogella ( http://www.vogella.com/articles/REST/article.html  ), extending with some extra details.  Using GSON in this as my  class had  a custom class wrapped in Java collection, GSON makes it very easy to marshall JSON, same also with JAXB using Jersy; But with GSON unmarshalling to Java is also pretty easy.  Also multiple parmeter support is shown So let us start with the interface first. Kindly read Roy Thomas Fielding's 2000 Dissertation, where he described his architecture style for the web This is a must read for , especially 'architects'. Enough Talk, Let us show some code Yes read about JAX-RS annotations, otherwise it is a simple Java Class (packaged as a servlet - WAR, see Vogellas article first. Okay here goes the interface (in rest everything is HTTP,GET,SET, POST etc package com.test.prog; import java.util.ArrayList; import java.util.List; import javax.ws.rs.GET; import javax.ws.rs.Path...

Ubuntu 11.10 on my Dell Inspirion M101Z (dual core)

From the time I had this  laptop   Dell Inspiron M101z (AMD Athlon II Neo K325 Processor 1.3GHz, 2GB RAM)   ( http://asia.cnet.com/product/dell-inspiron-m101z-amd-athlon-ii-neo-k325-processor-1-3ghz-4gb-ram-45287123.htm ), I had used the excellent wubi installer to dual boot Ubuntu  10.10 to my system. This was okay, however the Windows 7 starter OS I have in this is also pretty light and fast and most often I was using it. I guess with Windows Ubuntu half lost the battle. Since Ubuntu has lot of releases, one day I tried upgrading Ubuntu in place. I guess upgrade is one area where Ubuntu is not that strong as earlier also upgrade has not been smooth.However this time, it managed to corrupt the Windows booting also. Since mine is a kind of high power Netbook, there is no CD tray. My hear skipped a beat when I saw this. However Windows 7 asked if it should go ahead and repair. Usually this sort of dialog from windows results in nothing much wort...

Clojure and maven

Image
I had started about learning clojure and though the REPL interpreter seems to be the standard way of starting learning, I wanted to do it in a more Test driven method using maven. So I created a source and test directory and went about writing a simple learn.clj and a simple testlearn.clj. Took some time to figure things out and make the tests work Here is the directory structure  (Learn.clj dir structure \NetBeans2\ClojureLearn2\src\main\clojure\my\clojure\learn.clj) (ns my.clojure.learn  (:gen-class)) (defn main  [args]   (println  "A red apple tree" )    (println (def x(str "Hello " args "!")) )    x  ) (defn add [x y]     (+ x y) ) ( defn workingwithlist []   (println "In the function workingwithlist")   (def listx (list 1 (add 1 1) 3 4  ))    (doseq [item listx]    (println item))      listx   )  (TestLern.clj dir s...

Booting OS/Ubuntu from an external Hard disk uisng Virtual Box virtual harddrive feature

First you need to boot from the hard drive For that put the harddrive in an hardrive enclosure and connect it via usb to your host OS Then follow the steps in the Virtual box help guide 9.9.1. Access to entire physical hard disk While this variant is the simplest to set up, you must be aware that this will give a guest operating system direct and full access to an entire physical disk. If your host operating system is also booted from this disk, please take special care to not access the partition from the guest at all. On the positive side, the physical disk can be repartitioned in arbitrary ways without having to recreate the image file that gives access to the raw disk. To create an image that represents an entire physical hard disk (which will not contain any actual data, as this will all be stored on the physical disk), on a Linux host, use the command VBoxManage internalcommands createrawvmdk -filename /path/to/file.vmdk -rawdisk /dev/sda This creates the ima...

Connecting to JMX with username and password

Got the tip from http://mx4j.sourceforge.net/docs/api/mx4j/tools/remote/PasswordAuthenticator.html ----------------------------------------- echo("\nCreate an RMI connector client and " + "connect it to the RMI connector server"); JMXServiceURL url = //new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi"); new JMXServiceURL("service:jmx:rmi:///jndi/rmi://11.11.11.11:711/jmxrmi"); String[] credentials = new String[2]; // The user will travel as clear text credentials[0] = "user"; //user name credentials[1] = "password"; //password Map environment = new HashMap(); environment.put(JMXConnector.CREDENTIALS, credentials); JMXConnector jmxc = JMXConnectorFactory.connect(url, environment);

Creating a Servicemix Binding Component and using it

Here are the steps I followed to do this Prerequisite - A working knowledge of maven is a must - Some knowledge of using Xbean is good ( not a must) Creating a BC 1. Follow steps in http://servicemix.apache.org/hello-world-bc.html mvn archetype:create -DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-binding-component -DarchetypeVersion=3.3.2 -DgroupId=com.nsn.hiq -DartifactId=hello-world-bc 2. http://markmail.org/message/gfxipkxic73fq2rg#query:+page:1+mid:keescdr6cm6g3hhc+state:results 3. http://servicemix.396122.n5.nabble.com/Exception-on-hello-world-BC-sample-td415697.html 4. http://www.mail-archive.com/users@servicemix.apache.org/msg02389.html xmlns:hellobc="http://com.nsn.hiq/1.0" Some tips In MyProviderEndPoint class the Xbean annnotation marks the name of the provider endpoint (which we will need later to use this component) /** * @org.apache.xbean.XBean element=" provider " */ public class MyProvid...

Service mix error compiling SA - "does not have a dependency which is packaged as a jbi-component or a project property 'componentName'"

This error used to come especially when you have two or more service units that is dependent on the same component (ex a file sender and a file poller , both being dependent on servicemix-file component) Googling found me that this was an error - https://issues.apache.org/activemq/browse/SM-694 but putting the componentName property was not working. In the end updated the verison of the jbi-maven-plugin to verison 4.0 in the pom.xml of the Service Assembly - SA org.apache.servicemix.tooling jbi-maven-plugin 4.0 true service-assembly (Note this error was comming only when you compile the SA and the individual compilation of the SU was going fine; Also this can come if you have for example not put the depedencies, or say the correct verison of the dependencies in the pom.xml of the SU)

Tomcat and servlets

Sevlet Package Strucutre package proto.inmc.fm.servlet; Web Xml Structure    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"    version="2.5">          inmcservlet      proto.inmc.fm.servlet.inmcservlet            inmcservlet      /servlet/inmcservlet2      Deploy dir in Tomcat D:\Program Files\Apache Group\apache-tomcat-6.0.16\apache-tomcat-6.0.16\webapps\inmc\WEB-INF\classes\proto\inmc\fm\servlet Html depl0y place in Tomcat D:\Program Files\Apache Group\apache-tomcat-6.0.16\apache-tomcat-6.0.16\webapps\docs\inmc.html Html invocation of servlet form name="myForm" method="GET" action="../inmc/servlet/inmcjnlp" input type="submit" value="Get Logged in User"  form Paths  http://localhost:8090/docs/inmc.html  http://localhost:8090/docs/inmcjnlp.html http://localhost:8090...

Jacorb Publish a Corba Servant on well know port without Naming Service

Thanks to the posts from - [jacorb-developer] ' Publish a Servant on well know port ' I was able to do the same. Below are the server and client snippet. This is using Jacorb ORB. Server code String[] args3=  { "-DOAPort=4013" };         java.util.Properties argProps = ObjectUtil.argsToProps( args3 );                         Properties props = System.getProperties();         props.put("org.omg.CORBA.ORBClass", "org.jacorb.orb.ORB");//JACORB         props.put("org.omg.CORBA.ORBSingletonClass", "org.jacorb.orb.ORBSingleton");         props.put("org.omg.PortableInterceptor.ORBInitializerClass.bidir_init",           "org.jacorb.orb.giop.BiDirConnectionInitializer");         props.put("jacorb.implname","StandardImplName");         props.putAll( argProps );         System.setProperties(props); orb = org.omg.CORBA.ORB.init(args, props); root_poa = org.omg.PortableServer.POAHelper.narrow( ...