net.sf.eBusx.monitor.MonitorUpdate 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, 2016. Charles W. Rapp
// All Rights Reserved.
//
package net.sf.eBusx.monitor;
import java.io.Serializable;
import java.util.Formatter;
import net.sf.eBus.messages.EFieldInfo;
import net.sf.eBus.messages.ENotificationMessage;
/**
* Reports the {@link Monitor#register(Monitorable) registration}
* or {@link Monitor#deregister(Monitorable) deregistration} or
* a {@link Monitorable} instance. The {@link #instance} field
* contains the monitored object unique identifier and
* {@link #updateFlag} is {@code true} if the object registered
* and {@code false} if the object deregistered.
*
* In order to receive this notification message, subscribe to:
* {@code net.sf.eBusx.monitor.MonitorUpdate}:{@link Monitor#MONITOR_UPDATE_SUBJECT}.
*
* @see ApplicationInfo
* @see Monitor
*
* @author Charles Rapp
*/
@EFieldInfo(fields={"instance", "updateFlag"})
public final class MonitorUpdate
extends ENotificationMessage
implements Serializable
{
//---------------------------------------------------------------
// Member methods.
//
//-----------------------------------------------------------
// Constructors.
//
/**
* Creates a new MonitorUpdate instance for the given
* instance and flag.
* @param subject the notification subject.
* @param inst the updated monitored instance.
* @param flag the update type.
* @exception IllegalArgumentException
* if {@code inst} is {@code null}.
*/
public MonitorUpdate(final String subject,
final MonitorId inst,
final boolean flag)
throws IllegalArgumentException
{
this (subject,
System.currentTimeMillis(),
inst,
flag);
} // end of MonitorUpdate(String, MonitorId, boolean)
/**
* Deserialization constructor.
* @param subject the notification subject.
* @param timestamp the message timestamp.
* @param inst updated instance.
* @param flag update type.
* @exception IllegalArgumentException
* if {@code inst} is {@code null}.
*/
public MonitorUpdate(final String subject,
final long timestamp,
final MonitorId inst,
final boolean flag)
throws IllegalArgumentException
{
super (subject, timestamp);
if (inst == null)
{
throw (new IllegalArgumentException("null inst"));
}
instance = inst;
updateFlag = flag;
} // end of MonitorUpdate(String, long, MonitorId, boolean)
//
// end of Constructors.
//-----------------------------------------------------------
//-----------------------------------------------------------
// Object Method Overrides.
//
@Override
public String toString()
{
final Formatter retval = new Formatter();
retval.format("%s%n instance: %s%n",
super.toString(),
instance);
retval.format(" update: %b",
updateFlag);
return (retval.toString());
} // end of toString()
//
// end of Object Method Overrides.
//-----------------------------------------------------------
//---------------------------------------------------------------
// Member data.
//
/**
* This monitored object was either added or removed.
*/
public final MonitorId instance;
/**
* {@code true} if added and {@code false} if removed.
*/
public final boolean updateFlag;
//-----------------------------------------------------------
// Constants.
//
/**
* Serialization version identifier.
*/
private static final long serialVersionUID = 0x060100L;
} // end of class MonitorUpdate