/*public void stabilize() * { * AsyncCallback getPredecessorCallBack = new AsyncCallback(processGetPredecessorForStabilize); * successor.beginGetPredecessor(getPredecessorCallBack); * //if(((Node)self<x) && ((Node)x<successor)) * // successor = x; * //successor.notify(self); * }*/ public void beginStabilize(AsyncCallback beginStabilizeCallBack, Object appState) { Console.WriteLine("Chord::Engine::beginStabilize ENTER"); lock (successorLock) { if (successor == self) { if (beginStabilizeCallBack != null) { IAsyncResult res = new Tashjik.Common.ObjectAsyncResult(appState, true, true); beginStabilizeCallBack(res); } else { return; } } } Tashjik.Common.AsyncCallback_Object thisAppState = new Tashjik.Common.AsyncCallback_Object(); thisAppState.callBack = beginStabilizeCallBack; thisAppState.obj = appState; Console.WriteLine("Chord::Engine::beginStabilize successor != self"); AsyncCallback getPredecessorCallBack = new AsyncCallback(processGetPredecessorForStabilize); lock (successorLock) { successor.beginGetPredecessor(getPredecessorCallBack, thisAppState); } Console.WriteLine("Chord::Engine::beginStabilize EXIT"); }
void processFingerTableFindSuccessorForJoin(IAsyncResult result) { Console.WriteLine("ChordRealNode::Engine::processFingerTableFindSuccessorForJoin ENTER"); ChordCommon.IChordNode_Object iNode_Object = (ChordCommon.IChordNode_Object)(result.AsyncState); Tashjik.Common.AsyncCallback_Object thisAppState = (Tashjik.Common.AsyncCallback_Object)(iNode_Object.obj); finger[((ObjectInt)(thisAppState.obj)).i] = iNode_Object.node; }
void processCheckPredecesorForOnClockTick(IAsyncResult result) { Console.WriteLine("ChordRealNode::processCheckPredecesorForOnClockTick ENTER"); Tashjik.Common.AsyncCallback_Object thisAppState = (Tashjik.Common.AsyncCallback_Object)(result.AsyncState); //AsyncCallback callBack = ((Tashjik.Common.AsyncCallback_Object)thisAppState).callBack; //Object appState1 = ((Tashjik.Common.AsyncCallback_Object)thisAppState).obj; AsyncCallback stabilizeCallBack = new AsyncCallback(processStabilizeForOnClockTick); engine.beginStabilize(stabilizeCallBack, thisAppState); }
void processStabilizeForOnClockTick(IAsyncResult result) { Console.WriteLine("ChordRealNode::processStabilizeForOnClockTick ENTER"); Tashjik.Common.AsyncCallback_Object thisAppState = (Tashjik.Common.AsyncCallback_Object)(result.AsyncState); AsyncCallback callBack = null; Object appState1 = null; if (thisAppState != null) { callBack = ((Tashjik.Common.AsyncCallback_Object)thisAppState).callBack; appState1 = ((Tashjik.Common.AsyncCallback_Object)thisAppState).obj; } engine.beginFixFingers(callBack, appState1); }
void processFindSuccessorForJoin(IAsyncResult result) { Console.WriteLine("ChordRealNode::Engine::processFindSuccessorForJoin ENTER"); ChordCommon.IChordNode_Object iNode_Object = (ChordCommon.IChordNode_Object)(result.AsyncState); Tashjik.Common.AsyncCallback_Object thisAppState = (Tashjik.Common.AsyncCallback_Object)(iNode_Object.obj); lock (successorLock) { successor = iNode_Object.node; } Console.WriteLine("ChordRealNode::Engine::processFindSuccessorForJoin successor has been set"); lock (successorLock) { successor.beginGetFingerTable(new AsyncCallback(processGetFingerTableForJoin), thisAppState); } //we have found the successor, and a request has been made for its finger table //once the finger table comes in, a findSiccessor call will be made to each of them //do we need to wait till all of them respond? wat if a few of them go down // we can't hang forever... better to return back, and allow the client to query // if the queries happen immediately, tey will fail because the finger table is still empty // as the finger table starts filling up, the queries will get answered better // // other possible solutions: wait for some time (and not indefinitely), and then allow // the client to query. But how long should we wait? In the literature do we have any such // approximate times by which quesries will come back? totally unpredictable I feel... depends // on whether the n/w is the intyernet or a LAN, etc,. // // maybe we could wait till a certain number of entries inthe finger table get filled up ... // maybe 60% .... but how do we decide on this number ... perhaps ChordCylinder will have // data on Churn rates and can set this. Will require significant chanes to the architecture, // because here the client is deciding on how long we should wait AsyncCallback callBack = thisAppState.callBack; Object appState1 = thisAppState.obj; if (!(callBack == null)) { IAsyncResult res = new Tashjik.Common.ObjectAsyncResult(appState1, true, true); callBack(res); } }
void processFindSuccessorForFixFingers(IAsyncResult result) { Console.WriteLine("Chord::ChordRealNode::Engine processFindSuccessorForFixFingers ENTER"); ChordCommon.IChordNode_Object iNode_Object = (ChordCommon.IChordNode_Object)(result.AsyncState); Tashjik.Common.AsyncCallback_Object thisAppState = (Tashjik.Common.AsyncCallback_Object)(iNode_Object.obj); ObjectInt fingerState = (ObjectInt)(thisAppState.obj); finger[fingerState.i] = iNode_Object.node; AsyncCallback callBack = thisAppState.callBack; Object origAppState = fingerState.appState; if (!(callBack == null)) { IAsyncResult res = new Tashjik.Common.ObjectAsyncResult(origAppState, true, true); callBack(res); } }
public void beginFixFingers(AsyncCallback beginStabilizeCallBack, Object appState) { Console.WriteLine("Chord::Engine::beginFixFingers ENTER"); //static int next = -1; fingerNext++; if (fingerNext >= 160) { fingerNext = 0; } //bit wise addition is required //will require some effort byte[] byteVal = getByteArrayOfValue(fingerNext); /* byte[] C = new byte[20]; * * * int bitPos = Int32.MaxValue; * int bytePos = Math.DivRem(fingerNext - 1,8, out bitPos); * * C[19-bytePos] = (byte) (1 << bitPos); */ ObjectInt fingerState = new ObjectInt(); fingerState.appState = appState; fingerState.i = fingerNext; Tashjik.Common.AsyncCallback_Object thisAppState = new Tashjik.Common.AsyncCallback_Object(); thisAppState.callBack = beginStabilizeCallBack; thisAppState.obj = fingerState; AsyncCallback findSuccessorCallBack = new AsyncCallback(processFindSuccessorForFixFingers); beginFindSuccessor(Tashjik.Common.UtilityMethod.moduloAdd1(selfNodeBasic.getHashedIP(), byteVal), null, findSuccessorCallBack, thisAppState, new Guid("00000000-0000-0000-0000-000000000000")); }
void processGetFingerTableForJoin(IAsyncResult result) { Console.WriteLine("ChordRealNode::Engine::processFindFingerTableForJoin ENTER"); ChordCommon.IChordNodeArray_Object iNodeArray_Object = (ChordCommon.IChordNodeArray_Object)(result.AsyncState); Tashjik.Common.AsyncCallback_Object thisAppState = (Tashjik.Common.AsyncCallback_Object)(iNodeArray_Object.obj); IChordNode[] successorFingerTable = iNodeArray_Object.nodeArray; for (int i = 0; i < successorFingerTable.Length; i++) { IChordNode chordNode = successorFingerTable[i]; if (chordNode != null) { ObjectInt fingerState = new ObjectInt(); fingerState.appState = thisAppState; fingerState.i = i; byte[] jumpVal = getByteArrayOfValue(i); successorFingerTable[i].beginFindSuccessor(Common.UtilityMethod.moduloAdd1(self.getHashedIP(), jumpVal), self, new AsyncCallback(processFingerTableFindSuccessorForJoin), fingerState, new Guid("00000000-0000-0000-0000-000000000000")); } } }
/* This is the method that the node uses to initilize its own state based on a supplied * bootstrap node here, it has been suppied with a bootstrap node which will be used to * initilize itself as well as tell other nodes in n/w of its existence * ALGO(from Chord TR): n.join(n′) * predecessor = nil; * s = n′.find successor(n); * build fingers(s); * successor = s; */ internal void beginJoin(IChordNode joinNode, AsyncCallback joinCallBack, Object appState) { Console.WriteLine("ChordRealNode::Engine::beginJoin ENTER"); predecessor = null; Tashjik.Common.AsyncCallback_Object thisAppState = new Tashjik.Common.AsyncCallback_Object(); thisAppState.callBack = joinCallBack; thisAppState.obj = appState; Console.WriteLine("ChordRealNode::Engine::beginJoin before calling beginFindSuccessor ahem ahem"); if (joinNode == null) { Console.WriteLine("ChordRealNode::Engine::beginJoin joinNode ==null"); } //queryingNode is passed as null, because it is of no use to beginFindSuccessor //if we were to pass 'self', then the system would hang. This is because Engine is part of //ChordRealNode. We haven't yet constructed ChordRealNode fully, and are in the process //of constructing Engine, and we want to send the partially constructed ChordRealNode // on a call to beginFindSuccessor // //What are the alternatives? //1. Make JoinNode as a public method tht needs to be called after construction of ChordRealNode //This may lead to maintainance issues of the calling code. What if at some later stage, someone //constructs the object, but forgets to call joinNode(..). This is typical of init(..) methods //which are supposed to be called by the user after constructor. Many a times, coders forget to do it. //2.Have a flag internal to ChordRealNode that will signal whether the object is ready for operation. //This would mean joinNode(..) has been called after construction. If this is not the case, throw an //excetion. This will easily be caught during basic testing. However, it may be a maintainance problem //for the maintainers of ChordRealNode itself> What if a new operation is added, and the engineer //forgets to check the flag before proceeding? // //We are fortunate here to have a hack (a nifty solution for me), that solves a larger design problem. joinNode.beginFindSuccessor(selfNodeBasic.getHashedIP(), null, new AsyncCallback(processFindSuccessorForJoin), thisAppState, new Guid("00000000-0000-0000-0000-000000000000")); }
void processPingForCheckPredecessor(IAsyncResult result) { Console.WriteLine("Chord::ChordRealNode::Engine processPingForCheckPredecessor ENTER"); Tashjik.Common.Bool_Object thisAppState = (Tashjik.Common.Bool_Object)(result.AsyncState); Tashjik.Common.AsyncCallback_Object checkPredecessorAppState = (Tashjik.Common.AsyncCallback_Object)(thisAppState.obj); if (!(thisAppState.b)) { predecessor = null; } //AsyncCallback callBack = ((Tashjik.Common.AsyncCallback_Object)appState).callBack; //Object appState1 = ((Tashjik.Common.AsyncCallback_Object)appState).obj; if (!(checkPredecessorAppState.callBack == null)) { Console.WriteLine("Chord::ChordRealNode::Engine processPingForCheckPredecessor callBack!=null"); IAsyncResult res = new Tashjik.Common.ObjectAsyncResult(checkPredecessorAppState.obj, true, true); checkPredecessorAppState.callBack(res); } }
public void beginCheckPredecessor(AsyncCallback checkPredecesorCallBack, Object appState) { Console.WriteLine("Chord::ChordRealNode::Engine beginCheckPredecessor ENTER"); if (predecessor == null) { if (checkPredecesorCallBack != null) { IAsyncResult res = new Tashjik.Common.ObjectAsyncResult(appState, true, true); checkPredecesorCallBack(res); } else { return; } } Tashjik.Common.AsyncCallback_Object thisAppState = new Tashjik.Common.AsyncCallback_Object(); thisAppState.callBack = checkPredecesorCallBack; thisAppState.obj = appState; AsyncCallback pingCallBack = new AsyncCallback(processPingForCheckPredecessor); predecessor.beginPing(pingCallBack, thisAppState); }
/* This is the method that the node uses to initilize its own state based on a supplied * bootstrap node here, it has been suppied with a bootstrap node which will be used to * initilize itself as well as tell other nodes in n/w of its existence * ALGO(from Chord TR): n.join(n′) * predecessor = nil; * s = n′.find successor(n); * build fingers(s); * successor = s; */ internal void beginJoin(IChordNode joinNode, AsyncCallback joinCallBack, Object appState) { Console.WriteLine("ChordRealNode::Engine::beginJoin ENTER"); predecessor = null; Tashjik.Common.AsyncCallback_Object thisAppState = new Tashjik.Common.AsyncCallback_Object(); thisAppState.callBack = joinCallBack; thisAppState.obj = appState; Console.WriteLine("ChordRealNode::Engine::beginJoin before calling beginFindSuccessor ahem ahem"); if (joinNode == null) Console.WriteLine("ChordRealNode::Engine::beginJoin joinNode ==null"); //queryingNode is passed as null, because it is of no use to beginFindSuccessor //if we were to pass 'self', then the system would hang. This is because Engine is part of //ChordRealNode. We haven't yet constructed ChordRealNode fully, and are in the process //of constructing Engine, and we want to send the partially constructed ChordRealNode // on a call to beginFindSuccessor // //What are the alternatives? //1. Make JoinNode as a public method tht needs to be called after construction of ChordRealNode //This may lead to maintainance issues of the calling code. What if at some later stage, someone //constructs the object, but forgets to call joinNode(..). This is typical of init(..) methods //which are supposed to be called by the user after constructor. Many a times, coders forget to do it. //2.Have a flag internal to ChordRealNode that will signal whether the object is ready for operation. //This would mean joinNode(..) has been called after construction. If this is not the case, throw an //excetion. This will easily be caught during basic testing. However, it may be a maintainance problem //for the maintainers of ChordRealNode itself> What if a new operation is added, and the engineer //forgets to check the flag before proceeding? // //We are fortunate here to have a hack (a nifty solution for me), that solves a larger design problem. joinNode.beginFindSuccessor(selfNodeBasic.getHashedIP(), null, new AsyncCallback(processFindSuccessorForJoin), thisAppState, new Guid("00000000-0000-0000-0000-000000000000")); }
/*public void stabilize() { AsyncCallback getPredecessorCallBack = new AsyncCallback(processGetPredecessorForStabilize); successor.beginGetPredecessor(getPredecessorCallBack); //if(((Node)self<x) && ((Node)x<successor)) // successor = x; //successor.notify(self); }*/ public void beginStabilize(AsyncCallback beginStabilizeCallBack, Object appState) { Console.WriteLine("Chord::Engine::beginStabilize ENTER"); lock (successorLock) { if (successor == self) { if (beginStabilizeCallBack != null) { IAsyncResult res = new Tashjik.Common.ObjectAsyncResult(appState, true, true); beginStabilizeCallBack(res); } else return; } } Tashjik.Common.AsyncCallback_Object thisAppState = new Tashjik.Common.AsyncCallback_Object(); thisAppState.callBack = beginStabilizeCallBack; thisAppState.obj = appState; Console.WriteLine("Chord::Engine::beginStabilize successor != self"); AsyncCallback getPredecessorCallBack = new AsyncCallback(processGetPredecessorForStabilize); lock (successorLock) { successor.beginGetPredecessor(getPredecessorCallBack, thisAppState); } Console.WriteLine("Chord::Engine::beginStabilize EXIT"); }
public void beginFixFingers(AsyncCallback beginStabilizeCallBack, Object appState) { Console.WriteLine("Chord::Engine::beginFixFingers ENTER"); //static int next = -1; fingerNext ++; if (fingerNext>=160) fingerNext = 0; //bit wise addition is required //will require some effort byte[] byteVal = getByteArrayOfValue(fingerNext); /* byte[] C = new byte[20]; int bitPos = Int32.MaxValue; int bytePos = Math.DivRem(fingerNext - 1,8, out bitPos); C[19-bytePos] = (byte) (1 << bitPos); */ ObjectInt fingerState = new ObjectInt(); fingerState.appState = appState; fingerState.i = fingerNext; Tashjik.Common.AsyncCallback_Object thisAppState = new Tashjik.Common.AsyncCallback_Object(); thisAppState.callBack = beginStabilizeCallBack; thisAppState.obj = fingerState; AsyncCallback findSuccessorCallBack = new AsyncCallback(processFindSuccessorForFixFingers); beginFindSuccessor(Tashjik.Common.UtilityMethod.moduloAdd1(selfNodeBasic.getHashedIP(), byteVal), null, findSuccessorCallBack, thisAppState, new Guid("00000000-0000-0000-0000-000000000000")); }
public void beginCheckPredecessor(AsyncCallback checkPredecesorCallBack, Object appState) { Console.WriteLine("Chord::ChordRealNode::Engine beginCheckPredecessor ENTER"); if(predecessor==null) { if(checkPredecesorCallBack!=null) { IAsyncResult res = new Tashjik.Common.ObjectAsyncResult(appState, true, true); checkPredecesorCallBack(res); } else return; } Tashjik.Common.AsyncCallback_Object thisAppState = new Tashjik.Common.AsyncCallback_Object(); thisAppState.callBack = checkPredecesorCallBack; thisAppState.obj = appState; AsyncCallback pingCallBack = new AsyncCallback(processPingForCheckPredecessor); predecessor.beginPing(pingCallBack, thisAppState); }