org.jgroups.protocols
Class PDC

java.lang.Object
  extended by org.jgroups.stack.Protocol
      extended by org.jgroups.protocols.PDC

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
protected static class PDC.Mapping
           
 
Field Summary
protected  java.util.concurrent.ConcurrentMap<Address,PhysicalAddress> cache
           
protected  java.lang.String cache_dir
           
protected  java.io.FilenameFilter filter
           
protected  Address local_addr
           
protected  java.io.File root_dir
           
protected static java.lang.String SUFFIX
           
 
Fields inherited from class org.jgroups.stack.Protocol
down_prot, ergonomics, id, log, name, stack, stats, up_prot
 
Constructor Summary
PDC()
           
 
Method Summary
protected static java.lang.String addressAsString(Address address)
           
protected  void createDiskCacheFile()
           
protected  boolean deleteFile(java.io.File file)
          Attempts to delete the provided file.
Logging is performed on the result
 java.lang.Object down(Event evt)
          An event is to be sent down the stack.
 void init()
          Called after instance has been created (null constructor) and before protocol is started.
 java.lang.String printCache()
           
protected  void readCacheFromDisk()
          Reads all mappings from disk
protected  void removeNodeFromDisk(Address logical_addr)
           
protected  void writeNodeToDisk(Address logical_addr, PhysicalAddress physical_addr)
           
protected  java.io.File writeToTempFile(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
destroy, dumpStats, enableStats, getConfigurableObjects, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getName, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, printStats, providedDownServices, providedUpServices, requiredDownServices, requiredUpServices, resetStatistics, resetStats, setDownProtocol, setErgonomics, setId, setLevel, setProtocolStack, setSocketFactory, setUpProtocol, setValue, setValues, start, statsEnabled, stop, up
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

local_addr

protected Address local_addr
Constructor Detail

PDC

public PDC()
Method Detail

printCache

public java.lang.String printCache()

init

public void init()
          throws java.lang.Exception
Description copied from class: Protocol
Called after instance has been created (null constructor) and before protocol is started. Properties are already set. Other protocols are not yet connected and events cannot yet be sent.

Overrides:
init in class Protocol
Throws:
java.lang.Exception - Thrown if protocol cannot be initialized successfully. This will cause the ProtocolStack to fail, so the channel constructor will throw an exception

down

public java.lang.Object down(Event evt)
Description copied from class: Protocol
An event is to be sent down the stack. The layer 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 layer may need to add a header to it (or do nothing at all) before sending it down the stack using down_prot.down(). In case of a GET_ADDRESS event (which tries to retrieve the stack's address from one of the bottom layers), the layer may need to send a new response event back up the stack using up_prot.up().

Overrides:
down in class Protocol

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.Exception
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

Parameters:
dir - The disk cache root dir
logical_addr - The logical address
physical_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:


Copyright © 1998-2012 Bela Ban / Red Hat. All Rights Reserved.