Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ns

  • Loading branch information...
commit c992dac3fc995506c6fc7fea665d10f787a30e29 1 parent c6eabe6
Bela Ban authored
16 src/org/jgroups/blocks/locking/AbstractLockService.java
View
@@ -34,7 +34,14 @@
/** Bypasses message bundling if set */
protected boolean bypass_bundling=true;
- protected static enum Type {GRANT_LOCK, LOCK_GRANTED, LOCK_DENIED, RELEASE_LOCK}
+ protected static enum Type {
+ GRANT_LOCK, // request to acquire a lock
+ LOCK_GRANTED, // response to sender of GRANT_LOCK on succcessful lock acquisition
+ LOCK_DENIED, // response to sender of GRANT_LOCK on unsuccessful lock acquisition (e.g. on tryLock())
+ RELEASE_LOCK, // request to release a lock
+ CREATE_LOCK, // request to create a server lock (sent by coordinator to backups). Used by CentralLockService
+ DELETE_LOCK // request to delete a server lock (sent by coordinator to backups). Used by CentralLockService
+ }
@@ -188,7 +195,7 @@ protected void sendRequest(Address dest, Type type, String lock_name, Owner owne
if(bypass_bundling)
msg.setFlag(Message.DONT_BUNDLE);
if(log.isTraceEnabled())
- log.trace("[" + ch.getAddress() + "] --> [ALL] " + req);
+ log.trace("[" + ch.getAddress() + "] --> [" + (dest == null? "ALL" : dest) + "] " + req);
try {
ch.send(msg);
}
@@ -346,7 +353,10 @@ protected synchronized void handleRequest(Request req) {
sendLockResponse(AbstractLockService.Type.LOCK_GRANTED, req.owner, req.lock_name);
}
else {
- if(!current_owner.equals(req.owner)) {
+ if(current_owner.equals(req.owner)) {
+ sendLockResponse(AbstractLockService.Type.LOCK_GRANTED, req.owner, req.lock_name);
+ }
+ else {
if(req.is_trylock && req.timeout <= 0)
sendLockResponse(AbstractLockService.Type.LOCK_DENIED, req.owner, req.lock_name);
else
57 src/org/jgroups/blocks/locking/CentralLockService.java
View
@@ -3,6 +3,10 @@
import org.jgroups.Address;
import org.jgroups.JChannel;
import org.jgroups.View;
+import org.jgroups.annotations.Experimental;
+
+import java.util.ArrayList;
+import java.util.List;
/**
* Implementation of a lock service which acquires locks by contacting the coordinator.</p> Because the central
@@ -10,10 +14,17 @@
* An alternative is also the {@link PeerLockService}.
* @author Bela Ban
*/
+@Experimental
public class CentralLockService extends AbstractLockService {
protected Address coord;
protected boolean is_coord;
+ /** Number of backups to the coordinator. Server locks get replicated to these nodes as well */
+ protected int num_backups=1;
+
+ protected final List<Address> backups=new ArrayList<Address>();
+
+
public CentralLockService() {
super();
}
@@ -22,6 +33,22 @@ public CentralLockService(JChannel ch) {
super(ch);
}
+ public Address getCoord() {
+ return coord;
+ }
+
+ public boolean isCoord() {
+ return is_coord;
+ }
+
+ public int getNumberOfBackups() {
+ return num_backups;
+ }
+
+ public void setNumberOfBackups(int num_backups) {
+ this.num_backups=num_backups;
+ }
+
protected void sendGrantLockRequest(String lock_name, Owner owner, long timeout, boolean is_trylock) {
if(coord != null)
sendRequest(coord, Type.GRANT_LOCK, lock_name, owner, timeout, is_trylock);
@@ -41,8 +68,38 @@ public void viewAccepted(View view) {
if(log.isDebugEnabled())
log.debug("local_addr=" + ch.getAddress() + ", coord=" + coord + ", is_coord=" + is_coord);
}
+
+ if(num_backups > 0) {
+ List<Address> new_joiners=null;
+ synchronized(backups) {
+ List<Address> tmp=determineBackups(view.getMembers());
+ if(!tmp.isEmpty() && !tmp.equals(backups)) {
+ // copy locks to new joiners
+
+ new_joiners=determineNewJoiners();
+ }
+ backups.clear();
+ backups.addAll(tmp);
+ }
+ if(new_joiners != null && !new_joiners.isEmpty())
+ copyLocksTo(new_joiners);
+ }
}
+ protected List<Address> determineBackups(List<Address> members) {
+ List<Address> retval=new ArrayList<Address>();
+
+ return retval;
+ }
+
+ protected List<Address> determineNewJoiners() {
+ return null;
+ }
+
+ protected void copyLocksTo(List<Address> new_joiners) {
+
+ }
+
}
2  src/org/jgroups/blocks/locking/PeerLockService.java
View
@@ -4,6 +4,7 @@
import org.jgroups.JChannel;
import org.jgroups.Message;
import org.jgroups.View;
+import org.jgroups.annotations.Experimental;
import java.util.ArrayList;
import java.util.List;
@@ -26,6 +27,7 @@
* An alternative is also the {@link CentralLockService}.
* @author Bela Ban
*/
+@Experimental
public class PeerLockService extends AbstractLockService {
public PeerLockService() {
Please sign in to comment.
Something went wrong with that request. Please try again.