Wednesday, March 4, 2009

OSGi - Putting classes into Boot delegation path

To put any classes into the the boot delegation path in Osgi the follwoing needs to be done
add the entry into org.osgi.framework.bootdelegation
in the follwing file --> springsource-dm-server-ee-1.0.1.RELEASE\lib\java6-server.profile
Once classes are added into the this boot path there is no need to import this in any of the bundle manifests.
But the disadvantage here is that these classe are loaded by the Boot Class loader , and hence we loose the independent runtime deployments of these classes.
But this trick can be used while integrating with teraacotta or other cases , where we can give away independent deploymenta dvantage , but get flexibilty of loading these classes using boot class laoder and also have these classes directly without any imports.

The other way of getting classes under boot class path is to make it system package or extender bundle of a system package.

Osgi - Package Imports to Shared Services Benefits

Whenever a bundle gets updated in a OSgi environments the direct affect is that all bundles which have any import will also get bounced . This information is not displayed in the dm server console.
I have observed this change only by putting sysouts in the bundle activator. I feel this should not be hidden in the console.
This will also happen in the service model if the interfaces are bundled along with the implementation.
Bundle a -> Implementation & interface and provides Osgi service
Bundle c -> osgi service importer,has import for intercface packages from a
Now if we bounce the bundle a to change the implementaion bundle c also gets refreshed though we dont change the interface.
The only way to avoid this is to have a seperate bundle b with interface
Bundle b - > has interface
and now bundle c imports from bundle b , also bundle a imports from bundle b . Thus any changes in bundle a, thats the implementaion will not have any refresh of other bundles.

Modifying the web pages inside OSGi web bundle

The imapct of packaging into a web module in OSgi was that we lost the ability to modify JSp pages on the fly. This was a drawback since our teams used to modify the JSps in production environment very often.
Spring Dm has promised to avoid this change by providing a flexibilty to allow breaking of web bundles into multiple parts and allow for thier independent deployments in the future releases.
Untill then the hack could be to commit the jsp pages into the work directory and it gets reflected.
Location for change
.\SpringServer\work\com.springsource.server.deployer\Module\Bundle-A.jar-0\Bundle-A.jar\MODULE-INF\jsp\data.jsp

Spring Dm(OSGi) integration with terracota

I have tried integrating terracotta with spring DM and it works fine. My use case included a instance a stand alone java,jetty web server,apache tomcat and Spring Dm connected to the same instance of terracotta sharing a custom class as the root.
The changes i had to make were
Added the Terracotta lib and shared classes under boot delegation path of Spring DM –
1. In springsource-dm-server-ee-1.0.1.RELEASE\lib\java6-server.profile org.osgi.framework.bootdelegation = \ com.tc.*,\--> àddedd this is to avoid errors from Spring DM which tries to load these classes from Bundle class loader share.* --> Classes which are shared
2 .Copied shared jar under springsource-dm-server-ee-1.0.1.RELEASE\lib\
The above changes are doen to ensure that teh shared classes are loaded by the boot classloader which will enable terracotta toidentify this class and share with other processes()stadalobe,jetty.tomcat).In teh above case since the shared jar is added intothe bootdelegation , any chage in the teracotta shared classes will need restart of the spring dm server.

The other staratergy to achive the same is by changing the classloader names in all the other processes which are connected to terracotta, but i found this more complicated and cumbersome.

Thursday, January 1, 2009

Searching for a class in Multiple jars using shell script

#!/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

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

 
Free Domain Names @ .co.nr!