|
Oracle Fusion Middleware Java API Reference for Oracle Service Bus 11g Release 1 (11.1.1.6.3) E15033-08 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface SessionManagementMBean
Provides API to create, activate or discard sessions.
OSB features the concept of a session which allows different users to update different parts of configuration data without interfering with each other. In order to modify resources and OSB configuration, the user must create a session, and perform changes in that session. The changes are only reflected to the core data (the data which OSB runs on) when the session is activated.
A session is essentially a named sandbox, which is used to isolate the changes from other users, as well as from the core data, until the changes are activated. A user can create as many sessions as he wishes, with arbitrary names, provided that no other session with the same name already exists.
A session can be created, and then discarded or activated using the SessionManagementMBean API. There is one instance of SessionManagementMBean in the whole domain.
Once a session is created, updates can be performed using only the instance of an MBean that works on that session data. Each MBean type, except for SessionManagementMBean, has one instance per session. When a session is created, a new set of MBean instances, one for each MBean Type, are created automatically. Furthermore there is one instance of each MBean Type for operating on core data. However operations on core data are limited to read only operations. For example, if there are 10 sessions, there will be 11 instance of ProxyServiceConfigurationMBean, 10 for operating on each session, and 1 for operating on the core data. The MBean instance that works on core data will not support update operations.
MBean instances are destroyed when a session is discarded or activated. MBean instances that operate on core data are never destroyed.
The following sample code shows how to obtain SessionManagementMBean for creating a session, and ALSBConfigurationMBean for operating on both the session that is created, and on core data.
Note: Never embed username/password in source code. The code below does so for clarity
import weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean; import weblogic.management.jmx.MBeanServerInvocationHandler; import com.bea.wli.sb.management.configuration.ALSBConfigurationMBean; import com.bea.wli.sb.management.configuration.SessionManagementMBean; public class MBeanSample { static public void main(String[] args) throws Exception { // get the jmx connector JMXConnector conn = initConnection("localhost", 7001, "weblogic", "weblogic"); // get mbean connection MBeanServerConnection mbconn = conn.getMBeanServerConnection(); // get domain service mbean. This is the topmost mbean DomainRuntimeServiceMBean domainService = (DomainRuntimeServiceMBean) MBeanServerInvocationHandler. newProxyInstance(mbconn, new ObjectName(DomainRuntimeServiceMBean.OBJECT_NAME)); // obtain session management mbean to create a session. // This mbean instance can be used more than once to // create/discard/commit many sessions SessionManagementMBean sm = (SessionManagementMBean) domainService. findService(SessionManagementMBean.NAME, SessionManagementMBean.TYPE, null); // create a session sm.createSession("mysession"); // obtain the ALSBConfigurationMBean instance that operates on the session that has // just been created. Notice that the name of the mbean contains the session name. ALSBConfigurationMBean alsbSession = (ALSBConfigurationMBean) domainService. findService(ALSBConfigurationMBean.NAME + "." + "mysession", ALSBConfigurationMBean.TYPE, null); // Perform updates or read operations in the session using alsbSession ... // activate changes performed in the session sm.activateSession("mysession", "description"); // Obtain MBean for peforming read only operations. Notice that the name // of the mbean for the core data does not contain any session name. ALSBConfigurationMBean alsbCore = (ALSBConfigurationMBean) domainService.findService(ALSBConfigurationMBean.NAME, ALSBConfigurationMBean.TYPE, null); // Perform read-only operations on core data using alsbCore .... conn.close(); } public static JMXConnector initConnection(String hostname, int port, String username, String password) throws IOException,MalformedURLException { JMXServiceURL serviceURL = new JMXServiceURL("t3", hostname, port, "/jndi/" + DomainRuntimeServiceMBean.MBEANSERVER_JNDI_NAME); Hashtable<String, String> h = new Hashtable<String, String>(); h.put(Context.SECURITY_PRINCIPAL, username); h.put(Context.SECURITY_CREDENTIALS, password); h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote"); return JMXConnectorFactory.connect(serviceURL, h); } }
The management API provided by MBeans is available for scripting via WLST. The java client code presented above is reimplemented here using the following python script. To run this example simply save the code below in a file named basic.py and invoke it via the following command
java weblogic.WLST basic.py You must set the classpath and environment variables correctly by invoking the setDomainEnv.[cmd|sh] script in the bin directory of your domain.
import wlstModule from com.bea.wli.sb.management.configuration import SessionManagementMBean from com.bea.wli.sb.management.configuration import ALSBConfigurationMBean from com.bea.wli.config import Ref try: connect("weblogic", "weblogic", "t3://localhost:7001") domainRuntime() # obtain session management mbean to create a session. # This mbean instance can be used more than once to # create/discard/commit many sessions sessionMBean = findService(SessionManagementMBean.NAME,SessionManagementMBean.TYPE) # create a session sessionMBean.createSession("mysession") # obtain the ALSBConfigurationMBean instance that operates # on the session that has just been created. Notice that # the name of the mbean contains the session name. alsbSession = findService(ALSBConfigurationMBean.NAME + "." + "mysession", ALSBConfigurationMBean.TYPE) # Perform updates or read operations in the session using alsbSession ... # activate changes performed in the session sessionMBean.activateSession("mysession", "description for session activation") # Obtain MBean for peforming read only operations. # Notice that the name of the mbean for the core # data does not contain any session name. alsbCore = findService(ALSBConfigurationMBean.NAME, ALSBConfigurationMBean.TYPE) # Perform read-only operations on core data using alsbCore ... except: print "Unexpected error: ", sys.exc_info()[0] dumpStack() raise
Field Summary | |
---|---|
static java.lang.String |
NAME |
static java.lang.String |
OBJECT_NAME |
static java.lang.String |
TYPE |
Method Summary | |
---|---|
void |
activateSession(java.lang.String session, java.lang.String description) Commits a session |
void |
createSession(java.lang.String session) Creates a new session with an arbitrary user given name |
void |
discardSession(java.lang.String session) Deletes the session without activating the changes. |
boolean |
sessionExists(java.lang.String session) Returns true if a session with the given session exists |
Field Detail |
---|
static final java.lang.String NAME
static final java.lang.String TYPE
static final java.lang.String OBJECT_NAME
Method Detail |
---|
void createSession(java.lang.String session) throws java.lang.Exception
session
- the name of the session that will be createdjava.lang.Exception
boolean sessionExists(java.lang.String session)
session
- the name of the sessionvoid discardSession(java.lang.String session) throws java.lang.Exception
session
- the name of the sessionjava.lang.Exception
void activateSession(java.lang.String session, java.lang.String description) throws java.lang.Exception
session
- the name of the sessiondescription
- the description for this session activationjava.lang.Exception
|
Oracle Fusion Middleware Java API Reference for Oracle Service Bus 11g Release 1 (11.1.1.6.3) E15033-08 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |