public void becomeClient() { ClientGmsImpl tmp=(ClientGmsImpl)impls.get(CLIENT); if(tmp == null) { tmp=new ClientGmsImpl(this); impls.put(CLIENT, tmp); } try { tmp.init(); } catch(Exception e) { log.error(Util.getMessage("ExceptionSwitchingToClientRole"), e); } setImpl(tmp); }
if(installViewIfValidJoinRsp(join_promise, false)) return; if(installViewIfValidJoinRsp(join_promise, false)) return; if(responses.isEmpty()) { log.info("%s: no members discovered after %d ms: creating cluster as first member", gms.local_addr, diff); becomeSingletonMember(mbr); return; List<Address> coords=getCoords(responses); if(firstOfAllClients(mbr, responses)) return; sendJoinMessage(coord, mbr, joinWithStateTransfer, useFlushIfPresent); if(installViewIfValidJoinRsp(join_promise, true)) return; log.warn("%s: JOIN(%s) sent to %s timed out (after %d ms), on try %d", becomeSingletonMember(mbr); return;
protected boolean installViewIfValidJoinRsp(final Promise<JoinRsp> join_promise, boolean block_for_rsp) { boolean success=false; JoinRsp rsp=null; try { if(join_promise.hasResult()) rsp=join_promise.getResult(1, true); else if(block_for_rsp) rsp=join_promise.getResult(gms.join_timeout, true); return success=rsp != null && isJoinResponseValid(rsp) && installView(rsp.getView(), rsp.getDigest()); } finally { if(success) gms.sendViewAck(rsp.getView().getCreator()); } }
findInitialMembers(); if(log.isDebugEnabled()) log.debug("initial_mbrs are " + initial_mbrs); if(initial_mbrs.isEmpty()) { becomeSingletonMember(mbr); return; coord=determineCoord(initial_mbrs); if(coord == null) { // e.g. because we have all clients only if(gms.handle_concurrent_startup == false) { if(log.isTraceEnabled()) log.trace("handle_concurrent_startup is false; ignoring responses of initial clients"); becomeSingletonMember(mbr); return; if(log.isTraceEnabled()) log.trace("I (" + mbr + ") am the first of the clients, will become coordinator"); becomeSingletonMember(mbr); return; if(log.isDebugEnabled()) log.debug("sending handleJoin(" + mbr + ") to " + coord); sendJoinMessage(coord, mbr); rsp=(JoinRsp)join_promise.getResult(gms.join_timeout); if(!installView(tmp_view)) { if(log.isErrorEnabled()) log.error("view installation failed, retrying to join group"); Util.sleep(gms.join_retry_timeout);
public void leave(Address mbr) { leaving=true; wrongMethod("leave"); }
/** Handles the case where no coord responses were received. Returns true if we became the coord * (caller needs to terminate the join() call), or false when the caller needs to continue */ protected boolean firstOfAllClients(final Address joiner, final Responses rsps) { log.trace("%s: could not determine coordinator from rsps %s", gms.local_addr, rsps); // so the member to become singleton member (and thus coord) is the first of all clients SortedSet<Address> clients=new TreeSet<>(); clients.add(joiner); // add myself again (was removed by findInitialMembers()) for(PingData response: rsps) clients.add(response.getAddress()); log.trace("%s: nodes to choose new coord from are: %s", gms.local_addr, clients); Address new_coord=clients.first(); if(new_coord.equals(joiner)) { log.trace("%s: I (%s) am the first of the nodes, will become coordinator", gms.local_addr, joiner); becomeSingletonMember(joiner); return true; } log.trace("%s: I (%s) am not the first of the nodes, waiting for another client to become coordinator", gms.local_addr, joiner); // Util.sleep(500); return false; }
public void leave(Address mbr) { leaving=true; wrongMethod("leave"); }
/** Handles the case where no coord responses were received. Returns true if we became the coord * (caller needs to terminate the join() call), or false when the caller needs to continue */ protected boolean firstOfAllClients(final Address joiner, final Responses rsps) { log.trace("%s: could not determine coordinator from rsps %s", gms.local_addr, rsps); // so the member to become singleton member (and thus coord) is the first of all clients SortedSet<Address> clients=new TreeSet<>(); clients.add(joiner); // add myself again (was removed by findInitialMembers()) for(PingData response: rsps) clients.add(response.getAddress()); log.trace("%s: nodes to choose new coord from are: %s", gms.local_addr, clients); Address new_coord=clients.first(); if(new_coord.equals(joiner)) { log.trace("%s: I (%s) am the first of the nodes, will become coordinator", gms.local_addr, joiner); becomeSingletonMember(joiner); return true; } log.trace("%s: I (%s) am not the first of the nodes, waiting for another client to become coordinator", gms.local_addr, joiner); // Util.sleep(500); return false; }
if(installViewIfValidJoinRsp(join_promise, false)) return; if(installViewIfValidJoinRsp(join_promise, false)) return; if(responses.isEmpty()) { log.trace("%s: no members discovered after %d ms: creating cluster as first member", gms.local_addr, diff); becomeSingletonMember(mbr); return; List<Address> coords=getCoords(responses); if(firstOfAllClients(mbr, responses)) return; sendJoinMessage(coord, mbr, joinWithStateTransfer, useFlushIfPresent); if(installViewIfValidJoinRsp(join_promise, true)) return; log.warn("%s: JOIN(%s) sent to %s timed out (after %d ms), on try %d", becomeSingletonMember(mbr); return;
public void becomeClient() { ClientGmsImpl tmp=(ClientGmsImpl)impls.get(CLIENT); if(tmp == null) { tmp=new ClientGmsImpl(this); impls.put(CLIENT, tmp); } try { tmp.init(); } catch(Exception e) { log.error("exception switching to client role", e); } setImpl(tmp); }
protected boolean installViewIfValidJoinRsp(final Promise<JoinRsp> join_promise, boolean block_for_rsp) { boolean success=false; JoinRsp rsp=null; try { if(join_promise.hasResult()) rsp=join_promise.getResult(1, true); else if(block_for_rsp) rsp=join_promise.getResult(gms.join_timeout, true); return success=rsp != null && isJoinResponseValid(rsp) && installView(rsp.getView(), rsp.getDigest()); } finally { if(success) gms.sendViewAck(rsp.getView().getCreator()); } }
public void leave(Address mbr) { leaving=true; wrongMethod("leave"); }
public void becomeClient() { ClientGmsImpl tmp=(ClientGmsImpl)impls.get(CLIENT); if(tmp == null) { tmp=new ClientGmsImpl(this); impls.put(CLIENT, tmp); } try { tmp.init(); } catch(Exception e) { log.error(Util.getMessage("ExceptionSwitchingToClientRole"), e); } setImpl(tmp); }