ehcache

net.sf.ehcache.terracotta
Class TerracottaBootstrapCacheLoader

java.lang.Object
  extended by net.sf.ehcache.store.MemoryLimitedCacheLoader
      extended by net.sf.ehcache.terracotta.TerracottaBootstrapCacheLoader
All Implemented Interfaces:
Cloneable, BootstrapCacheLoader, Disposable

public class TerracottaBootstrapCacheLoader
extends MemoryLimitedCacheLoader
implements Disposable

A BootstrapCacheLoader that will load Elements into a Terracotta clustered cache, based on a previously snapshotted key set. It is also responsible to create snapshot files to disk

Author:
Alex Snaps

Field Summary
static boolean DEFAULT_DEDICATED_THREAD
          The default on whether to do the snapshot on a dedicated thread or using the CacheManager's ScheduledExecutorService
static long DEFAULT_INTERVAL
          The default interval in seconds, between each snapshot
 
Constructor Summary
TerracottaBootstrapCacheLoader(boolean asynchronous, String directory, boolean doKeySnapshots)
          Constructor
TerracottaBootstrapCacheLoader(boolean asynchronous, String directory, long interval)
          Constructor
TerracottaBootstrapCacheLoader(boolean asynchronous, String directory, long interval, boolean onDedicatedThread)
          Constructor
 
Method Summary
 Object clone()
          Clones the loader
 void dispose()
          Will shut the keysnapshot thread and other resources down.
 void doLocalKeySnapshot()
          Calling this method will result in a snapshot being taken or wait for the one in progress to finish
 boolean isAsynchronous()
          
 boolean isImmediateShutdown()
          Whether the on going keysnapshot will finish before the instance is disposed
 void load(Ehcache cache)
          Instructs the loader to load the given cache
 void setImmediateShutdown(boolean immediateShutdown)
          Sets whether the disposal of the instance will let the potential current key set being written to disk finish, or whether the shutdown will be immediate
 void setSnapshotOnDispose(boolean doKeySnapshotOnDispose)
          Configures the Loader to take a snapshot when it is being disposed
 
Methods inherited from class net.sf.ehcache.store.MemoryLimitedCacheLoader
isInMemoryLimitReached
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_INTERVAL

public static final long DEFAULT_INTERVAL
The default interval in seconds, between each snapshot

See Also:
Constant Field Values

DEFAULT_DEDICATED_THREAD

public static final boolean DEFAULT_DEDICATED_THREAD
The default on whether to do the snapshot on a dedicated thread or using the CacheManager's ScheduledExecutorService

See Also:
Constant Field Values
Constructor Detail

TerracottaBootstrapCacheLoader

public TerracottaBootstrapCacheLoader(boolean asynchronous,
                                      String directory,
                                      boolean doKeySnapshots)
Constructor

Parameters:
asynchronous - do the loading asynchronously, or synchronously
directory - the directory to read snapshot files from, and write them to
doKeySnapshots - Whether to do keysnapshotting

TerracottaBootstrapCacheLoader

public TerracottaBootstrapCacheLoader(boolean asynchronous,
                                      String directory,
                                      long interval)
Constructor

Parameters:
asynchronous - do the loading asynchronously, or synchronously
directory - the directory to read snapshot files from, and write them to
interval - the interval in seconds at which the snapshots of the local key set has to occur

TerracottaBootstrapCacheLoader

public TerracottaBootstrapCacheLoader(boolean asynchronous,
                                      String directory,
                                      long interval,
                                      boolean onDedicatedThread)
Constructor

Parameters:
asynchronous - do the loading asynchronously, or synchronously
directory - the directory to read snapshot files from, and write them to
interval - the interval in seconds at which the snapshots of the local key set has to occur
onDedicatedThread - whether to do the snapshot on a dedicated thread or using the CacheManager's ScheduledExecutorService
Method Detail

isImmediateShutdown

public boolean isImmediateShutdown()
Whether the on going keysnapshot will finish before the instance is disposed

Returns:
true if disposable is immediate
See Also:
Disposable

setImmediateShutdown

public void setImmediateShutdown(boolean immediateShutdown)
Sets whether the disposal of the instance will let the potential current key set being written to disk finish, or whether the shutdown will be immediate

Parameters:
immediateShutdown - true if immediate, false to let the snapshot finish

load

public void load(Ehcache cache)
          throws CacheException
Instructs the loader to load the given cache

Specified by:
load in interface BootstrapCacheLoader
Throws:
CacheException

isAsynchronous

public boolean isAsynchronous()

Specified by:
isAsynchronous in interface BootstrapCacheLoader
Returns:
true if this bootstrap loader is asynchronous

dispose

public void dispose()
Will shut the keysnapshot thread and other resources down. If a snapshot is currently in progress, the method will either shutdown immediately or let the snapshot finish based on the configured setImmediateShutdown(boolean) value

Specified by:
dispose in interface Disposable

doLocalKeySnapshot

public void doLocalKeySnapshot()
                        throws IOException
Calling this method will result in a snapshot being taken or wait for the one in progress to finish

Throws:
IOException - On exception being thrown while doing the snapshot

clone

public Object clone()
             throws CloneNotSupportedException
Clones the loader

Specified by:
clone in interface BootstrapCacheLoader
Overrides:
clone in class MemoryLimitedCacheLoader
Throws:
CloneNotSupportedException

setSnapshotOnDispose

public void setSnapshotOnDispose(boolean doKeySnapshotOnDispose)
Configures the Loader to take a snapshot when it is being disposed

Parameters:
doKeySnapshotOnDispose - whether to snapshot on loader disposal

ehcache

Copyright 2001-2016, Terracotta, Inc.