On 04.01.2013 11:35, Nigel Deakin wrote:
> On 03/01/2013 22:21, Philippe Marschall wrote:
>>
>>
>> On 03.01.2013 17:58, Nigel Deakin wrote:
>>> Philippe,
>>>
>>> On 02/01/2013 16:29, Philippe Marschall wrote:
>>>> I wanted to ask whether it would make sense to make TemporaryQueue and
>>>> TemporaryTopic implement AutoCloseable so that they can be used in a
>>>> try-with-resources block?
>>>
>>> Thanks for your comment.
>>>
>>> TemporaryQueue and TemporaryTopic don't have a close method. A temporary
>>> queue or topic will be automatically deleted when the Connection (or
>>> JMSContext) used to create it is closed.
>>>
>>> Are you proposing that we add a close method to TemporaryQueue and
>>> TemporaryTopic which causes the temporary queue or topic to be deleted?
>>
>> Yes, more or less. That would allow a TemporaryQueue/TemporaryTopic to
>> be used in a create/use/delete pattern with language support. Thinking
>> about it I'm not so sure anymore. Maybe I just want to use
>> try-with-resources wherever I can.
>
> OK. So you're asking for new methods TemporaryQueue.close() and
> TemporaryTopic.close(), where "close" actually means "delete".
Yes
> Can you say more about the use case where this might be useful? I don't
> want to guess, but it sounds like you want to create large numbers of
> temporary destinations using the same connection.
The way my code usually looks is like this:
TemporaryQueue queue = session.createTemporaryQueue(…);
try {
// work with queue
} finally {
queue.delete();
}
with AutoCloseable it would look like this
try (TemporaryQueue queue = session.createTemporaryQueue(…)) {
// work with queue
}
Again, I'm not sure whether this is a good idea™ or a misuse of a
language feature.
Cheers
Philippe