summaryrefslogtreecommitdiff
path: root/java/newclient/src/main/java/org/apache/qpid/nclient/impl/AbstractResource.java
blob: d202bab84334ec22b74e4ff1b2b8052a626d27e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package org.apache.qpid.nclient.impl;

import org.apache.qpid.nclient.api.QpidException;
import org.apache.qpid.nclient.core.AMQPException;

/**
 * This abstracts the error handling for open
 * and close methods for a resource. This class
 * eliminates the duplication of error handling 
 * code
 */
public abstract class AbstractResource
{
	private String _resourceName;
	
	public AbstractResource(String resourceName)
	{
		_resourceName = resourceName;
	}
	
	public void open() throws QpidException
	{
		try
		{
			openResource();

		}
		catch(AMQPException e)
		{
			throw new QpidException("Error creating " + _resourceName  + " due to " + e.getMessage(),e);
		}
	}
		
	public void close() throws QpidException
	{
		try
		{
			closeResource();

		}
		catch(Exception e)
		{
			throw new QpidException("Error destroying " + _resourceName  + " due to " + e.getMessage(),e);
		}
		
	}
	
	protected abstract void openResource() throws AMQPException;
	
	protected abstract void closeResource() throws AMQPException;
}