001/*
002 * VM-Operator
003 * Copyright (C) 2023 Michael N. Lipp
004 * 
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Affero General Public License as
007 * published by the Free Software Foundation, either version 3 of the
008 * License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU Affero General Public License for more details.
014 *
015 * You should have received a copy of the GNU Affero General Public License
016 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
017 */
018
019package org.jdrupes.vmoperator.manager.events;
020
021import org.jdrupes.vmoperator.common.VmPool;
022import org.jgrapes.core.Channel;
023import org.jgrapes.core.Components;
024import org.jgrapes.core.Event;
025
026/**
027 * Indicates a change in a pool configuration. 
028 */
029@SuppressWarnings("PMD.DataClass")
030public class VmPoolChanged extends Event<Void> {
031
032    private final VmPool vmPool;
033    private final boolean deleted;
034
035    /**
036     * Instantiates a new VM changed event.
037     *
038     * @param pool the pool
039     * @param deleted true, if the pool was deleted
040     */
041    public VmPoolChanged(VmPool pool, boolean deleted) {
042        vmPool = pool;
043        this.deleted = deleted;
044    }
045
046    /**
047     * Instantiates a new VM changed event for an existing pool.
048     *
049     * @param pool the pool
050     */
051    public VmPoolChanged(VmPool pool) {
052        this(pool, false);
053    }
054
055    /**
056     * Returns the VM pool.
057     *
058     * @return the vm pool
059     */
060    public VmPool vmPool() {
061        return vmPool;
062    }
063
064    /**
065     * Pool has been deleted.
066     *
067     * @return true, if successful
068     */
069    public boolean deleted() {
070        return deleted;
071    }
072
073    @Override
074    public String toString() {
075        StringBuilder builder = new StringBuilder(30);
076        builder.append(Components.objectName(this))
077            .append(" [");
078        if (deleted) {
079            builder.append("Deleted: ");
080        }
081        builder.append(vmPool);
082        if (channels() != null) {
083            builder.append(", channels=").append(Channel.toString(channels()));
084        }
085        builder.append(']');
086        return builder.toString();
087    }
088}