Apache.NMS.ActiveMQ.Transactions.RecoveryFileLogger.LogRecoveryInfo C# (CSharp) Method

LogRecoveryInfo() public method

public LogRecoveryInfo ( XATransactionId xid, byte recoveryInformation ) : void
xid Apache.NMS.ActiveMQ.Commands.XATransactionId
recoveryInformation byte
return void
        public void LogRecoveryInfo(XATransactionId xid, byte[] recoveryInformation)
        {
            if (recoveryInformation == null || recoveryInformation.Length == 0)
            {
                return;
            }

            try
            {
                lock (syncRoot)
                {
                    RecoveryInformation info = new RecoveryInformation(xid, recoveryInformation);
                    Tracer.Debug("Serializing Recovery Info to file: " + Filename);

                    IFormatter formatter = new BinaryFormatter();
                    using (FileStream recoveryLog = new FileStream(Filename, FileMode.OpenOrCreate, FileAccess.Write))
                    {
                        formatter.Serialize(recoveryLog, info);
                    }
                }
            }
            catch (Exception ex)
            {
                Tracer.Error("Error while storing TX Recovery Info, message: " + ex.Message);
                throw;
            }
        }

Usage Example

Exemplo n.º 1
0
        public void TestRecoverLoggedRecord()
        {
            RecoveryFileLogger logger = new RecoveryFileLogger();

            byte[] globalId = new byte[32];
            byte[] branchQ = new byte[32];
            byte[] recoveryData = new byte[256];

            Random gen = new Random();

            gen.NextBytes(globalId);
            gen.NextBytes(branchQ);
            gen.NextBytes(recoveryData);

            logger.Location = nonDefaultLogLocation;
            logger.Initialize(rmId.ToString());

            XATransactionId xid = new XATransactionId();
            xid.GlobalTransactionId = globalId;
            xid.BranchQualifier = branchQ;

            logger.LogRecoveryInfo(xid, recoveryData);

            Assert.IsTrue(File.Exists(logger.Location + Path.DirectorySeparatorChar + rmId.ToString() + ".bin"),
                          "Recovery File was not created");
            Assert.IsTrue(logger.GetRecoverables().Length == 1,
                          "Did not recover the logged record.");

            KeyValuePair<XATransactionId, byte[]>[] records = logger.GetRecoverables();
            Assert.AreEqual(1, records.Length);

            Assert.AreEqual(globalId, records[0].Key.GlobalTransactionId, "Incorrect Global TX Id returned");
            Assert.AreEqual(branchQ, records[0].Key.BranchQualifier, "Incorrect Branch Qualifier returned");
            Assert.AreEqual(recoveryData, records[0].Value, "Incorrect Recovery Information returned");
        }
All Usage Examples Of Apache.NMS.ActiveMQ.Transactions.RecoveryFileLogger::LogRecoveryInfo