Skip to main content

Posts

Showing posts from 2014

Hadoop Tutorial - How to install pseudo-distributed Hadoop cluster on a Mac Book Pro

In this tutorial I am going to explain the steps required to install and run Hadoop on a MacBook Pro. In this Demo I am using Mac OS X version 10.6.8. STEP 1 : Preparing Environment The first step in Hadoop installation is to setup the environment like Java, ssh connectivity etc. We will go through each of the required setup in detail. Hadoop is written in Java and requires Java 1.6 or higher for Hadoop installation. Mac comes with Java and you need to make sure that you have the required Java version installed on. Open the terminal and type the below. Jinesh-Mathews-MacBook-Pro:~ jineshmathew$ java -version java version "1.6.0_65" Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-10M4609) Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode) If java is not installed or the version is below 1.6 then you need to download and install java.Please see the below note. For Java versions 6 and below, Apple supplies their own version of Java . Fo

Java standalone webservice : Multithreading the Endpoint Publisher

While going through a very good book on web services by Martin Kalin ( Java Web services : Up and Running) I came across the section that is dealing with how to multithread the endpoint publisher so that the web service request wont wait for another one to finish. Given below is the enhancement to the example mentioned in the above book where I am using multithreaded endpoint publisher. STEP 1 : Web service Server 1. Create a new Java project. 2. Create a class TimeServer which is Service Endpoint Interface (SEI) as below. package ch01.ts; import javax.jws.WebService; import javax.jws.WebMethod; import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding.Style; /** * The annotation @WebService signals that this is the * SEI (Service Endpoint Interface). @WebMethod signals * that each method is a service operation. * * The @SOAPBinding annotation impacts the under-the-hood * construction of the service contract, the WSDL * (Web Serv

SNMP Trap Generator using SNMP4J

This project is set up as a maven project where snmp4j library is mentioned as a dependency. <dependency>     <groupId>org.snmp4j</groupId>     <artifactId>snmp4j</artifactId>     <version>1.10.1</version> </dependency> This program will send SNMPv2 Trap message to any ip address mentioned. A SNMP Trap receiver program or application which is listening on port 162 would be able to receive the message. import java.io.IOException; import org.snmp4j.CommunityTarget; import org.snmp4j.PDU; import org.snmp4j.Snmp; import org.snmp4j.mp.SnmpConstants; import org.snmp4j.smi.Address; import org.snmp4j.smi.OID; import org.snmp4j.smi.OctetString; import org.snmp4j.smi.TimeTicks; import org.snmp4j.smi.UdpAddress; import org.snmp4j.smi.Variable; import org.snmp4j.smi.VariableBinding; import org.snmp4j.transport.DefaultUdpTransportMapping; public class TrapGenerator { /** * @param args

How to add Javadoc for a class in eclipse IDE

1. Go to Project Properties->Java Build Path -> Libraries  and Expand the library that you need to add     Java doc. 2. Click on ‘Javadoc location’ as shown in the image below and ‘edit’ it. 3. For spring framework I have given the URL as http://docs.spring.io/autorepo/docs/spring-framework/3.1.x/javadoc-api/ . Now the Javadoc is appearing in Eclipse IDE as below.

Terminal emulator for Windows operating system

If you are a heavy UNIX user then you might find it very difficult to use windows command prompt because of different set of commands and look and feel. If you need a terminal emulator for windows then  you may check it out the 'Git Bash' tool provided by Git community. You can download and install Git from the link :  http://msysgit.github.io/ Once installation is completed then got to Start menu and type 'Git Bash' to open the terminal.

Useful SQL queries and tips

1 How to find all indexes associated with a table in Oracle select index_name, table_name from all_indexes where lower(TABLE_NAME)=lower(<your_table_name>) and OWNER='<owner>' 2 How to view DDL for any index in Oracle select dbms_metadata.get_ddl('INDEX',<index_name> ','<owner>') from dual; 3 How to view DDL for any view in Oracle select dbms_metadata.get_ddl('VIEW',<view_name>,'<owner>') from dual; 4 What to do when sqlplus is not displaying all lines in output Run below on sqlplus prompt: set heading off; set echo off; Set pages 999; set long 90000;  5 How to edit a sql you previously ran on sqlplus prompt Type ‘ed’ on prompt SQL> ed This will open a vi editor with your last sql query. Edit it and save and exit Type ‘r’ on prompt SQL> r This will run the updated sql. 6 H

Filesystem is full, but can't find space being used - Solaris

I saw a strange issue once  where the  /staging filesystem is almost full, but I can't find where the space is being used.  'df -h' command shows that the filesystem is 100% used as below. ==> df -h Filesystem             size   used  avail capacity  Mounted on /staging                  99G   99G   0K     100%      /staging But 'du -h' command says that only 3.7G out of 99G is used. ==> pwd /staging ==> du -h | grep "\.$" 3.7G . This is strange , now how will you find which files are consuming remaining 95.3G of disk space. The unix command which can be used here is 'lsof' - l ist o f o pen f iles. ==>  lsof | grep -i /staging cat        4723  user1 txt   VREG     270,28001          50028743680      15496 /staging (/dev/vx/dsk/staging) cat        4723  user1 3r  VREG     270,28001          50028743680      15496 /staging (/dev/vx/dsk/staging) sed        4724  user1 1w  VREG     270,28001      

JAXB - Marshalling and Unmarshalling object in Java

JAXB, stands for Java Architecture for XML Binding, which can be used to convert a Java object to XML file or a XML document to corresponding Java Object. Given below are the two terminologies used in Java for the conversions. Marshalling - Convert a Java object to XML file Unmarshalling - Convert a XML file to Java object. Here we have a class called Car which contains object of another class called Wheel. The UML diagram is as below. First we will need to write  the class Car as follows. import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement // This annotation is required to indicate that this is the top level class public class Car { Wheel wheel; String color; public Wheel getWheel() { return wheel; } public void setWheel(Wheel wheel) { this.wheel = wheel; } public String getColor() { return color; } public void setColor(String color) {

Java - getting Date without time

Java Calender and Date object is always confusing for a beginner and one of the typical situation is to create a Date object with no time information from a Calender or another Date object. One of the typical usage is when we need to compare Date with one stored in a database in say 'dd-MMM-yy' format. Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, offset); SimpleDateFormat dayMonthYear = new SimpleDateFormat("dd-MMM-yy"); String newDate=dayMonthYear.format(calendar.getTime()); Date fmtDate=null; try { fmtDate = dayMonthYear.parse(newDate); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("Time in getDate" + fmtDate);

Failed to load class "org.slf4j.impl.StaticLoggerBinder" - How to resolve

This can be resolved by adding the following dependencies to your pom.xml. <dependency>         <groupId>org.slf4j</groupId>         <artifactId>slf4j-api</artifactId>         <version>1.7.5</version>     </dependency>     <dependency>         <groupId>org.slf4j</groupId>         <artifactId>slf4j-simple</artifactId>         <version>1.6.4</version>     </dependency>     <dependency>         <groupId>org.slf4j</groupId>         <artifactId>slf4j-log4j12</artifactId>         <version>1.7.5</version>     </dependency>

How to find and delete files under a directory not looking at subdirectories in Solaris

How to find and delete files under a directory not looking at subdirectories in Solaris? In GNU linux there is a –maxdepth option to ‘find’ command which can be used to prevent looking at subdirectories but it is not available for Sun solaris. I use the below approach, here I want to remove all files except from NOTSENT and RESEND and which are older than 1 day. find . -type d \( -name NOTSENT -o -name RESEND \)  -prune -o -type f -mtime +1 -print -exec rm -rf {} \; try 'man find' on solaris for more details.