net.sf.eBusx.monitor.MonitorUpdate Maven / Gradle / Ivy
//
// Copyright 2012, 2013, 2016, 2019, 2020 Charles W. Rapp
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package net.sf.eBusx.monitor;
import java.io.Serializable;
import net.sf.eBus.messages.ENotificationMessage;
import net.sf.eBus.util.Validator;
/**
* 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.
//
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 StringBuilder retval = new StringBuilder();
retval.append(super.toString())
.append("\n instance: ")
.append(instance)
.append("\n update: ")
.append(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