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.util.*;
 
MBean implementation of an ObjectStore entry that represents an AtomicAction

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 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;
 
     protected List<UidWrapperrecuids = new ArrayList<UidWrapper>();
     private static final ThreadLocal<Stringclassname = new ThreadLocal<String>();
 
     public ActionBean(UidWrapper w) {
         super(w);
 
         boolean isJTS = JMXServer.isJTS() && w.getType().contains("ArjunaTransactionImple");
 
         if (isJTS) {
             try {
                 UidWrapper.setRecordWrapperTypeName(w.getType());
                 Class<ActionBeanWrapperInterfacecl = (Class<ActionBeanWrapperInterface>) Class.forName(w.getClassName());
                 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 we also store participant details under "CosTransactions/XAResourceRecord"
              * We may at some point want to augment the beans created in findParticipants below with
              * w.probe(JMXServer.AJT_RECORD_TYPE);
              */
         } else {
              = createWrapper(wtrue);  // com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeManager.manager()
         }
 
          = new StateManagerWrapper(StoreManager.getRecoveryStore(), getUid(), getType());
 
         for (ParticipantStatus lt : ParticipantStatus.values()) {
             findParticipants(.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() {
        // first unregister each participant of this action
        while (i.hasNext()) {
            LogRecordWrapper w = i.next();
            w.remove(false);
            i.remove();
        }
        try {
            if (!StoreManager.getRecoveryStore().remove_committed(getUid(), getType()))
                return "Attempt to remove transaction failed";
            .unregister();
            return "Transaction successfully removed";
        } catch (ObjectStoreException e) {
            return "Unable to remove transaction: " + e.getMessage();
        } finally {
            .probe();
        }
    }

    
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();
    }

    
remove the a participant

Parameters:
logRecordWrapper the wrapped log record
    public void remove(LogRecordWrapper logRecordWrapper) {
        .remove(logRecordWrapper);
    }

    
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 static class GenericAtomicActionWrapper implements ActionBeanWrapperInterface {
        boolean activated;
        BasicAction action;
        Map<StringRecordListrecs;
        Method updateState = null;
        UidWrapper uidWrapper;
        private static BasicAction createAction(String classTypeUidWrapper wrapper) {
            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] = wrapper.getUid();
                return (BasicActionctor.newInstance(args);
            } catch (Exception e) {
                if (..isDebugEnabled())
                    ..debug("unable to create log wrapper for type " + wrapper.getType() + ": error: " + e.getMessage());
                return null;
            }
        }
        public GenericAtomicActionWrapper(BasicAction baUidWrapper w) {
             = ba;
             = w;
             = new HashMap<StringRecordList>();
            if ( != null) {
                 = getMethod(.getClass(), "setHeuristicDecision"int.class);
                 = getMethod(.getClass(), "updateState");
                if ( != null)
                    .setAccessible(true);
                if ( != null)
                    .setAccessible(true);
            }
        }
        public GenericAtomicActionWrapper(String classTypeUidWrapper w) {
            this(createAction(classTypew), w);
        }
        public BasicAction getAction() {
            return ;
        }
        public boolean activate() {
            if (! &&  != null) {
                try {
                     = .activate();
                } catch (Exception e) {
                     = false;
                    ..warn("Activate of " +  + " failed: " + e.getMessage());
                }
            }
            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());
                }
        }
        @Override
        public void remove(LogRecordWrapper logRecordWrapper) {
            RecordList rl = getRecords(logRecordWrapper.getListType());
            if (rl != null && rl.size() > 0) {
                if (rl.remove(logRecordWrapper.getRecord())) {
                    doUpdateState(); // rewrite the list
                }
            }
        }
        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