|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.jalios.jstore.jsync.JSyncReplica
public class JSyncReplica
This class provides supports to manage a replica, manages JSyncListener, send and process the JSyncMessage.
Field Summary | |
---|---|
static String |
REVISION
|
Fields inherited from interface com.jalios.jstore.jsync.JSyncConstants |
---|
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 |
Fields inherited from interface com.jalios.util.JaliosConstants |
---|
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 |
Method Summary | |
---|---|
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,
String url,
boolean syncFiles,
boolean canBeJoined,
boolean canLeaderJoin,
boolean autoUpdate,
File logDir,
File fileDir,
File downloadDir,
long downloadInterval,
String leaderUrl)
Gets a replica |
ReplicaInfo |
getLeader()
|
String |
getLeaderUrl()
|
JSyncLogger |
getLogger()
|
long |
getMaxOpPerUpdate()
|
Stamp |
getProgressStamp()
|
StampTable |
getProgressTable()
|
Map<String,ReplicaInfo> |
getReplicaMap()
|
String |
getStatus()
Return the status of this replica (STATUS_LONE, STATUS_MEMBER, STATUS_SUBLEADER or STATUS_LEADER) |
String |
getStatusLabel(int sc,
Locale locale)
|
boolean |
getSyncFiles()
Return true if file replication is enabled |
String |
getUrid()
|
String |
getUrl()
|
void |
globalSuggestJoin(JSyncPreviousReplicaManager previousReplicaManager)
Suggest all replica to join this replica as leader. |
boolean |
isCanBeJoined()
|
boolean |
isJoined()
|
boolean |
isKnownReplica(String urid)
Returns true if this replica is known (i.e. |
boolean |
isLeader()
|
boolean |
isSubLeader()
|
boolean |
isSuperLeader()
|
int |
join()
Joins a replica. |
boolean |
needForUpdate()
|
boolean |
processDisjoinMessage(OutputStream out,
DisjoinMessage msg)
Process a DisjoinMessage |
boolean |
processJoinMessage(OutputStream out,
JoinMessage msg)
Process a JoinMessage |
boolean |
processMessage(OutputStream out,
Message msg)
Dispatches on the right method to process the given message |
boolean |
processSuggestJoinMessage(OutputStream out,
SuggestJoinMessage msg)
Process a SuggestJoinMessage |
boolean |
processUpdateMessage(OutputStream out,
UpdateMessage msg)
Process an UpdateMessage |
void |
removeListener(JSyncListener listener)
Removes a JSync listener |
void |
removeReplica(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(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(String url)
Set the url of this replica |
void |
suggestJoin(String urlReplica)
Suggest one replica to join this replica as leader. |
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String REVISION
Method Detail |
---|
public static JSyncReplica getInstance(Store store, String url, boolean syncFiles, boolean canBeJoined, boolean canLeaderJoin, boolean autoUpdate, File logDir, File fileDir, File downloadDir, long downloadInterval, 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 String getUrid()
Store.getUrid()
public String getUrl()
public void setUrl(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(String urid)
urid
- the urid to check
public void removeReplica(String urid)
urid
- the urid of the replica to be removedpublic Map<String,ReplicaInfo> getReplicaMap()
public boolean needForUpdate()
public JSyncLogger getLogger()
public String getStatusLabel(int sc, Locale locale)
sc
- the status code (must be a new status code value (e.g. 1101, 1200, ...)locale
- the locale
public String toString()
toString
in class Object
public String getStatus()
public int join()
public void globalSuggestJoin(JSyncPreviousReplicaManager previousReplicaManager)
public void suggestJoin(String urlReplica)
urlReplica
- url of one joined replicapublic int disjoin()
public int update()
updateLeader()
,
updateGroup()
public int updateLeader()
public int updateGroup()
public boolean processMessage(OutputStream out, Message msg) throws IOException
out
- the output stream to replymsg
- the message to process
IOException
public boolean processJoinMessage(OutputStream out, JoinMessage msg) throws IOException
out
- the output stream to replymsg
- the message to process
IOException
public boolean processSuggestJoinMessage(OutputStream out, SuggestJoinMessage msg) throws IOException
out
- the output stream to replymsg
- the message to process
IOException
public boolean processDisjoinMessage(OutputStream out, DisjoinMessage msg) throws IOException
out
- the output stream to replymsg
- the message to process
IOException
public boolean processUpdateMessage(OutputStream out, UpdateMessage msg) throws IOException
out
- the output stream to replymsg
- the message to process
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 String getLeaderUrl()
public void setLeaderUrl(String leaderUrl)
public boolean isCanBeJoined()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |