D
- the class of the administrative messages sent between directory instances. Must be serializable.public abstract class BaseDirectory<D extends java.io.Serializable> extends ListeningPost<D,java.lang.String>
Modifier and Type | Field and Description |
---|---|
static int |
MEMBER_ROLE |
static int |
OWNER_LOC |
static int |
OWNER_ROLE |
static int |
UNKNOWN_ROLE |
Constructor and Description |
---|
BaseDirectory(DataPipe<D,java.lang.String> pipe,
int networkID,
java.lang.String localDeviceID)
Alternative constructor, that initializes with request code and local display name 'null'.
|
BaseDirectory(DataPipe<D,java.lang.String> pipe,
java.lang.String reqCode,
int networkID,
java.lang.String localDeviceID)
Alternative constructor, that initializes with local display name 'null'.
|
BaseDirectory(DataPipe<D,java.lang.String> pipe,
java.lang.String reqCode,
int networkID,
java.lang.String localDisplayName,
java.lang.String localDeviceID,
boolean useDeviceIDAsLocationID)
Basic Constructor of the directory
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close all operations of the directory.
|
boolean |
connect()
Client (Non-group owner) Routine, tries to establish a connection with the
group owner, with default settings: unlimited retries, 3 secs apart.
|
abstract boolean |
connect(int tries,
int time_out)
Client (Non-group owner) Routine, tries to establish a connection with the
group owner.
|
void |
doWifiAdapterStatusChanged(boolean enabled)
Invoke network status changed listeners.
|
void |
doWifiConnectionStatusChanged(boolean connected)
Invoke network status changed listeners.
|
boolean |
establishRole()
Try to establish the role of this directory.
|
java.lang.String |
getDeviceID()
Returns the unique identify of the application that this directory is part of.
|
java.lang.String |
getDisplayName()
Returns the display name of this directory.
|
java.lang.String |
getLocalName()
Returns the device name of this location.
|
NodeInfo |
getLocalNode() |
int |
getLocation()
Get the location of the local node
|
java.util.Collection<java.lang.Integer> |
getLocations()
Return a list containing all location ids in this directory.
|
java.util.Collection<java.lang.Integer> |
getLocations(int networkID)
Get all locations associated with a given network type
|
java.lang.String |
getName(int loc)
Returns the device name of the given location identifier
|
int |
getNetworkID()
Returns the network ID of this directory
|
NodeInfo |
getNode(java.net.InetAddress inetaddr)
Get the node info corresponding to the input inet address.
|
NodeInfo |
getNode(int loc)
Get a node given a unique location identifier.
|
NodeInfo |
getNode(java.lang.String ipAddr)
Get the node info corresponding to the input ip address.
|
NodeInfo[] |
getNodeArray() |
java.util.HashMap<java.lang.Integer,java.lang.String> |
getNodeMap()
Return a hash map that maps locations to IP addresses.
|
java.util.List<NodeInfo> |
getNodes() |
java.lang.String |
getReqCode()
Returns the request code of this directory.
|
boolean |
hasNode(java.net.InetAddress inetaddr)
Returns true if a peer with this InetAddress exists in this directory.
|
boolean |
hasNode(int loc)
Returns true if a peer with this location ID exists in this directory.
|
boolean |
hasNode(NodeInfo peer)
Returns true if a node with this InetAddress exists in this directory.
|
boolean |
hasNode(java.lang.String ipAddr)
Returns true if a peer with this IP address exists in this directory.
|
void |
init()
Runs the 'start' method of this Thread class.
|
boolean |
isConnected()
Returns true if directory has either established a connection with an owner directory,
or is an owner and is ready to receive connection request.
|
boolean |
isConnectedTo(int destLoc)
Checks if given location is connected to local node, period.
|
boolean |
isConnectedTo(int destLoc,
int networkID)
Checks if given location is connected to local node via the given network type.
|
boolean |
isKnown() |
boolean |
isMember() |
boolean |
isOwner() |
boolean |
isUnknown() |
boolean |
isWifiConnected()
Returns true if directory has been notified that Wifi adapter is connected.
|
boolean |
isWifiEnabled()
Returns true if directory has been notified that Wifi adapter is enabled.
|
NodeInfo |
localNodeInfo(int loc,
java.lang.String ipAddress,
java.lang.String role) |
int |
locRole(int loc)
Return the role of the given location identifier
|
java.lang.String |
lookupIPAddress(int loc)
Lookup for given location's address
|
java.util.Map<java.lang.Integer,java.lang.String> |
lookupIPAddresses(int loc)
Lookup for all possible network-identifier/address pairs of a given location
|
NodeInfo |
newNodeInfo(java.lang.String ipAddress,
java.lang.String name,
java.lang.String deviceID,
java.lang.String role) |
void |
run()
Run thread operation of a BaseDirectory.
|
abstract void |
serve()
Run owner service
|
void |
setDisplayName(java.lang.String name)
Set display name to the given String argument
|
void |
setIsConnected(boolean b) |
void |
setIsWifiEnabled(boolean wifiEnabled) |
void |
setLocalNode(NodeInfo node)
Set the local node to the given node.
|
void |
setMemberRole()
Set this directory to the role of a member.
|
void |
setOwnerIP(java.lang.String ownerIP)
Set the owner's IP address
|
void |
setOwnerRole()
Set this directory to the role of an owner.
|
void |
setReqCode(java.lang.String reqCode)
Set request code to the given String argument
|
void |
setUseHashCodeIdentity(boolean set)
Sets this directory to use Hash Code Identity.
|
java.lang.String |
showRole() |
java.lang.String |
showRole(int role)
protected int loc_count = 1;
|
void |
stopRoutines()
Signals the directory to stop all active subroutines.
|
addConnectionEstablishedListener, addDirectoryChangedListener, addLocalNodeInfoAvailableListener, addNetworkStatusChangedListener, addOwnerTerminationListener, addRoleEstablishedListener, displayDirectorySetupDialogs, initNetworkNotifications, pauseNetworkNotifications, removeConnectionEstablishedListener, removeDirectoryChangedListener, removeLocalNodeInfoAvailableListener, removeNetworkStatusChangedListener, removeOwnerTerminationListener, removeRoleEstablishedListener, resumeNetworkNotifications
sendData, sendData, sendData, sendData, sendDataThreaded, sendDataThreaded
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
public static final int OWNER_ROLE
public static final int MEMBER_ROLE
public static final int UNKNOWN_ROLE
public static final int OWNER_LOC
public BaseDirectory(DataPipe<D,java.lang.String> pipe, java.lang.String reqCode, int networkID, java.lang.String localDisplayName, java.lang.String localDeviceID, boolean useDeviceIDAsLocationID)
pipe
- the data pipe that exchanges administrative data, to be embedded in this base directory.reqCode
- the request code that is required to join this directory.networkID
- the unique identifier of the network used by this directory.localDisplayName
- the local display name of the directory.localDeviceID
- the local device ID, used to uniquely identify the application which this directory is part of.useDeviceIDAsLocationID
- true if device ID should be used as location ID. Otherwise, owner location will be assign '0'
with members uniquely assigned increments of 1.public BaseDirectory(DataPipe<D,java.lang.String> pipe, java.lang.String reqCode, int networkID, java.lang.String localDeviceID)
pipe
- the data pipe that exchanges administrative data, to be embedded in this base directory.reqCode
- the request code that is required to join this directory.networkID
- the unique identifier of the network used by this directory.localDeviceID
- the local device ID, used to uniquely identify the application which this directory is part of.public BaseDirectory(DataPipe<D,java.lang.String> pipe, int networkID, java.lang.String localDeviceID)
pipe
- the data pipe that exchanges administrative data, to be embedded in this base directory.networkID
- the unique identifier of the network used by this directory.localDeviceID
- the local device ID, used to uniquely identify the application which this directory is part of.public int getNetworkID()
public java.lang.String getDeviceID()
public java.lang.String getDisplayName()
public java.lang.String getReqCode()
public void setUseHashCodeIdentity(boolean set)
set
- true if directory is to use hash code identity.public void setReqCode(java.lang.String reqCode)
reqCode
- the request codepublic void setDisplayName(java.lang.String name)
name
- the display namepublic boolean establishRole()
public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public void init()
public void stopRoutines()
public void close()
close
in class DataPipeManager<D extends java.io.Serializable,java.lang.String>
public abstract void serve()
public abstract boolean connect(int tries, int time_out)
tries
- number of tries.time_out
- time in milliseconds till next try.public boolean connect()
public void setOwnerIP(java.lang.String ownerIP)
ownerIP
- IP address of the ownerpublic boolean isOwner()
public boolean isMember()
public boolean isUnknown()
public boolean isKnown()
public void setOwnerRole()
public void setMemberRole()
public java.lang.String showRole()
public java.lang.String showRole(int role)
role
- the role of a directory.public int locRole(int loc)
loc
- the location identifierpublic boolean isWifiEnabled()
public void setIsWifiEnabled(boolean wifiEnabled)
public boolean isWifiConnected()
public boolean isConnected()
public void setIsConnected(boolean b)
public NodeInfo newNodeInfo(java.lang.String ipAddress, java.lang.String name, java.lang.String deviceID, java.lang.String role)
public NodeInfo localNodeInfo(int loc, java.lang.String ipAddress, java.lang.String role)
public java.util.HashMap<java.lang.Integer,java.lang.String> getNodeMap()
public NodeInfo[] getNodeArray()
public java.util.List<NodeInfo> getNodes()
public NodeInfo getLocalNode()
public void setLocalNode(NodeInfo node)
node
- a node info class to be set as the local node.public boolean hasNode(int loc)
loc
- public boolean hasNode(java.net.InetAddress inetaddr)
inetaddr
- public boolean hasNode(java.lang.String ipAddr)
ipAddr
- public boolean hasNode(NodeInfo peer)
inetaddr
- public NodeInfo getNode(java.net.InetAddress inetaddr)
inetaddr
- the inet address of the desired node.public NodeInfo getNode(java.lang.String ipAddr)
ipAddr
- the ip address of the desired node.public NodeInfo getNode(int loc)
loc
- the location of the nodepublic java.lang.String getLocalName()
public java.lang.String getName(int loc)
loc
- the locationpublic void doWifiAdapterStatusChanged(boolean enabled)
doWifiAdapterStatusChanged
in class ListeningPost<D extends java.io.Serializable,java.lang.String>
enabled
- true if the wifi adapter is enabled.public void doWifiConnectionStatusChanged(boolean connected)
doWifiConnectionStatusChanged
in class ListeningPost<D extends java.io.Serializable,java.lang.String>
connected
- true if the wifi adapter is connected to some network.public int getLocation()
Neighborhood
public java.util.Collection<java.lang.Integer> getLocations(int networkID)
Neighborhood
networkID
- the unique identifier of the networkpublic java.util.Collection<java.lang.Integer> getLocations()
public boolean isConnectedTo(int destLoc, int networkID)
Neighborhood
destLoc
- destination locationnetworkID
- unique identifier of the networkpublic boolean isConnectedTo(int destLoc)
Neighborhood
destLoc
- destination locationpublic java.lang.String lookupIPAddress(int loc)
Neighborhood
loc
- location to lookuppublic java.util.Map<java.lang.Integer,java.lang.String> lookupIPAddresses(int loc)
Neighborhood
loc
- location to lookup