View Javadoc

1   /**
2    *
3    * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4    *
5    * ====================================================================
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   * ====================================================================
18   */
19  package org.jclouds.cloudsigma.domain;
20  
21  import static com.google.common.base.Preconditions.checkNotNull;
22  
23  import java.util.Map;
24  
25  import com.google.common.collect.ImmutableMap;
26  
27  /**
28   * 
29   * @author Adrian Cole
30   */
31  public class ServerMetrics {
32  
33     public static class Builder {
34        protected long txPackets;
35        protected long tx;
36        protected long rxPackets;
37        protected long rx;
38        protected Map<String, DriveMetrics> driveMetrics = ImmutableMap.<String, DriveMetrics> of();
39  
40        public Builder txPackets(long txPackets) {
41           this.txPackets = txPackets;
42           return this;
43        }
44  
45        public Builder tx(long tx) {
46           this.tx = tx;
47           return this;
48        }
49  
50        public Builder rxPackets(long rxPackets) {
51           this.rxPackets = rxPackets;
52           return this;
53        }
54  
55        public Builder rx(long rx) {
56           this.rx = rx;
57           return this;
58        }
59  
60        public Builder driveMetrics(Map<String, ? extends DriveMetrics> driveMetrics) {
61           this.driveMetrics = ImmutableMap.copyOf(checkNotNull(driveMetrics, "driveMetrics"));
62           return this;
63        }
64  
65        public ServerMetrics build() {
66           return new ServerMetrics(tx, txPackets, rx, rxPackets, driveMetrics);
67        }
68     }
69  
70     protected final long txPackets;
71     protected final long tx;
72     protected final long rxPackets;
73     protected final long rx;
74     protected final Map<String, DriveMetrics> driveMetrics;
75  
76     public ServerMetrics(long tx, long txPackets, long rx, long rxPackets, Map<String, DriveMetrics> driveMetrics) {
77        this.txPackets = txPackets;
78        this.tx = tx;
79        this.rxPackets = rxPackets;
80        this.rx = rx;
81        this.driveMetrics = ImmutableMap.copyOf(checkNotNull(driveMetrics, "driveMetrics"));
82     }
83  
84     // TODO undocumented
85     public long getTxPackets() {
86        return txPackets;
87     }
88  
89     // TODO undocumented
90     public long getTx() {
91        return tx;
92     }
93  
94     // TODO undocumented
95     public long getRxPackets() {
96        return rxPackets;
97     }
98  
99     // TODO undocumented
100    public long getRx() {
101       return rx;
102    }
103 
104    /**
105     * 
106     * @return metrics keyed on device id ex. {@code ide:0:0}
107     */
108    public Map<String, DriveMetrics> getDriveMetrics() {
109       return driveMetrics;
110    }
111 
112    @Override
113    public int hashCode() {
114       final int prime = 31;
115       int result = 1;
116       result = prime * result + ((driveMetrics == null) ? 0 : driveMetrics.hashCode());
117       result = prime * result + (int) (rx ^ (rx >>> 32));
118       result = prime * result + (int) (rxPackets ^ (rxPackets >>> 32));
119       result = prime * result + (int) (tx ^ (tx >>> 32));
120       result = prime * result + (int) (txPackets ^ (txPackets >>> 32));
121       return result;
122    }
123 
124    @Override
125    public boolean equals(Object obj) {
126       if (this == obj)
127          return true;
128       if (obj == null)
129          return false;
130       if (getClass() != obj.getClass())
131          return false;
132       ServerMetrics other = (ServerMetrics) obj;
133       if (driveMetrics == null) {
134          if (other.driveMetrics != null)
135             return false;
136       } else if (!driveMetrics.equals(other.driveMetrics))
137          return false;
138       if (rx != other.rx)
139          return false;
140       if (rxPackets != other.rxPackets)
141          return false;
142       if (tx != other.tx)
143          return false;
144       if (txPackets != other.txPackets)
145          return false;
146       return true;
147    }
148 
149    @Override
150    public String toString() {
151       return "[ txPackets=" + txPackets + ", tx=" + tx + ", rxPackets=" + rxPackets + ", rx=" + rx + ", driveMetrics="
152             + driveMetrics + "]";
153    }
154 
155 }