net.sf.eBusx.monitor.MonitorId 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, 2016. Charles W. Rapp
// All Rights Reserved.
//
package net.sf.eBusx.monitor;
import java.io.Serializable;
import net.sf.eBus.messages.EField;
import net.sf.eBus.messages.EFieldInfo;
/**
* A passive, immutable class for storing a monitored object's
* type name, instance name and its assigned unique, 4-byte
* integer identifier. The {@link #toString()} return value
* serves as the subject for the {@link Monitorable} instance
* {@link PersistentStatusMessage} and
* {@link TransientStatusMessage} notifications.
*
* @author Charles Rapp
*/
@EFieldInfo (fields = {"typeName", "instanceName", "id"})
public final class MonitorId
extends EField
implements Serializable
{
//---------------------------------------------------------------
// Member methods.
//
//-----------------------------------------------------------
// Constructors.
//
/**
* Creates a new {@code MonitorId} instance.
* @param typeName the object type name.
* @param instanceName the object name. Should be unique
* within the process for the given type name.
* @param id the assigned unique identifier. Unique within
* the process.
*/
public MonitorId(final String typeName,
final String instanceName,
final int id)
{
this.typeName = typeName;
this.instanceName = instanceName;
this.id = id;
} // end of MonitorId(String, String, int)
//
// end of Constructors.
//-----------------------------------------------------------
//-----------------------------------------------------------
// Object Method Overrides.
//
/**
* Returns {@code true} if {@code o} is a
* non-{@code null MonitorId} instance with the same
* integer identifier; otherwise, returns {@code false}.
* @param o comparison object.
* @return {@code true} if {@code o} equals
* {@code this MonitorId} instance and {@code false}
* otherwise.
*/
@Override
public boolean equals(final Object o)
{
boolean retcode = (this == o);
if (retcode == false && o instanceof MonitorId)
{
retcode = (id == ((MonitorId) o).id);
}
return (retcode);
} // end of equals(Object)
/**
* Returns the unique, 4-byte, signed monitor identifier.
* @return the unique, 4-byte, signed monitor identifier.
*/
@Override
public int hashCode()
{
return (id);
} // end of hashCode()
/**
* Returns "<type name>.<instance name>". This
* return values is the subject for a registered
* {@link Monitorable} instance
* {@link PersistentStatusMessage} and
* {@link TransientStatusMessage} notifications.
* @return the textual representation of this monitor
* identifier.
*/
@Override
public String toString()
{
return (String.format("%s.%s", typeName, instanceName));
} // end of toString()
//
// end of Object Method Overrides.
//-----------------------------------------------------------
//---------------------------------------------------------------
// Member data.
//
/**
* The monitored object's type.
*/
public final String typeName;
/**
* The monitored object's name. Should be unique within the
* type and process.
*/
public final String instanceName;
/**
* The object's assigned integer identifier.
*/
public final int id;
//-----------------------------------------------------------
// Constants.
//
/**
* Serialization version identifier.
*/
private static final long serialVersionUID = 0x060100L;
} // end of MonitorId
© 2015 - 2025 Weber Informatics LLC | Privacy Policy