All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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, 2019, 2020. Charles W. Rapp
// All Rights Reserved.
//

package net.sf.eBusx.monitor;

import java.io.Serializable;
import java.util.Formatter;
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 */ public final class MonitorUpdate extends ENotificationMessage implements Serializable { //--------------------------------------------------------------- // Member data. // //----------------------------------------------------------- // Constants. // /** * Serialization version identifier. */ private static final long serialVersionUID = 0x050200L; //----------------------------------------------------------- // Locals. // /** * 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; //--------------------------------------------------------------- // 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}. */ @Deprecated 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}. */ @Deprecated 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) private MonitorUpdate(final Builder builder) { super (builder); this.instance = builder.mInstance; this.updateFlag = builder.mUpdateFlag; } // end of MonitorUpdate(Builder) // // 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. //----------------------------------------------------------- public static Builder builder() { return (new Builder()); } // end of builder() //--------------------------------------------------------------- // Inner classes. // public static final class Builder extends ENotificationMessage.Builder { //----------------------------------------------------------- // Member data. // //------------------------------------------------------- // Locals. // private MonitorId mInstance; private boolean mUpdateFlag; //----------------------------------------------------------- // Member methods. // //------------------------------------------------------- // Constructors. // private Builder() { super (MonitorUpdate.class); this.subject(Monitor.MONITOR_UPDATE_SUBJECT); } // end of Builder() // // end of Constructors. //------------------------------------------------------- //------------------------------------------------------- // Builder Method Overrides. // @Override protected MonitorUpdate buildImpl() { return (new MonitorUpdate(this)); } // end of buildImpl() @Override protected Validator validate(final Validator problems) { return (super.validate(problems) .requireNotNull(mInstance, "instance")); } // end of validate(Validator) // // end of Builder Method Overrides. //------------------------------------------------------- //------------------------------------------------------- // Set Methods. // public Builder instance(final MonitorId id) { if (id == null) { throw (new NullPointerException("id is null")); } mInstance = id; return (this); } // end of instance(MonitorId) public Builder updateFlag(final boolean flag) { mUpdateFlag = flag; return (this); } // end of updateFlag(boolean) // // end of Set Methods. //------------------------------------------------------- } // end of class Builder } // end of class MonitorUpdate





© 2015 - 2024 Weber Informatics LLC | Privacy Policy