Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.arjuna.ats.arjuna.tools.osb.mbean;
  
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  
An MBean implementation for walking an ObjectStore and creating/deleting MBeans that represent completing transactions (ie ones on which the user has called commit)
 
 public class ObjStoreBrowser implements ObjStoreBrowserMBean {
     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";
 
     // defines a (default) map of object store types to the corresponding MBean for instrumentation.
     // The format is OSType1=BeanType1,OSType2=BeanType2,etc
     // Can be over-ridden by setting a system property called com.arjuna.ats.arjuna.tools.osb.mbean.ObjStoreBrowserHandlers
     private static final String saaStateType = "com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.SubordinateAtomicAction";
     private static final String saaBeanType = "com.arjuna.ats.internal.jta.tools.osb.mbean.jta.SubordinateActionBean";
     private static final String defaultStateHandlers =
             "com.arjuna.ats.arjuna.AtomicAction=com.arjuna.ats.internal.jta.tools.osb.mbean.jta.JTAActionBean"
 //            + ",com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.SubordinateAtomicAction=com.arjuna.ats.internal.jta.tools.osb.mbean.jta.SubordinateActionBean"
                     + ",com.arjuna.ats.internal.jta.tools.osb.mbean.jts.ArjunaTransactionImpleWrapper=com.arjuna.ats.arjuna.tools.osb.mbean.ActionBean";
 
     private Map<StringStringstateTypes = null// defines which object store types will be instrumented
     private Map<StringStringbeanTypes = null;  // defines which bean types are used to represent object store types
     private Map<StringList<UidWrapper>> allUids;
     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()
     {
         for (List<UidWrapperuids : .values()) {
             for (Iterator<UidWrapperi = uids.iterator(); i.hasNext(); ) {
                 UidWrapper w = i.next();
                 i.remove();
                 w.unregister();
             }
         }
 
         JMXServer.getAgent().unregisterMBean();
     }

    
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) {
         String typeName = getOSType(osTypeClassName);
 
         if (typeName != null) {
 
             if (typeName.startsWith("/"))
                 typeName = typeName.substring(1);
 
             .put(typeNameosTypeClassName);
             .put(typeNamebeanTypeClassName);
 
             return true;
         }
        return false;
    }
    private void initTypeHandlers(String handlers) {
        for (String h : handlers.split(",")) {
            String[] handler = h.split("=");
            if (handler.length == 2) {
                String typeName = getOSType(handler[0]);
                if (typeName != null) {
                    if (typeName.startsWith("/"))
                        typeName = typeName.substring(1);
                    .put(typeNamehandler[0]);
                    .put(typeNamehandler[1]);
                }
            }
        }
    }
    private void init(String logDir) {
        if (logDir != null)
            arjPropertyManager.getObjectStoreEnvironmentBean().setObjectStoreDir(logDir);
        if (..isTraceEnabled())
            ..trace("ObjectStoreDir: " + arjPropertyManager.getObjectStoreEnvironmentBean().getObjectStoreDir());
         = new HashMap<StringList<UidWrapper>> ();
         = new HashMap<StringString>();
         = new HashMap<StringString>();
    }
    public ObjStoreBrowser() {
        init(null);
    }
    public ObjStoreBrowser(String logDir) {
        init(logDir);
    }
    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) {
        return findUid(uid.stringForm());
    }
    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 String getOSType(String classType) {
        try {
            Class cls = Class.forName(classType);
            StateManager sm = (StateManagercls.getConstructor().newInstance();
            return sm.type();
        } catch (Exception e) {
            if (..isDebugEnabled())
                ..debug("Invalid class type in system property ObjStoreBrowserHandlers: " + classType);
        }
        return null;
    }
    
See if any new MBeans need to be registered or if any existing MBeans no longer exist as ObjectStore entries.
	public void probe() {
		try {
			if (StoreManager.getRecoveryStore().allTypes(types)) {
				String tname;
				do {
					try {
						tname = types.unpackString();
catch (IOException e1) {
						tname = "";
					}
					if (tname.length() != 0) {
						List<UidWrapperuids = .get(tname);
						if (uids == null) {
							uids = new ArrayList<UidWrapper>();
							.put(tnameuids);
						}
					}
while (tname.length() != 0);
			}
catch (ObjectStoreException e2) {
			if (..isTraceEnabled())
		}
		while (iterator.hasNext()) {
			String tname = iterator.next();
			List<UidWrapperuids = .get(tname);
			if (uids == null) {
				uids = new ArrayList<UidWrapper>();
				.put(tnameuids);
			}
				updateMBeans(uids, System.currentTimeMillis(), truetname);
		}
	}
    public void viewSubordinateAtomicActions(boolean enable) {
        if (enable) {
            setType();
        } else {
            String typeName = getOSType();
            if (typeName != null) {
                if (typeName.startsWith("/"))
                    typeName = typeName.substring(1);
                .remove(typeName);
                .remove(typeName);
                for (List<UidWrapperuids : .values()) {
                    for (Iterator<UidWrapperi = uids.iterator(); i.hasNext(); ) {
                        UidWrapper w = i.next();
                        if (.equals(w.getClassName())) {
                            i.remove();
                            w.unregister();
                        }
                    }
                }
            }
        }
    }
    public void setExposeAllRecordsAsMBeans(boolean exposeAllLogs) {
        this. = exposeAllLogs;
    }

    
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 (!.containsKey(type)) {
			try {
				if (StoreManager.getRecoveryStore().allTypes(types)) {
					String tname;
					do {
						try {
							tname = types.unpackString();
catch (IOException e1) {
							tname = "";
						}
						if (tname.length() != 0) {
							List<UidWrapperuids = .get(tname);
							if (uids == null) {
								uids = new ArrayList<UidWrapper>();
								.put(tnameuids);
							}
						}
while (tname.length() != 0);
				}
catch (ObjectStoreException e2) {
				if (..isTraceEnabled())
			}
			if (!.containsKey(type))
				return null;
		}
        List<UidWrapperuids = .get(type);
        updateMBeans(uids, System.currentTimeMillis(), falsetype);
        return uids;
    }
    private String getBeanType(String type) {
        if (.containsKey(type))
            return .get(type);
        return OSEntryBean.class.getName();
    }
    private void updateMBeans(List<UidWrapperuidslong tstampboolean registerString type) {
        ObjectStoreIterator iter = new ObjectStoreIterator(StoreManager.getRecoveryStore(), type);
        while (true) {
            Uid u = iter.iterate();
            if (u == null || Uid.nullUid().equals(u))
                break;
            UidWrapper w = new UidWrapper(thisgetBeanType(type), type.get(type), u);
            int i = uids.indexOf(w);
            if (i == -1) {
                w.setTimestamp(tstamp);
                uids.add(w);
                w.createMBean();
                if (register)
                    w.register();
            } else {
                uids.get(i).setTimestamp(tstamp);
            }
        }
        for (Iterator<UidWrapperi = uids.iterator(); i.hasNext(); ) {
            UidWrapper w = i.next();
            if (w.getTimestamp() != tstamp) {
                if (register)
                    w.unregister();
                i.remove();
            }
        }
    }
New to GrepCode? Check out our FAQ X