| 
 | |||||||||
| 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.
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.
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.
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);
}
}
java weblogic.WLST basic.py weblogic.jar and sb-public.jar must be in the classpath.
The environment variable WL_HOME can be set 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 String | NAME | 
| static String | TYPE | 
| Method Summary | |
|---|---|
|  void | activateSession(String session,
                String description)Commits a session | 
|  void | createSession(String session)Creates a new session with an arbitrary user given name | 
|  void | discardSession(String session)Deletes the session without activating the changes. | 
|  boolean | sessionExists(String session)Returns true if a session with the given session exists | 
| Methods inherited from interface weblogic.management.mbeanservers.Service | 
|---|
| getName, getParentAttribute, getParentService, getPath, getType | 
| Field Detail | 
|---|
static final String NAME
static final String TYPE
| Method Detail | 
|---|
void createSession(String session)
                   throws Exception
session - the name of the session that will be created
Exceptionboolean sessionExists(String session)
session - the name of the session
void discardSession(String session)
                    throws Exception
session - the name of the session
Exception
void activateSession(String session,
                     String description)
                     throws Exception
session - the name of the sessiondescription - the description for this session activation
Exception| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||