Posts

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( ...

Configuring PHP in Apache 2 in Windows

1. Install php and crate a dir in c:\php and copy the unzipped file there Copy all the dll's under php to c:\windows\system32 reanme php.ini-dist to php.ini and put it in path c:\windows for example Also in php.ini add support to mysql "As with enabling any PHP extension (such as php_mysql.dll), the PHP directive extension_dir should be set to the directory where the PHP extensions are located. See also the Manual Windows Installation Instructions. An example extension_dir value for PHP 5 is c:\php\ext" 2. In the Apache httpd.conf After #ExtendedStatus On Add LoadModule rewrite_module modules/mod_rewrite.so LoadModule php5_module "c:/php/php5apache2.dll" AddType application/x-httpd-php .php AddType application/x-httpd-php .php3 AddType application/x-httpd-php .php4 Then set permission to # # This should be changed to whatever you set DocumentRoot to. # Options Indexes Includes FollowSymLinks MultiViews ExecCGI AllowOverride All Note - check the security risk...

Periodic refresh with AJAX

Hint use - timerID = window.setInterval("ajaxFunction()",5000); Below is the AJAX script And in the HTML body

Deploying under tomcat

Deploying under tomcat 1 Class inmcservlet.class is under the package proto.inmc.fm.servlet. 2 Directory strcture of tomcat depolyment D:\Program Files\Apache Group\apache-tomcat-6.0.16\apache-tomcat-6.0.16\webapps\inmc\WEB-INF\classes\proto\inmc\fm\servlet Under servlet inmcservlet.class 3. The web Xml Web.xml 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 4 . The url string http://localhost:8080/inmc/servlet/inmcservlet2

Java Log4j

Code snippet log4j.properties ### direct log messages to stdout ### #log4j.appender.stdout=org.apache.log4j.ConsoleAppender #log4j.appender.stdout.Target=System.out #log4j.appender.stdout.layout=org.apache.log4j.PatternLayout #log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n #log4j.rootLogger=debug, stdout ### direct log messages to a file ### log4j.appender.file=org.apache.log4j.FileAppender log4j.appender.file.File = mylog.txt log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n log4j.rootLogger=debug,file

Checking Memory Corruption using Gflags and NTSD debugger

>gflags /p /enable mmladc.exe path: SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options mmladc.exe: page heap enabled >gflags /p path: SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options mmladc.exe: page heap enabled with flags (traces ) >ntsd -g -x -pn mmladc.exe If there is a heap corruption you will see something like this =========================================================== VERIFIER STOP 00000006: pid 0x3634: corrupted heap pointer or using wrong heap 01421000 : Heap used in the call 0152C100 : Heap block 00000000 : Block size 70F0F0F0 : Heap owning the block =========================================================== >.lines Line number information will be loaded >kb

Porting fron VC6 to VC7 compiler errors

------------------------------------------------------------------------ Code which compiles in VC6 typedef priority_queue *,//value type deque *>,//container type Command ::Compare > REQUESTQUEUE; //comapritor typedef map ::iterator REQUESTQUEUEITR; std::map RequestQueue; std::map ::iterator CurrentItr; Changes to be done to compile in VC7 ------------------------------------------------------------------------ typedef priority_queue *,//value type deque *>,//container type typename Command ::Compare > REQUESTQUEUE; //comapritor typedef typename map ::iterator REQUESTQUEUEITR; //todo make this a priority queue - priority_queue std::map RequestQueue; typename std::map ::iterator CurrentItr; ------------------------------------------------------------------------ tags vc7 nested class template cannot access private class declared in class vc7 dependent name is not a type

A little Perl goes a long way

I have found Perl as very powerful language , a must in the toolkit for any programmer Here are some Perl code snippets. It is always better to start your perl code with use strict; use warnings; With this you have to declare variable before you use them like my $SearchStep=0; my $line; Also if you want to use special Perl modules like for example working with ini files , you include it use IniFiles; Everything is pretty simple in Perl, only thing is that the syntax can become unreadable; so put in a lot of comments # This is a comment Okay let us jump in -- here is the code to open a file my $FilePath = "system1.txt"; my $opened =open (FH, $FilePath) ; if( !$opened) { print "Cannot open file\n"; die; } and to read line by line from the file my $line; while ( $line = ) { chomp ($line); : Now to test if a line matches a perl pattern if($line = ~ m/ $SearchPattern/ i ) /i stands for case insensitive search. Okay a few other matche examples ( b...

Java JVM high memory usage problems

Though I have some three four years experience in C++ ,I did not have that much oppurtunity to work in Java. Currenly I was doing some analysis for a very simple CLI and was surprised to come with a memory restriction. I found that if I use Java for developing the CLI application I will be exhausting the memory of our Application Server (AS). Just to mention the architecture ,users (telecom operators) use a metaframe server client ( =something like remote desktop) to login to the AS and then open a GUI to work on it. With Java I can service only about 15 clients with the available memory . I just checked the reason for this resource crunch and found that already many Java based GUI's are served by the AS and each is taking some 25 MB or more. The first thing I thought is that adding more RAM will solve this ( though this is not an easy option) . Then I understood that a 32 bit system can have just about 3 gb ram for applciations and our AS had already 4 GB with 1.5 GB VM also co...

Windebug and Adplus for debugging process hang

1. Set the symbol, especillay windows symbols .......26_Merged\UNCRelease;\\blrm2fsp\SCSD-Common\Sym\WinSym2K3SP1 2. Set the souce and image 3. Load the extension dll ( for !locks command ) if not already loaded .load C:\Program Files\Debugging Tools for Windows\winxp\kdexts.dll 4. Use the !ntsdexts.locks ( or !locks ) command to see a list of critical section :004> !ntsdexts.locks CritSec ntdll!LdrpLoaderLock +0 at 7C889D94 LockCount -6902 RecursionCount 1 OwningThread 2b3c EntryCount 0 ContentionCount 28f3 *** Locked CritSec +12f9b4 at 0012F9B4 LockCount 0 RecursionCount 0 OwningThread 0 *** Locked CritSec +12f70c at 0012F70C LockCount 0 RecursionCount 0 OwningThread 0 *** Locked CritSec +128202c at 0128202C LockCount -2 RecursionCount 1 OwningThread 3d9c EntryCount 0 ContentionCount 0 *** Locked ----------- A 'LockCount' other than 0 means that many threads are waitiing on t...

windbg command

Wednesday, 25 August 2004 To list all modules loaded by the process -LM (shows the loaded module address also) : WinDebug thread commands To see all threads ~ To freeze all threads ~*F to unfreeze thread 1 ~1U to set the thread ~S copying to stl list If destination is an empty list lstOfInt.push_back(1); lstOfInt.push_back(2); lstOfInt.push_back(3); copy(lstOfInt.begin(),lstOfInt.end(),lstOfIntDest.begin() ); -->WRONG copy(lstOfInt.begin(),lstOfInt.end(),back_inserter(lstOfIntDest) ); -->CORRECT

CORBA - C++ Client (ACE TAO) Java Server (JacORB) A simple example

Step 1 I downloaded the binary relaease of JacOrb Extracted the zip file to E:\Program Files\JacORB-2.2.4\ Step 2 Then also downloaded Ant Also jdk was downloaded and installed Step 3 Then created the batch file (to set the path) Set ANT_HOME=E:\Program Files\Java_Ant\apache-ant-1.6.5 Set JAVA_HOME=E:\Program Files\Java\jdk1.5.0_03 Set JACORB_HOME=E:\Program Files\JacORB-2.2.4 Set Path=%ANT_HOME%\bin;%JAVA_HOME%\bin;%JACORB_HOME%\bin;%JACORB_HOME%; Set CLASSPATH=%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib;%JAVA_HOME%;%JACORB_HOME%\lib; ----now to configure JacORB - In the command promt E:\Program Files\Java_Ant\apache-ant-1.6.5>ant jaco E:\Program Files\Java_Ant\apache-ant-1.6.5>ant idlcmd okay that’s done Now write the idl --- test1.idl------ module Quoter1 { //a test interface interface Stock { double price(); //to get the quote of the stock readonly attribute string symbol; readonly attribute string fullname; }; //interface to get the stock object exception InvalidStockSymbol {}; //to...

Importance of TypeSafety -An example

class Bank { private: bool bFirstLock; bool bSecondLock; BankVault* pBankVault; public: Bank() { bFirstLock=0; bSecondLock=0; pBankVault= new BankVault ; } bool IsLocked() { if(( true == bFirstLock) && (true== bSecondLock)) { printf("Both Locks unlocked- Bank is UNLOCKED\n"); return false; } else { printf("Bank is LOCKED\n"); return true; } }; }; //----------------------------------------------------- class Robber { short ForgedKey; void* pAceesor; public: Robber() { ForgedKey=0; }; RemoveLocks() { //This method has the instruction to set the first // 2 bytes (short) of the start of the class to value //257; This in binary is 00000001 00000001;ie the first 2 bytes to 1 ; //But since we are using the pointer of the Bank object to call //this method, it sets the first 2 bytes of the object of //bank to 00000001 00000001; But in the Bank object the first 2 //bytes are occupied by two boolean varia...

Unix - Checking the virtual memory of process

ps -elf | grep In Solaris the size (SIZ) column specifies memory size

customising stl find algorithm

customising stl find algorithm class tTaskType { public: int data; bool operator == (int k) { if(k ==data) return true; else return false; } }; --------------------------------- Main() tTaskType s1,s2,s3; s1.data =10; s2.data =12; s3.data =13; list test; list ::iterator Itrtest; test.push_back(s1); test.push_back(s2); test.push_back(s3); Itrtest =std::find(test.begin(),test.end() ,10) ; if(Itrtest!=test.end() ) { printf("Found\n"); }

Signalling event

Main thread { //Create an eventin the non signalled mode and wait for it HANDLE g_Event =CreateEvent(0,0,0,0); //this method will wait till the event is Signalled WaitForSingleObject(g_Event,INFINITE) ; } In another thread { //Set the event to signelled state, so that waitforsingle object can return SetEvent(g_Event) }

#define variable arguments

Since #define does not take variable arguments you have to work around using function pointers. void __format_out(const char* fmt, ...); typedef void (*ptr2Fn) (const char* fmt, ...) ; ptr2Fn _storeLine(int nSeverity,int lineNumber,char* fileName); #define CTRACE _storeLine(40,__LINE__,__FILE__) ----------------------- ptr2Fn _storeLine(int nPSeverity,int nPlineNumber,char* szPfileName) { nSeverity = nPSeverity; nlineNumber=nPlineNumber; szfileName = (char*)szPfileName; return __format_out; } ----------------------- inline void __format_out(const char * fmt, ...) { CString ___str; va_list marker; va_start(marker, fmt); USES_CONVERSION; ___str.FormatV(A2T(fmt), marker); va_end(marker); } TRACE("nUMBER IS %d",223);

vba code for iterating through colums

Private Sub CommandButton1_Click() CalculateAndDispalyDifference End Sub Sub CalculateAndDispalyDifference() Dim t1, t2 As Date For counter = 2 To 91 t1 = Worksheets("Sheet1").Cells(counter, 4).Value t2 = Worksheets("Sheet1").Cells(counter + 1, 4).Value If t2 > t1 Then Worksheets("Sheet1").Cells(counter, 6).Value = t2 - t1 Else Worksheets("Sheet1").Cells(counter, 6).Value = t1 - t2 End If counter = counter + 1 Next counter End Sub

VBA xode snippet for iterating through colums

Private Sub CommandButton1_Click() CalculateAndDispalyDifference End Sub Sub CalculateAndDispalyDifference() Dim t1, t2 As Date For counter = 2 To 91 t1 = Worksheets("Sheet1").Cells(counter, 2).Value //.Cells(row,column) t2 = Worksheets("Sheet1").Cells(counter, 4).Value If t2 > t1 Then Worksheets("Sheet1").Cells(counter, 5).Value = t2 - t1 Else Worksheets("Sheet1").Cells(counter, 5).Value = t1 - t2 End If Next counter End Sub

wcstok,strtok memory corruption

CString mystring("ob_jw_ay"); CString anotherstring ; anotherstring =mystring;//memory corruption!!! TCHAR* string = (TCHAR*)(LPCTSTR)mystring; TCHAR seps[] = "_"; TCHAR* token; token = strtok( string, seps ); while( token != NULL ) token = strtok( NULL, seps ); //Now both strings will be changed.Because both CString::m_pchData are pointing to the same memory and strok/wcstok changes it. If you want 'anotherstring' to remain unchanged do anotherstring + =mystring;