Tuesday 2 April 2013

Hadoop implementation(setup) with window 7 using CYGWIN

 I'll just show how to configure Hadoop on a single window in pseudo distributed mode.

Versions used :

1- window 7 with CYGWIN
2- Java (Oracle java-1.6)
3- Hadoop (Apache hadoop-1.0.3)

If you have everything in place, start following the steps shown below to configure Hadoop on your machine :

1) For install cygwin properly follow the link :
3) Extract hadoop 1.0.3 inside cygwin ( c:\cygwin\usr\local\hadoop-1.0.3
4) Now open and edit  hadoop-env.sh using path C:\cygwin\usr\local\hadoop-1.0.3\conf  and change java    path according to environment path(NOTE : Before change in java path first set java path in environment variable)
  export JAVA_HOME=C:\\Java\\jre1.6.0
Than go to cygwin terminal and check:

5)Now ,we ll start with the actual configuration process. Hadoop is configured using a set of configuration files present inside the HADOOP_HOME/conf directory. These are xml files having a set of properties in form of key value pairs.We'll modify the following 3 files for our setup.

Edit in mapred-site
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
 <name>mapred.job.tracker</name>
 <value>localhost:9001</value>
</property>
</configuration>

Edit in hdfs-site
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
 <name>dfs.replication</name>
 <value>1</value>
</property>
 </configuration>

Edit in core-site 
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
 <property>
 <name>fs.default.name</name>
 <value>hdfs://localhost:9000</value>
</property>
</configuration>

save all files and close.

6)To format the filesystem, enter the following command in cygwin:
 bin/hadoop namenode -format


7) Now type command  bin/start-dfs.sh 
8) and than bin/start-mapred.sh
ar in palce of therse command we can type bin/start-all.sh (deprecated)

9) Check logs inside C:\cygwin\usr\local\hadoop-1.0.3\logs

10) After check log findout particular ips than check and get output like that
 if these screen show successfully than we ask hadoop configure properly.




Friday 18 May 2012

client bundle using gwt

Paste thisproject.gwt.xml
 <inherits name="com.google.gwt.resources.Resources" />

For image ,textfile and pdf

1)create  a folder image in workspace  client folder(with some image) sameas create text folder and paste any .txt file and last create a pdf folder and any pd f paste in folder

2) go to client folder in ide than click new and select client bundle .

3)clientbundle.java

package com.ruchi.bundle.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Frame;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.PushButton;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextArea;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class ClientBundle implements EntryPoint {
/**
* The message displayed to the user when the server cannot be reached or
* returns an error.
*/
private static final String SERVER_ERROR = "An error occurred while "
+ "attempting to contact the server. Please check your network "
+ "connection and try again.";

/**
* Create a remote service proxy to talk to the server-side Greeting service.
*/

/**
* This is the entry point method.
*/
public void onModuleLoad() {
 Grid grid = new Grid(5, 5);
       grid.setBorderWidth(1);

       int numRows = grid.getRowCount();
       int numColumns = grid.getColumnCount();
       for (int row = 0; row < numRows; row++)
       {
         for (int col = 0; col < numColumns; col++)
         {
             grid.setWidget(row, col, new Image(Resource.INSTANCE.alpha1()));
           
         }
       }

       RootPanel.get().add(grid);
     //  Window.alert(Resource.INSTANCE.ruchi().getText());
     
       AbsolutePanel abs=new AbsolutePanel();
       abs.setSize("500px","400px");
     
       TextArea myTextArea=new TextArea();
       myTextArea.setSize("400px","300px");
       abs.add(myTextArea);
     
       myTextArea.setText(Resource.INSTANCE.ruchi().getText());
       RootPanel.get().add(abs);
     
       HorizontalPanel hrzz=new HorizontalPanel();
       hrzz.setSize("1000px", "500px");
       Frame f=new Frame(Resource.INSTANCE.taxUpdatesForJune2012Exams().getUrl());
       f.setSize("1000px", "500px");
       hrzz.add(f);
       RootPanel.get().add(hrzz);
     
   }
}


4) Resource.java

package com.ruchi.bundle.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.DataResource;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.resources.client.TextResource;
import com.google.gwt.resources.client.ClientBundle.Source;

public interface Resource extends ClientBundle {
public static final Resource INSTANCE =GWT.create(Resource.class);
@Source("com/ruchi/bundle/images/alpha1.jpg")
ImageResource alpha1();
@Source("com/ruchi/bundle/text/ruchi.txt")
public TextResource ruchi();
@Source("com/ruchi/bundle/pdf/Tax updates for June 2012 Exams.pdf")
DataResource taxUpdatesForJune2012Exams();

@Source("com/ruchi/bundle/images/Back.gif")
ImageResource back();

@Source("com/ruchi/bundle/images/joinus.gif")
ImageResource joinus();

@Source("com/ruchi/bundle/images/next.gif")
ImageResource next();

}


Thursday 12 January 2012

GWT calling Flex and Flex calling GWT


Can GWT and Flex speak together?
Yes,  Flex can communicate with GWT client side very well, as they both can speak the same language (JavaScript).
How?
It is very easy, GWT can call Flex methods through native functions, and Flex can call GWT methods through external interface
Hello World example (as usual) ,
GWT calling Flex Methods:
1. Initialize Flex application (Flexy):
In “creationComplete” event add this line of code

ExternalInterface.addCallback( “sayHello”, sayHello);
“sayHello” is the java script function to call from outside flex.
sayHello is the flex function to call when someone call sayHello from outside .
2.  Create sayHello Flex function :

Function void sayHello(hello:String):void {
Alert.show(hello);
}

then compile and add Flexy.swf file in the public folder of GWT project.
3. Add SWF file to GWT Panel:
Create new panel inside your application to hold the swf file “Flexy.swf”,

Panel  swfHolder = new Panel();
swfHolder.setWidth(400);
swfHolder.setHeight(400);
swfHolder.setHtml(
"<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'"+
"id='flexy' width='100%' height='100%'"+
"codebase='http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab'>"+
"<param name='movie' value=' Flexy.swf' />"+
"<param name='quality' value='high' />"+
"<param name='bgcolor' value='#ffffff' />"+
"<param name='allowScriptAccess' value='sameDomain' />"+
"<embed src=' Flexy.swf' quality='high' bgcolor='#ffffff'"+
"width='100%' height='100%' name='flexy' align='middle'"+
"play='true'"+
"loop='false'"+
"quality='high'"+
"allowScriptAccess='sameDomain'"+
"type='application/x-shockwave-flash'"+
"pluginspage='http://www.adobe.com/go/getflashplayer'>"+
"</embed>"+
"</object>");

4.  GWT call Flex Methods:
In your main java file add a new native method

Private native void helloFlex(String  hello)/*-{
function getFlexApp(appName) {
if (navigator.appName.indexOf ("Microsoft") !=-1) {
return $wnd[appName];
} else {
return $doc[appName];
}
};
getFlexApp('Flexy').sayHello(hello);
}-*/;

Now you can call helloFlex(“hello World”) from GWT client code and it will call the flex function and show the message box inside Flex.
Flex calling GWT functions:
1. Create GWT function:

Private void helloGwt(String hello)
{
MessageBox.alert(hello);
}

2. Publish the method so Flex can call it:
The problem is that GWT converts the java code to java script so all the function names will change
We can override this by creating definition method,

Private native void defHelloGwt(Panel holderPanel)/*-{
$wnd.sayHello = function(hello){
holderPanel.@{your package name}.{class name}::helloGwt(Ljava/lang/String;)(hello);
};
}-*/;

Now we can call sayHello from flex.
3. Flex call GWT method :
From flex app we can use

ExternalInterface.call(“sayHello”,”hello world”);

And a message box in GWT will show with text “hello World” .

Monday 3 October 2011

Fetch system time using gwt


SYSTEM TIME

package com.client;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import com.shared.FieldVerifier;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class systemtime implements EntryPoint {
 
 
  private final GreetingServiceAsync greetingService = GWT.create(GreetingService.class);

  /**
   * This is the entry point method.
   */
  public void onModuleLoad() {

     
      Date date = new Date();
      int Month = date.getMonth();
      int Day = date.getDate();
      int Year = date.getYear();
      int Hour = date.getHours();
      int min = date.getMinutes();
      int sec = date.getSeconds();
      int tz = date.getTimezoneOffset();
      int UnixTimeStamp = (int) (date.getTime() * .001);

      //get unix time stamp example (seconds)
      Long lTimeStamp = date.getTime(); //time in milleseconds since the epoch
      int iTimeStamp = (int) (lTimeStamp * .001); //(Cast) to Int from Long, Seconds since epoch
      String sTimeStamp = Integer.toString(iTimeStamp); //seconds to string

      //get the gmt date - will show tz offset in string in browser, not eclipse debug window
      String TheDate = date.toString();

      //render date to root panel in gwt
      Label label = new Label(TheDate);
      RootPanel.get().add(label);
     
     
  }
}

Wednesday 27 July 2011

Creating chemistry toolbar and fetch image

tlbrbtnChemisrty = new ToolbarButton("CHEMISRTY DIAGRAMS\r\n");
       tlbrbtnChemisrty.addListener(new ButtonListenerAdapter() {
            @Override
            public void onClick(com.gwtext.client.widgets.Button button, EventObject e) {
           
                chem=new Toolbar();
               
               
                chem.setAutoWidth(false);
                absolutePanel_1.add(chem, 15, 132);
               
                chem.setSize("850px", "35px");
               
               
               

            
               

                 textBoxchem = new TextBox();
                    absolutePanel.add(textBoxchem, 74, 128);
                 periodic=new ToolbarButton();
               
                 periodic.setText("View Periodic Table");
                 periodic.setTooltip("Periodic Table");
                 periodic.setCls("a");
                 periodic.setToggleGroup("");
                 periodic.setIcon("");
                    chem.addButton(periodic);
                    periodic.setSize("34px", "35px");
                    periodic.addListener(new ButtonListenerAdapter() {
                        @Override
                        public void onClick(com.gwtext.client.widgets.Button button, EventObject e) {
                       
                             funperiodic();
                           
                           
                       
                        }
                    });


                    insertimage=new ToolbarButton();
                    insertimage.setText("Insert image");
                    insertimage.setTooltip("insert image");
                    insertimage.setToggleGroup("");
                    insertimage.setIcon("");

                    chem.addButton(insertimage);
                    insertimage.setCls("italic:hover");
                    insertimage.addListener(new ButtonListenerAdapter() {
                        @Override
                        public void onClick(com.gwtext.client.widgets.Button button, EventObject e) {
                       
                       
                            sschem=textBoxchem.getText();
                            System.out.println(sschem);
                           
                       
                           
                         s1chem=richTextArea.getText();
                         fun(sschem);
                       
                                flagchem=true;

                     

                      
                           
                       
                        }
                    });
                   
                   
                   

                    getimage=new ToolbarButton();
                    getimage.setText("Get image");
                    getimage.setTooltip("Get image");
                    getimage.setToggleGroup("");
                    getimage.setIcon("");
                    chem.addButton(getimage);
                    getimage.setCls("under:hover");
               
                   
                   
                    getimage.addListener(new ButtonListenerAdapter() {
                        @Override
                        public void onClick(com.gwtext.client.widgets.Button button, EventObject e) {
                       
                            if(flagchem==true)
                             {


                                 richTextArea.getExtendedFormatter().insertImage("http://localhost:8082/image2.php?name="+sschem+"");
                       
                             }
                           
                           
                       
                        }
                    });

                   
                   
                   
                   
                   
                   
                    panel.add(absolutePanel,84,267);
            }
        });
       
       
       
       
       
       
   
       
       
       
       
       
       
       
       
       
        toolbar.addButton(tlbrbtnChemisrty);
        toolbar.addSeparator();
       
       

Converting Text into array and creating Combined image(Text + image)


            public String path(String text,String id) {
               
               
                String query;


                BufferedImage image;
                OutputStream targetFile1;
                //Image image1;
                byte[] buf=new byte[1024];


                byte[] fileBytes;
                ResultSet rs;
                int i;
                char a[]=text.toCharArray(); 
                int t= text.length();
                System.out.println("i is"+t);
                float x=t/40;
                double value=Math.ceil(x);
                int val=(int)value;
                String [] str=new String[val+1];
                int len=0;
                int k=0,j;
                char [] temp={' '};
                StringBuffer strbuf;
               
               
               
                for( i=1;i<=val;i++)
                {
                    //System.out.println("print value"+i);
                   for(j=40*(i-1);j<t;j++)
                   {
               
                if(j==40*i)
                {
                    for( k=40*i;k>40*(i-1);k--)
                    {
                       
                       
                       
                        if(a[k]==(char)(32))
                        {
                           
                            //System.out.println("k is"+k);
                           
                            break;
                        }
                    }
                    //System.out.println("len  is........"+len);
                    strbuf =new StringBuffer();
                    for(int l=len;l<k;l++)
                    {
                       


                        //System.out.println("print"+a[l]);
                       
                       
                          strbuf.append(a[l]);
                         
                       
                    }
                    //System.out.println("a39 is..."+a[39]);
                    //System.out.println("a39 is"+a[40]);
                    //System.out.println("print stringbuffer"+strbuf);
                      
                len=k;
               
               
                       String s=new String();
                    s=strbuf.toString();
                       //System.out.println("print karo"+s);
                        str[i-1]=s;
                        //System.out.println(str[i-1]+"check");
                   
                    strbuf=null;
                    break;
                   
               
                }
           
               
               
                   }  
                  
                //System.out.println(j+"welcome to all");
                }
               
               
               strbuf =new StringBuffer();
                System.out.println("what is val-1"+val);
                for(int last=k;last<t;last++)
                {
                    strbuf.append(a[last]);
                    //System.out.print("ye h ........"+a[last]);
                }

                   String s=new String();
                s=strbuf.toString();
                   System.out.println("print karo"+s);
                    str[val]=s;
                   
                    //System.out.println(str[i-1]+"check");
               
                strbuf=null;
               
              
               
                for(int extra=0;extra<=val;extra++)
                {
                    System.out.println("hello ji kya hua "+str[extra]+"\n");
                }
               
                try
                {
                   
                   
                   
                    connect();
                        query = "select image from save1";


                        rs= st.executeQuery(query);
                        if (rs.next())
                       {
                            System.out.println("hello");
                                 fileBytes = rs.getBytes("image");
                                 OutputStream targetFile= 
                                 new FileOutputStream(
                                      "d://flex.JPG");

                                 targetFile.write(fileBytes);
                                 targetFile.close();
                       }       
                      
                }
                catch (Exception e)
                {
                        e.printStackTrace();
                }


        //String totallen=text;


                try
                {

                   
                   
                   
                   

                   
                    BufferedImage imagefinal = ImageIO.read(new File("d://flex.jpg"));
                               
                //    int w = Math.max(image.getWidth(), overlay.getWidth());
                    //int h = Math.max(image.getHeight(), overlay.getHeight());
                   
                    BufferedImage combined = new BufferedImage(500, 800, BufferedImage.TYPE_INT_ARGB);
                   
                   
                    //combined.setRGB(40,30,30);
                   
                   
                    Graphics g = combined.getGraphics();
                   
                    Font font = new Font("Serif", Font.PLAIN, 24);
                       g.setFont(font);
                       g.setColor(Color.black);
                      
                       g.drawImage(imagefinal, 20, 20, null);
                       int faltu=20;
                for(int m=0;m<=val;m++)
                {

                    g.drawString(str[m], 20, 150+m*faltu);

                   
                }
                   
                    //g.drawImage(overlay, 40, 40, null);// Save as

                   ImageIO.write(combined, "PNG", new File("d://final.jpg"));

                   


                }
                catch(Exception e)
                {
                    e.printStackTrace();
                }

               
                         int len1;
                    String query1;
                 
                    PreparedStatement pstmt;
                    try
                  
                    {
                        connect();
                            File file = new File("d://final.jpg");
                            FileInputStream fis = new FileInputStream(file);
                          
                            len1 = (int)file.length();

                            query1 = ("insert into last VALUES(?,?)");
                            pstmt = con.prepareStatement(query1);
                            pstmt.setString(1,id);
                           
                            // Method used to insert a stream of bytes
                            pstmt.setBinaryStream(2, fis, len1);
                            pstmt.executeUpdate();

                    }


                  
                    catch (Exception e)
                    {
                            e.printStackTrace();
                    }
          
                  //sending
              
                 int len1;
                    String query1;
                 
                    PreparedStatement pstmt;
                    try
                  
                    {
                        connect();
                            File file = new File("d://final.jpg");
                            FileInputStream fis = new FileInputStream(file);
                          
                            len1 = (int)file.length();

                            query1 = ("insert into last VALUES(?,?)");
                            pstmt = con.prepareStatement(query1);
                            pstmt.setString(1,id);
                           
                            // Method used to insert a stream of bytes
                            pstmt.setBinaryStream(2, fis, len1);
                            pstmt.executeUpdate();

                    }


                  
                    catch (Exception e)
                    {
                            e.printStackTrace();
                    }
          
              
              
              
              
              
              
              
              
              
              
              
              
              
              
              
              
                return null;
              
              
              
            }



 
              
       
               

Monday 25 July 2011

Open file selection dialog programatically for hidden UploadItem

package com.client;

import com.shared.FieldVerifier;


public class FileUploadsmart implements EntryPoint {
    //FormPanel formPanel ;
    //TextField textField1;


 
  private final GreetingServiceAsync greetingService = GWT.create(GreetingService.class);
  VLayout layout;
 
  public void onModuleLoad() {
     
      RootPanel p=RootPanel.get();
    
      VLayout layout = new VLayout();
      layout.setSize("100px", "44px");
    
      final DynamicForm uploadForm = new DynamicForm();      
      uploadForm.setSize("54px", "147px");
      uploadForm.setEncoding(Encoding.MULTIPART);
    
    
     //  UploadItem fileItem = new UploadItem("image");
      
       HTML q =new HTML();
       q.setHTML("<"+"div style='display: block; width: 100px; height: 20px; overflow: hidden;'"+">"
      
                      +  "<"+"button style='width: 110px; height: 30px; position: relative; top: -5px; left: -5px;'"+">"+ "<a href=  'javascript: void(0)'>upload file</a>"+"</button>"
              
              +"<"+"input type='file' id='upload_input' name='upload' style='font-size: 50px; width: 120px; opacity: 0; filter:alpha(opacity: 0); position: relative; top: -40px; left: -20px'"+"/>" +
              
              "</div>" );
     
     
     
     
      uploadForm.setAction(GWT.getModuleBaseURL()+"upload");
   
      IButton uploadButton = new IButton("Attachment");
      uploadButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler()
      {
          @Override
          public void onClick(
                  com.smartgwt.client.widgets.events.ClickEvent event) {
              // TODO Auto-generated method stub
           
              
              uploadForm.submitForm();
          }
      });
      uploadForm.addChild(q);  
  ///uploadForm.setItems(fileItem);

      layout.setMembers(uploadForm, uploadButton);

    
    
    
      RootPanel.get().add(layout, 2, 2);

      
      

       
       
    }
}