#!/bin/sh
LOOK_FOR="funn/class/name"
for i in `find . -name "*jar"`
do
echo "Searching in jar $i ..."
jar tvf $i | grep $LOOK_FOR > /dev/null
if [ $? == 0 ]
then
echo "==> Class Available in \"$LOOK_FOR\" in $i"
fi
done
Thursday, January 1, 2009
Searching for a class in Multiple jars using shell script
Monday, November 24, 2008
Daemon Threads in Java
Any Java thread can be a daemon thread. Daemon threads are service providers for other threads running in the same process as the daemon thread.
When the only remaining threads in a process are daemon threads, the interpreter exits. This makes sense because when only daemon threads remain, there is no other thread for which a daemon thread can provide a service.
Daemon threads are sometimes called “service” threads. These are threads that normally run at a low priority and provide a basic service to a program or programs when activity on a machine is reduced. An example of a daemon thread that is continuously running is the garbage collector thread. This thread is provided by the JVM.
The Thread Object
class HelloThread extends Thread {
public void run() {
try {
for ( ; ; ) { System.out.println("hello"); sleep(1000); }
}
catch(Exception e ){}
}
}
The normal thread
public class RegularThreader{public static void main(String[] args){
Thread hello = new HelloThread();
hello.start();
thread.sleep(10000);
System.out.println("Sorry, I must be leaving destroy");
}
}
The Daemon Thread
public class DaemonThreader{
public static void main(String[] args) {
Thread hello = new HelloThread();
hello.setDaemon(true);
hello.start();
System.out.println("Sorry, I must be leaving");}}
Just the check the difference in the way ther run
1. In the first case the child thread runs continously
2. but the Daemon thread exits when the main thread is complete;
Thursday, November 20, 2008
Oracle Streams Advanced Queuing (AQ)
Advanced Queuing provides database-integrated message queuing functionality. Advanced Queuing leverages the functions of the Oracle database so that messages can be stored persistently, propagated between queues on different machines and databases, and transmitted using Oracle Net Services, HTTP(S), and SMTP.
You must set up the following data structures for certain examples to work:
CONNECT system/manager;
DROP USER aqadm CASCADE;
GRANT CONNECT, RESOURCE TO aqadm;
CREATE USER aqadm IDENTIFIED BY aqadm;
GRANT EXECUTE ON DBMS_AQADM TO aqadm;
GRANT Aq_administrator_role TO aqadm;
DROP USER aq CASCADE;
CREATE USER aq IDENTIFIED BY aq;
GRANT CONNECT, RESOURCE TO aq;
GRANT EXECUTE ON dbms_aq TO aq;
Creating a Queue Table and Queue of Object Type
CREATE OR REPLACETYPE TEST_TRANSACTION AS OBJECT(f_user_id VARCHAR2 (40),f_points NUMBER,f_update_date DATE)
commit;
BEGIN
DBMS_AQADM.CREATE_QUEUE_TABLE (
queue_table => 'TEST_TRANSACTION_TABLE',multiple_consumers => TRUE, queue_payload_type => 'TEST_TRANSACTION');
DBMS_AQADM.CREATE_QUEUE (queue_name => 'TEST_QUEUE',queue_table => 'TEST_TRANSACTION_TABLE');DBMS_AQADM.START_QUEUE (queue_name => 'TEST_QUEUE');
end;
Adding subscriber to the queue
DECLAREsubscriber SYS.AQ$_AGENT;
BEGIN
subscriber := SYS.AQ$_AGENT('SUDHEER', NULL, NULL);
SYS.DBMS_AQADM.ADD_SUBSCRIBER(queue_name => 'TEST_QUEUE',subscriber => subscriber);
END;/
commit;
Procedure to Enqueue
PROCEDURE ENQUEUE_OBJ_MSG(message IN TEST_TRANSACTION)
DECLAREmessage TEST_TRANSACTION;enqueue_options DBMS_AQ.enqueue_options_t;message_properties DBMS_AQ.message_properties_t;message_handle RAW(16);BEGINmessage := TEST_TRANSACTION('TESUSER',5,NULL);dbms_aq.enqueue(queue_name => 'TEST_QUEUE',enqueue_options => enqueue_options,message_properties => message_properties,payload => message,msgid => message_handle);
COMMIT;
END;
SELECT USER_DATA FROM AQ$TEST_TRANSACTION_TABLE
Java Agent to access Queue
public static void main(String args[]){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Class.forName("oracle.AQ.AQOracleDriver");
Connection connection = DriverManager.getConnection( "jdbc:oracle:thin:@10.1.66.109:1521:real", "ppokerops", "ppokerops");
connection.setAutoCommit(false);
AQSession aqsession = AQDriverManager.createAQSession(connection);
AQQueue queue = aqsession.getQueue("ppokerops","QUEUE1");
queue.start();
TransDAO data = null;
AQMessage message = queue.createMessage();
AQDequeueOption dq_option = new AQDequeueOption(); dq_option.setConsumerName("SUDHEER");
message = queue.dequeue(dq_option, Class.forName("com.pg.gateway.AQ.TransDAO"));
data = (TransDAO)message.getObjectPayload().getPayloadData();
connection.commit();
queue.close();
aqsession.close();
connection.close();
System.out.println("HERE"+data.getF_userid());
} catch(Exception e) {
e.printStackTrace();
}}
REFERENCE
http://download.oracle.com/docs/cd/B10500_01/appdev.920/a96587/qintro.htm
http://www.itk.ilstu.edu/docs/oracle/server.101/b10785/aq_start.htm#i634413
Thursday, November 13, 2008
Spring AOP Basics
The best atricle i have come across to start with Spring AOP
http://www.javabeat.net/articles/51-introduction-to-springs-aspect-oriented-programminga-1.html
This can be followed by Spring tutorial from www.springframework.org
Wednesday, November 12, 2008
Fetching Property Files Using Resource Bundle
Put the property Files in the classpath ,which contains key value pairs.
If the files are putin any other location thean classpath , give the path in tomcat startup.sh or classpath.sh next to the bootstrap jar listing.
Now access the files as accessing any other Bundle
ResourceBundle myResources = ResourceBundle.getBundle("propertfilename");
Then u can do a bundle.getValue() to the required key value pair.
XML -RPC
Apache XML-RPC is a Java implementation of XML-RPC, a popular protocol that uses XML over HTTP to implement remote procedure calls.
Steps
1.Client class
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL("http://127.0.0.1:8080/xmlrpc"));
XmlRpcClient client = new XmlRpcClient();
client.setConfig(config);
Object[] params = new Object[]{new Integer(33), new Integer(9)};
Integer result = (Integer) client.execute("Calculator.add", params);
2.Server Class
public class Calculator {
public int add(int i1, int i2) {
return i1 + i2;
}
public int subtract(int i1, int i2) {
return i1 - i2;
}
}
3. Create Propert File
Create a property file, which contains at least one property. The property name is arbitrary, and the property value is the fully qualified name of the Calculator class. For example, like that:
Calculator=org.apache.xmlrpc.demo.Calculator
The property file must be called XmlRpcServlet.properties, and it must be located in the package org.apache.xmlrpc.webserver. In other words, you would typically put it into the directory org/apache/xmlrpc/webserver and add it to your jar file.
4. Add Entry to Web.xml
<servlet>
<servlet-name> XmlRpcServlet</servlet-name>
<servlet-class>org.apache.xmlrpc.webserver.XmlRpcServlet</servlet-class>
<init-param>
<param-name>
enabledForExtensions</param-name>
<param-value>true</param-value>
<description> Sets, whether the servlet supports vendor extensions for XML-RPC. </description>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>XmlRpcServlet</servlet-name>
<url-pattern>/xmlrpc</url-pattern>
</servlet-mapping>
Reference http://ws.apache.org/xmlrpc/
XStream - Convert XMl to Java & Vice Versa
</person></code>
.jpg)