Package org.jgroups.protocols
Class PDC
- java.lang.Object
-
- org.jgroups.stack.Protocol
-
- org.jgroups.protocols.PDC
-
- All Implemented Interfaces:
Lifecycle
public class PDC extends Protocol
Persistent Discovery Cache. Caches mapping between logical and physical addresses on disk, merges them with the results of the get physical address(es) events. This is done by intercepting the get and set physical address(es) event. Needs to be placed between the transport and the discovery protocol. The disk cache stores each mapping in a separate file, named by the logical address.- Since:
- 3.3
- Author:
- Bela Ban
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classPDC.Mapping
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.ConcurrentMap<Address,PhysicalAddress>cacheprotected java.lang.Stringcache_dirprotected java.io.FilenameFilterfilterprotected java.io.Fileroot_dirprotected static java.lang.StringSUFFIX-
Fields inherited from class org.jgroups.stack.Protocol
after_creation_hook, down_prot, ergonomics, id, local_addr, log, policies, stack, stats, up_prot
-
-
Constructor Summary
Constructors Constructor Description PDC()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static java.lang.StringaddressAsString(Address address)protected voidcreateDiskCacheFile()protected booleandeleteFile(java.io.File file)Attempts to delete the provided file.
Logging is performed on the resultjava.lang.Objectdown(Event evt)An event is to be sent down the stack.voidinit()Called after a protocol has been created and before the protocol is started.java.lang.StringprintCache()protected voidreadCacheFromDisk()Reads all mappings from diskprotected voidremoveNodeFromDisk(Address logical_addr)protected voidwriteNodeToDisk(Address logical_addr, PhysicalAddress physical_addr)protected java.io.FilewriteToTempFile(java.io.File dir, Address logical_addr, Address physical_addr, java.lang.String logical_name)Writes the data to a temporary file.
The file is stored in the same directory as the other cluster files but is given the .tmp suffix-
Methods inherited from class org.jgroups.stack.Protocol
accept, addPolicy, addr, addr, afterCreationHook, destroy, down, down, enableStats, getAddress, getComponents, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getName, getPolicies, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, level, parse, policies, providedDownServices, providedUpServices, removePolicy, requiredDownServices, requiredUpServices, resetStatistics, resetStats, setAddress, setDownProtocol, setErgonomics, setId, setLevel, setPolicies, setProtocolStack, setSocketFactory, setUpProtocol, setValue, start, statsEnabled, stop, toString, up, up, up
-
-
-
-
Field Detail
-
cache
protected final java.util.concurrent.ConcurrentMap<Address,PhysicalAddress> cache
-
cache_dir
protected java.lang.String cache_dir
-
SUFFIX
protected static final java.lang.String SUFFIX
- See Also:
- Constant Field Values
-
root_dir
protected java.io.File root_dir
-
filter
protected java.io.FilenameFilter filter
-
-
Method Detail
-
printCache
public java.lang.String printCache()
-
init
public void init() throws java.lang.ExceptionDescription copied from class:ProtocolCalled after a protocol has been created and before the protocol is started. Attributes are already set. Other protocols are not yet connected and events cannot yet be sent.
-
down
public java.lang.Object down(Event evt)
Description copied from class:ProtocolAn event is to be sent down the stack. A protocol may want to examine its type and perform some action on it, depending on the event's type. If the event is a message MSG, then the protocol may need to add a header to it (or do nothing at all) before sending it down the stack usingdown_prot.down().
-
createDiskCacheFile
protected void createDiskCacheFile() throws java.io.IOException- Throws:
java.io.IOException
-
readCacheFromDisk
protected void readCacheFromDisk()
Reads all mappings from disk
-
writeNodeToDisk
protected void writeNodeToDisk(Address logical_addr, PhysicalAddress physical_addr)
-
writeToTempFile
protected java.io.File writeToTempFile(java.io.File dir, Address logical_addr, Address physical_addr, java.lang.String logical_name) throws java.lang.ExceptionWrites the data to a temporary file.
The file is stored in the same directory as the other cluster files but is given the .tmp suffix- Parameters:
dir- The disk cache root dirlogical_addr- The logical addressphysical_addr- The physical address- Returns:
- Throws:
java.lang.Exception
-
removeNodeFromDisk
protected void removeNodeFromDisk(Address logical_addr)
-
addressAsString
protected static java.lang.String addressAsString(Address address)
-
deleteFile
protected boolean deleteFile(java.io.File file)
Attempts to delete the provided file.
Logging is performed on the result- Parameters:
file-- Returns:
-
-