
net.sf.eBus.client.sysmessages.AdMessage 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 2011, 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.EMessage.MessageType;
import net.sf.eBus.messages.EMessageKey;
/**
* Reports either a notification publisher or a request replier
* advertisement to a remote eBus application and whether the
* advertisement should be put into place or retracted.
*
* @author Charles Rapp
*/
@EFieldInfo(fields = {"adStatus", "adMessageType", "feedState"})
public final class AdMessage
extends AbstractKeyMessage
implements Serializable
{
//---------------------------------------------------------------
// Member methods.
//
//-----------------------------------------------------------
// Constructors.
//
/**
* Creates a new advertise message for the given status,
* message key, and message type. The subject and timestamp
* are set to the
* {@link net.sf.eBus.messages.ESystemMessage} defaults,
* {@link net.sf.eBus.messages.ESystemMessage#SYSTEM_SUBJECT}
* and the current time, respectively.
* @param adStatus add or retract this message.
* @param adMsgKey the advertised message class and subject.
* @param adMsgType the advertised message type.
* @param feedState advertised feed's current state.
* @throws IllegalArgumentException
* if either {@code adStatus}, {@code adMsgClass},
* {@code adMsgType}, or {@code adSubject} is {@code null}.
*/
public AdMessage(final EMessageKey adMsgKey,
final AdStatus adStatus,
final MessageType adMsgType,
final EFeedState feedState)
throws IllegalArgumentException
{
super (adMsgKey);
if (adStatus == null)
{
throw (
new IllegalArgumentException(
"adStatus is null"));
}
else if (adMsgType == null)
{
throw (
new IllegalArgumentException(
"adMsgType is null"));
}
this.adStatus = adStatus;
this.adMessageType = adMsgType;
this.feedState = feedState;
} // end of AdMessage(...)
/**
* Creates an outbound advertisement message for the given
* values. The subject and timestamp are set to the
* {@link net.sf.eBus.messages.ESystemMessage} defaults,
* {@link net.sf.eBus.messages.ESystemMessage#SYSTEM_SUBJECT}
* and the current time, respectively.
* @param adMsgClass the advertised message class.
* @param adMsgSubject the advertised message subject.
* @param adStatus add or retract this message.
* @param adMsgType advertised message type.
* @param feedState advertised feed's current state.
* @throws IllegalArgumentException
* if any of the given arguments are invalid.
*/
public AdMessage(final Class extends EMessage> adMsgClass,
final String adMsgSubject,
final AdStatus adStatus,
final MessageType adMsgType,
final EFeedState feedState)
throws IllegalArgumentException
{
super (adMsgClass, adMsgSubject);
if (adStatus == null)
{
throw (
new IllegalArgumentException(
"adStatus is null"));
}
else if (adMsgType == null)
{
throw (
new IllegalArgumentException(
"adMsgType is null"));
}
this.adStatus = adStatus;
this.adMessageType = adMsgType;
this.feedState = feedState;
} // end of AdMessage(...)
/**
* Creates an outbound AdMessage instance for the given
* values. The subject and timestamp are set to the
* {@link net.sf.eBus.messages.ESystemMessage} defaults,
* {@link net.sf.eBus.messages.ESystemMessage#SYSTEM_SUBJECT}
* and the current time, respectively.
* @param adMsgClass the advertised message class name.
* @param adMsgSubject the advertised message subject.
* @param adStatus add or retract this message.
* @param adMsgType advertised message type.
* @param feedState advertised feed's current state.
* @throws IllegalArgumentException
* if {@code subject} is either {@code null} or empty.
*/
public AdMessage(final String adMsgClass,
final String adMsgSubject,
final AdStatus adStatus,
final MessageType adMsgType,
final EFeedState feedState)
throws IllegalArgumentException
{
super (adMsgClass, adMsgSubject);
if (adStatus == null)
{
throw (
new IllegalArgumentException(
"adStatus is null"));
}
else if (adMsgType == null)
{
throw (
new IllegalArgumentException(
"adMsgType is null"));
}
this.adStatus = adStatus;
this.adMessageType = adMsgType;
this.feedState = feedState;
} // end of AdMessage(...)
/**
* Creates a new AdMessage instance for the de-serialized
* values. The subject and timestamp are set to the
* {@link net.sf.eBus.messages.ESystemMessage} defaults,
* {@link net.sf.eBus.messages.ESystemMessage#SYSTEM_SUBJECT}
* and the current time, respectively.
* @param subject {@link net.sf.eBus.messages.ESystemMessage#SYSTEM_SUBJECT}.
* @param timestamp the message millisecond timestamp.
* @param adStatus add or retract this message.
* @param adMsgClass the advertised message class name.
* @param adMsgSubject the advertised message subject.
* @param adMsgType advertised message type.
* @param feedState advertised feed's current state.
* @throws IllegalArgumentException
* if {@code subject} is either {@code null} or empty.
*/
public AdMessage(final String subject,
final long timestamp,
final String adMsgClass,
final String adMsgSubject,
final AdStatus adStatus,
final MessageType adMsgType,
final EFeedState feedState)
throws IllegalArgumentException
{
super (subject, timestamp, adMsgClass, adMsgSubject);
this.adStatus = adStatus;
this.adMessageType = adMsgType;
this.feedState = feedState;
} // end of AdMessage(...)
//
// end of Constructors.
//-----------------------------------------------------------
//-----------------------------------------------------------
// Object Method Overrides.
//
/**
* Returns {@code true} if {@code o} is a
* non-{@code null AdMessage} instance with ad status,
* message class, and message type equal to
* {@code this AdMessage} 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 AdMessage)
{
final AdMessage adMsg = (AdMessage) o;
retcode = (super.equals(o) == true &&
adStatus == adMsg.adStatus &&
adMessageType == adMsg.adMessageType &&
feedState == adMsg.feedState);
}
return (retcode);
} // end of equals(Object)
/**
* Returns the advertisement message hash code.
* @return the advertisement message hash code.
*/
@Override
public int hashCode()
{
return (
(((((super.hashCode() * 37) +
adStatus.ordinal()) * 37) +
adMessageType.ordinal()) * 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 advertise status: %s%n message type: %s%n feed state: %s",
super.toString(),
adStatus,
adMessageType,
feedState));
} // end of toString()
//
// end of Object Method Overrides.
//-----------------------------------------------------------
//---------------------------------------------------------------
// Enums.
//
/**
* This enum specifies whether an advertisement should be
* added or removed.
*/
public enum AdStatus
{
/**
* Put the advertisement in place.
*/
ADD,
/**
* Retract the advertisement.
*/
REMOVE
} // end of enum AdStatus
//---------------------------------------------------------------
// Member data.
//
/**
* Add or retract this advertisement.
*/
public final AdStatus adStatus;
/**
* The advertised message is for either a notification or a
* request.
*/
public final MessageType adMessageType;
/**
* The advertised feed's current state.
*/
public final EFeedState feedState;
//-----------------------------------------------------------
// Constants.
//
/**
* Serialization version identifier.
*/
private static final long serialVersionUID = 0x060201L;
} // end of class AdMessage
© 2015 - 2025 Weber Informatics LLC | Privacy Policy