activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Dillon <ja...@planet57.com>
Subject Re: PolicyMap api is really bad :-(
Date Wed, 11 Jan 2012 20:10:20 GMT
On Jan 11, 2012, at 11:46 AM, Dejan Bosanac wrote:
> there are a lot of examples on how to use destination in unit tests. For
> example, how to set default destination policy see
> 
> https://fisheye6.atlassian.com/browse/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/policy/IndividualDeadLetterTest.java?hb=true

Thanks, I did find many examples of how to set the default...


> or how to set it for a specific destinations see
> 
> https://fisheye6.atlassian.com/browse/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/UnlimitedEnqueueTest.java?r=911650

This was what I was looking for, but missed.  Thanks :-)

The api here is still a bit clunky IMO.  Broker service for example will automatically create
a SystemUsage bits on demand, is there any reason why BrokerService.getDestinationPolicy()
doesn't create the PolicyMap on demand?  Or why PolicyMap isn't more builder-like?  Guess
most folks still using Spring to configure the broker and thus never need a nicer API to configure
it?

Would be nice to see a rich fluent api as a first-class broker configuration mechanism one
day :-)

Anyways, related to forQueue() and forTopic() below, I believe these will work to build up
the entries w/o needing to build a List and setPolicyEntries().  Related, can you recommend
the easiest way to verify if a policy entry has taken effect or not?

Thanks,

--jason


>> To get around this and provide a better API I created this:
>> 
>> <snip>
>> public class ExtPolicyMap
>>   extends PolicyMap
>> {
>>   @NonNls
>>   private static final Logger log =
>> LoggerFactory.getLogger(ExtPolicyMap.class);
>> 
>>   @ScriptAccessible
>>   public PolicyEntry forQueue(final String name) {
>>       log.debug("Looking up policy-entry for queue: {}", name);
>>       PolicyEntry entry = getEntryFor(new ActiveMQQueue(name));
>>       if (entry == null) {
>>           entry = new PolicyEntry();
>>           entry.setQueue(name);
>>           put(entry.getDestination(), entry);
>>       }
>>       log.debug("Entry: {}", entry);
>>       return entry;
>>   }
>> 
>>   @ScriptAccessible
>>   public PolicyEntry forTopic(final String name) {
>>       log.debug("Looking up policy-entry for topic: {}", name);
>>       PolicyEntry entry = getEntryFor(new ActiveMQTopic(name));
>>       if (entry == null) {
>>           entry = new PolicyEntry();
>>           entry.setTopic(name);
>>           put(entry.getDestination(), entry);
>>       }
>>       log.debug("Entry: {}", entry);
>>       return entry;
>>   }
>> }
>> </snip>
>> 
>> And then exposed via:
>> 
>> <snip>
>> public class ExtBrokerService
>>   extends SslBrokerService
>> {
>>   public ExtBrokerService() {
>>       // Force our version of the policy map to be used
>>       setDestinationPolicy(new ExtPolicyMap());
>>   }
>> 
>>   @Override
>>   public ExtPolicyMap getDestinationPolicy() {
>>       return (ExtPolicyMap) super.getDestinationPolicy();
>>   }
>> }
>> </snip>
>> 
>> And then I can go configure things like:
>> 
>> <snip>
>> service.getDestinationPolicy().forQueue(">").setOptimizedDispatch(true);
>> service.start();
>> </snip>
>> 
>> I'm not sure how to easily verify if this is correct or not, so I wanted
>> to know if this looks sane.  Given use of ExtBrokerService here with
>> ExtPolicyMap, will this properly configure optimizeDispatch for all queues?
>> 
>> --jason
>> 
>> 
>> 


Mime
View raw message