/** 
 * 
 * Copyright 2004 Protique Ltd
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 * 
 **/

package org.codehaus.activemq.message;

/**
 * Denotes life cycle infomation for a Producer of messages
 */

public class ProducerInfo extends AbstractPacket {
    private ActiveMQDestination destination;
    private String producerId;
    private String clientId;
    private String sessionId;
    private long startTime;
    private boolean started;


    /**
     * Test for equality
     *
     * @param obj object to test
     * @return true if equivalent
     */
    public boolean equals(Object obj) {
        boolean result = false;
        if (obj != null && obj instanceof ProducerInfo) {
            ProducerInfo info = (ProducerInfo) obj;
            result = this.producerId == info.producerId;
        }
        return result;
    }

    /**
     * @return hash code for instance
     */
    public int hashCode() {
        return this.producerId != null ? this.producerId.hashCode() : super.hashCode();
    }


    /**
     * @return Returns the producerId.
     */
    public String getProducerId() {
        return producerId;
    }

    /**
     * @param producerId The producerId to set.
     */
    public void setProducerId(String producerId) {
        this.producerId = producerId;
    }

    /**
     * @return Returns the sessionId.
     */
    public String getSessionId() {
        return sessionId;
    }

    /**
     * @param sessionId The sessionId to set.
     */
    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    /**
     * Return the type of Packet
     *
     * @return integer representation of the type of Packet
     */

    public int getPacketType() {
        return PRODUCER_INFO;
    }


    /**
     * @return Returns the clientId.
     */
    public String getClientId() {
        return this.clientId;
    }

    /**
     * @param newClientId The clientId to set.
     */
    public void setClientId(String newClientId) {
        this.clientId = newClientId;
    }


    /**
     * @return Returns the destination.
     */
    public ActiveMQDestination getDestination() {
        return this.destination;
    }

    /**
     * @param newDestination The destination to set.
     */
    public void setDestination(ActiveMQDestination newDestination) {
        this.destination = newDestination;
    }


    /**
     * @return Returns the started.
     */
    public boolean isStarted() {
        return this.started;
    }

    /**
     * @param flag to indicate if started
     */
    public void setStarted(boolean flag) {
        this.started = flag;
    }

    /**
     * @return Returns the startTime.
     */
    public long getStartTime() {
        return this.startTime;
    }

    /**
     * @param newStartTime The startTime to set.
     */
    public void setStartTime(long newStartTime) {
        this.startTime = newStartTime;
    }

    public String toString() {
        return super.toString() + " ProducerInfo{ " +
                "clientId = '" + clientId + "' " +
                ", destination = " + destination +
                ", producerId = '" + producerId + "' " +
                ", sessionId = '" + sessionId + "' " +
                ", startTime = " + startTime +
                ", started = " + started +
                " }";
    }
}
