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 */ 017package org.apache.activemq.partition.dto; 018 019 020 021import com.fasterxml.jackson.annotation.JsonInclude; 022import com.fasterxml.jackson.databind.DeserializationFeature; 023import com.fasterxml.jackson.databind.ObjectMapper; 024import com.fasterxml.jackson.databind.DeserializationConfig; 025import com.fasterxml.jackson.databind.SerializationFeature; 026import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 027import com.fasterxml.jackson.databind.annotation.JsonSerialize; 028import com.fasterxml.jackson.annotation.JsonProperty; 029 030import java.io.IOException; 031import java.util.HashMap; 032 033/** 034 * The main Configuration class for the PartitionBroker plugin 035 */ 036public class Partitioning { 037 038 static final public ObjectMapper MAPPER = new ObjectMapper(); 039 static { 040 MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL); 041 MAPPER.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); 042 } 043 044 static final public ObjectMapper TO_STRING_MAPPER = new ObjectMapper(); 045 static { 046 TO_STRING_MAPPER.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); 047 TO_STRING_MAPPER.enable(SerializationFeature.INDENT_OUTPUT); 048 } 049 050 /** 051 * If a client connects with a clientId which is listed in the 052 * map, then he will be immediately reconnected 053 * to the partition target immediately. 054 */ 055 @JsonProperty("by_client_id") 056 @JsonDeserialize(contentAs = Target.class) 057 public HashMap<String, Target> byClientId; 058 059 /** 060 * If a client connects with a user priciple which is listed in the 061 * map, then he will be immediately reconnected 062 * to the partition target immediately. 063 */ 064 @JsonProperty("by_user_name") 065 @JsonDeserialize(contentAs = Target.class) 066 public HashMap<String, Target> byUserName; 067 068 /** 069 * If a client connects with source ip which is listed in the 070 * map, then he will be immediately reconnected 071 * to the partition target immediately. 072 */ 073 @JsonProperty("by_source_ip") 074 @JsonDeserialize(contentAs = Target.class) 075 public HashMap<String, Target> bySourceIp; 076 077 /** 078 * Used to map the preferred partitioning of queues across 079 * a set of brokers. Once a it is deemed that a connection mostly 080 * works with a set of targets configured in this map, the client 081 * will be reconnected to the appropriate target. 082 */ 083 @JsonProperty("by_queue") 084 @JsonDeserialize(contentAs = Target.class) 085 public HashMap<String, Target> byQueue; 086 087 /** 088 * Used to map the preferred partitioning of topics across 089 * a set of brokers. Once a it is deemed that a connection mostly 090 * works with a set of targets configured in this map, the client 091 * will be reconnected to the appropriate target. 092 */ 093 @JsonProperty("by_topic") 094 @JsonDeserialize(contentAs = Target.class) 095 public HashMap<String, Target> byTopic; 096 097 /** 098 * Maps broker names to broker URLs. 099 */ 100 @JsonProperty("brokers") 101 @JsonDeserialize(contentAs = String.class) 102 public HashMap<String, String> brokers; 103 104 105 @Override 106 public String toString() { 107 try { 108 return TO_STRING_MAPPER.writeValueAsString(this); 109 } catch (IOException e) { 110 return super.toString(); 111 } 112 } 113 114 public HashMap<String, String> getBrokers() { 115 return brokers; 116 } 117 118 public void setBrokers(HashMap<String, String> brokers) { 119 this.brokers = brokers; 120 } 121 122 public HashMap<String, Target> getByClientId() { 123 return byClientId; 124 } 125 126 public void setByClientId(HashMap<String, Target> byClientId) { 127 this.byClientId = byClientId; 128 } 129 130 public HashMap<String, Target> getByQueue() { 131 return byQueue; 132 } 133 134 public void setByQueue(HashMap<String, Target> byQueue) { 135 this.byQueue = byQueue; 136 } 137 138 public HashMap<String, Target> getBySourceIp() { 139 return bySourceIp; 140 } 141 142 public void setBySourceIp(HashMap<String, Target> bySourceIp) { 143 this.bySourceIp = bySourceIp; 144 } 145 146 public HashMap<String, Target> getByTopic() { 147 return byTopic; 148 } 149 150 public void setByTopic(HashMap<String, Target> byTopic) { 151 this.byTopic = byTopic; 152 } 153 154 public HashMap<String, Target> getByUserName() { 155 return byUserName; 156 } 157 158 public void setByUserName(HashMap<String, Target> byUserName) { 159 this.byUserName = byUserName; 160 } 161}