Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
//
// 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 com.google.common.base.Strings;
import java.io.Serializable;
import java.util.Formatter;
import net.sf.eBus.messages.ENotificationMessage;
/**
* Reports a monitorable object's on-going status. This status
* is in effect until further notice. The notification subject
* is the {@link MonitorId#typeName} and
* {@link MonitorId#instanceName} in the format
* "<type name>.<instance name>". This means that
* in order to subscribe to this notification, you must first
* request the registered monitored objects using the
* {@link MonitoredObjectRequest} message.
*
* @author Charles Rapp
*/
public final class PersistentStatusMessage
extends ENotificationMessage
implements Serializable
{
//---------------------------------------------------------------
// Member data.
//
//-----------------------------------------------------------
// Constants.
//
/**
* Serialization version identifier.
*/
private static final long serialVersionUID = 0x050200L;
//-----------------------------------------------------------
// Locals.
//
/**
* The monitored object's 4-byte integer identifier.
*/
public final int instance;
/**
* The instance on-going action level.
*/
public final ActionLevel actionLevel;
/**
* The on-going action name.
*/
public final String actionName;
/**
* Optional message explaining the action.
*/
public final String actionMessage;
//---------------------------------------------------------------
// Member methods.
//
//-----------------------------------------------------------
// Constructors.
//
/**
* Creates a new instance of PersistentStatusMessage.
* @param subject the
* {@link MonitorId#toString() monitor identifier}.
* @param inst the monitored instance integer identifier.
* @param level the action level.
* @param name the action name.
* @param message the action message.
*/
@Deprecated
public PersistentStatusMessage(final String subject,
final int inst,
final ActionLevel level,
final String name,
final String message)
{
this (subject,
System.currentTimeMillis(),
inst,
level,
name,
message);
} // end of PersistentStatusMessage(...)
/**
* Deserialization constructor.
* @param subject the
* {@link MonitorId#toString() monitor identifier}.
* @param timestamp message timestamp.
* @param inst the monitored instance integer identifier.
* @param level the action level.
* @param name the action name.
* @param message the action message.
*/
@Deprecated
public PersistentStatusMessage(final String subject,
final long timestamp,
final int inst,
final ActionLevel level,
final String name,
final String message)
{
super (subject, timestamp);
instance = inst;
actionLevel = level;
actionName = name;
actionMessage = message;
} // end of PersistentStatusMessage(...)
private PersistentStatusMessage(final Builder builder)
{
super (builder);
this.instance = builder.mInstanceId;
this.actionLevel = builder.mActionLevel;
this.actionName = builder.mActionName;
this.actionMessage = builder.mActionMessage;
} // end of PerisistentStatusMessage(Builder)
//
// end of Constructors.
//-----------------------------------------------------------
//-----------------------------------------------------------
// Object Method Overrides.
//
/**
* Returns the application information message as text.
* @return textual representation of application information.
*/
@Override
public String toString()
{
final Formatter retval = new Formatter();
retval.format("%s%n instance: %s%n",
super.toString(),
instance);
retval.format(" action level: %s%n",
actionLevel);
retval.format(" action name: %s%n",
actionName);
retval.format(" action message: %s",
actionMessage);
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 int mInstanceId;
private ActionLevel mActionLevel;
private String mActionName;
private String mActionMessage;
//-----------------------------------------------------------
// Member methods.
//
//-------------------------------------------------------
// Constructors.
//
private Builder()
{
super (PersistentStatusMessage.class);
} // end of Builder()
//
// end of Constructors.
//-------------------------------------------------------
//-------------------------------------------------------
// Builder Method Overrides.
//
@Override
public PersistentStatusMessage buildImpl()
{
return (new PersistentStatusMessage(this));
} // end of buildImpl()
@Override
public Validator validate(final Validator problems)
{
return (super.validate(problems)
.requireNotNull(mActionLevel,
"actionLevel")
.requireNotNull(mActionName,
"actionName"));
} // end of validate()
//
// end of Builder Method Overrides.
//-------------------------------------------------------
//-------------------------------------------------------
// Set Methods.
//
public Builder instance(final int id)
{
mInstanceId = id;
return (this);
} // end of instance(int)
public Builder actionLevel(final ActionLevel level)
{
if (level == null)
{
throw (new NullPointerException("level is null"));
}
mActionLevel = level;
return (this);
} // end of actionLevel(ActionLevel)
public Builder actionName(final String name)
{
if (Strings.isNullOrEmpty(name))
{
throw (
new IllegalArgumentException(
"name is null or empty"));
}
mActionName = name;
return (this);
} // end of actionName(String)
public Builder actionMessage(final String message)
{
mActionMessage = message;
return (this);
} // end of actionMessage(String)
//
// end of Set Methods.
//-------------------------------------------------------
} // end of class Builder
} // end of class PersistentStatusMessage