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 */ 029public class VmPoolChanged extends Event<Void> { 030 031 private final VmPool vmPool; 032 private final boolean deleted; 033 034 /** 035 * Instantiates a new VM changed event. 036 * 037 * @param pool the pool 038 * @param deleted true, if the pool was deleted 039 */ 040 public VmPoolChanged(VmPool pool, boolean deleted) { 041 vmPool = pool; 042 this.deleted = deleted; 043 } 044 045 /** 046 * Instantiates a new VM changed event for an existing pool. 047 * 048 * @param pool the pool 049 */ 050 public VmPoolChanged(VmPool pool) { 051 this(pool, false); 052 } 053 054 /** 055 * Returns the VM pool. 056 * 057 * @return the vm pool 058 */ 059 public VmPool vmPool() { 060 return vmPool; 061 } 062 063 /** 064 * Pool has been deleted. 065 * 066 * @return true, if successful 067 */ 068 public boolean deleted() { 069 return deleted; 070 } 071 072 @Override 073 public String toString() { 074 StringBuilder builder = new StringBuilder(30); 075 builder.append(Components.objectName(this)) 076 .append(" ["); 077 if (deleted) { 078 builder.append("Deleted: "); 079 } 080 builder.append(vmPool); 081 if (channels() != null) { 082 builder.append(", channels=").append(Channel.toString(channels())); 083 } 084 builder.append(']'); 085 return builder.toString(); 086 } 087}