/*
 * 
 * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
 * 
 * The contents of this file are subject to the Sun Community Source
 * License v3.0/Jini Technology Specific Attachment v 1.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://wwws.sun.com/software/jini/licensing/SCSL3_JiniTSA1.html.
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 * the License for the specific language governing rights and limitations
 * under the License.
 * 
 * The Reference Code is Jini Technology Core Platform code, v2.0. The
 * Developer of the Reference Code is Sun Microsystems, Inc.
 * 
 * Contributor(s): Sun Microsystems, Inc.
 * 
 */

package net.jini.core.event;

import net.jini.core.lease.Lease;

/**
 * A utility class for use as a return value for event-interest registration
 * methods.  Objects of this class are meant to encapsulate the information
 * needed by a client to identify a notification as a response to a
 * registration request and to maintain that registration request.  It is
 * not mandatory for an event-interest registration method to use this class.
 * <p>
 * A registration of interest in some kind of event that occurs within the
 * scope of a transaction is leased in the same way as other event interest
 * registrations.  However, the duration of the registration is the minimum
 * of the length of the lease and the duration of the transaction.  Simply
 * put, when the transaction ends (either because of a commit or an abort)
 * the interest registration also ends.  This is true even if the lease for
 * the event registration has not expired and no call has been made to
 * cancel the lease.
 *
 * @author Sun Microsystems, Inc.
 *
 * @since 1.0
 */
public class EventRegistration implements java.io.Serializable {

    private static final long serialVersionUID = 4055207527458053347L;

    /**
     * The event identifier.
     *
     * @serial
     */
    protected long eventID;

    /**
     * The event source.
     *
     * @serial
     */
    protected Object source;

    /**
     * The registration lease.
     *
     * @serial
     */
    protected Lease lease;

    /**
     * The current sequence number.
     *
     * @serial
     */
    protected long seqNum;

    /**
     * Constructs an <tt>EventRegistration</tt> object.
     *
     * @param eventID  a <tt>long</tt> representing the event identifier
     * @param source   an <tt>Object</tt> representing the event source
     * @param lease    the registration <tt>Lease</tt> object
     * @param seqNum   a <tt>long</tt> representing the current
     *                 sequence number
     */
    public EventRegistration(long eventID, Object source,
			     Lease lease, long seqNum) {
	this.eventID = eventID;
	this.source = source;
	this.lease = lease;
	this.seqNum = seqNum;
    }

    /**
     * Returns the identifier that will be used in all RemoteEvents generated
     * for this interest registration.
     *
     * @return a long used to identify all RemoteEvents that are generated
     *         for this interest registration.
     * @see RemoteEvent#getID
     */
    public long getID() {
	return eventID;
    }

    /**
     * Returns the source that will be used in all RemoteEvents generated
     * for this interest registration.
     *
     * @return an Object that represents the source of all RemoteEvents 
     *         for this interest registration
     * @see java.util.EventObject#getSource
     */
    public Object getSource() {
	return source;
    }

    /** 
     * Returns the Lease object for this registration. 
     * 
     * @return the Lease object for this registration.
     */
    public Lease getLease() {
	return lease;
    }

    /**
     * Returns the value of the sequence number on the event kind that was
     * current when the registration was granted, allowing comparison with
     * the sequence number in any subsequent notifications.
     *
     * @return a long representing the value of the sequence number on the 
     *         event type that was current when the registration was 
     *         granted, allowing comparison with the sequence number in any 
     *         subsequent notifications.
     */
    public long getSequenceNumber() {
	return seqNum;
    }
}
