public class JSyncReplica extends java.lang.Object implements JSyncConstants
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
REVISION |
SC_BAD_ADDRESS, SC_BAD_LEADER, SC_BAD_MESSAGE, SC_INTERNAL_SERVER_ERROR, SC_JOIN_REJECTED, SC_LEADER_CANNOT_JOIN, SC_NO_ACK, SC_NO_SEND, SC_OK, SC_UNKNOWN, SC_UNKNOWN_URID, SC_URID_ALREADY_ADDED, STATUS_LEADER, STATUS_LONE, STATUS_MEMBER, STATUS_SUBLEADER
CRLF, MILLIS_IN_ONE_DAY, MILLIS_IN_ONE_HOUR, MILLIS_IN_ONE_MINUTE, MILLIS_IN_ONE_MONTH, MILLIS_IN_ONE_SECOND, MILLIS_IN_ONE_WEEK, MILLIS_IN_ONE_YEAR
Modifier and Type | Method and Description |
---|---|
void |
addListener(JSyncListener listener)
Adds a JSync listener
|
void |
close()
Close all JSyncReplica resources when ending.
|
int |
disjoin()
Disjoins from the leader replica.
|
static JSyncReplica |
getInstance(Store store,
java.lang.String url,
boolean syncFiles,
boolean canBeJoined,
boolean canLeaderJoin,
boolean autoUpdate,
java.io.File logDir,
java.io.File fileDir,
java.io.File downloadDir,
long downloadInterval,
java.lang.String leaderUrl)
Gets a replica
|
ReplicaInfo |
getLeader() |
java.lang.String |
getLeaderUrl() |
JSyncLogger |
getLogger() |
long |
getMaxOpPerUpdate() |
Stamp |
getProgressStamp() |
StampTable |
getProgressTable() |
java.util.Map<java.lang.String,ReplicaInfo> |
getReplicaMap() |
java.lang.String |
getStatus()
Return the status of this replica (STATUS_LONE, STATUS_MEMBER, STATUS_SUBLEADER or STATUS_LEADER)
|
java.lang.String |
getStatusLabel(int sc,
java.util.Locale locale) |
boolean |
getSyncFiles()
Return true if file replication is enabled
|
java.lang.String |
getUrid() |
java.lang.String |
getUrl() |
void |
globalSuggestJoin(JSyncPreviousReplicaManager previousReplicaManager)
Suggest all replica to join this replica as leader.
|
boolean |
isCanBeJoined() |
boolean |
isJoined() |
boolean |
isKnownReplica(java.lang.String urid)
Returns true if this replica is known (i.e. is my leader or a replica of my group)
|
boolean |
isLeader() |
boolean |
isSubLeader() |
boolean |
isSuperLeader() |
int |
join()
Joins a replica.
|
boolean |
needForUpdate() |
boolean |
processDisjoinMessage(java.io.OutputStream out,
DisjoinMessage msg)
Process a DisjoinMessage
|
boolean |
processJoinMessage(java.io.OutputStream out,
JoinMessage msg)
Process a JoinMessage
|
boolean |
processMessage(java.io.OutputStream out,
Message msg)
Dispatches on the right method to process the given message
|
boolean |
processSuggestJoinMessage(java.io.OutputStream out,
SuggestJoinMessage msg)
Process a SuggestJoinMessage
|
boolean |
processUpdateMessage(java.io.OutputStream out,
UpdateMessage msg)
Process an UpdateMessage
|
void |
removeListener(JSyncListener listener)
Removes a JSync listener
|
void |
removeReplica(java.lang.String urid)
Removes the given replica of the group of this leader
|
void |
setAutoUpdate(boolean autoUpdate)
Enable or disable update propagation when joining
|
void |
setLeaderUrl(java.lang.String leaderUrl) |
void |
setMaxOpPerUpdate(long maxOpPerUpdate)
Set the maximum count of operations sent per update
|
void |
setSyncFiles(boolean syncFiles)
Enable or disable file replication
|
void |
setUrl(java.lang.String url)
Set the url of this replica
|
void |
suggestJoin(java.lang.String urlReplica)
Suggest one replica to join this replica as leader.
|
java.lang.String |
toString() |
int |
update()
Sends updates to the leader (if any) and to the group (if any)
|
int |
updateGroup()
Sends the update to each replica of the group
|
int |
updateLeader()
Sends the updates to the leader replica.
|
public static final java.lang.String REVISION
public static JSyncReplica getInstance(Store store, java.lang.String url, boolean syncFiles, boolean canBeJoined, boolean canLeaderJoin, boolean autoUpdate, java.io.File logDir, java.io.File fileDir, java.io.File downloadDir, long downloadInterval, java.lang.String leaderUrl)
store
- the storeurl
- the url this replica listen tosyncFiles
- true if files must be replicatedcanBeJoined
- can other replica join this onecanLeaderJoin
- if this replica is a leader, can it join another leaderlogDir
- the log directory (if null, no log)fileDir
- the file directory to synchronize (if null, no file sync.)downloadDir
- the directory used by FileFetcher to manage the file to be downloadeddownloadInterval
- the time interval between each download try.public java.lang.String getUrid()
Store.getUrid()
public java.lang.String getUrl()
public void setUrl(java.lang.String url)
url
- the url of this replicapublic boolean getSyncFiles()
public void setSyncFiles(boolean syncFiles)
syncFiles
- true if files must be replicatedpublic void setAutoUpdate(boolean autoUpdate)
autoUpdate
- true if updates must be propagated at joinpublic void setMaxOpPerUpdate(long maxOpPerUpdate)
maxOpPerUpdate
- the maximum count of operations sent by updatepublic long getMaxOpPerUpdate()
public boolean isJoined()
public ReplicaInfo getLeader()
public StampTable getProgressTable()
Store.getProgressTable()
public Stamp getProgressStamp()
Store.getProgressStamp()
public boolean isLeader()
public boolean isSuperLeader()
public boolean isSubLeader()
public boolean isKnownReplica(java.lang.String urid)
urid
- the urid to checkpublic void removeReplica(java.lang.String urid)
urid
- the urid of the replica to be removedpublic java.util.Map<java.lang.String,ReplicaInfo> getReplicaMap()
public boolean needForUpdate()
public JSyncLogger getLogger()
public java.lang.String getStatusLabel(int sc, java.util.Locale locale)
sc
- the status code (must be a new status code value (e.g. 1101, 1200, ...)locale
- the localepublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String getStatus()
public int join()
public void globalSuggestJoin(JSyncPreviousReplicaManager previousReplicaManager)
public void suggestJoin(java.lang.String urlReplica)
urlReplica
- url of one joined replicapublic int disjoin()
public int update()
updateLeader()
,
updateGroup()
public int updateLeader()
public int updateGroup()
public boolean processMessage(java.io.OutputStream out, Message msg) throws java.io.IOException
out
- the output stream to replymsg
- the message to processjava.io.IOException
public boolean processJoinMessage(java.io.OutputStream out, JoinMessage msg) throws java.io.IOException
out
- the output stream to replymsg
- the message to processjava.io.IOException
public boolean processSuggestJoinMessage(java.io.OutputStream out, SuggestJoinMessage msg) throws java.io.IOException
out
- the output stream to replymsg
- the message to processjava.io.IOException
public boolean processDisjoinMessage(java.io.OutputStream out, DisjoinMessage msg) throws java.io.IOException
out
- the output stream to replymsg
- the message to processjava.io.IOException
public boolean processUpdateMessage(java.io.OutputStream out, UpdateMessage msg) throws java.io.IOException
out
- the output stream to replymsg
- the message to processjava.io.IOException
public void addListener(JSyncListener listener)
listener
- the JSync listener to be addedpublic void removeListener(JSyncListener listener)
listener
- the JSync listener to be removedpublic void close()
public java.lang.String getLeaderUrl()
public void setLeaderUrl(java.lang.String leaderUrl)
public boolean isCanBeJoined()
Copyright © 2001-2010 Jalios SA. All Rights Reserved.