org.planx.xmlstore.stores
Class DistributedXMLStore

java.lang.Object
  extended by org.planx.xmlstore.stores.AbstractXMLStore<ValueReference>
      extended by org.planx.xmlstore.stores.DistributedXMLStore
All Implemented Interfaces:
ExecXMLStore<ValueReference>, XMLStore<ValueReference>

public class DistributedXMLStore
extends AbstractXMLStore<ValueReference>
implements ExecXMLStore<ValueReference>

A peer-to-peer XMLStore that uses Kademlia as routing module. It only operates on location independent ValueReferences. If an XMLStore that does not operate on ValueReferences is used as the underlying XMLStore (e.g. LocalXMLStore), it must be wrapped in a TranslatorXMLStore. System applications that need access to the routing module instance can get so by calling the getDistributedMap() method. The store implements the ExecXMLStore interface, but it will throw UnsupportedOperationException if exec is invoked and the underlying XML Store does not implement the ExecXMLStore interface.

Author:
Thomas Ambus

Constructor Summary
DistributedXMLStore(XMLStore<ValueReference> xmlstore, int udpPort, int tcpPort, InetSocketAddress bootstrap)
          Creates a DistributedXMLStore which listens for routing requests on the specified UDP port and listens for data transfer requests on the specified TCP port.
DistributedXMLStore(XMLStore<ValueReference> xmlstore, int udpPort, int tcpPort, InetSocketAddress bootstrap, Configuration conf, int repLevel)
          Creates a DistributedXMLStore which listens for routing requests on the specified UDP port and listens for data transfer requests on the specified TCP port.
 
Method Summary
 void close()
          The method is used to let the XMLStore properly commit all data to the underlying ressource, release resources, and so forth.
 ValueReference exec(ValueReference code, ValueReference args)
          Execute the code referenced by codeRef supplied with the argument reference by argsRef.
 DistributedMap getDistributedMap()
          Returns the DistributedMap used by this DistributedXMLStore to exchange peer-to-peer information.
 NameServer<ValueReference> getNameServer()
          Returns a GlobalNameServer that uses the same DistributedMap as this DistributedXMLStore.
 Node load(ValueReference vref)
          If the Reference is not known in the underlying XMLStore it is looked up in the network and loaded from another peer if it exists.
 ValueReference save(Node node)
          Always saves locally even if the node might already be stored elsewhere in the network.
 
Methods inherited from class org.planx.xmlstore.stores.AbstractXMLStore
toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DistributedXMLStore

public DistributedXMLStore(XMLStore<ValueReference> xmlstore,
                           int udpPort,
                           int tcpPort,
                           InetSocketAddress bootstrap)
                    throws IOException
Creates a DistributedXMLStore which listens for routing requests on the specified UDP port and listens for data transfer requests on the specified TCP port. The XMLStore is bootstraped to an existing XMLStore network by specifying a bootstrap IP and UDP port. If the bootstrap IP is null the XML Store will not attempt to connect to an existing network. The DistributedXMLStore only saves locally.

Parameters:
xmlstore - The underlying XMLStore.
udpPort - UDP port on which to listen for routing requests
tcpPort - TCP port on which to listen for data transfer requests
bootstrap - IP and UDP port of an existing peer in the network
Throws:
IOException

DistributedXMLStore

public DistributedXMLStore(XMLStore<ValueReference> xmlstore,
                           int udpPort,
                           int tcpPort,
                           InetSocketAddress bootstrap,
                           Configuration conf,
                           int repLevel)
                    throws IOException

Creates a DistributedXMLStore which listens for routing requests on the specified UDP port and listens for data transfer requests on the specified TCP port. The XMLStore is bootstraped to an existing XMLStore network by specifying a bootstrap IP and UDP port. If the bootstrap IP is null the XMLStore will not attempt to connect to an existing network.

The DistributedXMLStore always saves locally but will also replicate data to repLevel other peers, where repLevel is a number which is less than or equal to Configuration.K. This coupling between repLevel and the Kademlia implementation of the routing layer should be viewed as a short-coming of the Kademlia implementation rather than a restriction on future routing layer implementations.

Parameters:
xmlstore - The underlying XMLStore.
udpPort - UDP port on which to listen for routing requests
tcpPort - TCP port on which to listen for data transfer requests
bootstrap - IP and UDP port of an existing peer in the network
conf - Kademlia configuration. If null a default configuration is used.
repLevel - Replication level, that is, number of peers beyond the local peer that saved data will be replicated to. Note that for the Kademlia routing implementation, this number can at most be K - the Kademlia bucket/neighbourhood size.
Throws:
IOException
Method Detail

getNameServer

public NameServer<ValueReference> getNameServer()
Returns a GlobalNameServer that uses the same DistributedMap as this DistributedXMLStore.

Specified by:
getNameServer in interface XMLStore<ValueReference>
Overrides:
getNameServer in class AbstractXMLStore<ValueReference>

getDistributedMap

public DistributedMap getDistributedMap()
Returns the DistributedMap used by this DistributedXMLStore to exchange peer-to-peer information.


close

public void close()
           throws IOException
Description copied from interface: XMLStore
The method is used to let the XMLStore properly commit all data to the underlying ressource, release resources, and so forth. Once close has been issued on an XMLStore, the store is no longer available for handling requests. Any subsequent request to the store will result in an exception being thrown. An XMLStore implementation has to ensure that this happens.

Specified by:
close in interface XMLStore<ValueReference>
Overrides:
close in class AbstractXMLStore<ValueReference>
Throws:
IOException - if it is not possible to properly close the store

save

public ValueReference save(Node node)
                    throws IOException
Always saves locally even if the node might already be stored elsewhere in the network. This is because it is considered very likely that the node will be loaded locally later.

Specified by:
save in interface XMLStore<ValueReference>
Overrides:
save in class AbstractXMLStore<ValueReference>
Parameters:
node - representing XML data in the form of semi-structured tree data
Returns:
a reference to the saved node/tree
Throws:
IOException - if an error occurs during disk, network, etc access

load

public Node load(ValueReference vref)
          throws IOException
If the Reference is not known in the underlying XMLStore it is looked up in the network and loaded from another peer if it exists. If the Reference could not be found an UnknownReferenceException is thrown.

Specified by:
load in interface XMLStore<ValueReference>
Overrides:
load in class AbstractXMLStore<ValueReference>
Parameters:
vref - the Reference to the data
Returns:
node representing the loaded XML data
Throws:
IOException - if an error occurs during disk, network, etc access
UnknownReferenceException - if the data referenced is not stored in the XMLStore or the Reference is of a type not supported by the XMLStore

exec

public ValueReference exec(ValueReference code,
                           ValueReference args)
                    throws IOException,
                           ExecException,
                           UnsupportedOperationException
Description copied from interface: ExecXMLStore
Execute the code referenced by codeRef supplied with the argument reference by argsRef. Returns a reference to the result of the execution.

Specified by:
exec in interface ExecXMLStore<ValueReference>
Parameters:
code - the Reference to a binary node containing class code implementing StoredCode
args - reference to arguments
Returns:
a reference to the result
Throws:
IOException - if an error occurs during loading of code or arguments
ExecException
UnsupportedOperationException


Copyright © 2004-2005 Plan-X. All Rights Reserved.