001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.activemq.partition.dto;
018    
019    import org.codehaus.jackson.annotate.JsonProperty;
020    import scala.actors.threadpool.Arrays;
021    
022    import java.io.IOException;
023    import java.util.Collection;
024    import java.util.HashSet;
025    
026    /**
027     * Represents a partition target.  This identifies the brokers that
028     * a partition lives on.
029     */
030    public class Target {
031    
032        @JsonProperty("ids")
033        public HashSet<String> ids = new HashSet<String>();
034    
035        public Target() {
036            ids = new HashSet<String>();
037        }
038    
039        public Target(String ...ids) {
040            this.ids.addAll(Arrays.asList(ids));
041        }
042    
043        @Override
044        public String toString() {
045            try {
046                return Partitioning.TO_STRING_MAPPER.writeValueAsString(this);
047            } catch (IOException e) {
048                return super.toString();
049            }
050        }
051    
052        public HashSet<String> getIds() {
053            return ids;
054        }
055    
056        public void setIds(Collection<String> ids) {
057            this.ids = new HashSet<String>(ids);
058        }
059    
060    }