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.elasticstack.domain;
20  
21  import static com.google.common.base.Preconditions.checkNotNull;
22  
23  import java.util.Map;
24  import java.util.Set;
25  
26  import javax.annotation.Nullable;
27  
28  
29  import com.google.common.collect.ImmutableSet;
30  
31  /**
32   * 
33   * @author Adrian Cole
34   */
35  public class Drive extends Item {
36     public static class Builder extends Item.Builder {
37        protected long size;
38        protected ClaimType claimType = ClaimType.EXCLUSIVE;
39        protected Set<String> readers = ImmutableSet.of();
40  
41        public Builder claimType(ClaimType claimType) {
42           this.claimType = claimType;
43           return this;
44        }
45  
46        public Builder readers(Iterable<String> readers) {
47           this.readers = ImmutableSet.copyOf(checkNotNull(readers, "readers"));
48           return this;
49        }
50  
51        public Builder size(long size) {
52           this.size = size;
53           return this;
54        }
55  
56        /**
57         * {@inheritDoc}
58         */
59        @Override
60        public Builder uuid(String uuid) {
61           return Builder.class.cast(super.uuid(uuid));
62        }
63  
64        /**
65         * {@inheritDoc}
66         */
67        @Override
68        public Builder name(String name) {
69           return Builder.class.cast(super.name(name));
70        }
71  
72        /**
73         * {@inheritDoc}
74         */
75        @Override
76        public Builder tags(Iterable<String> tags) {
77           return Builder.class.cast(super.tags(tags));
78        }
79  
80        /**
81         * {@inheritDoc}
82         */
83        @Override
84        public Builder userMetadata(Map<String, String> userMetadata) {
85           return Builder.class.cast(super.userMetadata(userMetadata));
86        }
87  
88        public Drive build() {
89           return new Drive(uuid, name, size, claimType, readers, tags, userMetadata);
90        }
91  
92        @Override
93        public int hashCode() {
94           final int prime = 31;
95           int result = super.hashCode();
96           result = prime * result + ((claimType == null) ? 0 : claimType.hashCode());
97           result = prime * result + ((readers == null) ? 0 : readers.hashCode());
98           result = prime * result + (int) (size ^ (size >>> 32));
99           return result;
100       }
101 
102       @Override
103       public boolean equals(Object obj) {
104          if (this == obj)
105             return true;
106          if (!super.equals(obj))
107             return false;
108          if (getClass() != obj.getClass())
109             return false;
110          Builder other = (Builder) obj;
111          if (claimType != other.claimType)
112             return false;
113          if (readers == null) {
114             if (other.readers != null)
115                return false;
116          } else if (!readers.equals(other.readers))
117             return false;
118          if (size != other.size)
119             return false;
120          return true;
121       }
122    }
123 
124    protected final long size;
125    protected final ClaimType claimType;
126    protected final Set<String> readers;
127 
128    public Drive(@Nullable String uuid, String name, long size, @Nullable ClaimType claimType,
129          Iterable<String> readers, Iterable<String> tags, Map<String, String> userMetadata) {
130       super(uuid, name, tags, userMetadata);
131       this.size = size;
132       this.claimType = checkNotNull(claimType, "set claimType to exclusive, not null");
133       this.readers = ImmutableSet.copyOf(checkNotNull(readers, "readers"));
134    }
135 
136    /**
137     * 
138     * @return either 'exclusive' (the default) or 'shared' to allow multiple servers to access a
139     *         drive simultaneously
140     */
141    @Nullable
142    public ClaimType getClaimType() {
143       return claimType;
144    }
145 
146    /**
147     * 
148     * @return list of users allowed to read from a drive or 'ffffffff-ffff-ffff-ffff-ffffffffffff'
149     *         for all users
150     */
151    public Set<String> getReaders() {
152       return readers;
153    }
154 
155    /**
156     * 
157     * @return size of drive in bytes
158     */
159    public long getSize() {
160       return size;
161    }
162 
163    @Override
164    public int hashCode() {
165       final int prime = 31;
166       int result = 1;
167       result = prime * result + ((claimType == null) ? 0 : claimType.hashCode());
168       result = prime * result + ((name == null) ? 0 : name.hashCode());
169       result = prime * result + ((readers == null) ? 0 : readers.hashCode());
170       result = prime * result + (int) (size ^ (size >>> 32));
171       result = prime * result + ((tags == null) ? 0 : tags.hashCode());
172       result = prime * result + ((userMetadata == null) ? 0 : userMetadata.hashCode());
173       return result;
174    }
175 
176    @Override
177    public boolean equals(Object obj) {
178       if (this == obj)
179          return true;
180       if (obj == null)
181          return false;
182       if (getClass() != obj.getClass())
183          return false;
184       Drive other = (Drive) obj;
185       if (claimType != other.claimType)
186          return false;
187       if (name == null) {
188          if (other.name != null)
189             return false;
190       } else if (!name.equals(other.name))
191          return false;
192       if (readers == null) {
193          if (other.readers != null)
194             return false;
195       } else if (!readers.equals(other.readers))
196          return false;
197       if (size != other.size)
198          return false;
199       if (tags == null) {
200          if (other.tags != null)
201             return false;
202       } else if (!tags.equals(other.tags))
203          return false;
204       if (userMetadata == null) {
205          if (other.userMetadata != null)
206             return false;
207       } else if (!userMetadata.equals(other.userMetadata))
208          return false;
209       return true;
210    }
211 
212    @Override
213    public String toString() {
214       return "[uuid=" + uuid + ", name=" + name + ", tags=" + tags + ", userMetadata=" + userMetadata + ", size="
215             + size + ", claimType=" + claimType + ", readers=" + readers + "]";
216    }
217 
218 }