net.sf.eBusx.monitor.ApplicationInfoReply Maven / Gradle / Ivy
The newest version!
//
// Copyright 2024 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 com.google.common.base.Strings;
import java.io.Serializable;
import java.util.Formatter;
import javax.annotation.Nullable;
import net.sf.eBus.messages.EField;
import net.sf.eBus.messages.EReplyMessage;
import net.sf.eBus.util.Validator;
/**
* Returns application information currently registered with
* {@link Monitor}.
*
* @see ApplicationInfoRequest
* @see ApplicationInfo
*
* @author Charles W. Rapp
*/
public final class ApplicationInfoReply
extends EReplyMessage
implements Serializable
{
//---------------------------------------------------------------
// Member data.
//
//-----------------------------------------------------------
// Constants.
//
/**
* Serialization version identifier.
*/
private static final long serialVersionUID = 0x070400L;
//-----------------------------------------------------------
// Locals.
//
/**
* Application is running on this named host. Note: this
* name does not necessarily need to be a network
* host name but should be a name meaningful to both the
* monitored system and those monitoring it.
*/
public final String hostName;
/**
* The application name.
*/
public final String appName;
/**
* The application version.
*/
public final String appVersion;
/**
* The application copyright information.
*/
@Nullable public final String copyright;
/**
* Optional human-readable description of this application.
*/
@Nullable public final String description;
/**
* The application-specific attributes.
*/
@Nullable public final EField attributes;
//---------------------------------------------------------------
// Member methods.
//
//-----------------------------------------------------------
// Constructors.
//
/**
* Creates a new application information reply instance
* based on builder's settings.
* @param builder contains reply settings.
*/
private ApplicationInfoReply(final Builder builder)
{
super (builder);
this.hostName = builder.mHost;
this.appName = builder.mAppName;
this.appVersion = builder.mAppVersion;
this.copyright = builder.mCopyright;
this.description = builder.mDescription;
this.attributes = builder.mAttributes;
} // end of ApplicationInfoReply(Builder)
//
// end of Constructors.
//-----------------------------------------------------------
//-----------------------------------------------------------
// Object Method Overrides.
//
/**
* Returns the application information message as text.
* @return textual representation of application information.
*/
@SuppressWarnings({"java:S3457"})
@Override
public String toString()
{
final String retval;
try (Formatter output = new Formatter())
{
output.format("%s%n host: %s%n",
super.toString(),
hostName)
.format(" app name: %s%n",
appName)
.format(" app version: %s%n",
appVersion)
.format(" copyright: %s%n",
copyright)
.format(" description: %s%n",
description)
.format(" attributes: ");
if (attributes == null)
{
output.format(" (none)");
}
else
{
output.format("%n%s", attributes);
}
retval = output.toString();
}
return (retval);
} // end of toString()
//
// end of Object Method Overrides.
//-----------------------------------------------------------
/**
* Returns a new instance of a {@code ApplicationInfoReply}
* message builder.
* @return new message builder instance.
*/
public static Builder builder()
{
return (new Builder());
} // end of builder()
//---------------------------------------------------------------
// Inner classes.
//
/**
* Builder class used to create an
* {@link ApplicationInfoReply} message. A
* new {@code Builder} instance is obtained from
* {@link ApplicationInfoReply#builder()}.
*/
public static final class Builder
extends EReplyMessage.Builder
{
//-----------------------------------------------------------
// Member data.
//
//-------------------------------------------------------
// Locals.
//
private String mHost;
private String mAppName;
private String mAppVersion;
@Nullable private String mCopyright;
@Nullable private String mDescription;
@Nullable private EField mAttributes;
//-----------------------------------------------------------
// Member methods.
//
//-------------------------------------------------------
// Constructors.
//
private Builder()
{
super (ApplicationInfoReply.class);
} // end of Builder()
//
// end of Constructors.
//-------------------------------------------------------
//-------------------------------------------------------
// Builder Method Overrides.
//
@Override
protected ApplicationInfoReply buildImpl()
{
return (new ApplicationInfoReply(this));
} // end of buildImpl()
@Override
protected Validator validate(final Validator problems)
{
return (super.validate(problems)
.requireNotNull(mHost, "hostName")
.requireNotNull(mAppName, "appName")
.requireNotNull(mAppVersion, "appVersion"));
} // end of validate(Validator)
//
// end of Builder Method Overrides.
//-------------------------------------------------------
//-------------------------------------------------------
// Set Methods.
//
/**
* Sets host name to given value. This name does
* not need to be a network host name but any
* name meaningful to the application and those
* monitoring it.
* @param name host name.
* @return {@code this Builder} instance.
* @throws IllegalArgumentException
* if {@code name} is either {@code null} or empty.
*/
public Builder hostName(final String name)
{
if (Strings.isNullOrEmpty(name))
{
throw (
new IllegalArgumentException(
"host name is either null or empty"));
}
mHost = name;
return (this);
} // end of hostName(String)
/**
* Sets application name to given value.
* @param name application name.
* @return {@code this Builder} instance.
* @throws IllegalArgumentException
* if {@code name} is either {@code null} or empty.
*/
public Builder appName(final String name)
{
if (Strings.isNullOrEmpty(name))
{
throw (
new IllegalArgumentException(
"name is null or empty"));
}
mAppName = name;
return (this);
} // end of appName(String)
public Builder appVersion(final String version)
{
if (Strings.isNullOrEmpty(version))
{
throw (
new IllegalArgumentException(
"version is null or empty"));
}
mAppVersion = version;
return (this);
} // end of appVersion(String)
public Builder copyright(@Nullable final String copyright)
{
mCopyright = copyright;
return (this);
} // end of copyright(String)
public Builder description(@Nullable final String description)
{
mDescription = description;
return (this);
} // end of description(String)
public Builder attributes(@Nullable final EField attributes)
{
mAttributes = attributes;
return (this);
} // end of attributes(EFoield)
//
// end of Set Methods.
//-------------------------------------------------------
} // end of class Builder
} // end of class ApplicationInfoReply