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

net.sf.eBusx.monitor.MonitoredObjectReply 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 java.io.Serializable;
import net.sf.eBus.messages.EReplyMessage;
import net.sf.eBus.util.Validator;

/**
 * Returns the currently registered monitored objects within the
 * eBus virtual machine, specified as an array of
 * {@link MonitorId}s. This message is sent in reply to a
 * {@link MonitoredObjectRequest} with the subject
 * {@link Monitor#MONITOR_REQUEST}.
 *
 * @see MonitoredObjectRequest
 *
 * @author Charles Rapp
 */

public final class MonitoredObjectReply
    extends EReplyMessage
    implements Serializable
{
//---------------------------------------------------------------
// Member data.
//

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

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

    //-----------------------------------------------------------
    // Locals.
    //

    /**
     * The currently registered monitor objects.
     */
    public final MonitorId[] instances;

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

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

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

        this.instances = builder.mInstances;
    } // end of MonitoredObjectReply(Builder)

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

    /**
     * Returns a new instance of a {@code MonitoredObjectReply}
     * message builder.
     * @return new message builder instance.
     */
    public static Builder builder()
    {
        return (new Builder());
    } // end of builder()

//---------------------------------------------------------------
// Inner classes.
//

    public static final class Builder
        extends EReplyMessage.Builder
    {
    //-----------------------------------------------------------
    // Member data.
    //

        //-------------------------------------------------------
        // Locals.
        //

        private MonitorId[] mInstances;

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

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

        private Builder()
        {
            super (MonitoredObjectReply.class);
        } // end of Builder()

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

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

        @Override
        protected MonitoredObjectReply buildImpl()
        {
            return (new MonitoredObjectReply(this));
        } // end of buildImpl()

        @Override
        protected Validator validate(final Validator problems)
        {
            return (super.validate(problems)
                         .requireNotNull(mInstances, "instance"));
        } // end of validate(Validator)

        //
        // end of Builder Method Overrides.
        //-------------------------------------------------------

        //-------------------------------------------------------
        // Set Methods.
        //

        public Builder instances(final MonitorId[] ids)
        {
            if (ids == null)
            {
                throw (new NullPointerException("ids is null"));
            }

            final int numIds = ids.length;

            mInstances = new MonitorId[numIds];
            System.arraycopy(ids, 0, mInstances, 0, numIds);

            return (this);
        } // end of instances(MonitorId[])

        //
        // end of Set Methods.
        //-------------------------------------------------------
    } // end of class Builder
} // end of class MonitoredObjectReply




© 2015 - 2024 Weber Informatics LLC | Privacy Policy