Saturday, December 29, 2012

A little WINE

When I switched to Linux from Windows (which was not rally an option for me since my company is a window-less one :) ), i was missing some of the fancy free tools which ran only in Windows. I thought there must be someone out there who came up with a way to run windows compatible software in Linux machines.  I was Googling to find a solution and came across WINE.(http://www.winehq.org/)

WINE stands for "WINE Is Not an Emulator." An emulator is a piece of software that makes one computer act like another. A company named Connectix, for instance, sells an emulator that lets a Macintosh behave like a Windows PC so anyone can use their Windows software on the Mac. Emulators, however, are pretty slow because they're constantly translating information on the fly.

The WINE project is an ambitious attempt to knock out one of the most important structural elements of the Microsoft monopoly.

It tries to clone what is known as the Win32 API, a panoply of features that make it easier to write software for a Microsoft machine.

It has produced some dramatic accomplishments making it possible to run major programs like Microsoft Word or Microsoft Excel on a Linux box without using Windows.

Friday, December 28, 2012

Eclipse Plugins : MaintainJ

MaintainJ (http://www.maintainj.com/) is a tool that can be used to generate sequence digrams when you run the application. It's a great reverse engineering tool, but unfortunaly most of the options are not available in the free version. They allow a 7 day free trial of the full product, but I just used what is available for free.

My application is deployed in WebLogic and in order to use MaintainJ following things had to be done. (Official user guide http://www.maintainj.com/userGuide.jsp?param=install)

Step A: Install MaintainJ in WebLogic

Download MaintainJ.war from http://www.maintainj.com/updates/4.0.0/MaintainJ.war and deploy it in WebLogic

Once installed you can access the following console.



There is a very clear step by step demo here.


Step 1 and 2 are straightforward. In step 2 we need to give the package names that need to be instrumented.

Step 3 advised to start WebLogic using following wrapper script.

/.../Oracle/Middleware/user_projects/domains/commercerouter-domain/bin/startWebLogic_with_mnj.sh

Since my application had a custom ant target that starts WebLogic through it, I added what is there in the above script to my ant target as shown below.


        <wlserver>
            <classpath>
                ...                
                <pathelement location="${bea.home}/user_projects/domains/commercerouter-domain/maintainj"/>
                <pathelement location="${bea.home}/user_projects/domains/commercerouter-domain/maintainj/MaintainJAspect.jar"/>
            </classpath>
            ...
            <jvmarg value="-javaagent:${bea.home}/user_projects/domains/commercerouter-domain/maintainj/aspectjweaver.jar" />    
        </wlserver>

It's possible to add multiple javaagents. So no need to worry if it's already defined pointing to another jar.

Running my ant target started WebLogic and Step 4 in Wizard showd everything is fine.

Step 5 started call trace.

Ran a test case and stopped the trace. Trace files were generated.

Step B: Install MaintainJ plugin in Eclipse to view the trace files.


Installed plugin from update site http://www.maintainj.com/updates/4.0.0

Created a new MaintainJ project in eclipse and copy the trace files to it.

Diagrams were displayed as shown below.


Monday, December 24, 2012

Oracle 10g Express

Oracle Database Express Edition (Oracle Database XE) is an entry-level, small-footprint database which is free to develop, deploy, and distribute.

Install

Cent-OS
[bash]$ rpm -hiv oracle-xe-univ-10.2.0.1-1.0.i386.rpm
Ubuntu
[bash]$ sudo dpkg -i oracle-xe-universal_10.2.0.1-1.0_i386.deb

Configure

[bash]$ sudo /etc/init.d/oracle-xe configure

Specify the HTTP port that will be used for Oracle Application Express [8080]:8000
Specify a port that will be used for the database listener [1521]:
Specify a password to be used for database accounts.  Note that the same
password will be used for SYS and SYSTEM.  Oracle recommends the use of
different passwords for each database account.  This can be done after
initial configuration:
Confirm the password:
Do you want Oracle Database 10g Express Edition to be started on boot (y/n) [y]: y


/etc/default/oracle-xe

#This is a configuration file for automatic starting of the Oracle
#Database and listener at system startup.It is generated By running
#'/etc/init.d/oracle-xe configure'.Please use that method to modify this
#file

# ORACLE_DBENABLED:'true' means to load the Database at system boot.

ORACLE_DBENABLED=true

# LISTENER_PORT: Database listener

LISTENER_PORT=1521

# HTTP_PORT : HTTP port for Oracle Application Express

HTTP_PORT=8080

# Configuration : Check whether configure has been done or not

CONFIGURE_RUN=true 

Start/stop/check the status of oracle

Cent-OS
[bash]$ sudo /sbin/service oracle-xe start
[bash]$ sudo /sbin/service oracle-xe stop
[bash]$ sudo /sbin/service oracle-xe status

Ubuntu
[bash]$ sudo service oracle-xe start
[bash]$ sudo service oracle-xe stop
[bash]$ sudo service oracle-xe status
or
[bash]$ sudo /etc/init.d/oracle-xe start
[bash]$ sudo /etc/init.d/oracle-xe stop

Browse the Oracle service

http://localhost:8000/apex/

Uninstall

Stop server
sudo /etc/init.d/oracle-xe stop

Cent-OS
[bash]$ rpm -e oracle-xe-univ-10.2.0.1-1.0

Ubuntu
[bash]$ sudo dpkg -r oracle-xe-universal

Above doesn't remove everything

Use following
[bash]$ sudo apt-get remove --purge oracle-xe-universal

It removes following folders as well.
/usr/lib/oracle
/etc/init.d/oracle-xe
/etc/default/oracle-xe

Listeners

The Oracle Net foundation layer is responsible for establishing and maintaining the connection between the client application and database server, as well as exchanging messages between them. The Oracle Net foundation layer is able to perform these tasks because of a technology called Transparent Network Substrate (TNS). TNS provides a single, common interface for all industry-standard protocols. In other words, TNS enables peer-to-peer application connectivity, where two or more computers can communicate with each other directly, without the need for any intermediary devices.

On the client side, the Oracle Net foundation layer receives client application requests and resolves all generic computer-level connectivity issues, such as:
  • The location of the database server or destination
  • How many protocols are involved in the connection
  • How to handle interrupts between client and database server based on the capabilities of each

On the server side, the Oracle Net foundation layer performs the same tasks as it does on the client side and also works with the listener to receive incoming connection requests.

The database server receives an initial connection from a client application through the listener. The listener is an application positioned on top of the Oracle Net foundation layer

The listener brokers client requests, handing off the requests to the Oracle database server. Every time a client requests a network session with a database server, a listener receives the initial request.

Each listener is configured with one or more protocol addresses that specify its listening endpoints. Clients configured with one of these protocol addresses can send connection requests to the listener.

Once a client request has reached the listener, the listener selects an appropriate service handler to service the client's request and forwards the client's request to it. The listener determines if a database service and its service handlers are available through service registration. During service registration, the PMON process—an instance background process—provides the listener with information about the following:
  • Names of the database services provided by the database
  • Name of the instance associated with the services and its current and maximum load
  • Service handlers (dispatchers and dedicated servers) available for the instance, including their type, protocol addresses, and current and maximum load

Listener Parameters (listener.ora)

Listener configuration, stored in the listener.ora file, consists of the following elements:
  • Name of the listener
  • Protocol addresses that the listener is accepting connection requests on
  • Database services
  • Control parameters
ORACLE_HOME/network/admin/listener.ora

# listener.ora Network Configuration File:SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = /usr/lib/oracle/xe/app/oracle/product/10.2.0/server)
      (PROGRAM = extproc)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
      (ADDRESS = (PROTOCOL = TCP)(HOST = dev30)(PORT = 1521))
    )
  )

DEFAULT_SERVICE_LISTENER = (XE)

Local Naming Parameters (tnsnames.ora)

This tnsnames.ora file is a configuration file that contains net service names mapped to connect descriptors for the local naming method, or net service names mapped to listener protocol addresses.

A net service name is an alias mapped to a database network address contained in a connect descriptor. A connect descriptor contains the location of the listener through a protocol address and the service name of the database to which to connect. Clients and database servers (that are clients of other database servers) use the net service name when making a connection with an application.

ORACLE_HOME/network/admin/tnsnames.ora

# tnsnames.ora Network Configuration File:XE =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = dev30)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = XE)
    )
  )

EXTPROC_CONNECTION_DATA =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
    )
    (CONNECT_DATA =
      (SID = PLSExtProc)
      (PRESENTATION = RO)
    )
  )


Troubleshooting


[bash] $ tnsping xe

TNS Ping Utility for Linux: Version 10.2.0.1.0 - Production on 24-DEC-2012 14:54:26

Copyright (c) 1997, 2005, Oracle.  All rights reserved.

Used parameter files:


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = cnb18)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)))
OK (0 msec)


java.sql.SQLException: Io exception: The Network Adapter could not establish the connection

I recived the above due to adding the wrong port when configuring. Eventhough it was reconfigured and everything looked fine in config files stil I got the following error.

ORA-12505: TNS:listener does not currently know of SID given in connect descriptor

Uninstalling didn't solve the problem. Finally deleting /usr/lib/oracle/xe and reinstall worked!!

I recived the following error
[WLServer adminserver] ORA-12519, TNS:no appropriate service handler found


And increasing the number of processes by running the following query as the admin user solved it.

ALTER SYSTEM SET PROCESSES=200 SCOPE=SPFILE; ALTER SYSTEM SET;

Saturday, December 22, 2012

Using Java’s reflection for testing private methods














Groovy is the dynamic language syntax for Java. As such, it can interact pretty seamlessly with
Java code (including compiled byte code), allowing you much more flexible syntax. You can invoke the standard reflection mechanism in Java using the Groovy syntax as shown below.


Ship Vasa


In 1625, King Gustav II Adolf of Sweden commissioned the finest warship ever built. He hired the best ship builder, grew a special forest of the mightiest oaks, and started work on the ship Vasa.
The king kept making requests to make the ship grander and grander, with ornate decorations everywhere. At some point, he decided that he wanted a ship with two gun decks, unlike any in the world. His ship was going to be the most powerful in the ocean. And he needed it right away because of a diplomatic issue that was popping up.
Of course, the ship builder had designed the ship with only one gun deck in mind, but because the king asked for it, he got his extra gun deck. Because they were in a rush, the builders didn’t have time for “lurch” tests, where a group of sailors would run from one side to the other to make sure the ship didn’t rock too much (in other words, wasn’t too top heavy).
On the inaugural voyage, the Vasa sank within a few hours. While adding all the “features” to the ship, they managed to make it unseaworthy. The Vasa sat at the bottom of the North Sea until early in the 20th century, when the well-preserved ship was raised and placed in a museum.
And here is the interesting question: whose fault was the sinking of the Vasa? The king, for asking for more and more features? Or the builders, who built what he wanted without vocalizing their concerns loudly enough? Look around at the project on which you are currently working: are you creating another Vasa?  

Little things that can make you a productive programmer



  • Launchers that allow you to type the first part of the name of an application (or document) to launch it.
  • VI editor that allows mouseless editing.
  • Auto completion
  • Clipboads. Allows to copy multiple things before pasting begins. Prevents context switching
  • History in command line
  • IDE shortcuts
  • Most used icons on the top of screen
  • Switch off email notifications
  • Have an official quite time at office
  • Search over navigation
  • Know find commands
  • Rooted views
  • Multiple monitors
  • Virtual desktops
-The Productive Programmer by Neal Ford

What can Galileo teach a software engineer?


One of the great rebels of history was Galileo, who apparently didn’t believe anything that anyone told him. He always had to try it for himself. The accepted wisdom before his time maintained that a heavier object would fall faster than a lighter one. This was based on Aristotelian thinking, where thinking hard about something logically had more merit than experimenting. Galileo didn’t buy it, so he went to the top of the Leaning Tower of Pisa and dropped rocks. And fired rocks from cannons. And discovered that, nonintuitively, all objects fall at the same rate (if you discount air resistance).
What Galileo did was prove that things that seem nonintuitive can in fact be true, which is a valuable lesson. Some hard-fought knowledge about software development is not intuitive. The idea that you can design the entire software up front, and then just transcribe it seems logical, but it doesn’t work in the real world of constant change. 
-The Productive Programmer by Neal Ford

Friday, December 21, 2012

Eclipse Versions

Codename Date Platform version
N/A 2004 3.0
N/A 2005 3.1
Callisto 2006 3.2
Europa 2007 3.3
Ganymede 2008 3.4
Galileo 2009 3.5
Helios 2010 3.6
Indigo 2011 3.7
Juno 2012 4.2
Kepler 2013 (planned) 4.3
 
Legend:
Old version
Older version, still supported
Latest version
Latest preview version
Future release