Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.arjuna.ats.arjuna.tools.osb.mbean;
  
 import java.util.List;
 import java.util.Map;
 
MBean implementation of an ObjectStore entry that represents an AtomicAction
 
 public class ActionBean extends OSEntryBean implements ActionBeanMBean {
     // Basic properties this enty
     private StateManagerWrapper sminfo;
     // collection of participants belonging to this BasicAction
     // wrapper around the real AtomicAction
     protected ActionBeanWrapperInterface ra;
 
     public ActionBean(UidWrapper w) {
         super(w);
 
         boolean isJTS = JMXServer.isJTS() && w.getType().endsWith("ArjunaTransactionImple");
         // Participants in a JTS transaction are represented by entries in the ObjectStore
         List<UidWrapperrecuids = null;
 
         if (isJTS) {
             try {
                 Constructor<ActionBeanWrapperInterfaceconstructor = cl.getConstructor(ActionBean.classUidWrapper.class);
                  = constructor.newInstance(thisw);
                 .activate();
             } catch (Exception e) { // ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException
                 if (..isTraceEnabled())
                     ..trace("Error constructing " + . + ": " + e);
                  = createWrapper(wtrue);
             }
 
             /*
                 * for JTS actions the participants will have entries in the ObjectStore.
                 * these entries will be associated with the current MBean (refer to
                 * the method findParticipants below for details)
                 */
             recuids = w.probe(.);
         } else {
              = createWrapper(wtrue);  // com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeManager.manager()
         }
 
          = new StateManagerWrapper(StoreManager.getRecoveryStore(), getUid(), getType());
 
         for (ParticipantStatus lt : ParticipantStatus.values()) {
             findParticipants(recuids.getRecords(lt), lt);
         }
     }
 
     protected ActionBeanWrapperInterface createWrapper(UidWrapper wboolean activate) {
         GenericAtomicActionWrapper action = new GenericAtomicActionWrapper(w.getClassName(), w);
 
         if (activate)
             action.activate();
 
         return action;
     }
 
 
     public StringBuilder toString(String prefixStringBuilder sb) {
         .toString(prefixsb);
         prefix += '\t';
         sb.append('\n').append(prefix).append(.getCreationTime());
         sb.append('\n').append(prefix).append(.getAgeInSeconds());
 
         for (LogRecordWrapper p : ) {
             p.toString(prefixsb);
         }
 
         return sb;
     }

    
return the Uid for given AbstractRecord

Parameters:
rec the record whose Uid is required
Returns:
the Uid of the requested record
 
     public Uid getUid(AbstractRecord rec) {
        return .getUid(rec);
    }

    
Remove this AtomicAction from the ObjectStore

Returns:
a textual indication of whether the remove operation succeeded
    public String remove() {
        try {
            if (!StoreManager.getRecoveryStore().remove_committed(getUid(), getType()))
                return "Attempt to remove transaction failed";
            else
                .probe();
            return "Transaction successfully removed";
        } catch (ObjectStoreException e) {
            return "Unable to remove transaction: " + e.getMessage();
        }
    }

    
create MBean representations of the participants of this transaction

Parameters:
recuids some transaction participants are represented in the ObjectStore - if this is the case then recuids contains a list of MBean wrappers representing them. Otherwise this list will be empty.
list the records representing the participants
listType indicates the type of the records in list (PREPARED, PENDING, FAILED, READONLY, HEURISTIC)
    private void findParticipants(List<UidWrapperrecuidsRecordList listParticipantStatus listType) {
        if (list != null) {
            for (AbstractRecord rec = list.peekFront(); rec != nullrec = list.peekNext(rec)) {
                LogRecordWrapper lw;
                int i = recuids == null ? -1 : recuids.indexOf(new UidWrapper(.getUid(rec)));
                if (i != -1) {
                    OSEntryBean p = recuids.get(i).getMBean();
                    if (p instanceof LogRecordWrapper) {
                        lw = (LogRecordWrapperp;
                        lw.init(thisreclistType);
                    } else {
                        if (..isTraceEnabled())
                            ..trace("participant record is not a LogRecordWrapper");
                        lw = createParticipant(reclistTyperecuids.get(i));
                    }
                } else {
                    lw = createParticipant(reclistType);
                }
                lw.activate();
                .add(lw);
            }
        }
    }

    
Extension point for other Bean implementations to provide an implementation bean for its participants. For example

Parameters:
rec the record that should be represented by an MBean
listType the status of the record
Returns:
the MBean implementation of the participant
See also:
com.arjuna.ats.internal.jta.tools.osb.mbean.jta.JTAActionBean
        return new LogRecordWrapper(thisreclistType);
    }
    protected LogRecordWrapper createParticipant(AbstractRecord recParticipantStatus listTypeUidWrapper wrapper) {
        return new LogRecordWrapper(thisreclistTypewrapper);
    }
    
See if there is participant Bean corresponding to the given record

Parameters:
rec the record for the target participant
Returns:
the bean corresponding to the requested record
        for (LogRecordWrapper w : )
            if (w.getRecord().equals(rec))
                return w;
        return null;
    }

    
register this bean (and its participants) with the MBeanServer
    public void register() {
        super.register();
        for (LogRecordWrapper p : )
            JMXServer.getAgent().registerMBean(p.getName(), p);
    }

    
unregister this bean (and its participants) with the MBeanServer
    public void unregister() {
        for (LogRecordWrapper p : )
            JMXServer.getAgent().unregisterMBean(p.getName());
        super.unregister();
    }
    public long getAgeInSeconds() {
        return .getAgeInSeconds();
    }
    public String getCreationTime() {
        return .getCreationTime();
    }
    public boolean isParticipant() {
        return false;
    }

    
Request a change in status of a participant. For example if a record has a heuristic status then this method could be used to move it back into the prepared state so that the recovery system can replay phase 2 of the commitment protocol

Parameters:
logrec the record whose status is to be changed
newStatus the desired status
Returns:
true if the status was changed
    public boolean setStatus(LogRecordWrapper logrecParticipantStatus newStatus) {
        ParticipantStatus lt = logrec.getListType();
        AbstractRecord targRecord = logrec.getRecord();
        RecordList oldList = .getRecords(lt);
        RecordList newList = .getRecords(newStatus);
        // move the record from currList to targList
        if (oldList.remove(targRecord)) {
            if (newList.insert(targRecord)) {
                if (lt.equals(.)) {
                    switch (newStatus) {
                        case :
                            .clearHeuristicDecision(.);
                            break;
                        case :
                            .clearHeuristicDecision(.);
                            break;
                        case :
                            .clearHeuristicDecision(.);
                            break;
                        case :
                            .clearHeuristicDecision(.);
                            break;
                        default:
                            break;
                    }
                }
                .doUpdateState();
                return true;
            }
        }
        return false;
    }

    

Returns:
the MBeans corresponding to the participants within this action
        return Collections.unmodifiableCollection();
    }

    
The ActionBean needs access to the participant lists maintained by an AtomicAction but these lists are protected. Therefore define a simple extension class to get at these records:
    public class GenericAtomicActionWrapper implements ActionBeanWrapperInterface {
        boolean activated;
        BasicAction action;
        Map<StringRecordListrecs;
        Method updateState = null;
        UidWrapper uidWrapper;
        public GenericAtomicActionWrapper(String classTypeUidWrapper w) {
             = w;
             = new HashMap<StringRecordList>();
            if (classType == null)
                classType = "com.arjuna.ats.arjuna.AtomicAction";
            try {
                Class cls = Class.forName(classType);
                Class pTypes[] = new Class[1];
                pTypes[0] = Uid.class;
                Constructor ctor = cls.getConstructor(pTypes);
                Object args[] = new Object[1];
                args[0] = w.getUid();
                 = (BasicActionctor.newInstance(args);
                 = getMethod(.getClass(), "setHeuristicDecision"int.class);
                 = getMethod(.getClass(), "updateState");
                if ( != null)
                    .setAccessible(true);
                if ( != null)
                    .setAccessible(true);
            } catch (Exception e) {
                 = null;
                if (..isDebugEnabled())
                    ..debug("unable to create log wrapper for type " + w.getType() + ": error: " + e.getMessage());
            }
        }
        public BasicAction getAction() {
            return ;
        }
        public boolean activate() {
            if (! &&  != null) {
                 = .activate();
            }
            return ;
        }
        public void doUpdateState() {
            if ( != null &&  != null) {
                try {
                    .invoke();
                } catch (IllegalAccessException e) {
                    if (..isDebugEnabled())
                        ..debug("failed to update heuristic for " + .toString() + ": error: " + e.getMessage());
                } catch (InvocationTargetException e) {
                    if (..isDebugEnabled())
                        ..debug("failed to update heuristic for " + .toString() + ": error: " + e.getMessage());
                }
            }
        }
        public Uid get_uid() {
            return  != null ? .get_uid() : .getUid();
        }
        public Uid getUid(AbstractRecord rec) {
            return rec.order(); //get_uid();
        }
        public StringBuilder toString(String prefixStringBuilder sb) {
            prefix += '\t';
            return sb.append('\n').append(prefix).append(get_uid());
        }
        public void clearHeuristicDecision(int newDecision) {
            RecordList rl = getRecords("heuristicList");
            if ( != null && rl != null && rl.size() == 0)
                try {
                    .invoke(newDecision);
                } catch (IllegalAccessException e) {
                    if (..isDebugEnabled())
                        ..debug("failed to update heuristic for " + .toString() + ": error: " + e.getMessage());
                } catch (InvocationTargetException e) {
                    if (..isDebugEnabled())
                        ..debug("failed to update heuristic for " + .toString() + ": error: " + e.getMessage());
                }
        }
        private Field getField(Class clString fn) {
            try {
                return cl.getDeclaredField(fn);
            } catch (NoSuchFieldException e) {
                return getField(cl.getSuperclass(), fn);
            }
        }
        private Method getMethod(Class clString mnClass<?>... parameterTypes) {
            try {
                if (cl == null)
                    return null;
                return cl.getDeclaredMethod(mnparameterTypes);
            } catch (NoSuchMethodException e) {
                return getMethod(cl.getSuperclass(), mnparameterTypes);
            }
        }
        public RecordList getRecords(String ln) {
            if ( == null)
                return null;
            if (.containsKey(ln))
                return .get(ln);
            Field f = getField(.getClass(), ln);
            f.setAccessible(true);
            try {
                RecordList rl = (RecordListf.get();
                if (rl != null)
                    .put(lnrl);
                return rl;
            } catch (IllegalAccessException e) {
                return null;
            }
        }
        public RecordList getRecords(ParticipantStatus type) {
            switch (type) {
                default:
                case return getRecords("preparedList");
                case return getRecords("failedList");
                case return getRecords("heuristicList");
                case return getRecords("pendingList");
                case return getRecords("readonlyList");
            }
        }
    }
New to GrepCode? Check out our FAQ X