public CENTRAL_LOCK() { super(); addLockListener(this); }
protected void copyLocksTo(List<Address> new_joiners) { Map<String,ServerLock> copy; synchronized(server_locks) { copy=new HashMap<>(server_locks); } log.trace("[%s] copying locks to %s", local_addr, new_joiners); for(Map.Entry<String,ServerLock> entry: copy.entrySet()) { for(Address joiner: new_joiners) { ServerLock lock = entry.getValue(); if (lock.owner != null) { sendCreateLockRequest(joiner, entry.getKey(), entry.getValue().owner); } synchronized (lock.condition) { Queue<Owner> queue = lock.condition.queue; for (Owner owner : queue) { sendAwaitConditionRequest(lock.lock_name, owner); } } } } } }
protected void updateBackups(Type type, String lock_name, Owner owner) { synchronized(backups) { for(Address backup: backups) sendRequest(backup, type, lock_name, owner, 0, false); } }
public void unlocked(String lock_name, Owner owner) { if(is_coord) updateBackups(Type.DELETE_LOCK, lock_name, owner); }
@Override protected void init() { try { if (this.channel == null) { this.channel = newChannel(jgroupsConfig); } ProtocolStack protocolStack = channel.getProtocolStack(); Protocol centralLock = protocolStack.findProtocol(CENTRAL_LOCK.class); if (centralLock == null) { // add the locking protocol CENTRAL_LOCK lockingProtocol = new CENTRAL_LOCK(); // we have to call init because the channel has already been created lockingProtocol.init(); protocolStack.addProtocol(lockingProtocol); } // Add a listener through which we'll know what's going on within the cluster ... this.channel.addChannelListener(listener); // Set the receiver through which we'll receive all of the changes ... this.channel.setReceiver(receiver); // Now connect to the cluster ... this.channel.connect(clusterName); } catch (Exception e) { throw new RuntimeException(e); } }
public void handleView(View view) { super.handleView(view); Address old_coord=coord; if(view.size() > 0) { coord=view.getCoord(); is_coord=coord.equals(local_addr); log.debug("[%s] coord=%s, is_coord=%b", local_addr, coord, is_coord); } if(is_coord && num_backups > 0) { List<Address> new_backups=Util.pickNext(view.getMembers(), local_addr, num_backups); List<Address> copy_locks_list=null; synchronized(backups) { if(!backups.equals(new_backups)) { copy_locks_list=new ArrayList<>(new_backups); copy_locks_list.removeAll(backups); backups.clear(); backups.addAll(new_backups); } } if(copy_locks_list != null && !copy_locks_list.isEmpty()) copyLocksTo(copy_locks_list); } // For all non-acquired client locks, send the GRANT_LOCK request to the new coordinator (if changed) if(old_coord != null && !old_coord.equals(coord)) client_lock_table.resendPendingLockRequests(); }
this.channel = new ForkChannel(mainChannel, forkStackId, FORK_CHANNEL_NAME, new CENTRAL_LOCK());
public void awaiting(String lock_name, Owner owner) { if(is_coord) updateBackups(Type.CREATE_AWAITER, lock_name, owner); }
@Override protected void init() { try { if (this.channel == null) { this.channel = newChannel(jgroupsConfig); } ProtocolStack protocolStack = channel.getProtocolStack(); Protocol centralLock = protocolStack.findProtocol(CENTRAL_LOCK.class); if (centralLock == null) { // add the locking protocol CENTRAL_LOCK lockingProtocol = new CENTRAL_LOCK(); // we have to call init because the channel has already been created lockingProtocol.init(); protocolStack.addProtocol(lockingProtocol); } // Add a listener through which we'll know what's going on within the cluster ... this.channel.addChannelListener(listener); // Set the receiver through which we'll receive all of the changes ... this.channel.setReceiver(receiver); // Now connect to the cluster ... this.channel.connect(clusterName); } catch (Exception e) { throw new RuntimeException(e); } }
public void handleView(View view) { super.handleView(view); Address old_coord=coord; if(view.size() > 0) { coord=view.getCoord(); is_coord=coord.equals(local_addr); log.debug("[%s] coord=%s, is_coord=%b", local_addr, coord, is_coord); } if(is_coord && num_backups > 0) { List<Address> new_backups=Util.pickNext(view.getMembers(), local_addr, num_backups); List<Address> copy_locks_list=null; synchronized(backups) { if(!backups.equals(new_backups)) { copy_locks_list=new ArrayList<>(new_backups); copy_locks_list.removeAll(backups); backups.clear(); backups.addAll(new_backups); } } if(copy_locks_list != null && !copy_locks_list.isEmpty()) copyLocksTo(copy_locks_list); } // For all non-acquired client locks, send the GRANT_LOCK request to the new coordinator (if changed) if(old_coord != null && !old_coord.equals(coord)) client_lock_table.resendPendingLockRequests(); }
this.channel = new ForkChannel(mainChannel, forkStackId, FORK_CHANNEL_NAME, new CENTRAL_LOCK());
@Override protected void sendDeleteAwaitConditionRequest(String lock_name, Owner owner) { sendRequest(coord, Type.DELETE_LOCK_AWAIT, lock_name, owner, 0, false); }
public void awaited(String lock_name, Owner owner) { if(is_coord) updateBackups(Type.DELETE_AWAITER, lock_name, owner); }
protected void copyLocksTo(List<Address> new_joiners) { Map<String,ServerLock> copy; synchronized(server_locks) { copy=new HashMap<>(server_locks); } log.trace("[%s] copying locks to %s", local_addr, new_joiners); for(Map.Entry<String,ServerLock> entry: copy.entrySet()) { for(Address joiner: new_joiners) { ServerLock lock = entry.getValue(); if (lock.owner != null) { sendCreateLockRequest(joiner, entry.getKey(), entry.getValue().owner); } synchronized (lock.condition) { Queue<Owner> queue = lock.condition.queue; for (Owner owner : queue) { sendAwaitConditionRequest(lock.lock_name, owner); } } } } } }
public CENTRAL_LOCK() { super(); addLockListener(this); }
@Override protected void sendSignalConditionRequest(String lock_name, boolean all) { sendRequest(coord, all ? Type.COND_SIG_ALL : Type.COND_SIG, lock_name, null, 0, false); }
public void locked(String lock_name, Owner owner) { if(is_coord) updateBackups(Type.CREATE_LOCK, lock_name, owner); }
protected void sendCreateLockRequest(Address dest, String lock_name, Owner owner) { sendRequest(dest, Type.CREATE_LOCK, lock_name, owner, 0, false); }
public void locked(String lock_name, Owner owner) { if(is_coord) updateBackups(Type.CREATE_LOCK, lock_name, owner); }
@Override protected void sendAwaitConditionRequest(String lock_name, Owner owner) { sendRequest(coord, Type.LOCK_AWAIT, lock_name, owner, 0, false); }