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

net.sf.eBusx.monitor.ApplicationInfo Maven / Gradle / Ivy

The newest version!
//
// 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 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.ENotificationMessage;
import net.sf.eBus.util.Validator;

/**
 * Reports the application information. This includes the
 * application name, version, copyright, description and
 * user-defined attributes. These attributes are defined by
 * creating an {@link EField} sub-class. See the
 * {@code net.sf.eBus.messages} package documentation for more
 * information about sub-classing {@code EField}.
 * 

* In order to receive this message, subscribe to: * {@code net.sf.eBusx.monitor.ApplicationInfo}:{@code /eBus/monitor/update//} * where <host> is {@link Monitor#hostName()} and * <app> is {@link Monitor#applicationName()}. * * @see MonitorUpdate * @see ApplicationInfoRequest * @see ApplicationInfoReply * @see Monitor * * @author Charles Rapp */ public final class ApplicationInfo extends ENotificationMessage implements Serializable { //--------------------------------------------------------------- // Member data. // //----------------------------------------------------------- // Constants. // /** * Serialization version identifier. */ private static final long serialVersionUID = 0x050200L; //----------------------------------------------------------- // Locals. // /** * Application is running on this host. Note: this name is * not not required to be a network host name but * should be a name meaningful to the application and those * monitoring it. */ public final String hostName; /** * Application name. This name should be meaningful both to * the application and those monitoring it. */ 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. // private ApplicationInfo(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 ApplicationInfo(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 the {@code ApplicationInfo} message builder. * @return message builder. */ public static Builder builder() { return (new Builder()); } // end of builder() //--------------------------------------------------------------- // Inner classes. // /** * Builder class used to construct an {@link ApplicationInfo} * instance. A {@code Builder} instance is accessed via the * {@link ApplicationInfo#builder()} method. */ public static final class Builder extends ENotificationMessage.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 (ApplicationInfo.class); } // end of Builder() // // end of Constructors. //------------------------------------------------------- //------------------------------------------------------- // Builder Method Overrides. // /** * Returns an {@code ApplicationInfo} instance based on * this builder's configuration. This method is called * only after the builder configuration is successfully * validated. * @return new {@code ApplicationInfo} instance. */ @Override protected ApplicationInfo buildImpl() { return (new ApplicationInfo(this)); } // end of buildImpl() /** * Validates the builder configuration. A valid * configuration requires that the application name and * version be set. * @param problems add configuration problems to * @return {@code problems} to allow for * {@code Validator} method chaining. */ @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( "address 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 ApplicationInfo





© 2015 - 2024 Weber Informatics LLC | Privacy Policy