net.sf.eBusx.util.TimerReply Maven / Gradle / Ivy
//
// 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 (at your option) 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
//
// The Initial Developer of the Original Code is Charles W. Rapp.
// Portions created by Charles W. Rapp are
// Copyright 2012. 2013, 2015, 2016. Charles W. Rapp
// All Rights Reserved.
//
package net.sf.eBusx.util;
import java.io.Serializable;
import net.sf.eBus.client.ERequestFeed;
import net.sf.eBus.messages.EFieldInfo;
import net.sf.eBus.messages.EReplyMessage;
import net.sf.eBus.messages.EReplyMessage.ReplyStatus;
/**
* This reply message is sent when the requested timer expires.
* The reply contains the requestor-defined timer name and
* sequence number. If this is a one-shot timer, then
* {@link #replyStatus} is set to {@link ReplyStatus#OK_FINAL} and
* {@link #sequenceNumber} the final reply flag is set zero.
* Repeating timers always have a {@link #replyStatus} of
* {@link ReplyStatus#OK_CONTINUING} since timer replies keep
* coming until either the requestor
* {@link ERequestFeed.ERequest#close() closes} the timer or
* {@link ETimer} is {@link ETimer#stopETimer() shut down}.
*
* @author Charles W. Rapp
*/
@EFieldInfo(fields={"timerName", "sequenceNumber"})
public final class TimerReply
extends EReplyMessage
implements Serializable
{
//---------------------------------------------------------------
// Member methods.
//
//-----------------------------------------------------------
// Constructors.
//
/**
* Creates a new timer reply instance for the given timer
* name and sequence number.
* @param timerName the expired timer name.
* @param status either {@link ReplyStatus#OK_FINAL} if this
* is a one-time timer or {@link ReplyStatus#OK_CONTINUING}
* if this is an on-going timer.
* @param seqNum the timer sequence number.
* @throws IllegalArgumentException
* if {@code timerName} is either {@code null} or empty.
*/
public TimerReply(final String timerName,
final ReplyStatus status,
final int seqNum)
throws IllegalArgumentException
{
this (ETimer.TIMER_SUBJECT,
System.currentTimeMillis(),
status,
null,
timerName,
seqNum);
} // end of TimerReply(String, ReplyStatus, int)
/**
* The de-serialization constructor.
* @param subject the message subject.
* @param timestamp the message timestamp.
* @param status the reply status.
* @param reason the reply reason.
* @param timerName the expired timer name.
* @param seqNum the timer sequence number.
* @throws IllegalArgumentException
* if {@code timerName} is either {@code null} or empty.
*/
public TimerReply(final String subject,
final long timestamp,
final ReplyStatus status,
final String reason,
final String timerName,
final int seqNum)
throws IllegalArgumentException
{
super (subject,
timestamp,
status,
reason);
if (timerName == null || timerName.isEmpty() == true)
{
throw (
new IllegalArgumentException(
"timerName is null or empty"));
}
this.timerName = timerName;
this.sequenceNumber = seqNum;
} // end of TimerReply(...)
//
// end of Constructors.
//-----------------------------------------------------------
//-----------------------------------------------------------
// Object Method Overrides.
//
// Use default javadoc.
@Override
public boolean equals(final Object o)
{
boolean retcode = (this == o);
if (retcode == false &&
o instanceof TimerReply)
{
final TimerReply reply = (TimerReply) o;
retcode =
(super.equals(o) == true &&
timerName.equals(reply.timerName) == true &&
sequenceNumber == reply.sequenceNumber);
}
return (retcode);
} // end of equals(Object)
// Use default javadoc.
@Override
public int hashCode()
{
return ((((super.hashCode() * 37) +
timerName.hashCode()) * 37) +
sequenceNumber);
} // end of hashCode()
//
// end of Object Method Overrides.
//-----------------------------------------------------------
//---------------------------------------------------------------
// Member data.
//
/**
* The requestor-assigned name for this timer request.
*/
public final String timerName;
/**
* The time message sequence number. Values begin at zero.
* This means that a one-time timer has a zero sequence
* number.
*/
public final int sequenceNumber;
//-----------------------------------------------------------
// Constants.
//
/**
* Serialization version identifier.
*/
private static final long serialVersionUID = 0x060100L;
} // end of class TimerReply
© 2015 - 2025 Weber Informatics LLC | Privacy Policy