Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2014, Red Hat Middleware LLC, and individual contributors
   * as indicated by the @author tags. See the copyright.txt file in the
   * distribution for a full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package com.arjuna.ats.arjuna.tools.osb.mbean;
 
 import java.io.File;
 import java.util.*;
 
An MBean implementation for walking an ObjectStore and creating/deleting MBeans that represent completing transactions (ie ones on which the user has called commit)

Author(s):
Mike Musgrove
 

Deprecated:
as of 4.17.26.Final In a subsequent release we will change packages names in order to provide a better separation between public and internal classes.
 
 @Deprecated // in order to provide a better separation between public and internal classes.
 public class ObjStoreBrowser implements ObjStoreBrowserMBean {
 
     private static final String SUBORDINATE_AA_TYPE =
             "StateManager/BasicAction/TwoPhaseCoordinator/AtomicAction/SubordinateAtomicAction/JCA".replace("/".);
 
     private static OSBTypeHandler[] defaultOsbTypes = {
             new OSBTypeHandler(
                     true,
                     "com.arjuna.ats.internal.jta.recovery.arjunacore.RecoverConnectableAtomicAction",
                     "com.arjuna.ats.internal.jta.tools.osb.mbean.jta.RecoverConnectableAtomicActionBean",
                     "StateManager/BasicAction/TwoPhaseCoordinator/AtomicActionConnectable",
                     null
             ),
             new OSBTypeHandler(
                     false,
                     "com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.SubordinateAtomicAction",
                     "com.arjuna.ats.internal.jta.tools.osb.mbean.jta.SubordinateActionBean",
                     ,
                     null
             ),
             new OSBTypeHandler(
                     true,
                     "com.arjuna.ats.arjuna.AtomicAction",
                     "com.arjuna.ats.arjuna.tools.osb.mbean.ActionBean",
                     "StateManager/BasicAction/TwoPhaseCoordinator/AtomicAction",
                     null
             ),
     };
 
     private static OSBTypeHandler[] defaultJTSOsbTypes = {
             new OSBTypeHandler(
                     true,
                     false,
                     "com.arjuna.ats.internal.jta.tools.osb.mbean.jts.JTSXAResourceRecordWrapper",
                     "com.arjuna.ats.internal.jta.tools.osb.mbean.jts.JTSXAResourceRecordWrapper",
                     "CosTransactions/XAResourceRecord",
                     null
             ),
             new OSBTypeHandler(
                     true,
                     "com.arjuna.ats.internal.jta.tools.osb.mbean.jts.ArjunaTransactionImpleWrapper",
                     "com.arjuna.ats.internal.jta.tools.osb.mbean.jts.JTSActionBean",
                     "StateManager/BasicAction/TwoPhaseCoordinator/ArjunaTransactionImple",
                     null
             ),
             new OSBTypeHandler(
                     true,
                     "com.arjuna.ats.internal.jta.tools.osb.mbean.jts.ArjunaTransactionImpleWrapper",
                     "com.arjuna.ats.internal.jta.tools.osb.mbean.jts.JTSActionBean",
                     "StateManager/BasicAction/TwoPhaseCoordinator/ArjunaTransactionImple/ServerTransaction",
                     "com.arjuna.ats.internal.jta.tools.osb.mbean.jts.ServerTransactionHeaderReader"
            ),
            new OSBTypeHandler(
                    true,
                    "com.arjuna.ats.internal.jta.tools.osb.mbean.jts.ArjunaTransactionImpleWrapper",
                    "com.arjuna.ats.internal.jta.tools.osb.mbean.jts.JTSActionBean",
                    "StateManager/BasicAction/TwoPhaseCoordinator/ArjunaTransactionImple/AssumedCompleteServerTransaction",
                    null
            ),
            new OSBTypeHandler(
                    true,
                    "com.arjuna.ats.internal.jta.tools.osb.mbean.jts.ArjunaTransactionImpleWrapper",
                    "com.arjuna.ats.internal.jta.tools.osb.mbean.jts.JTSActionBean",
                    "StateManager/BasicAction/TwoPhaseCoordinator/ArjunaTransactionImple/AssumedCompleteHeuristicTransaction",
                    null
            ),
            new OSBTypeHandler(
                    true,
                    "com.arjuna.ats.internal.jta.tools.osb.mbean.jts.ArjunaTransactionImpleWrapper",
                    "com.arjuna.ats.internal.jta.tools.osb.mbean.jts.JTSActionBean",
                    "StateManager/BasicAction/TwoPhaseCoordinator/ArjunaTransactionImple/AssumedCompleteHeuristicServerTransaction",
                    null
            ),
            new OSBTypeHandler(
                    true,
                    "com.arjuna.ats.internal.jta.tools.osb.mbean.jts.ArjunaTransactionImpleWrapper",
                    "com.arjuna.ats.internal.jta.tools.osb.mbean.jts.JTSActionBean",
                    "StateManager/BasicAction/TwoPhaseCoordinator/ArjunaTransactionImple/AssumedCompleteTransaction",
                    null
            )
    };
    private static Map<StringOSBTypeHandlerosbTypeMap = new HashMap<StringOSBTypeHandler>();
    // A system property for defining extra bean types for instrumenting object store types
    // The format is OSType1=BeanType1,OSType2=BeanType2,etc
    public static final String OBJ_STORE_BROWSER_HANDLERS = "com.arjuna.ats.arjuna.tools.osb.mbean.ObjStoreBrowserHandlers";
    private static final String STORE_MBEAN_NAME = "jboss.jta:type=ObjectStore";
    public static HeaderStateReader getHeaderStateUnpacker(String type) {
        OSBTypeHandler osbType = .get(type);
        return (osbType != null) ? osbType.getHeaderStateReader() : null;
    }
    private Map<StringList<UidWrapper>> registeredMBeans = new HashMap<StringList<UidWrapper>> ();;
    private boolean exposeAllLogs = false;

    
Initialise the MBean
    public void start()
    {
        JMXServer.getAgent().registerMBean(this);
    }

    
Unregister all MBeans representing objects in the ObjectStore represented by this MBean
    public void stop()
    {
        unregisterMBeans();
        JMXServer.getAgent().unregisterMBean();
    }
    private void unregisterMBeans(List<UidWrapperbeans) {
        for (UidWrapper w : beans)
            w.unregister();
        beans.clear();
    }
    private void unregisterMBeans() {
        for (List<UidWrapperuids : .values())
            unregisterMBeans(uids);
        .clear();
    }
    private void registerMBeans() {
        for (List<UidWrapperuids : .values()) {
            for (UidWrapper w : uids)
                w.register();
        }
    }

    
This method is deprecated in favour of

Parameters:
types the list of ObjectStore types that can be represented as MBeans
SetType:
The issue with this method is there is no mechanism for determining which class is responsible for a given OS type. Define which object store types will registered as MBeans
    @Deprecated
    public void setTypes(Map<StringStringtypes) {
    }

    
Tell the browser which beans to use for particular Object Store Action type

Parameters:
osTypeClassName
beanTypeClassName
Returns:
    public boolean setType(String osTypeClassNameString beanTypeClassName) {
        try {
            Class cls = Class.forName(osTypeClassName);
            StateManager sm = (StateManagercls.getConstructor().newInstance();
            String typeName = sm.type();
            if (typeName != null && typeName.startsWith("/"))
                typeName = typeName.substring(1);
            typeName = typeName.replaceAll("/".);
            .put(typeNamenew OSBTypeHandler(trueosTypeClassNamebeanTypeClassNametypeNamenull));
            return true;
        } catch (Exception e) {
            if (..isDebugEnabled())
                ..debug("Invalid class type in system property ObjStoreBrowserHandlers: " + osTypeClassName);
            return false;
        }
    }

    

Parameters:
handler specification for handling object store types
Returns:
the previous value associated with type handler, or null if there was no previous handler.
    public OSBTypeHandler registerHandler(OSBTypeHandler handler) {
        return .put(handler.getTypeName(), handler);
    }
    private void initTypeHandlers(String handlers) {
        for (String h : handlers.split(",")) {
            String[] handler = h.split("=");
            if (handler.length == 2) {
                setType(handler[0], handler[1]);
            }
        }
    }
    private void init(String logDir) {
        if (logDir != null)
            arjPropertyManager.getObjectStoreEnvironmentBean().setObjectStoreDir(logDir);
        if (..isTraceEnabled())
            ..trace("ObjectStoreDir: " + arjPropertyManager.getObjectStoreEnvironmentBean().getObjectStoreDir());
        setExposeAllRecordsAsMBeans(arjPropertyManager.
        for (OSBTypeHandler osbType : )
            .put(osbType.getTypeName(), osbType);
        for (OSBTypeHandler osbType : )
            .put(osbType.getTypeName(), osbType);
    }
    public ObjStoreBrowser() {
        init(null);
    }
    public ObjStoreBrowser(String logDir) {
        init(logDir);
    }

    
Dump info about all registered MBeans

Parameters:
sb a buffer to contain the result
Returns:
the passed in buffer
    public StringBuilder dump(StringBuilder sb) {
        for (Map.Entry<StringList<UidWrapper>> typeEntry : .entrySet()) {
            sb.append(typeEntry.getKey()).append('\n');
            for (UidWrapper uid : typeEntry.getValue())
                uid.toString("\t"sb);
        }
        return sb;
    }

    
See if the given uid has previously been registered as an MBean

Parameters:
uid the unique id representing an ObjectStore entry
Returns:
the MBean wrapper corresponding to the requested Uid (or null if it hasn't been registered)
    public UidWrapper findUid(Uid uid) {
        for (Map.Entry<StringList<UidWrapper>> typeEntry : .entrySet())
            for (UidWrapper w : typeEntry.getValue())
                if (w.getUid().equals(uid))
                    return w;
        return null;
    }

    
Find the registered beand corresponding to a uid.

Deprecated:
use findUid(com.arjuna.ats.arjuna.common.Uid) ()} instead.
Parameters:
uid the uid
Returns:
the registered bean or null if the Uid is not registered
    @Deprecated
    public UidWrapper findUid(String uid) {
        for (Map.Entry<StringList<UidWrapper>> typeEntry : .entrySet())
            for (UidWrapper w : typeEntry.getValue())
                if (w.getUid().stringForm().equals(uid))
                    return w;
        return null;
    }
    private boolean isRegistered(String typeUid uid) {
        List<UidWrapperbeans = .get(type);
        if (beans != null)
            for (UidWrapper w : beans)
                if (uid.equals(w.getUid()))
                    return true;
        return false;
    }
    public void viewSubordinateAtomicActions(boolean enable) {
        OSBTypeHandler osbType = .get();
        if (osbType == null)
            return;
        osbType.setEnabled(enable);
        if (!enable) {
            for (List<UidWrapperuids : .values()) {
                for (Iterator<UidWrapperi = uids.iterator(); i.hasNext(); ) {
                    UidWrapper w = i.next();
                    if (osbType.getRecordClass().equals(w.getClassName())) {
                        i.remove();
                        w.unregister();
                    }
                }
            }
        }
    }
    public void setExposeAllRecordsAsMBeans(boolean exposeAllLogs) {
        this. = exposeAllLogs;
    }

    
Update registered MBeans based on the current set of Uids.

Parameters:
allCurrUids any registered MBeans not in this collection will be deregistered
    private void unregisterRemovedUids(Map<StringCollection<Uid>> allCurrUids) {
        for (Map.Entry<StringList<UidWrapper>> e : .entrySet()) {
            String type = e.getKey();
            List<UidWrapperregisteredBeansOfType = e.getValue();
            Collection<UidcurrUidsOfType = allCurrUids.get(type);
            if (currUidsOfType != null) {
                Iterator<UidWrapperiterator = registeredBeansOfType.iterator();
                while (iterator.hasNext()) {
                    UidWrapper w = iterator.next();
                    if (!currUidsOfType.contains(w.getUid())) {
                        w.unregister();
                        iterator.remove();
                    }
                }
            } else {
                unregisterMBeans(registeredBeansOfType);
            }
        }
    }

    
See if any new MBeans need to be registered or if any existing MBeans no longer exist as ObjectStore entries.
    public synchronized void probe() {
        Map<StringCollection<Uid>> currUidsForType = new HashMap<StringCollection<Uid>>();
        for (String type : getTypes())
            currUidsForType.put(typegetUids(type));
        // if there are any beans in registeredMBeans that don't appear in new list and unregister them
        unregisterRemovedUids(currUidsForType); //unregisterMBeans();
        for (Map.Entry<StringCollection<Uid>> e : currUidsForType.entrySet()) {
            String type = e.getKey();
            List<UidWrapperbeans = .get(type);
            if (beans == null) {
                beans = new ArrayList<UidWrapper>();
                .put(typebeans);
            }
            for (Uid uid : e.getValue()) {
                if (!isRegistered(typeuid)) {
                    UidWrapper w = createBean(uidtype); // can return null if type isn't instrumented
                    if (w != null)
                        beans.add(w);
                }
            }
        }
        /*
         * now create the actual MBeans - we create all the UidWrappers before registering because
         * the process of creating a bean can call back into the browser to probe for a particular type
         * (see for example com.arjuna.ats.arjuna.tools.osb.mbean.ActionBean
         */
        registerMBeans();
    }

    
Register new MBeans of the requested type (or unregister ones whose corresponding ObjectStore entry has been removed)

Parameters:
type the ObjectStore entry type
Returns:
the list of MBeans representing the requested ObjectStore type
    public List<UidWrapperprobe(String type) {
        if (type.startsWith(.))
            return .get(type.substring(..length()));
		return .get(type);
    }
    private UidWrapper createBean(Uid uidString type) {
        OSBTypeHandler osbType = .get(type);
        //boolean enabled = osbType == null || osbType.isEnabled();
        boolean registerBean = osbType != null && osbType.isAllowRegistration();
        if (osbType == null && !)
            return null;
        if ()
            registerBean = true;
//        if (osbType != null && !osbType.enabled)
//            return null;
        String beanType = osbType == null ? OSEntryBean.class.getName() : osbType.getBeanClass();
        String stateType = osbType == null ? null : osbType.getRecordClass();
        UidWrapper w = new UidWrapper(thisbeanTypetypestateTypeuidregisterBean);
        w.createMBean();
        return w;
    }
    private Collection<UidgetUids(String type) {
        Collection<Uiduids = new ArrayList<Uid>();
        ObjectStoreIterator iter = new ObjectStoreIterator(StoreManager.getRecoveryStore(), type);
        while (true) {
            Uid u = iter.iterate();
            if (u == null || Uid.nullUid().equals(u))
                break;
            uids.add(u);
        }
        return uids;
    }
    private Collection<StringgetTypes() {
        Collection<StringallTypes = new ArrayList<String>();
        InputObjectState types = new InputObjectState();
        try {
            if (StoreManager.getRecoveryStore().allTypes(types)) {
                while (true) {
                    try {
                        String typeName = types.unpackString();
                        if (typeName.length() == 0)
                            break;
                        allTypes.add(typeName);
                    } catch (IOException e1) {
                        break;
                    }
                }
            }
        } catch (ObjectStoreException e) {
            if (..isTraceEnabled())
                ..trace(e.toString());        }
        return allTypes;
    }
New to GrepCode? Check out our FAQ X