net.tomp2p.p2p
Class Peer

java.lang.Object
  extended by net.tomp2p.p2p.Peer

public class Peer
extends Object

TomP2P implements besides the following distributed hash table (DHT) operations:

also the following operations: The advantage of TomP2P is that multiple values can be stored in one location. Furthermore, TomP2P also provides to store keys in different domains to avoid key collisions.

Author:
Thomas Bocek

Field Summary
static int BLOOMFILTER_SIZE
           
 
Method Summary
 AddBuilder add(Number160 locationKey)
           
 void addPeerListener(PeerListener listener)
          Adds a listener to peer events.
 AddTrackerBuilder addTracker(Number160 locationKey)
           
 BootstrapBuilder bootstrap()
           
 BroadcastBuilder broadcast(Number160 messageKey)
           
 PeerConnection createPeerConnection(PeerAddress destination, int idleTCPMillis)
          Opens a TCP connection and keeps it open.
 void customLoggerMessage(String customMessage)
           
 DiscoverBuilder discover()
           
 GetBuilder get(Number160 locationKey)
           
 AsyncTask getAsyncTask()
           
 Bindings getBindings()
           
 BroadcastRPC getBroadcastRPC()
           
 ConnectionConfiguration getConfiguration()
           
 ConnectionBean getConnectionBean()
           
 ConnectionHandler getConnectionHandler()
           
 DirectDataRPC getDirectDataRPC()
           
 DistributedHashTable getDistributedHashMap()
           
 DistributedRouting getDistributedRouting()
           
 DistributedTask getDistributedTask()
           
 DistributedTracker getDistributedTracker()
           
 HandshakeRPC getHandshakeRPC()
           
 List<PeerListener> getListeners()
           
 NeighborRPC getNeighborRPC()
           
 int getP2PID()
           
 PeerAddress getPeerAddress()
           
 PeerBean getPeerBean()
           
 PeerExchangeRPC getPeerExchangeRPC()
           
 Number160 getPeerID()
           
 Map<BaseFuture,Long> getPendingFutures()
           
 QuitRPC getQuitRPC()
           
 List<ScheduledFuture<?>> getScheduledFutures()
           
 StorageRPC getStoreRPC()
           
 TaskRPC getTaskRPC()
           
 org.jboss.netty.util.Timer getTimer()
           
 GetTrackerBuilder getTracker(Number160 locationKey)
           
 TrackerRPC getTrackerRPC()
           
 boolean isListening()
           
 boolean isRunning()
           
 boolean isShutdown()
          Returns true if shutdown has been initiated
 ParallelRequestBuilder parallelRequest(Number160 locationKey)
           
 PingBuilder ping()
           
 PutBuilder put(Number160 locationKey)
           
 void release(ChannelCreator channelCreator)
          Release a ChannelCreator.
 RemoveBuilder remove(Number160 locationKey)
           
 void removePeerListener(PeerListener listener)
          Removes a peer listener.
 FutureChannelCreator reserve(RoutingConfiguration routingConfiguration, RequestP2PConfiguration requestP2PConfiguration, String name)
          Reserves a connection for a routing and DHT operation.
 SendBuilder send(Number160 locationKey)
          The send method works as follows:
 SendDirectBuilder sendDirect()
          Deprecated. 
 SendDirectBuilder sendDirect(PeerAddress recipientAddress)
           
 SendDirectBuilder sendDirect(PeerConnection recipientConnection)
           
 void setAsyncTask(AsyncTask asyncTask)
           
 void setBroadcastRPC(BroadcastRPC broadcastRPC)
           
 void setDirectDataRPC(DirectDataRPC directDataRPC)
           
 void setDistributedHashMap(DistributedHashTable distributedHashMap)
           
 void setDistributedRouting(DistributedRouting distributedRouting)
           
 void setDistributedTask(DistributedTask task)
           
 void setDistributedTracker(DistributedTracker distributedTracker)
           
 void setFutureTimeout(BaseFuture baseFuture, int millis, String reason)
          Sets a timeout for this future.
 void setHandshakeRPC(HandshakeRPC handshakeRPC)
           
 void setNeighborRPC(NeighborRPC neighborRPC)
           
 void setObjectDataReply(ObjectDataReply objectDataReply)
           
 void setPeerExchangeRPC(PeerExchangeRPC peerExchangeRPC)
           
 void setQuitRPC(QuitRPC quitRCP)
           
 void setRawDataReply(RawDataReply rawDataReply)
           
 void setStorageRPC(StorageRPC storageRPC)
           
 void setTaskRPC(TaskRPC taskRPC)
           
 void setTrackerRPC(TrackerRPC trackerRPC)
           
 boolean setupPortForwanding(String internalHost)
          The Dynamic and/or Private Ports are those from 49152 through 65535 (http://www.iana.org/assignments/port-numbers)
 void shutdown()
          Closes all connections of this node
 SubmitBuilder submit(Number160 locationKey, Worker worker)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BLOOMFILTER_SIZE

public static final int BLOOMFILTER_SIZE
See Also:
Constant Field Values
Method Detail

addPeerListener

public void addPeerListener(PeerListener listener)
Adds a listener to peer events. The events being triggered are: startup, shutdown, change of peer address. The change of the peer address is due to the discovery process. Since this process runs in an other thread, this method is thread safe.

Parameters:
listener - The listener

removePeerListener

public void removePeerListener(PeerListener listener)
Removes a peer listener. This method is thread safe.

Parameters:
listener - The listener

getListeners

public List<PeerListener> getListeners()

shutdown

public void shutdown()
Closes all connections of this node

Throws:
InterruptedException

getPendingFutures

public Map<BaseFuture,Long> getPendingFutures()

isRunning

public boolean isRunning()

isListening

public boolean isListening()

customLoggerMessage

public void customLoggerMessage(String customMessage)

getHandshakeRPC

public HandshakeRPC getHandshakeRPC()

setHandshakeRPC

public void setHandshakeRPC(HandshakeRPC handshakeRPC)

getStoreRPC

public StorageRPC getStoreRPC()

setStorageRPC

public void setStorageRPC(StorageRPC storageRPC)

getNeighborRPC

public NeighborRPC getNeighborRPC()

setNeighborRPC

public void setNeighborRPC(NeighborRPC neighborRPC)

getQuitRPC

public QuitRPC getQuitRPC()

setQuitRPC

public void setQuitRPC(QuitRPC quitRCP)

getPeerExchangeRPC

public PeerExchangeRPC getPeerExchangeRPC()

setPeerExchangeRPC

public void setPeerExchangeRPC(PeerExchangeRPC peerExchangeRPC)

getDirectDataRPC

public DirectDataRPC getDirectDataRPC()

setDirectDataRPC

public void setDirectDataRPC(DirectDataRPC directDataRPC)

getTrackerRPC

public TrackerRPC getTrackerRPC()

setTrackerRPC

public void setTrackerRPC(TrackerRPC trackerRPC)

getTaskRPC

public TaskRPC getTaskRPC()

setTaskRPC

public void setTaskRPC(TaskRPC taskRPC)

setBroadcastRPC

public void setBroadcastRPC(BroadcastRPC broadcastRPC)

getBroadcastRPC

public BroadcastRPC getBroadcastRPC()

getDistributedRouting

public DistributedRouting getDistributedRouting()

setDistributedRouting

public void setDistributedRouting(DistributedRouting distributedRouting)

getDistributedHashMap

public DistributedHashTable getDistributedHashMap()

setDistributedHashMap

public void setDistributedHashMap(DistributedHashTable distributedHashMap)

getDistributedTracker

public DistributedTracker getDistributedTracker()

setDistributedTracker

public void setDistributedTracker(DistributedTracker distributedTracker)

getAsyncTask

public AsyncTask getAsyncTask()

setAsyncTask

public void setAsyncTask(AsyncTask asyncTask)

getDistributedTask

public DistributedTask getDistributedTask()

setDistributedTask

public void setDistributedTask(DistributedTask task)

getScheduledFutures

public List<ScheduledFuture<?>> getScheduledFutures()

getConnectionHandler

public ConnectionHandler getConnectionHandler()

getBindings

public Bindings getBindings()

getTimer

public org.jboss.netty.util.Timer getTimer()

getPeerBean

public PeerBean getPeerBean()

getConnectionBean

public ConnectionBean getConnectionBean()

getPeerID

public Number160 getPeerID()

getP2PID

public int getP2PID()

getPeerAddress

public PeerAddress getPeerAddress()

getConfiguration

public ConnectionConfiguration getConfiguration()

setRawDataReply

public void setRawDataReply(RawDataReply rawDataReply)

setObjectDataReply

public void setObjectDataReply(ObjectDataReply objectDataReply)

createPeerConnection

public PeerConnection createPeerConnection(PeerAddress destination,
                                           int idleTCPMillis)
Opens a TCP connection and keeps it open. The user can provide the idle timeout, which means that the connection gets closed after that time of inactivity. If the other peer goes offline or closes the connection (due to inactivity), further requests with this connections reopens the connection. This methods blocks until a connection can be reserver.

Parameters:
destination - The end-point to connect to
idleSeconds - time in seconds after a connection gets closed if idle, -1 if it should remain always open until the user closes the connection manually.
Returns:
A class that needs to be passed to those methods that should use the already open connection. If the connection could not be reserved, maybe due to a shutdown, null is returned.

setupPortForwanding

public boolean setupPortForwanding(String internalHost)
The Dynamic and/or Private Ports are those from 49152 through 65535 (http://www.iana.org/assignments/port-numbers)

Parameters:
internalHost -
port -
Returns:

submit

public SubmitBuilder submit(Number160 locationKey,
                            Worker worker)

add

public AddBuilder add(Number160 locationKey)

put

public PutBuilder put(Number160 locationKey)

get

public GetBuilder get(Number160 locationKey)

remove

public RemoveBuilder remove(Number160 locationKey)

send

public SendBuilder send(Number160 locationKey)
The send method works as follows:
 1. routing: find close peers to the content hash. 
    You can control the routing behavior with 
    setRoutingConfiguration() 
 2. sending: send the data to the n closest peers. 
    N is set via setRequestP2PConfiguration(). 
    If you want to send it to the closest one, use 
    setRequestP2PConfiguration(1, 5, 0)
 

Parameters:
locationKey - The target hash to search for during the routing process
Returns:
The send builder that allows to set options

sendDirect

public SendDirectBuilder sendDirect(PeerAddress recipientAddress)

sendDirect

public SendDirectBuilder sendDirect(PeerConnection recipientConnection)

sendDirect

@Deprecated
public SendDirectBuilder sendDirect()
Deprecated. 


bootstrap

public BootstrapBuilder bootstrap()

ping

public PingBuilder ping()

discover

public DiscoverBuilder discover()

addTracker

public AddTrackerBuilder addTracker(Number160 locationKey)

getTracker

public GetTrackerBuilder getTracker(Number160 locationKey)

parallelRequest

public ParallelRequestBuilder parallelRequest(Number160 locationKey)

broadcast

public BroadcastBuilder broadcast(Number160 messageKey)

reserve

public FutureChannelCreator reserve(RoutingConfiguration routingConfiguration,
                                    RequestP2PConfiguration requestP2PConfiguration,
                                    String name)
Reserves a connection for a routing and DHT operation. This call does not blocks. At least one of the arguments routingConfiguration or requestP2PConfiguration must not be null.

Parameters:
routingConfiguration - The information about the routing
requestP2PConfiguration - The information about the DHT operation
name - The name of the ChannelCreator, used for easier debugging
Returns:
A ChannelCreator that can create channel according to routingConfiguration and requestP2PConfiguration
Throws:
IllegalArgumentException - If both arguments routingConfiguration and requestP2PConfiguration are null

release

public void release(ChannelCreator channelCreator)
Release a ChannelCreator. The permits will be returned so that they can be used again. This is a wrapper for ConnectionReservation.

Parameters:
channelCreator - The ChannelCreator that is not used anymore

setFutureTimeout

public void setFutureTimeout(BaseFuture baseFuture,
                             int millis,
                             String reason)
Sets a timeout for this future. If the timeout passes, the future fails with the reason provided

Parameters:
baseFuture - The future to set the timeout
millis - The time in milliseconds until this future is considered a failure.
reason - The reason why this future failed

isShutdown

public boolean isShutdown()
Returns true if shutdown has been initiated



Copyright © 2013. All Rights Reserved.