
net.sf.eBus.client.sysmessages.SubscribeMessage 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.eBus.client.sysmessages;
import java.io.Serializable;
import net.sf.eBus.client.EFeedState;
import net.sf.eBus.messages.EFieldInfo;
import net.sf.eBus.messages.EMessage;
import net.sf.eBus.messages.EMessageKey;
/**
* This message is sent to a remote publisher to have a
* notification feed either started or stopped.
*
* @author Charles Rapp
*/
@EFieldInfo(fields={"feedState"})
public final class SubscribeMessage
extends AbstractKeyMessage
implements Serializable
{
//---------------------------------------------------------------
// Member methods.
//
//-----------------------------------------------------------
// Constructors.
//
/**
* Creates an outbound publish status message for the given
* message key and up/down flag.
* @param msgKey notification message key.
* @param fs feed state. {@code EFeedState.UP} means start
* the feed and {@code EFeedState.DOWN} means stop the feed.
* @throws IllegalArgumentException
* if {@code fs} is {@code null}.
*
* @see #SubscribeMessage(Class, String, EFeedState)
* @see #SubscribeMessage(String, String, EFeedState)
* @see #SubscribeMessage(String, long, String, String, EFeedState)
*/
public SubscribeMessage(final EMessageKey msgKey,
final EFeedState fs)
throws IllegalArgumentException
{
super (msgKey);
if (fs == null)
{
throw (new IllegalArgumentException("fs is null"));
}
this.feedState = fs;
} // end of SubscribeMessage(EMessageKey, EFeedState)
/**
* Creates a new PublishStatusMessage instance for the given
* feed flag. The subject and timestamp are set to the
* {@link net.sf.eBus.messages.ESystemMessage} defaults which
* are
* {@link net.sf.eBus.messages.ESystemMessage#SYSTEM_SUBJECT}
* and {@link System#currentTimeMillis()}, respectively.
* @param mc the notification message class.
* @param msgSubject the notification message subject.
* @param fs feed state. {@code EFeedState.UP} means start
* the feed and {@code EFeedState.DOWN} means stop the feed.
* @throws IllegalArgumentException
* if {@code fs} is {@code null}.
*
* @see #SubscribeMessage(EMessageKey, EFeedState)
* @see #SubscribeMessage(String, String, EFeedState)
* @see #SubscribeMessage(String, long, String, String, EFeedState)
*/
public SubscribeMessage(final Class extends EMessage> mc,
final String msgSubject,
final EFeedState fs)
throws IllegalArgumentException
{
super (mc, msgSubject);
if (fs == null)
{
throw (new IllegalArgumentException("fs is null"));
}
this.feedState = fs;
} // end of SubscribeMessage(Class, String, EFeedState)
/**
* Create a new PublishStatus instance for the given
* parameters.
* @param msgClass the notification message class name.
* @param msgSubject the notification message subject.
* @param fs feed state. {@code EFeedState.UP} means start
* the feed and {@code EFeedState.DOWN} means stop the feed.
* @throws IllegalArgumentException
* if {@code msgClass} or {@code msgSubject} is either
* {@code null} or empty.
*
* @see #SubscribeMessage(EMessageKey, EFeedState)
* @see #SubscribeMessage(Class, String, EFeedState)
* @see #SubscribeMessage(String, long, String, String, EFeedState)
*/
public SubscribeMessage(final String msgClass,
final String msgSubject,
final EFeedState fs)
throws IllegalArgumentException
{
super (msgClass, msgSubject);
if (fs == null)
{
throw (new IllegalArgumentException("fs is null"));
}
this.feedState = fs;
} // end of SubscribeMessage(String, String, EFeedState)
/**
* Creates a new PublishStatus instance with the given
* de-serialized parameters.
* @param subject {@link net.sf.eBus.messages.ESystemMessage#SYSTEM_SUBJECT}.
* @param timestamp message timestamp.
* @param msgClass the notification message class.
* @param msgSubject the notification message subject.
* @param fs feed state. {@code EFeedState.UP} means start
* the feed and {@code EFeedState.DOWN} means stop the feed.
* @throws IllegalArgumentException
* if {@code fs} is {@code null}.
*
* @see #SubscribeMessage(EMessageKey, EFeedState)
* @see #SubscribeMessage(Class, String, EFeedState)
* @see #SubscribeMessage(String, String, EFeedState)
*/
public SubscribeMessage(final String subject,
final long timestamp,
final String msgClass,
final String msgSubject,
final EFeedState fs)
throws IllegalArgumentException
{
super (subject, timestamp, msgClass, msgSubject);
if (fs == null)
{
throw (new IllegalArgumentException("fs is null"));
}
this.feedState = fs;
} // end of SubscribeMessage(...)
//
// end of Constructors.
//-----------------------------------------------------------
//-----------------------------------------------------------
// Object Method Overrides.
//
/**
* Returns {@code true} if {@code o} is a
* non-{@code null SubscribeMessage} instance with the
* same up flag as {@code this SubscribeMessage} instance
* and {@code false} otherwise.
* @param o comparison object.
* @return {@code true} if the message fields are equal
* and {@code false} otherwise.
*/
@Override
public boolean equals(final Object o)
{
boolean retcode = (this == o);
if (retcode == false &&
o instanceof SubscribeMessage)
{
final SubscribeMessage psm =
(SubscribeMessage) o;
retcode = (super.equals(o) == true &&
feedState == psm.feedState);
}
return (retcode);
} // end of equals(Object)
/**
* Returns the feed status message hash code.
* @return the feed status message hash code.
*/
@Override
public int hashCode()
{
return ((super.hashCode() * 37) + feedState.ordinal());
} // end of hashCode()
/**
* Returns a human-readable text version of this message.
* @return text version of this message.
*/
@Override
public String toString()
{
return (
String.format("%s%n feed state: %s",
super.toString(),
feedState));
} // end of toString()
//
// end of Object Method Overrides.
//-----------------------------------------------------------
//---------------------------------------------------------------
// Member data.
//
/**
* The subscription is either {@code EFeedState.UP} or
* {@code EFeedState.DOWN}.
*/
public final EFeedState feedState;
//-----------------------------------------------------------
// Constants.
//
/**
* Serialization version identifier.
*/
private static final long serialVersionUID = 0x060100L;
} // end of class SubscribeMessage
© 2015 - 2025 Weber Informatics LLC | Privacy Policy