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

com.aoindustries.aoserv.cluster.Rack.txt Maven / Gradle / Ivy

The newest version!
/*
 * aoserv-cluster - Cluster optimizer for the AOServ Platform.
 * Copyright (C) 2007-2011, 2020  AO Industries, Inc.
 *     [email protected]
 *     7262 Bull Pen Cir
 *     Mobile, AL 36695
 *
 * This file is part of aoserv-cluster.
 *
 * aoserv-cluster 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 3 of the License, or
 * (at your option) any later version.
 *
 * aoserv-cluster 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 aoserv-cluster.  If not, see .
 */
package com.aoindustries.aoserv.cluster;

import java.io.Serializable;

/**
 * A solution could consider allocating resources between racks so
 * that a power failure in one rack would not effect the overall ability
 * of the cluster.  Also, specific DomU could be grouped to be in different
 * racks, such as MySQL master and MySQL slave(s).
 *
 * @author  AO Industries, Inc.
 */
public class Rack implements Comparable, Serializable {

	private static final long serialVersionUID = 1L;

	final Cluster cluster;
	final String id;

	/**
	 * @see Cluster#addRack
	 */
	Rack(Cluster cluster, String id) {
		this.cluster = cluster;
		this.id = id;
	}

	public Cluster getCluster() {
		return cluster;
	}

	/**
	 * Gets the per-cluster unique ID.
	 */
	public String getId() {
		return id;
	}

	@Override
	public String toString() {
		return cluster.toString()+'/'+id;
	}

	@Override
	public boolean equals(Object O) {
		if(O==null) return false;
		if(!(O instanceof Rack)) return false;
		Rack other = (Rack)O;
		return
			cluster==other.cluster
			&& id.equals(other.id)
		;
	}

	@Override
	public int hashCode() {
		return cluster.hashCode() * 31 + id.hashCode();
	}

	/**
	 * Sorted ascending by:
	 * 
    *
  1. clusterName
  2. *
  3. id
  4. *
*/ @Override public int compareTo(Rack other) { if(this==other) return 0; int diff = cluster.compareTo(other.cluster); if(diff!=0) return diff; return id.compareTo(other.id); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy