/**
* High Availability Service (HA) for JOnAS
*
* Copyright (C) 2007,2008 Bull S.A.S.
* Copyright (C) 2006 Distributed Systems Lab.
* Universidad Polit??cnica de Madrid (Spain)
* Contact: http://lsd.ls.fi.upm.es/lsd
*
* This library 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 any later version.
*
* This library 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 library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* --------------------------------------------------------------------------
* $Id$
* --------------------------------------------------------------------------
*/

package org.ow2.jonas.lib.ejb21.ha.interceptors.jrmp;

import org.ow2.carol.rmi.jrmp.interceptor.spi.JServiceContext;
import org.ow2.cmi.ha.RequestId;
import org.ow2.cmi.ha.interceptor.HAContext;

/**
 * This class holds the required information to pass between client/server
 * through HA interceptors
 * @author Francisco Perez-Sorrosal (fpsorrosal@no-spam@fi.upm.es)
 * @author Alberto Paz-Jimenez (apaz@no-spam@fi.upm.es)
 */
public class HAServiceContext  implements JServiceContext {

    /**
     * Id for serializable class.
     */
    private static final long serialVersionUID = -865951509875031008L;

    /**
     * A unique identifier for HA context
     */
    public static int HA_CTX_ID = 6666;

    private final HAContext haContext;

    /**
     * Constructor
     */
    public HAServiceContext(final HAContext haContext) {
        this.haContext = haContext;
    }

    /**
     * Returns the HA context identifier
     * @return the HA context id
     */
    public int getContextId() {
        return HA_CTX_ID;
    }



    /**
     * Returns a string representation of the object
     * @return the string representing the HAContext
     */
    @Override
    public String toString() {
        String ret = "\nHAContext: " + HA_CTX_ID + "\n";

        ret += "\tRequests:\n";
        for(RequestId request : haContext.getRequests()) {
            ret += "\t\t" + request + "\n";
        }
        ret += "\tOnFailover:" + haContext.isOnFailover() + "\n";

        return ret;

    }

    public HAContext getHaContext() {
        return haContext;
    }

}
