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

net.sf.eBusx.monitor.TransientStatusMessage 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 com.google.common.base.Strings;
import java.io.Serializable;
import net.sf.eBus.messages.ENotificationMessage;
import net.sf.eBus.util.Validator;

/**
 * Reports a monitored object's transient event. This event is
 * immediate and not on-going. 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 TransientStatusMessage
    extends ENotificationMessage
    implements Serializable
{
//---------------------------------------------------------------
// Member data.
//

    //-----------------------------------------------------------
    // 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;

    /**
     * Option message explaining the action.
     */
    public final String actionMessage;

    //-----------------------------------------------------------
    // Constants.
    //

    /**
     * Serialization version identifier.
     */
    private static final long serialVersionUID = 0x050200L;

//---------------------------------------------------------------
// Member methods.
//

    //-----------------------------------------------------------
    // Constructors.
    //

    private TransientStatusMessage(final Builder builder)
    {
        super (builder);

        this.instance = builder.mInstanceId;
        this.actionLevel = builder.mActionLevel;
        this.actionName = builder.mActionName;
        this.actionMessage = builder.mActionMessage;
    } // end of TransientStatusMessage(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 StringBuilder retval = new StringBuilder();

        return (retval.append(super.toString())
                      .append("\n               instance: ")
                      .append(instance)
                      .append("\n           action level: ")
                      .append(actionLevel)
                      .append("\n            action name: ")
                      .append(actionName)
                      .append("\n         action message: ")
                      .append(actionMessage)
                      .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 (TransientStatusMessage.class);
        } // end of Builder()

        //
        // end of Constructors.
        //-------------------------------------------------------

        //-------------------------------------------------------
        // Builder Method Overrides.
        //

        @Override
        public TransientStatusMessage buildImpl()
        {
            return (new TransientStatusMessage(this));
        } // end of buildImpl()

        @Override
        public Validator validate(final Validator problems)
        {
            return (super.validate(problems)
                         .requireNotNull(mActionLevel,
                                         "actionLevel")
                         .requireNotNull(mActionName,
                                         "actionName"));
        } // end of validate(Validator)

        //
        // 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 TransientStatusMessage




© 2015 - 2024 Weber Informatics LLC | Privacy Policy