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

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

//
// 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. Charles W. Rapp
// All Rights Reserved.
//

package net.sf.eBusx.monitor;

import java.io.Serializable;
import java.util.Formatter;
import net.sf.eBus.messages.EFieldInfo;
import net.sf.eBus.messages.ENotificationMessage;

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

@EFieldInfo(fields={"instance",
                    "actionLevel",
                    "actionName",
                    "actionMessage"})
public final class TransientStatusMessage
    extends ENotificationMessage
    implements Serializable
{
//---------------------------------------------------------------
// Member methods.
//

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

    /**
     * Creates a new instance of TransientStatusMessage.
     * @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.
     */
    public TransientStatusMessage(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 TransientStatusMessage(...)

    /**
     * The deserialization constructor.
     * @param subject the
     * {@link MonitorId#toString() monitor identifier}.
     * @param timestamp the message timestamp.
     * @param inst the monitored instance integer identifier.
     * @param level the action level.
     * @param name the action name.
     * @param message the action message.
     */
    public TransientStatusMessage(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 TransientStatusMessage(...)

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

//---------------------------------------------------------------
// Member data.
//

    /**
     * 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 = 0x060100L;
} // end of class TransientStatusMessage




© 2015 - 2025 Weber Informatics LLC | Privacy Policy