001/* 002 * Copyright 2009 Red Hat, Inc. 003 * Red Hat licenses this file to you under the Apache License, version 004 * 2.0 (the "License"); you may not use this file except in compliance 005 * with the License. You may obtain a copy of the License at 006 * http://www.apache.org/licenses/LICENSE-2.0 007 * Unless required by applicable law or agreed to in writing, software 008 * distributed under the License is distributed on an "AS IS" BASIS, 009 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 010 * implied. See the License for the specific language governing 011 * permissions and limitations under the License. 012 */ 013 014package org.hornetq.api.jms.management; 015 016import org.hornetq.utils.json.JSONArray; 017import org.hornetq.utils.json.JSONObject; 018 019/** 020 * Helper class to create Java Objects from the 021 * JSON serialization returned by {@link JMSServerControl#listConsumersAsJSON(String)} and related methods. 022 * 023 * @author <a href="mailto:jmesnil@redhat.com">Jeff Mesnil</a> 024 */ 025public class JMSConsumerInfo 026{ 027 // Constants ----------------------------------------------------- 028 029 // Attributes ---------------------------------------------------- 030 031 private final String consumerID; 032 033 private final String connectionID; 034 035 private final String destinationName; 036 037 private final String destinationType; 038 039 private final boolean browseOnly; 040 041 private final long creationTime; 042 043 private final boolean durable; 044 045 private final String filter; 046 047 // Static -------------------------------------------------------- 048 049 /** 050 * Returns an array of SubscriptionInfo corresponding to the JSON serialization returned 051 * by {@link TopicControl#listAllSubscriptionsAsJSON()} and related methods. 052 */ 053 public static JMSConsumerInfo[] from(final String jsonString) throws Exception 054 { 055 JSONArray array = new JSONArray(jsonString); 056 JMSConsumerInfo[] infos = new JMSConsumerInfo[array.length()]; 057 for (int i = 0; i < array.length(); i++) 058 { 059 JSONObject sub = array.getJSONObject(i); 060 JMSConsumerInfo info = new JMSConsumerInfo(sub.getString("consumerID"), 061 sub.getString("connectionID"), 062 sub.getString("destinationName"), 063 sub.getString("destinationType"), 064 sub.getBoolean("browseOnly"), 065 sub.getLong("creationTime"), 066 sub.getBoolean("durable"), 067 sub.optString("filter", null)); 068 infos[i] = info; 069 } 070 071 return infos; 072 } 073 074 // Constructors -------------------------------------------------- 075 076 private JMSConsumerInfo(final String consumerID, 077 final String connectionID, 078 final String destinationName, 079 final String destinationType, 080 final boolean browseOnly, 081 final long creationTime, 082 final boolean durable, 083 final String filter) 084 { 085 this.consumerID = consumerID; 086 this.connectionID = connectionID; 087 this.destinationName = destinationName; 088 this.destinationType = destinationType; 089 this.browseOnly = browseOnly; 090 this.creationTime = creationTime; 091 this.durable = durable; 092 this.filter = filter; 093 } 094 095 // Public -------------------------------------------------------- 096 097 public String getConsumerID() 098 { 099 return consumerID; 100 } 101 102 public String getConnectionID() 103 { 104 return connectionID; 105 } 106 107 public String getDestinationName() 108 { 109 return destinationName; 110 } 111 112 public String getDestinationType() 113 { 114 return destinationType; 115 } 116 117 public boolean isBrowseOnly() 118 { 119 return browseOnly; 120 } 121 122 public long getCreationTime() 123 { 124 return creationTime; 125 } 126 127 /** 128 * @return the durable 129 */ 130 public boolean isDurable() 131 { 132 return durable; 133 } 134 135 public String getFilter() 136 { 137 return filter; 138 } 139 140 // Package protected --------------------------------------------- 141 142 // Protected ----------------------------------------------------- 143 144 // Private ------------------------------------------------------- 145 146 // Inner classes ------------------------------------------------- 147}