Skip to content

Commit

Permalink
Handle lifecycle better.
Browse files Browse the repository at this point in the history
  • Loading branch information
alesj committed Nov 6, 2008
1 parent e3504ad commit 1cb6cc1
Showing 1 changed file with 21 additions and 10 deletions.
Expand Up @@ -36,7 +36,6 @@
public abstract class CachePolicyVFSCache extends PathMatchingVFSCache
{
private CachePolicy policy;
private boolean started;

public Iterable<VFSContext> getCachedContexts()
{
Expand All @@ -57,25 +56,37 @@ protected void check()

public void start() throws Exception
{
if (started == false)
{
policy = createCachePolicy();
policy = createCachePolicy();
if (policy == null)
throw new IllegalArgumentException("Policy is null.");

policy.create();
policy.create();
try
{
policy.start();

started = true;
}
catch (Exception e)
{
try
{
policy.destroy();
}
catch (Exception ignored)
{
}
throw e;
}
}

public void stop()
{
if (started)
if (policy != null)
{
policy.stop();
policy.destroy();

policy = null;
}
policy = null;
}

public void flush()
Expand Down Expand Up @@ -111,7 +122,7 @@ public void removeContext(String key, VFSContext context)
/**
* Read system property.
*
* @param key the property key
* @param key the property key
* @param defaultValue the default value
* @return system property or default value
*/
Expand Down

0 comments on commit 1cb6cc1

Please sign in to comment.