Monday, June 15, 2009

https://sugarcrm-ooo-integration.dev.java.net/

This open source project is aimed at creating a OpenOffice.org Extension for Sugar CRM(open source CRM product). I am committed to contribute for this cause. Any one who is interested can participate and contribute.

Project Home URL
https://sugarcrm-ooo-integration.dev.java.net

Developer Guide(How to setup build environment?)
https://sugarcrm-ooo-integration.dev.java.net/files/documents/8056/134956/file_134956.dat/Developers_Guide%20_OpenOffice.org_Extension_for_SugarCRM.pdf

Java.Util.Logging Example

This example is a simple illustration for using Java.Util.Logging. Java.Util.logging comes with J2SE.

create the following directory structure

->loggingdemo
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp|->Main.java
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp|->logging.properties

logging.properties

# Java Logging Properties
# Author : Deepak Dhanukodi
handlers=java.util.logging.FileHandler, java.util.logging.ConsoleHandler
# Default global logging level.
.level=SEVERE
# Loggers.
loggingdemo.level=ALL
# --- ConsoleHandler ---
# Override of global logging level
java.util.logging.ConsoleHandler.level=ALL
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
# --- FileHandler ---
# Override of global logging level
java.util.logging.FileHandler.level=ALL
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
# Unlimiting size for output file
java.util.logging.FileHandler.limit=0
# Number of output files to cycle through, by appending an
# integer to the base file name:
java.util.logging.FileHandler.count=1
# Append to already existing file
java.util.logging.FileHandler.append=true
java.util.logging.FileHandler.pattern=system.log

Main.java

package loggingdemo;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.logging.Filter;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.LogRecord;
import java.util.logging.Logger;

/**
* Java.utils.logging Demo
* @author Deepak Dhanukodi
*/
public class Main {
static String LOGGING_PROPERTIES = "loggingdemo/logging.properties";
private LogManager logManager;
private Logger logger;
/**
* @param args the command line arguments
*/
public void initialize() throws IOException
{
logManager = LogManager.getLogManager();
Properties prob = new Properties();
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(LOGGING_PROPERTIES);
logManager.readConfiguration(inputStream);
logger = Logger.getLogger(this.getClass().getName());
}
public void log()
{
logger.log(Level.WARNING, "I have hit a warning here.");
logger.warning("Same warning again");
//User defined filter
Filter filter= new Filter() {

public boolean isLoggable(LogRecord record) {
// Allow only FINE and filter the rest
if(Level.FINE == record.getLevel())
return true;
return false;
}
};
Filter oldFilter = logger.getFilter();
logger.setFilter(filter);
logger.severe("You can't reach me.");
logger.finer("You can't reach me, either.");
logger.fine("Horray,I am through.");
logger.setFilter(oldFilter);
logger.severe("You can reach me.");
logger.finer("You can reach me, either.");
logger.fine("Horray,I am through,again.");
}
public static void main(String[] args) throws IOException {
Main main = new Main();
// Initialize logger
main.initialize();
main.log();
}
}

Run

D:\>javac /loggingdemo/Main.java -d .

D:\>java -cp . loggingdemo.Main
15 Jun, 2009 5:10:53 PM loggingdemo.Main log
WARNING: I have hit a warning here.
15 Jun, 2009 5:10:53 PM loggingdemo.Main log
WARNING: Same warning again
15 Jun, 2009 5:10:53 PM loggingdemo.Main log
FINE: Horray,I am through.
15 Jun, 2009 5:10:53 PM loggingdemo.Main log
SEVERE: You can reach me.
15 Jun, 2009 5:10:53 PM loggingdemo.Main log
FINER: You can reach me, either.
15 Jun, 2009 5:10:53 PM loggingdemo.Main log
FINE: Horray,I am through,again.

D:\>

system.log

This log file is created in the same dir where you had executed java process.

15 Jun, 2009 5:10:53 PM loggingdemo.Main log
WARNING: I have hit a warning here.
15 Jun, 2009 5:10:53 PM loggingdemo.Main log
WARNING: Same warning again
15 Jun, 2009 5:10:53 PM loggingdemo.Main log
FINE: Horray,I am through.
15 Jun, 2009 5:10:53 PM loggingdemo.Main log
SEVERE: You can reach me.
15 Jun, 2009 5:10:53 PM loggingdemo.Main log
FINER: You can reach me, either.
15 Jun, 2009 5:10:53 PM loggingdemo.Main log
FINE: Horray,I am through,again.

Installing PHP as a Shared Module in APACHE HTTPD Server @ Open Solaris/ Solaris 10

Environment Details

cc = /usr/bin/cc
make = /usr/bin/make
Apache root = /export/home/Apache2.2.9/httpd-2.2.9_build/php
Src php = /export/home/php-5.2.6/php-5.2.6
Src Apache httpd= /export/home/Apache2.2.9/httpd-2.2.9_src

Setting the PATH

bash-3.2# export PATH=/usr/bin/cc:/usr/bin/make:$PATH

Building Apache httpd

bash-3.2#/export/home/Apache2.2.9/httpd-2.2.9_src/configure --prefix=/export/home/Apache2.2.9/httpd-2.2.9_build
bash-3.2#make
bash-3.2#make all

Start Apache HTTPD Server

bash-3.2#/export/home/Apache2.2.9/httpd-2.2.9_build/bin/apachectl start

Go to the following URL at Browser

http://localhost

The response at the browse should be "It works!".

Stop Apache HTTPD Server

/export/home/Apache2.2.9/httpd-2.2.9_build/bin/apachectl stop

Building PHP

./configure --prefix=/export/home/Apache2.2.9/httpd-2.2.9_build/php --with-apxs2=/export/home/Apache2.2.9/httpd-2.2.9_build/bin/apxs --with-config-file-path=/export/home/Apache2.2.9/httpd-2.2.9_build/php

bash-3.2# make
bash-3.2# make all

Configure Apache HTTPD with PHP

Add the following line to file 'Apacheroot/conf/httpd.conf'

LoadModule php5_module modules/libphp5.so

Note : # is a comment here @ Apache conf file...

Add the following mapping for PHP to invoke PHP parser for PHP files in the same conf file.
AddType application/x-httpd-php .php

Create PHP file

create a file named info.php @ /Apacheroot/htdocs
phpinfo();
?>

cp /export/home/php-5.2.6/php-5.2.6/php.ini-dist /export/home/Apache2.2.9/httpd-2.2.9_build/php/php.ini

Restart Apache HTTPD Server

$ /export/home/Apache2.2.9/httpd-2.2.9_build/bin/apachectl restart

Access the pho file as
http://localhost/info.php in a browser

The response shows the php configuration.

Monday, May 18, 2009

Export/Import data in MYSQL

EXPORT
mysqldump -u<user name>
-p<password> <dbname> > <dbname.sql with file path>
eg. mysqldump -uroot -padmin mydb > /mydb.sql

IMPORT
mysql -u<user name> -p<password> < <dbname.sql>
eg.
mysql -uroot -padmin < /mydb.sql

RUN SQL COMMAND FROM CONSOLE
mysql-u<user name> -p<password> -e "SQL Command"
eg.
mysql-uroot -padmin -e "INSERT
INTO NAME VALUES(10,20,'TEST');"

Tuesday, April 7, 2009

Understanding Open file limit in Solaris 10/ Open solaris

Shell level changes

To specify the file limit use

ulimit -n &lt no of files&gt

To see the changes made

ulimit -a

These limits are set and controlled by the user's shell to limit the system resources consumed by the current shell process and all it's descendants.

System level changes

To make the changes persistent across the whole machine, you'd need to tune the following settings in /etc/system

/etc/system:

rlim_fd_max
Description: "Hard" limit on file descriptors that a single process might have to open.
Minimum: 1
Maximum: MAXINT
Default: 65,536

rlim_fd_cur
Description: "Soft" limit on file descriptors that a single process can
have open.
Minimum: 1
Maximum: MAXINT
Default: 256

save and exit
reboot

Note that these settings are per process.

The plimit command can be used to find out the limitations imposed on a particular process. e.g.
plimit 1556
1556: /usr/apache2/2.2/bin/httpd -f /etc/vpanels/httpd.conf -DSSL -k start
resource current maximum
time(seconds) unlimited unlimited
file(blocks) unlimited unlimited
data(kbytes) unlimited unlimited
stack(kbytes) 10240 unlimited
coredump(blocks) unlimited unlimited
nofiles(descriptors) 65536 65536
vmemory(kbytes) unlimited unlimited

Tuesday, July 29, 2008

Home Made Wind Power Generator


How It all started??

I was wondering how to produce electricity from wind energy? I thought this when I was young and I was able to make one now :). It all started when I was removing my old 3.14" floppy drive from my computer. When I examined the drive, I got a stepper motor from that. After I had got stepper motor, I googled for a suitable wind bladge. I got some cool stuffs about making wind balade with PVC pipes. So, I started working on it and I was successfull in generating power.

Requisites

  • 1 Stepper Motor (12V)
  • 8 Diode 25V (reverse break down voltage). Any thing greater than or equal to 12V will do
  • 2 Capasitors 1000pF 16V(or some thing near that value)
  • 1 LED (this is the load)
  • Some wires
  • PVC pipe of length 70cms with diameter as 15cm or more..
  • 4 nuts with bolts
  • Some metal scraps to fix the wind blade with the stepper motor.

The Stepper Motor


Inside a stepper motor are four coils of wire located 90 degrees away from each other - i.e. at positions 12, 3, 6, and 9 o'clock. In the middle is the rotor which spins and has permanent magnets fitted around its circumference. As the rotor spins each magnet in turn approaches, passes, and moves away from each of the four coils in turn. A magnet passing a coil of wire causes electricity to flow through that coil and so each of the four coils will have different amounts of electricity flowing through it either one way or the other - alternating current.

Since a stepper motor has four coils of wire, it is said to be a four-phase motor. The advantage of this multi-phase set-up for electricity generation projects is that when one coil has no electricity flowing through it, the next coil will have reached its maximum. When the four-phases are brought together and rectified (more on rectification later) into direct current (DC), the total electricity generated therefore has a near constant voltage and current.



Place you can see stepper motors are FAX machine, Document copier, Floppy drives. I took the stepper motor from my old 3.14" floppy drive.


The Wind Blade

Cut the PVC pipe with 60cm length.

Then follow the below sketch to cut the pipe and make the blade.


I used Angled Cut as in this design and It worked really good.


The Circuit

We will be using two A/C to DC bridge as we have two coils. The circuit diagram is as follows.




Attach the wind blade with the stepper motor.

Pictures of my working model
Wind Blade

Wind Blade closer look

Stepper motor coupled with wind blade

A/C power from stepper motor

The circuit

LED glowing


Version 2 @ http://tekzgeek.blogspot.com/2011/06/home-made-wind-power-v20.html

Future Enchancements

  • Thinking to use the generated power to charge a battery.
  • This can be scaled to a larger extent and I hope this could power some home appliance.

After this I am thinking of taping solar energy to generate electric power.

-Tekzgeek

Saturday, June 9, 2007

Commanding Threads in Java


Following are source to command threads in java

Command.java

package tekzgeek.thread;

public class Command
{
public static int PAUSE=0;
public static int RESUME=1;
public static int EXIT=2;
int state=RESUME;
int command=RESUME;

synchronized public int getCommand()
{
if(this.state==this.command)
return this.state;

if((this.state==RESUME)&&(this.command==PAUSE))
{
this.state=PAUSE;
notify();
while((this.command!=Command.RESUME)&&(this.command!=Command.EXIT))
{
try
{
wait();
}
catch(InterruptedException e)
{}
}
if(this.command==Command.RESUME)
this.state=Command.RESUME;
else if(this.command==Command.EXIT)
this.state=Command.EXIT;


}
else if((this.state==Command.RESUME)&&(this.command==Command.EXIT))
{
this.state=Command.EXIT;
notify();
}
return this.state;
}

synchronized public void setCommand(int command_temp)
{
this.command=command_temp;

if(state==command)
return;

if((this.state==Command.RESUME)&&(this.command==Command.PAUSE))
{
while(this.state!=Command.PAUSE)
{
try
{
wait();
}
catch(InterruptedException e)
{}
}
}
else if((state==PAUSE)&&(command==RESUME))
{
notify();
}
else if((this.state==Command.RESUME)&&(this.command==Command.EXIT))
{
while(this.state!=Command.EXIT)
{
try
{
wait();
}
catch(InterruptedException e)
{}
}
}
else if((this.state==Command.PAUSE)&&(this.command==Command.EXIT))
{
notify();
}
}
}

WorkerThread.java
package tekzgeek.thread;
import tekzgeek.thread.Command;

public class WorkerThread extends Thread
{
Command command;
public WorkerThread(Command command)
{
this.command=command;
}
public void run()
{
boolean EXIT=false;
while(!EXIT)
{
// Do Some Work

System.out.println("Worker Thread Running.");
try
{
Thread.sleep(200);
}catch(InterruptedException e)
{}

int cmd=command.getCommand();
if(cmd==Command.EXIT)
EXIT=true;
}
System.out.println("I am done.");

}
}

Main.java
package tekzgeek.thread;
import tekzgeek.thread.Command;
import tekzgeek.thread.WorkerThread;

public class Main
{
public static void main(String args[])throws InterruptedException
{
Command command=new Command();
WorkerThread workerThread=new WorkerThread(command);
workerThread.start();

Thread.sleep(1000);

System.out.println("Main Thread is trying to Pause Worker Thread.");
command.setCommand(Command.PAUSE);
System.out.println("Main Thread Paused Worker Thread.");

Thread.sleep(1000);

System.out.println("Main Thread is trying to Resume Worker Thread.");
command.setCommand(Command.RESUME);
System.out.println("Main Thread Resumed Worker Thread.");

Thread.sleep(1000);

System.out.println("Main Thread is trying to Stop Worker Thread.");
command.setCommand(Command.EXIT);
System.out.println("Main Thread stopped Worker Thread.");
}
}


Command.java- The basic core for transfering messages between threads.
Main.java- Main Thread that commands Worker Thread.
WorkerThread.java- This thread does the work and is controlled by Main Thread.

pl note : One way command is only implemented. To go for two way communication or for feedback,create
one more command for getting feedback from worker thread.