Tuesday, August 5, 2008

Replacing RMI with Spring Remoting

Custom classes used

com.px.site.db.IExampleService - Service Interface

com.px.site.db.ExampleService - - Service Implementation

EXAMPLE_SERVICE_URL - urel (Ex :htpp://10.x.x.x/context/ExampleDetails

context - is the context name under jetty/tomcat where the remote service is running

All other classes are from the spring jar

Service Code(Server)

The bean is instantiated in the service side using the following entry in the spring xml

<bean id="exampleProxy" class="com.px.site.db.ExampleService"/>

The implementation is provided to the main applicatuion calling the following url

<bean name="/ExampleDetails" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="service" ref="exampleProxy"/>
<property name="serviceInterface" value="com.px.site.db.IExampleService"/>
</bean>

The the application can get a reference using the url --> htpp://10.x.x.x/context/ExampleDetails


Main Application Code(client)

The service reference is obtained in the main application by adding the following in the spring xml where
EXAMPLE_SERVICE_URL is htpp://10.x.x.x/context/ExampleDetails obtained from any of the config parameters


<bean id="exampleService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<property name="serviceUrl" value="${EXAMPLE_SERVICE_URL}"/>
<property name="serviceInterface" value="com.px.site.db.IExampleService"/>
</bean>


Now this service if needed can be used directly in any action or injected into any main service.

<bean id="application" class="com.examples.main.application">
<property name="exampleService" ref="exampleService"/>
</bean>

Them main advantage of this is a application can speak to any service which is remotely located.

Monday, August 4, 2008

Spring timer tasks for Threads

Create the bean which should be called on regular intervals.

This bean should extend the TimerTask and should have the run method which will be called on timely basis.

<bean id="example" class="com.examples.foo">

Make the bean a task and provide the time interval when it needs to be called. The time could be picked from property files.

<bean id="exampleTask" class="org.springframework.scheduling.timer.ScheduledTimerTask">
<property name="period" value="${exampleTime}">
<property name="timerTask" ref="example">
</property>

Add the tasks as part of Timerfactory which will be called based on the time given.

<bean id="timerFactory" class="org.springframework.scheduling.timer.TimerFactoryBean">
<property name="scheduledTimerTasks">
<list>
<ref bean="exampleTask">
</ref>
</list>
</property>

All the above entries will be part of the spring xml.More then one tasks can be added to the timerfactory
</bean></property></bean></bean>

Prototip for easy and Fancy tool Tips

Just came across Prototip which helps to create javascript based tool tips with ease

http://www.nickstakenburg.com/projects/prototip2/.

Could not work more on it as we needed something which supports from IE 5+ versions. Protip supports IE 6+ and Firefox 2+

Running Parallel Db queries on huge Databases.

When the size of the table is very high and the column you are looking for is not indexed then the best way to run the query would be by parallel execution.

This really speeds up the process . But the catch here is that the CPU utilization is high and in production systems this may end up in locks.

This technique can be safely used in backup db servers.

Example

SELECT /*+ parallel(huge_table,4 ) */ * FROM huge_table;

where 4 is the degree of parallelism.The degree of parallelism depends on the capacity of the machines.

Friday, August 1, 2008

Loading multiple property files using Spring

While loading multiple files using spring the following property needs to be added
into bean of the first xml which gets loaded.


< name="ignoreUnresolvablePlaceholders" value="true"/>

Else the subsequent property files will not be loaded.

Some useful unix commands i came across today

vmstat [pamam1] [param2]

shows the server statics along with swap space, cache,io and cpu utilization.

this stats are shown [param2] number of times with [param1] duration in between.

top

this command also shows the server statistics in detail with
contribution from each process.
This also shows the memory used,cpu utilization and command used for each thread.

finger

Shows the user who are currently logged into the node.

Simplest way to Configure Logging using Log4j

Ensure the log4j.jar & log4j.properties are in the classpath

Add the following into the required classes where logging is needed , so that log shows file name for each logger statement .

private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger([classname].class);

folowed by logger.[info,debug,error,fatal etc]("logger message");

Contents in Log 4j.properties

log4j.rootLogger=ON, ROOT[enabling the root logger]
log4j.appender.ROOT=org.apache.log4j.DailyRollingFileAppender[saving logs on the daily basis with date appended]
log4j.appender.ROOT.File=/a/b/c.log[root log file path]
log4j.appender.ROOT.layout=org.apache.log4j.PatternLayout
log4j.appender.ROOT.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss } %-5p [%t] %c{2} - %m%n [pattern for display in each line]

#FILE APPENDER [another logger file ]
log4j.appender.F2=org.apache.log4j.DailyRollingFileAppender
log4j.appender.F2.File=/a/b/d.log
log4j.appender.F2.layout=org.apache.log4j.PatternLayout
log4j.appender.F2.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss } %-5p [%t] %c{2} - %m%n


log4j.logger.org.apache=ERROR[apache specific errors to be shown on both logger files]
log4j.logger.com.example=DEBUG,F2[for com.example modules debug status messages to be shown in second logger file]

For Log4j debugging
Append -Dlog4j.debug in JAVA_OPTS in catalina.sh which will enable detailed logs in catalina.out showing the logger configerations.

 
Free Domain Names @ .co.nr!