Search in sources :

Example 1 with SerializableXAResourceDeserializer

use of com.arjuna.ats.jta.recovery.SerializableXAResourceDeserializer in project narayana by jbosstm.

the class XAResourceRecord method getXAResourceDeserializers.

private List<SerializableXAResourceDeserializer> getXAResourceDeserializers() {
    if (serializableXAResourceDeserializers != null) {
        return serializableXAResourceDeserializers;
    }
    synchronized (this) {
        if (serializableXAResourceDeserializers != null) {
            return serializableXAResourceDeserializers;
        }
        serializableXAResourceDeserializers = new ArrayList<SerializableXAResourceDeserializer>();
        for (RecoveryModule recoveryModule : RecoveryManager.manager().getModules()) {
            if (recoveryModule instanceof XARecoveryModule) {
                XARecoveryModule xaRecoveryModule = (XARecoveryModule) recoveryModule;
                serializableXAResourceDeserializers.addAll(xaRecoveryModule.getSeriablizableXAResourceDeserializers());
                return serializableXAResourceDeserializers;
            }
        }
    }
    return serializableXAResourceDeserializers;
}
Also used : SerializableXAResourceDeserializer(com.arjuna.ats.jta.recovery.SerializableXAResourceDeserializer) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule) RecoveryModule(com.arjuna.ats.arjuna.recovery.RecoveryModule) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule)

Example 2 with SerializableXAResourceDeserializer

use of com.arjuna.ats.jta.recovery.SerializableXAResourceDeserializer in project narayana by jbosstm.

the class XAResourceRecord method getXAResourceDeserializers.

private List<SerializableXAResourceDeserializer> getXAResourceDeserializers() {
    if (serializableXAResourceDeserializers != null) {
        return serializableXAResourceDeserializers;
    }
    synchronized (this) {
        if (serializableXAResourceDeserializers != null) {
            return serializableXAResourceDeserializers;
        }
        serializableXAResourceDeserializers = new ArrayList<SerializableXAResourceDeserializer>();
        for (RecoveryModule recoveryModule : RecoveryManager.manager().getModules()) {
            if (recoveryModule instanceof XARecoveryModule) {
                XARecoveryModule xaRecoveryModule = (XARecoveryModule) recoveryModule;
                serializableXAResourceDeserializers.addAll(xaRecoveryModule.getSeriablizableXAResourceDeserializers());
                return serializableXAResourceDeserializers;
            }
        }
    }
    return serializableXAResourceDeserializers;
}
Also used : SerializableXAResourceDeserializer(com.arjuna.ats.jta.recovery.SerializableXAResourceDeserializer) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) RecoveryModule(com.arjuna.ats.arjuna.recovery.RecoveryModule) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)

Example 3 with SerializableXAResourceDeserializer

use of com.arjuna.ats.jta.recovery.SerializableXAResourceDeserializer in project narayana by jbosstm.

the class XAResourceRecord method restore_state.

public boolean restore_state(InputObjectState os, int t) {
    boolean res = false;
    try {
        _heuristic = os.unpackInt();
        _committed = os.unpackBoolean();
        _tranID = XidImple.unpack(os);
        _theXAResource = null;
        _recoveryObject = null;
        if (os.unpackInt() == RecoverableXAConnection.OBJECT_RECOVERY) {
            _productName = os.unpackString();
            _productVersion = os.unpackString();
            _jndiName = os.unpackString();
            boolean haveXAResource = os.unpackBoolean();
            if (haveXAResource) {
                try {
                    // Read the classname of the serialized XAResource
                    String className = os.unpackString();
                    byte[] b = os.unpackBytes();
                    ByteArrayInputStream s = new ByteArrayInputStream(b);
                    ObjectInputStream o = new ObjectInputStream(s);
                    // Give the list of deserializers a chance to deserialize the record
                    boolean deserialized = false;
                    Iterator<SerializableXAResourceDeserializer> iterator = getXAResourceDeserializers().iterator();
                    while (iterator.hasNext()) {
                        SerializableXAResourceDeserializer proxyXAResourceDeserializer = iterator.next();
                        if (proxyXAResourceDeserializer.canDeserialze(className)) {
                            _theXAResource = proxyXAResourceDeserializer.deserialze(o);
                            deserialized = true;
                            break;
                        }
                    }
                    // Give it a go ourselves
                    if (!deserialized) {
                        try {
                            _theXAResource = (XAResource) o.readObject();
                            if (jtaLogger.logger.isTraceEnabled()) {
                                jtaLogger.logger.trace("XAResourceRecord.restore_state - XAResource de-serialized");
                            }
                        } catch (ClassNotFoundException e) {
                            // JBTM-2550 if we fail to deserialize the object, we treat it as haveXAResource is false
                            jtaLogger.i18NLogger.warn_resources_arjunacore_classnotfound(className);
                            haveXAResource = false;
                        }
                    }
                    o.close();
                } catch (Exception ex) {
                    // not serializable in the first place!
                    jtaLogger.i18NLogger.warn_resources_arjunacore_restorestate(ex);
                    return false;
                }
            }
            if (!haveXAResource) {
                /*
	                 * Lookup new XAResource via XARecoveryModule if possible.
	                 */
                _theXAResource = getNewXAResource();
                if (_theXAResource == null) {
                    jtaLogger.i18NLogger.warn_resources_arjunacore_norecoveryxa(toString());
                    /*
	                     * Don't prevent tx from activating because there may be
	                     * other participants that can still recover. Plus, we will
	                     * try to get a new XAResource later for this instance.
	                     */
                    res = true;
                }
            }
        } else {
            String creatorName = os.unpackString();
            _recoveryObject = ClassloadingUtility.loadAndInstantiateClass(RecoverableXAConnection.class, creatorName, null);
            if (_recoveryObject == null) {
                throw new ClassNotFoundException();
            }
            _recoveryObject.unpackFrom(os);
            _theXAResource = _recoveryObject.getResource();
            if (jtaLogger.logger.isTraceEnabled()) {
                jtaLogger.logger.trace("XAResourceRecord.restore_state - XAResource got from " + creatorName);
            }
        }
        res = true;
    } catch (Exception e) {
        jtaLogger.i18NLogger.warn_resources_arjunacore_restorestateerror(_theXAResource.toString(), XAHelper.xidToString(_tranID), e);
        res = false;
    } finally {
        if (res)
            res = super.restore_state(os, t);
        if (_heuristic != TwoPhaseOutcome.FINISH_OK) {
            jtaLogger.logger.warn("XAResourceRecord restored heuristic instance: " + this);
        }
    }
    return res;
}
Also used : SerializableXAResourceDeserializer(com.arjuna.ats.jta.recovery.SerializableXAResourceDeserializer) ByteArrayInputStream(java.io.ByteArrayInputStream) RecoverableXAConnection(com.arjuna.ats.jta.xa.RecoverableXAConnection) NotSerializableException(java.io.NotSerializableException) XAException(javax.transaction.xa.XAException) ObjectInputStream(java.io.ObjectInputStream)

Example 4 with SerializableXAResourceDeserializer

use of com.arjuna.ats.jta.recovery.SerializableXAResourceDeserializer in project narayana by jbosstm.

the class XAResourceRecord method restoreState.

public boolean restoreState(InputObjectState os) {
    boolean res = false;
    try {
        _heuristic = os.unpackInt();
        _committed = os.unpackBoolean();
        _tranID = XidImple.unpack(os);
        _theXAResource = null;
        _recoveryObject = null;
        if (os.unpackInt() == RecoverableXAConnection.OBJECT_RECOVERY) {
            boolean haveXAResource = os.unpackBoolean();
            if (haveXAResource) {
                try {
                    // Read the classname of the serialized XAResource
                    String className = os.unpackString();
                    byte[] b = os.unpackBytes();
                    ByteArrayInputStream s = new ByteArrayInputStream(b);
                    ObjectInputStream o = new ObjectInputStream(s);
                    // Give the list of deserializers a chance to deserialize the record
                    boolean deserialized = false;
                    Iterator<SerializableXAResourceDeserializer> iterator = getXAResourceDeserializers().iterator();
                    while (iterator.hasNext()) {
                        SerializableXAResourceDeserializer proxyXAResourceDeserializer = iterator.next();
                        if (proxyXAResourceDeserializer.canDeserialze(className)) {
                            _theXAResource = proxyXAResourceDeserializer.deserialze(o);
                            deserialized = true;
                            break;
                        }
                    }
                    try {
                        // Give it a go ourselves
                        if (!deserialized) {
                            _theXAResource = (XAResource) o.readObject();
                        }
                        if (jtaxLogger.logger.isTraceEnabled()) {
                            jtaxLogger.logger.trace("XAResourceRecord.restore_state - XAResource de-serialized");
                        }
                    } catch (ClassNotFoundException cnfe) {
                        jtaxLogger.i18NLogger.warn_could_not_load_class_will_wait_for_bottom_up(cnfe);
                    } finally {
                        o.close();
                    }
                } catch (Exception ex) {
                    // not serializable in the first place!
                    jtaxLogger.i18NLogger.warn_jtax_resources_jts_orbspecific_restoreerror1(ex);
                    return false;
                }
            }
        } else {
            String creatorName = os.unpackString();
            _recoveryObject = ClassloadingUtility.loadAndInstantiateClass(RecoverableXAConnection.class, creatorName, null);
            if (_recoveryObject == null) {
                throw new ClassNotFoundException();
            }
            _recoveryObject.unpackFrom(os);
            _theXAResource = _recoveryObject.getResource();
            if (_theXAResource == null) {
                jtaxLogger.i18NLogger.warn_jtax_resources_jts_orbspecific_norecoveryxa(XAHelper.xidToString(_tranID));
            }
            if (jtaxLogger.logger.isTraceEnabled()) {
                jtaxLogger.logger.trace("XAResourceRecord.restore_state - XAResource got from " + creatorName);
            }
        }
        boolean haveRecCoord = os.unpackBoolean();
        if (haveRecCoord) {
            String ior = os.unpackString();
            if (ior == null)
                return false;
            else {
                org.omg.CORBA.Object objRef = ORBManager.getORB().orb().string_to_object(ior);
                _recoveryCoordinator = RecoveryCoordinatorHelper.narrow(objRef);
            }
        } else
            _recoveryCoordinator = null;
        res = true;
    } catch (Exception e) {
        jtaxLogger.i18NLogger.warn_jtax_resources_jts_orbspecific_restoreerror2(e);
        res = false;
    } finally {
        if (_heuristic != TwoPhaseOutcome.FINISH_OK) {
            jtaxLogger.logger.warn("XAResourceRecord restored heuristic instance: " + this);
        }
    }
    return res;
}
Also used : SystemException(org.omg.CORBA.SystemException) XAException(javax.transaction.xa.XAException) NotSerializableException(java.io.NotSerializableException) SerializableXAResourceDeserializer(com.arjuna.ats.jta.recovery.SerializableXAResourceDeserializer) ByteArrayInputStream(java.io.ByteArrayInputStream) RecoverableXAConnection(com.arjuna.ats.jta.xa.RecoverableXAConnection) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

SerializableXAResourceDeserializer (com.arjuna.ats.jta.recovery.SerializableXAResourceDeserializer)4 RecoveryModule (com.arjuna.ats.arjuna.recovery.RecoveryModule)2 RecoverableXAConnection (com.arjuna.ats.jta.xa.RecoverableXAConnection)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 NotSerializableException (java.io.NotSerializableException)2 ObjectInputStream (java.io.ObjectInputStream)2 XAException (javax.transaction.xa.XAException)2 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)1 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule)1 SystemException (org.omg.CORBA.SystemException)1