Fields Summary |
---|
static final String | NUM_TRANSACTIONS_COMPLETED |
static final String | NUM_TRANSACTIONS_ROLLEDBACK |
static final String | NUM_TRANSACTIONS_INFLIGHT |
static final String | IS_FROZEN |
static final String | INFLIGHT_TRANSACTIONS |
static final String | ROLLBACK |
static final String | FREEZE |
static final int | COLUMN_LENGTH |
public static final String | TRANSACTION_ID |
public static final String | STATE |
public static final String | ELAPSED_TIME |
public static final String | COMPONENT_NAME |
public static final String | RESOURCE_NAMES |
private static com.sun.enterprise.util.i18n.StringManager | sm |
static Logger | _loggerLogger to log transaction messages |
private static Object[] | attrNameTypeArrayA 2-d array initialized to attribute names and their types |
private static MBeanOperationInfo[] | operationInfoArray |
private com.sun.enterprise.J2EETransactionManager | txnMgrJTSAdminClient to get the monitor data from, and to invoke user actions |
private Hashtable | txnTable |
private com.sun.enterprise.admin.monitor.MonitoredObjectType | type |
private boolean | monitorOn |
private long | startTime |
private static Map | attrNameTypeMapMap of attribute names and their types |
private static MBeanInfo | mBeanInfoInfo on this MBean |
Constructors Summary |
---|
public JTSMonitorMBean()Creates a new instance of JTSMonitorMBean
attrNameTypeMap = createAttrNameTypeMap(attrNameTypeArray);
operationInfoArray[0] = new MBeanOperationInfo(ROLLBACK,
"rollback(String txnId): Marks the transaction for rollback",
null, "void", MBeanOperationInfo.ACTION);
operationInfoArray[1] = new MBeanOperationInfo(FREEZE,
"freeze(): Freezes the transactions",
null, "void", MBeanOperationInfo.ACTION);
mBeanInfo = createMBeanInfo(attrNameTypeMap, operationInfoArray);
txnMgr = Switch.getSwitch().getTransactionManager();
ServerContext sCtx = ApplicationServer.getServerContext();
if (sCtx != null) {
try {
ConfigContext ctx = sCtx.getConfigContext();
Config cfg = ServerBeansFactory.getConfigBean(ctx);
String lvl = cfg.getMonitoringService().getModuleMonitoringLevels().getTransactionService();
MonitoringLevel l = MonitoringLevel.instance(lvl);
if (l != MonitoringLevel.OFF) {
startMonitoring();
}
MonitoringRegistry registry = sCtx.getMonitoringRegistry();
JTAStatsImpl.createInstance(this);
JTAStatsImpl statImpl = JTAStatsImpl.getInstance();
registry.registerJTAStats(statImpl, statImpl);
_logger.log(Level.FINE,"JTAStats monitoring registration completed");
TransactionService txnService = ServerBeansFactory.getTransactionServiceBean(ctx);
ElementProperty[] eprops = txnService.getElementProperty();
for (int index = 0; index < eprops.length; index++) {
if ("pending-txn-cleanup-interval".equals(eprops[index].getName())) {
int interval = 60;
if (eprops[index].getValue() != null)
interval = Integer.parseInt(eprops[index].getValue());
new RecoveryHelperThread(interval).start();
if (_logger.isLoggable(Level.FINE))
_logger.log(Level.FINE,"Asynchronous thread for incomplete tx is enabled with interval " + interval);
}
}
} catch (MonitoringRegistrationException mex) {
_logger.log(Level.WARNING,"transaction.monitor.registration_failed", mex);
} catch (ConfigException e) {
_logger.log(Level.WARNING,"transaction.monitor.registration_failed", e);
}
}
else {
_logger.log(Level.FINE,"JTSMonitorMBean: ServerContext is null: monitoring is not enabled");
}
|
Methods Summary |
---|
public void | freeze()
txnMgr.freeze();
|
public java.lang.Object | getAttribute(java.lang.String attribute)Obtains the value of a specific monitored attribute.
if (attribute == null) {
/**
throw new RuntimeOperationsException(
new IllegalArgumentException("Attribute name cannot be null"));
**/
throw new RuntimeOperationsException(
new IllegalArgumentException(sm.getString("transaction.monitor.attribute_is_null")));
}
// Call the corresponding getter for a recognized attribute_name
if (attribute.equals(NUM_TRANSACTIONS_COMPLETED)) {
return new Integer(txnMgr.getNumberOfTransactionsCommitted());
}
if (attribute.equals(NUM_TRANSACTIONS_ROLLEDBACK)) {
return new Integer(txnMgr.getNumberOfTransactionsRolledBack());
}
if (attribute.equals(NUM_TRANSACTIONS_INFLIGHT)) {
return new Integer(txnMgr.getNumberOfActiveTransactions());
}
if (attribute.equals(IS_FROZEN)) {
if (txnMgr.isFrozen())
return "True";
else
return "False";
}
if (attribute.equals(INFLIGHT_TRANSACTIONS)) {
ArrayList aList = txnMgr.getActiveTransactions();
// if (aList.isEmpty()) return "No active transaction found.";
if (aList.isEmpty()) return "";
StringBuffer strBuf = new StringBuffer(1024);
txnTable = new Hashtable();
//Set the headings for the tabular output
if (aList.size() > 0) {
String colName = "Transaction Id";
strBuf.append("\n\n");
strBuf.append(colName);
for (int i=colName.length(); i<COLUMN_LENGTH+15; i++){
strBuf.append(" ");
}
colName = "Status";
strBuf.append(colName);
for (int i=colName.length(); i<COLUMN_LENGTH; i++){
strBuf.append(" ");
}
colName = "ElapsedTime(ms)";
strBuf.append(colName);
for (int i=colName.length(); i<COLUMN_LENGTH; i++){
strBuf.append(" ");
}
colName = "ComponentName";
strBuf.append(colName);
for (int i=colName.length(); i<COLUMN_LENGTH; i++){
strBuf.append(" ");
}
strBuf.append("ResourceNames\n");
}
for (int i=0; i < aList.size(); i++) {
TransactionAdminBean txnBean = (TransactionAdminBean)aList.get(i);
Transaction j2eeTxn = (Transaction) txnBean.getIdentifier();
String txnId = txnBean.getId();
txnTable.put(txnId, j2eeTxn);
strBuf.append("\n");
strBuf.append(txnId);
for (int j=txnId.length(); j<COLUMN_LENGTH+15; j++){
strBuf.append(" ");
}
strBuf.append(txnBean.getStatus());
for (int j=txnBean.getStatus().length(); j<COLUMN_LENGTH; j++){
strBuf.append(" ");
}
strBuf.append(String.valueOf(txnBean.getElapsedTime()));
for (int j=(String.valueOf(txnBean.getElapsedTime()).length()); j<COLUMN_LENGTH; j++){
strBuf.append(" ");
}
strBuf.append(txnBean.getComponentName());
for (int j=txnBean.getComponentName().length(); j<COLUMN_LENGTH; j++){
strBuf.append(" ");
}
ArrayList<String> resourceList = txnBean.getResourceNames();
if (resourceList != null) {
for (int k = 0; k < resourceList.size(); k++) {
strBuf.append(resourceList.get(k));
strBuf.append(",");
}
}
}
return strBuf.toString();
}
// If attribute_name has not been recognized
// throw(new AttributeNotFoundException("Cannot find " + attribute + " attribute" ));
throw(new AttributeNotFoundException(sm.getString("transaction.monitor.attribute_not_found",attribute ) ));
|
public com.sun.enterprise.admin.monitor.types.MonitoredAttributeType | getAttributeType(java.lang.String attrName)Get type of the specified monitored attribute.
MonitoredAttributeType type = null;
if (attrNameTypeMap != null && attrName != null) {
type = (MonitoredAttributeType)attrNameTypeMap.get(attrName);
}
return type;
|
public javax.management.AttributeList | getAttributes(java.lang.String[] attributeNames)Get the values of several attributes of the monitoring MBean.
// Check attributeNames to avoid NullPointerException later on
if (attributeNames == null) {
/**
throw new RuntimeOperationsException(
new IllegalArgumentException(
"attributeNames[] cannot be null"));
**/
throw new RuntimeOperationsException(
new IllegalArgumentException(
sm.getString("transaction.monitor.attributes_not_null")));
}
AttributeList resultList = new AttributeList();
// if attributeNames is empty, return an empty result list
if (attributeNames.length == 0)
return resultList;
// build the result attribute list
for (int i=0 ; i<attributeNames.length ; i++){
try {
Object value = getAttribute((String) attributeNames[i]);
resultList.add(new Attribute(attributeNames[i],value));
} catch (Exception e) {
// print debug info but continue processing list
_logger.log(Level.WARNING,"transaction.monitor.error_while_getting_monitor_attr",e);
}
}
return(resultList);
|
public javax.management.MBeanInfo | getMBeanInfo()Provides the exposed attributes and actions of the monitoring MBean using
an MBeanInfo object.
return mBeanInfo;
|
public com.sun.enterprise.admin.monitor.MonitoredObjectType | getMonitoredObjectType()
return type;
|
public java.util.Map | getMonitoringMetaData()Get a map of monitored attribute names and their types. The keys in
the map are names of the attribute and the values are their types. The
type value are instances of class
com.iplanet.ias.monitor.type.MonitoredAttributeType (or its sub-classes)
return attrNameTypeMap;
|
public long | getStartTime()
return startTime;
|
public java.lang.Object | invoke(java.lang.String operationName, java.lang.Object[] params, java.lang.String[] signature)
if (operationName == null || operationName.equals("")) {
/**
throw new RuntimeOperationsException(
new IllegalArgumentException("operationName cannot be null"));
**/
throw new RuntimeOperationsException(
new IllegalArgumentException(sm.getString("transaction.monitor.operation_name_is_null")));
}
if (params == null)
return null;
AttributeList resultList = new AttributeList();
if (operationName.equals(ROLLBACK)) {
for (int i=0; i<params.length; i++) {
String txnId = (String) params[i];
Object value = setRollback(txnId);
resultList.add(new Attribute(txnId, value));
}
} else if (operationName.equals(FREEZE)) {
if (params[0].equals("true")) {
txnMgr.freeze();
resultList.add(new Attribute("freeze", "Successful"));
} else {
txnMgr.unfreeze();
resultList.add(new Attribute("unfreeze", "Successful"));
}
} else {
throw new UnsupportedOperationException(UNSUPPORTED_ERRMSG);
}
return resultList;
|
public java.util.List | listActiveTransactions()
ArrayList aList = txnMgr.getActiveTransactions();
if (aList.isEmpty())
return new ArrayList<Map<String, String>>(0);
txnTable = new Hashtable();
List<Map<String, String>> activeTxnList = new ArrayList<Map<String, String>>();
Map<String, String> txnListEntry = null;
for (int i=0; i < aList.size(); i++) {
TransactionAdminBean txnBean = (TransactionAdminBean)aList.get(i);
Transaction j2eeTxn = (Transaction) txnBean.getIdentifier();
String txnId = txnBean.getId();
txnTable.put(txnId, j2eeTxn);
txnListEntry = new HashMap<String, String>(5);
txnListEntry.put(TRANSACTION_ID, txnId);
txnListEntry.put(ELAPSED_TIME, String.valueOf(txnBean.getElapsedTime()));
txnListEntry.put(COMPONENT_NAME, txnBean.getComponentName());
ArrayList<String> resourceList = txnBean.getResourceNames();
StringBuffer strBuf = new StringBuffer(" ");
if (resourceList != null) {
for (int k = 0; k < resourceList.size(); k++) {
strBuf.append(resourceList.get(k));
strBuf.append(",");
}
}
txnListEntry.put(RESOURCE_NAMES, strBuf.toString());
txnListEntry.put(STATE, txnBean.getStatus());
activeTxnList.add(txnListEntry);
}
return activeTxnList;
|
public static void | recover(boolean delegated, java.lang.String txLogDir)
ResourceInstaller resInstaller = Switch.getSwitch().getResourceInstaller();
boolean result = true;
if (resInstaller == null) {
throw new IllegalStateException();
}
if (!delegated) { // own recovery
result = resInstaller.recoverIncompleteTx(false, null);
}
else { // delegated recovery
result = resInstaller.recoverIncompleteTx(true, txLogDir);
}
if (!result)
throw new IllegalStateException();
|
public java.lang.String[] | rollback(java.lang.String[] txnIds)
if (txnIds == null || txnIds.length == 0)
return new String[0];
String result[] = new String[txnIds.length];
for (int i = 0; i < txnIds.length; i++) {
result[i] = (String) setRollback(txnIds[i]);
}
return result;
|
public java.lang.Object | setRollback(java.lang.String txnId)
// Lookup the transaction Array for the txnid
String result = "";
if (txnTable == null || txnTable.get(txnId) == null) {
result = sm.getString("transaction.monitor.rollback_invalid_id");
throw new IllegalStateException(result);
}
else {
// Call the TransactionManager to rollback
try {
txnMgr.forceRollback((Transaction)txnTable.get(txnId));
result = sm.getString("transaction.monitor.rollback_sucessful");
} catch (IllegalStateException e) {
// current thread is not associated with the transaction
result = sm.getString("transaction.monitor.rollback_unsuccessful_not_associated");
IllegalStateException ex = new IllegalStateException(result);
ex.initCause(e);
throw ex;
} catch (SecurityException e) {
// Thread is not allowed to rollback the transaction
result = sm.getString("transaction.monitor.rollback_unsuccessful_security_exception");
SecurityException ex = new SecurityException(result);
ex.initCause(e);
throw ex;
} catch (SystemException e) {
// Transaction Manager encountered unexpected error condition
result = sm.getString("transaction.monitor.rollback_unsuccessful_unexpected_exception");
IllegalStateException ex = new IllegalStateException(result);
ex.initCause(e);
throw ex;
}
}
return result;
|
public void | startMonitoring()Start monitoring on this component. This will be called when monitoring
is enabled on this component (or the group containing this component)
through user interface.
txnMgr.setMonitoringEnabled(true);
monitorOn = true;
startTime = System.currentTimeMillis();
|
public void | stopMonitoring()Stop monitoring on this component. Called when monitoring is disabled on
user interface.
txnMgr.setMonitoringEnabled(false);
monitorOn = false;
startTime = 0;
|
public void | unfreeze()
txnMgr.unfreeze();
|