001/*
002 * jPOS Project [http://jpos.org]
003 * Copyright (C) 2000-2026 jPOS Software SRL
004 *
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Affero General Public License as
007 * published by the Free Software Foundation, either version 3 of the
008 * License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU Affero General Public License for more details.
014 *
015 * You should have received a copy of the GNU Affero General Public License
016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
017 */
018
019package org.jpos.transaction;
020
021import java.io.Serializable;
022
023public class TransactionStatusEvent {
024    int session;
025    long id;
026    long timestamp;
027    String info;
028    State state;
029    Serializable context;
030
031    public enum State {
032        READY(0),
033        PREPARING(1),
034        PREPARING_FOR_ABORT(2),
035        COMMITING(3),
036        ABORTING(4),
037        DONE(5),
038        PAUSED(6);
039
040        int state;
041        String[] stateAsString = new String[] {
042            "Ready", "Preparing", "Preparing for abort", "Commiting", "Aborting", "Done", "Paused"
043        };
044        State (int state) {
045            this.state = state;
046        }
047        public String toString () {
048            return stateAsString [state];
049        }
050        public int intValue() {
051            return state;
052        }
053    }
054
055    public TransactionStatusEvent (int session, State state, long id, String info, Serializable context) {
056        super();
057        this.session = session;
058        this.state = state;
059        this.id = id;
060        this.info = info;
061        this.context = context;
062        timestamp = System.nanoTime();
063    }
064    public String toString() {
065        return String.format("%02d %08d %s %s", session, id, state.toString(), info);
066    }
067    public int getSession() {
068        return session;
069    }
070    public long getId() {
071        return id;
072    }
073    public String getInfo() {
074        return info;
075    }
076    public State getState() {
077        return state;
078    }
079    public String getStateAsString () {
080        return state.toString();
081    }
082    public Serializable getContext(){
083        return context;
084    }
085}