OC4J 10.1.3.x allows users to start/stop MDBs dynamically without having recycle container or application.
For example, you can disable an MDB upon start/deployment by adding enabled="false" in your orion-ejb-jar.xml as follows
<message-driven-deployment name="MessageLogger" enabled="false">
MDB will not start when the application is deployed/started.
You can use Application Server Control to start the MDB later as shown in the following screen shot:
You may want to perform this operation from command line. You can download this zip file that contains code to stop/start MDB using JMX.
- Unpackage the zip and change ant-oracle.properties file to change your URL, userid and password
- Set ORACLE_HOME to the directory where OC4J installed
- To start your MDB:
ant start -DappName=ejb30mdb -DejbModule=ejb30mdb-ejb -DmdbName MessageLogger
- To stop it
ant stop -DappName=ejb30mdb -DejbModule=ejb30mdb-ejb -DmdbName MessageLogger
Following is the code snippet from the Java Class that perform the stop/start operation:
StartStopMDB mdb = new StartStopMDB();
try {
mdb.connect("service:jmx:"+args[0], args[1] ,args[2] );
System.out.println(mdb);
System.out.printf("Client connected? %s\n",mdb.isConnected());
MBeanServerConnection mbs = jmxCon.getMBeanServerConnection();
String objName = "oc4j:j2eeType=MessageDrivenBean,EJBModule=\""+args[4]
+"\",J2EEApplication="+args[3]+",J2EEServer=standalone,name=\""+args[5]+"\"";
ObjectName myMDBObjectName = new ObjectName(objName);
MessageDrivenBeanMBeanProxy MDBMBean =
(MessageDrivenBeanMBeanProxy)MBeanServerInvocationHandler.newProxyInstance(mbs,
myMDBObjectName, MessageDrivenBeanMBeanProxy.class, false);
if (args[6].equals("start"))
{
System.out.println("Starting up MDB: "+args[5] +" in ejb module:"+args[4]+
" in application name:"+args[3]);
MDBMBean.start();
System.out.println("Successfully started MDB!");
}
else if (args[6].equals("stop")) {
System.out.println("Stopping MDB: "+args[5] +
" in ejb module:"+args[4]+ " in application name:"+args[3]);
MDBMBean.stop();
System.out.println("Successfully started MDB!");
}
mdb.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Hope this helps!