
net.sf.eBus.client.sysmessages.AbstractLogonMessage 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 2013, 2016. Charles W. Rapp
// All Rights Reserved.
//
package net.sf.eBus.client.sysmessages;
import java.io.Serializable;
import net.sf.eBus.messages.EFieldInfo;
import net.sf.eBus.messages.ESystemMessage;
/**
* Base class for the eBus logon messages {@link LogonMessage},
* {@link LogonReply}, and {@link LogoffMessage}. Contains the
* unique eBus identifier. For a Java application, this is the
* JVM identifier and for a .Net application, the process
* identifier.
*
* @author Charles Rapp
*/
@EFieldInfo(fields={"eid"})
public abstract class AbstractLogonMessage
extends ESystemMessage
implements Serializable
{
//---------------------------------------------------------------
// Member methods.
//
//-----------------------------------------------------------
// Constructors.
//
/**
* Creates a new abstract logon message for the given eBus
* identifier. The subject and timestamp are set to the
* {@link ESystemMessage} defaults.
* @param eid the eBus identifier.
* @throws IllegalArgumentException
* if {@code eid} is either {@code null} or empty.
*/
protected AbstractLogonMessage(final String eid)
throws IllegalArgumentException
{
super ();
if (eid == null || eid.isEmpty() == true)
{
throw (
new IllegalArgumentException(
"null or empty eid"));
}
this.eid = eid;
} // end of AbstractLogonMessage(String)
/**
* Creates a new abstract logon message from the
* de-serialized values.
* @param subject {@link ESystemMessage#SYSTEM_SUBJECT}.
* @param timestamp the message millisecond timestamp.
* @param eid the eBus identifier.
* @throws IllegalArgumentException
* if {@code subject} is either {@code null} or empty.
*/
protected AbstractLogonMessage(final String subject,
final long timestamp,
final String eid)
throws IllegalArgumentException
{
super (subject, timestamp);
if (eid == null || eid.isEmpty() == true)
{
throw (
new IllegalArgumentException(
"null or empty eid"));
}
this.eid = eid;
} // end of AbstractLogonMessage(String, long, String)
//
// end of Constructors.
//-----------------------------------------------------------
//-----------------------------------------------------------
// Object Method Overrides.
//
/**
* Returns {@code true} if {@code o} is a
* non-{@code null AbstractLogonMessage} instance with an
* eBus identifier equal to
* {@code this AbstractLogonMessage} 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 AbstractLogonMessage)
{
final AbstractLogonMessage alm =
(AbstractLogonMessage) o;
retcode = (super.equals(o) == true &&
eid.equals(alm.eid) == true);
}
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) + eid.hashCode());
} // 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 eBus ID: %s",
super.toString(),
eid));
} // end of toString()
//
// end of Object Method Overrides.
//-----------------------------------------------------------
//---------------------------------------------------------------
// Member data.
//
/**
* The eBus identifier.
*/
public final String eid;
//-----------------------------------------------------------
// Constants.
//
/**
* Serialization version identifier.
*/
private static final long serialVersionUID = 0x060100L;
} // end of class AbstractLogonMessage
© 2015 - 2025 Weber Informatics LLC | Privacy Policy