1 23 24 29 30 package com.sun.enterprise.management.support; 31 32 import javax.management.ObjectName ; 33 import javax.management.MBeanInfo ; 34 import javax.management.MBeanAttributeInfo ; 35 import javax.management.MBeanOperationInfo ; 36 37 import javax.management.Attribute ; 38 import javax.management.AttributeList ; 39 40 import com.sun.appserv.management.base.BulkAccess; 41 import com.sun.appserv.management.base.XTypes; 42 import com.sun.appserv.management.base.AMX; 43 import com.sun.appserv.management.util.jmx.JMXUtil; 44 45 46 48 public class BulkAccessImpl extends AMXImplBase 49 implements BulkAccess 50 { 51 public 52 BulkAccessImpl() 53 { 54 } 55 56 public String 57 getGroup() 58 { 59 return( AMX.GROUP_UTILITY ); 60 } 61 62 public Object [] 63 bulkGetMBeanInfo( final ObjectName [] objectNames ) 64 { 65 final Object [] infos = new Object [ objectNames.length ]; 66 67 for( int i = 0; i < infos.length; ++i ) 68 { 69 try 70 { 71 infos[ i ] = getMBeanServer().getMBeanInfo( objectNames[ i ] ); 72 } 73 catch( Throwable t ) 74 { 75 infos[ i ] = t; 76 } 77 } 78 return( infos ); 79 } 80 81 public Object [] 82 bulkGetMBeanAttributeInfo( final ObjectName [] objectNames ) 83 { 84 final Object [] results = new Object [objectNames.length]; 85 final Object [] mbeanInfos = bulkGetMBeanInfo( objectNames ); 86 87 for( int i = 0; i < results.length; ++i ) 88 { 89 if ( mbeanInfos[ i ] instanceof MBeanInfo ) 90 { 91 results[ i ] = ((MBeanInfo )mbeanInfos[ i ]).getAttributes(); 92 } 93 else 94 { 95 results[ i ] = mbeanInfos[ i ]; 96 } 97 } 98 return( results ); 99 } 100 101 public Object [] 102 bulkGetAttributeNames( final ObjectName [] objectNames ) 103 { 104 final Object [] results = new Object [ objectNames.length ]; 105 final Object [] mbeanInfos = bulkGetMBeanInfo( objectNames ); 106 107 for( int i = 0; i < results.length; ++i ) 108 { 109 if ( mbeanInfos[ i ] instanceof MBeanInfo ) 110 { 111 final MBeanInfo info = (MBeanInfo )mbeanInfos[ i ]; 112 113 results[ i ] = JMXUtil.getAttributeNames( info.getAttributes() ); 114 } 115 else 116 { 117 results[ i ] = mbeanInfos[ i ]; 118 } 119 } 120 return( results ); 121 } 122 123 public Object [] 124 bulkGetMBeanOperationInfo( final ObjectName [] objectNames ) 125 { 126 final Object [] results = new Object [ objectNames.length ]; 127 final Object [] mbeanInfos = bulkGetMBeanInfo( objectNames ); 128 129 for( int i = 0; i < results.length; ++i ) 130 { 131 if ( mbeanInfos[ i ] instanceof MBeanInfo ) 132 { 133 final MBeanInfo info = (MBeanInfo )mbeanInfos[ i ]; 134 135 results[ i ] = info.getOperations(); 136 } 137 else 138 { 139 results[ i ] = mbeanInfos[ i ]; 140 } 141 } 142 return( results ); 143 } 144 145 public Object [] 146 bulkGetAttribute( 147 final ObjectName [] objectNames, 148 final String attributeName ) 149 { 150 final Object [] results = new Object [ objectNames.length ]; 151 152 for( int i = 0; i < objectNames.length; ++i ) 153 { 154 try 155 { 156 results[ i ] = getMBeanServer().getAttribute( objectNames[ i ], attributeName ); 157 } 158 catch( Throwable t ) 159 { 160 results[ i ] = t; 161 } 162 } 163 return( results ); 164 } 165 166 public Object [] 167 bulkSetAttribute( 168 final ObjectName [] objectNames, 169 final Attribute attr ) 170 { 171 final Object [] results = new Object [ objectNames.length ]; 172 173 for( int i = 0; i < objectNames.length; ++i ) 174 { 175 try 176 { 177 results[ i ] = null; 178 getMBeanServer().setAttribute( objectNames[ i ], attr ); 179 } 180 catch( Throwable t ) 181 { 182 results[ i ] = t; 183 } 184 } 185 return( results ); 186 } 187 188 189 public Object [] 190 bulkGetAttributes( 191 final ObjectName [] objectNames, 192 final String [] attributeNames ) 193 { 194 final Object [] results = new Object [ objectNames.length ]; 195 196 if ( attributeNames.length != 0 ) 199 { 200 for( int i = 0; i < objectNames.length; ++i ) 201 { 202 final String [] attributesCopy = (String [])attributeNames.clone(); 204 205 try 206 { 207 results[ i ] = getMBeanServer().getAttributes( objectNames[ i ], attributesCopy ); 208 } 209 catch( Throwable t ) 210 { 211 results[ i ] = t; 212 } 213 } 214 } 215 return( results ); 216 } 217 218 219 public Object [] 220 bulkSetAttributes( 221 final ObjectName [] objectNames, 222 final AttributeList attrs ) 223 { 224 final Object [] results = new Object [ objectNames.length ]; 225 226 for( int i = 0; i < objectNames.length; ++i ) 227 { 228 try 229 { 230 final AttributeList attrsCopy = (AttributeList )attrs.clone(); 232 233 results[ i ] = getMBeanServer().setAttributes( objectNames[ i ], attrsCopy ); 234 } 235 catch( Throwable t ) 236 { 237 results[ i ] = t; 238 } 239 } 240 return( results ); 241 } 242 243 244 public Object [] 245 bulkInvoke( 246 final ObjectName [] objectNames, 247 final String operationName, 248 final Object [] args, 249 final String [] types ) 250 { 251 final Object [] results = new Object [ objectNames.length ]; 252 253 for( int i = 0; i < objectNames.length; ++i ) 254 { 255 try 256 { 257 results[ i ] = getMBeanServer().invoke( objectNames[ i ], 259 operationName, args, types ); 260 } 261 catch( Throwable t ) 262 { 263 results[ i ] = t; 264 } 265 } 266 return( results ); 267 } 268 } 269 270 271 272 273 274 275 276 277 278 279 280 | Popular Tags |