1 package org.jacorb.notification.util; 2 3 22 23 import java.util.ArrayList ; 24 import java.util.Collections ; 25 import java.util.HashSet ; 26 import java.util.List ; 27 import java.util.Set ; 28 29 import org.apache.avalon.framework.configuration.Configuration; 30 import org.jacorb.notification.conf.Attributes; 31 import org.jacorb.notification.conf.Default; 32 import org.omg.CORBA.Any ; 33 import org.omg.CORBA.BAD_OPERATION ; 34 import org.omg.CosNotification.AnyOrder; 35 import org.omg.CosNotification.BestEffort; 36 import org.omg.CosNotification.ConnectionReliability; 37 import org.omg.CosNotification.DeadlineOrder; 38 import org.omg.CosNotification.DiscardPolicy; 39 import org.omg.CosNotification.EventReliability; 40 import org.omg.CosNotification.FifoOrder; 41 import org.omg.CosNotification.LifoOrder; 42 import org.omg.CosNotification.MaxEventsPerConsumer; 43 import org.omg.CosNotification.MaximumBatchSize; 44 import org.omg.CosNotification.NamedPropertyRangeSeqHolder; 45 import org.omg.CosNotification.OrderPolicy; 46 import org.omg.CosNotification.PacingInterval; 47 import org.omg.CosNotification.Persistent; 48 import org.omg.CosNotification.Priority; 49 import org.omg.CosNotification.PriorityOrder; 50 import org.omg.CosNotification.Property; 51 import org.omg.CosNotification.PropertyError; 52 import org.omg.CosNotification.PropertyRange; 53 import org.omg.CosNotification.QoSError_code; 54 import org.omg.CosNotification.StartTime; 55 import org.omg.CosNotification.StartTimeSupported; 56 import org.omg.CosNotification.StopTime; 57 import org.omg.CosNotification.StopTimeSupported; 58 import org.omg.CosNotification.Timeout; 59 import org.omg.CosNotification.UnsupportedQoS; 60 import org.omg.TimeBase.TimeTHelper; 61 62 66 67 public class QoSPropertySet extends PropertySet 68 { 69 public static final int CHANNEL_QOS = 0; 70 public static final int ADMIN_QOS = 1; 71 public static final int PROXY_QOS = 2; 72 73 private Property[] defaultChannelQoS_; 74 private Property[] defaultAdminQoS_; 75 76 private static final Set sValidChannelQoSNames_; 77 private static final Set sValidAdminQoSNames_; 78 private static final Set sValidProxyQoSNames_; 79 private static final Set sValidMessageQoSNames_; 80 81 private static final Any connectionReliabilityLow_; 82 private static final Any connectionReliabilityHigh_; 83 84 private static final Any eventReliabilityLow_; 85 private static final Any eventReliabilityHigh_; 86 87 private static Any orderPolicyLow_; 88 private static Any orderPolicyHigh_; 90 91 private static Any discardPolicyLow_; 92 private static Any discardPolicyHigh_; 93 94 private static Any priorityLow_; 95 private static Any priorityDefault_; 96 private static Any priorityHigh_; 97 98 private Any maxEventsPerConsumerLow_; 99 private Any maxEventsPerConsumerDefault_; 100 private Any maxEventsPerConsumerHigh_; 101 102 private Any timeoutDefault_; 104 106 private static final Any trueAny; 107 private static final Any falseAny; 108 109 111 static { 112 trueAny = sORB.create_any(); 113 falseAny = sORB.create_any(); 114 trueAny.insert_boolean(true); 115 falseAny.insert_boolean(false); 116 117 119 HashSet _validChannelQoS = new HashSet (); 120 _validChannelQoS.add(EventReliability.value); 121 _validChannelQoS.add(ConnectionReliability.value); 122 _validChannelQoS.add(Priority.value); 123 _validChannelQoS.add(Timeout.value); 124 _validChannelQoS.add(StartTimeSupported.value); 125 _validChannelQoS.add(StopTimeSupported.value); 126 _validChannelQoS.add(MaxEventsPerConsumer.value); 127 _validChannelQoS.add(OrderPolicy.value); 128 _validChannelQoS.add(DiscardPolicy.value); 129 _validChannelQoS.add(MaximumBatchSize.value); 130 _validChannelQoS.add(PacingInterval.value); 131 132 sValidChannelQoSNames_ = Collections.unmodifiableSet(_validChannelQoS); 133 134 136 HashSet _adminNames = new HashSet (sValidChannelQoSNames_); 137 _adminNames.remove(EventReliability.value); 138 sValidAdminQoSNames_ = Collections.unmodifiableSet(_adminNames); 139 140 142 sValidProxyQoSNames_ = sValidAdminQoSNames_; 143 144 146 HashSet _validMessageQoS = new HashSet (); 147 _validMessageQoS.add(EventReliability.value); 148 _validMessageQoS.add(Priority.value); 149 _validMessageQoS.add(StartTime.value); 150 _validMessageQoS.add(StopTime.value); 151 _validMessageQoS.add(Timeout.value); 152 153 sValidMessageQoSNames_ = Collections.unmodifiableSet(_validMessageQoS); 154 155 157 connectionReliabilityHigh_ = sORB.create_any(); 158 connectionReliabilityHigh_.insert_short(Persistent.value); 159 160 connectionReliabilityLow_ = sORB.create_any(); 161 connectionReliabilityLow_.insert_short(BestEffort.value); 162 163 165 eventReliabilityLow_ = sORB.create_any(); 166 eventReliabilityLow_.insert_short(BestEffort.value); 167 168 eventReliabilityHigh_ = sORB.create_any(); 169 eventReliabilityHigh_.insert_short(BestEffort.value); 170 171 173 orderPolicyLow_ = sORB.create_any(); 174 orderPolicyLow_.insert_short(AnyOrder.value); 175 176 orderPolicyHigh_ = sORB.create_any(); 177 orderPolicyHigh_.insert_short(DeadlineOrder.value); 178 179 181 discardPolicyLow_ = sORB.create_any(); 182 discardPolicyLow_.insert_short(AnyOrder.value); 183 184 discardPolicyHigh_ = sORB.create_any(); 185 discardPolicyHigh_.insert_short(DeadlineOrder.value); 186 187 189 priorityLow_ = sORB.create_any(); 190 priorityLow_.insert_short(Short.MIN_VALUE); 191 192 priorityDefault_ = sORB.create_any(); 193 priorityDefault_.insert_short((short)0); 194 195 priorityHigh_ = sORB.create_any(); 196 priorityHigh_.insert_short(Short.MAX_VALUE); 197 } 198 199 200 private void configure (Configuration conf) 201 { 202 int _maxEventsPerConsumerDefault = 203 conf.getAttributeAsInteger( Attributes.MAX_EVENTS_PER_CONSUMER, 204 Default.DEFAULT_MAX_EVENTS_PER_CONSUMER ); 205 206 maxEventsPerConsumerDefault_ = sORB.create_any(); 207 maxEventsPerConsumerDefault_.insert_long(_maxEventsPerConsumerDefault); 208 209 maxEventsPerConsumerHigh_ = sORB.create_any(); 210 maxEventsPerConsumerLow_ = sORB.create_any(); 211 212 maxEventsPerConsumerLow_.insert_long(0); 213 maxEventsPerConsumerHigh_.insert_long(Integer.MAX_VALUE); 214 215 217 timeoutDefault_ = sORB.create_any(); 218 TimeTHelper.insert(timeoutDefault_, 0); 219 220 222 Any _isStartTimeSupportedDefault = sORB.create_any(); 223 224 boolean _isStartTimeSupported = 225 conf.getAttribute(Attributes.START_TIME_SUPPORTED, 226 Default.DEFAULT_START_TIME_SUPPORTED). 227 equalsIgnoreCase("on"); 228 229 _isStartTimeSupportedDefault.insert_boolean(_isStartTimeSupported); 230 231 233 Any _isStopTimeSupportedDefault = sORB.create_any(); 234 235 boolean _isStopTimeSupported = 236 conf.getAttribute(Attributes.STOP_TIME_SUPPORTED, 237 Default.DEFAULT_STOP_TIME_SUPPORTED). 238 equalsIgnoreCase("on"); 239 _isStopTimeSupportedDefault.insert_boolean(_isStopTimeSupported); 240 241 243 int _maxBatchSize = 244 conf.getAttributeAsInteger(Attributes.MAX_BATCH_SIZE, 245 Default.DEFAULT_MAX_BATCH_SIZE); 246 247 Any _maxBatchSizeDefault = sORB.create_any(); 248 _maxBatchSizeDefault.insert_long(_maxBatchSize); 249 250 252 defaultChannelQoS_ = new Property[] { 253 new Property(EventReliability.value, eventReliabilityLow_), 254 new Property(ConnectionReliability.value, 255 connectionReliabilityLow_), 256 new Property(Priority.value, priorityDefault_), 257 new Property(MaxEventsPerConsumer.value, 258 maxEventsPerConsumerDefault_), 259 new Property(Timeout.value, timeoutDefault_), 260 new Property(StartTimeSupported.value, 261 _isStartTimeSupportedDefault), 262 new Property(StopTimeSupported.value, 263 _isStartTimeSupportedDefault), 264 new Property(MaximumBatchSize.value, 265 _maxBatchSizeDefault) 266 }; 267 268 defaultAdminQoS_ = new Property[] { 269 new Property(ConnectionReliability.value, 270 connectionReliabilityLow_), 271 new Property(Priority.value, priorityDefault_), 272 new Property(MaxEventsPerConsumer.value, 273 maxEventsPerConsumerDefault_), 274 new Property(Timeout.value, timeoutDefault_), 275 new Property(StartTimeSupported.value, 276 _isStartTimeSupportedDefault), 277 new Property(StopTimeSupported.value, 278 _isStartTimeSupportedDefault), 279 new Property(MaximumBatchSize.value, _maxBatchSizeDefault) 280 }; 281 } 282 283 285 private final Set validNames_; 286 287 289 public QoSPropertySet(Configuration configuration, int type) 290 { 291 super(); 292 293 configure(configuration); 294 295 switch (type) 296 { 297 case CHANNEL_QOS: 298 validNames_ = sValidChannelQoSNames_; 299 300 set_qos(defaultChannelQoS_); 301 break; 302 case ADMIN_QOS: 303 validNames_ = sValidAdminQoSNames_; 304 305 set_qos(defaultAdminQoS_); 306 break; 307 case PROXY_QOS: 308 validNames_ = sValidProxyQoSNames_; 309 break; 310 default: 311 throw new IllegalArgumentException ("Type " + type + " is invalid"); 312 } 313 } 314 315 317 protected Set getValidNames() 318 { 319 return validNames_; 320 } 321 322 323 public void set_qos(Property[] ps) 324 { 325 set_properties(ps); 326 } 327 328 329 public Property[] get_qos() 330 { 331 return toArray(); 332 } 333 334 335 public void validate_qos(Property[] props, 336 NamedPropertyRangeSeqHolder namedPropertyRange) 337 throws UnsupportedQoS 338 { 339 List _errors = new ArrayList (); 340 341 checkPropertyExistence(props, _errors); 342 343 if (!_errors.isEmpty()) { 344 throw new UnsupportedQoS((PropertyError[])_errors.toArray(PROPERTY_ERROR_ARRAY_TEMPLATE)); 345 } 346 347 checkPropertyValues(props, _errors); 348 349 if (!_errors.isEmpty()) { 350 throw new UnsupportedQoS((PropertyError[])_errors.toArray(PROPERTY_ERROR_ARRAY_TEMPLATE)); 351 } 352 } 353 354 355 private short checkIsShort(String name, Any value, List errors) throws BAD_OPERATION { 356 try { 357 return value.extract_short(); 358 } catch (BAD_OPERATION e) { 359 errors.add(badType(name)); 360 361 throw e; 362 } 363 } 364 365 366 private void logError(List errors, 367 QoSError_code error_code, 368 String name, 369 Any value, 370 Any high, 371 Any low) { 372 373 if (logger_.isInfoEnabled()) { 374 logger_.info("wrong value for Property '" +name + "': " + value); 375 } 376 377 errors.add(new PropertyError(error_code, 378 name, 379 new PropertyRange(high, 380 low))); 381 } 382 383 384 private void checkPropertyValues(Property[] ps, List errors) 385 { 386 for (int x = 0; x < ps.length; ++x) { 387 String _propertyName = ps[x].name; 388 Any _value = ps[x].value; 389 390 try { 391 if (ConnectionReliability.value.equals(_propertyName)) { 392 393 short _connectionReliability = 394 checkIsShort(_propertyName, _value, errors); 395 396 switch (_connectionReliability) 397 { 398 case BestEffort.value: 399 case Persistent.value: 401 break; 402 default: 403 logError(errors, 404 QoSError_code.BAD_VALUE, 405 _propertyName, 406 _value, 407 connectionReliabilityLow_, 408 connectionReliabilityHigh_ ); 409 } 410 } else if (EventReliability.value.equals(_propertyName)) { 411 412 short _eReliability = checkIsShort(_propertyName, _value, errors); 413 414 switch (_eReliability) 415 { 416 case BestEffort.value: 417 case Persistent.value: 419 break; 420 default: 421 logError(errors, 422 QoSError_code.BAD_VALUE, 423 _propertyName, 424 _value, 425 eventReliabilityLow_, 426 eventReliabilityHigh_); 427 } 428 } else if (OrderPolicy.value.equals(_propertyName)) { 429 430 short _oPolicy = checkIsShort(_propertyName, _value, errors); 431 432 switch (_oPolicy) 433 { 434 case AnyOrder.value: 435 break; 436 case FifoOrder.value: 437 break; 438 case PriorityOrder.value: 439 break; 440 case DeadlineOrder.value: 441 break; 442 default: 443 logError(errors, 444 QoSError_code.BAD_VALUE, 445 _propertyName, 446 _value, 447 orderPolicyLow_, 448 orderPolicyHigh_); 449 } 450 } else if (DiscardPolicy.value.equals(_propertyName)) { 451 short _dPolicy = checkIsShort(_propertyName, _value, errors); 452 453 switch (_dPolicy) 454 { 455 case AnyOrder.value: 456 break; 457 case FifoOrder.value: 458 break; 459 case LifoOrder.value: 460 break; 461 case PriorityOrder.value: 462 break; 463 case DeadlineOrder.value: 464 break; 465 default: 466 logError(errors, 467 QoSError_code.BAD_VALUE, 468 _propertyName, 469 _value, 470 discardPolicyLow_, 471 discardPolicyHigh_); 472 } 473 } 474 } catch (BAD_OPERATION e) { 475 } 478 } 479 } 480 } 481 | Popular Tags |