public IChordNode_ObjectAsyncResult(IChordNode_Object n, bool compSync, bool isComp) { AsyncState = (Object)n; AsyncWaitHandle = null; // CompletedSynchronously = compSync; // IsCompleted = isComp; }
public IChordNode_ObjectAsyncResult(IChordNode_Object n, bool compSync, bool isComp) { AsyncState = (Object)n; AsyncWaitHandle = null; // CompletedSynchronously = compSync; // IsCompleted = isComp; }
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; }
/* * public Node findSuccessor(byte[] queryHashedKey, Node queryingNode) * { * if((Node)self<queryHashedKey && queryHashedKey<(Node)successor) * return successor; * else * { * Node closestPrecNode = findClosestPreceedingNode(queryHashedKey); * if (closestPrecNode==self) * return successor; * else * { * return closestPrecNode.findSuccessor(queryHashedKey, queryingNode); * } * } * } */ public void beginFindSuccessor(byte[] queryHashedKey, IChordNode queryingNode, AsyncCallback findSuccessorCallBack, Object appState, Guid relayTicket) { Console.WriteLine("Chord::engine::beginFindSuccessor ENTER"); ChordCommon.IChordNode_Object iNode_Object; lock (successorLock) { if ((ChordRealNode)self < queryHashedKey && queryHashedKey < (ChordRealNode)successor) { Console.WriteLine("Chord::engine::beginFindSuccessor query falls inbetween node and successor"); if (!(findSuccessorCallBack == null)) { iNode_Object = new ChordCommon.IChordNode_Object(); lock (successorLock) { iNode_Object.node = successor; } iNode_Object.obj = appState; IAsyncResult res = new ChordCommon.IChordNode_ObjectAsyncResult(iNode_Object, true, true); findSuccessorCallBack(res); } } else { Console.WriteLine("Chord::engine::beginFindSuccessor query DOES NOT fall inbetween node and successor"); IChordNode closestPrecNode = findClosestPreceedingNode(queryHashedKey); if (closestPrecNode == self) { Console.WriteLine("Chord::engine::beginFindSuccessor closestPrecNode==self"); if (!(findSuccessorCallBack == null)) { Console.WriteLine("Chord::engine::beginFindSuccessor if(!(findSuccessorCallBack==null))"); iNode_Object = new ChordCommon.IChordNode_Object(); lock (successorLock) { iNode_Object.node = successor; } iNode_Object.obj = appState; Console.WriteLine("Chord::engine::beginFindSuccessor before new IChordNode_ObjectAsyncResult"); IAsyncResult res = new ChordCommon.IChordNode_ObjectAsyncResult(iNode_Object, true, true); Console.WriteLine("Chord::engine::beginFindSuccessor before calling findSuccessorCallBack"); findSuccessorCallBack(res); } } else { Console.WriteLine("Chord::engine::beginFindSuccessor relaying request to closestPrecNode"); closestPrecNode.beginFindSuccessor(queryHashedKey, queryingNode, findSuccessorCallBack, appState, relayTicket); } } } Console.WriteLine("Chord::engine::beginFindSuccessor EXIT"); }
static void processFindSuccessor_notifyTwoWayRelayMsg_callback(IAsyncResult ayncResult) { ChordCommon.IChordNode_Object iNode_Object = (ChordCommon.IChordNode_Object)(ayncResult.AsyncState); IChordNode successor = (iNode_Object.node); ChordProxyNode chordProxyNode = ((IP_ChordProxyNode)(iNode_Object.obj)).chordProxyNode; IPAddress originalFromIP = ((IP_ChordProxyNode)(iNode_Object.obj)).IP; Guid relayTicket = ((IP_ChordProxyNode)(iNode_Object.obj)).ticket; byte[] compositeMsg = UtilityMethod.convertToTabSeparatedByteArray(true, "FIND_SUCCESSOR_REPLY", successor.getIP().ToString()); chordProxyNode.proxyController.sendMsgTwoWayRelay(chordProxyNode.proxyController.getProxyNode(originalFromIP), compositeMsg, 0, compositeMsg.Length, null, null, relayTicket); }
static void processFindSuccessorForGetData(IAsyncResult result) { Console.WriteLine("ChordServer::processFindSuccessorForGetData ENTER"); ChordCommon.IChordNode_Object iNode_Object = (ChordCommon.IChordNode_Object)(result.AsyncState); IChordNode successor = iNode_Object.node; Stack <Object> recAppState = (Stack <Object>)(iNode_Object.obj); Object origAppState = recAppState.Pop(); AsyncCallback getDataCallBack = (AsyncCallback)(recAppState.Pop()); byte[] queryKey = (byte[])(recAppState.Pop()); successor.beginGetData(queryKey, getDataCallBack, origAppState); Console.WriteLine("ChordServer::processFindSuccessorForGetData EXIT"); }
/* public Node getPredecessor() * { * return engine.getPredecessor(); * * } */ public void beginGetPredecessor(AsyncCallback getPredecessorCallBack, Object appState) { Console.WriteLine("ChordRealNode::beginGetPredecessor ENTER"); IChordNode predecessor = engine.getPredecessor(); ChordCommon.IChordNode_Object iNode_Object = new ChordCommon.IChordNode_Object(); iNode_Object.node = predecessor; iNode_Object.obj = appState; if (!(getPredecessorCallBack == null)) { IAsyncResult res = new ChordCommon.IChordNode_ObjectAsyncResult(iNode_Object, false, true); getPredecessorCallBack(res); } }
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); } }
void processGetPredecessorForStabilize(IAsyncResult result) { Console.WriteLine("Chord::Engine::processGetPredecessorForStabilize ENTER"); ChordCommon.IChordNode_Object iNode_Object = (ChordCommon.IChordNode_Object)(result.AsyncState); Object appState = iNode_Object.obj; AsyncCallback callBack = ((Tashjik.Common.AsyncCallback_Object)appState).callBack; Object appState1 = ((Tashjik.Common.AsyncCallback_Object)appState).obj; IChordNode x = iNode_Object.node; if (x == null) { Console.WriteLine("Chord::Engine::processGetPredecessorForStabilize UNKNOWN_PREDECESSOR"); if (callBack != null) { iNode_Object = new ChordCommon.IChordNode_Object(); iNode_Object.node = null; iNode_Object.obj = appState1; IAsyncResult res = new ChordCommon.IChordNode_ObjectAsyncResult(iNode_Object, true, true); // callBack(res); } } else { Console.WriteLine("Chord::Engine::processGetPredecessorForStabilize before condition check"); lock (successorLock) { if ((self < (IChordNode)x) && ((ChordRealNode)x /*.getHashedIP()*/ < (successor))) { successor = x; } } Console.WriteLine("Chord::Engine::processGetPredecessorForStabilize before calling beginNotify on successor"); } lock (successorLock) { successor.beginPredecessorNotify(self, callBack, appState1); } }
static void processFindSuccessorForPutData(IAsyncResult result) { Console.WriteLine("ChordServer::processFindSuccessorForPutData ENTER"); ChordCommon.IChordNode_Object iNode_Object = (ChordCommon.IChordNode_Object)(result.AsyncState); IChordNode successor = iNode_Object.node; Stack <Object> recAppState = (Stack <Object>)(iNode_Object.obj); Object origAppState = recAppState.Pop(); AsyncCallback putDataCallBack = (AsyncCallback)(recAppState.Pop()); int size = (int)(recAppState.Pop()); int offset = (int)(recAppState.Pop()); byte[] data = (byte[])(recAppState.Pop()); byte[] key = (byte[])(recAppState.Pop()); Console.WriteLine("ChordServer::processFindSuccessorForPutData calling beginPutData"); successor.beginPutData(key, data, offset, size, putDataCallBack, origAppState); Console.WriteLine("ChordServer::processFindSuccessorForPutData EXIT"); }
void processFindSuccessorForFindSuccessor(IAsyncResult result) { Console.WriteLine("ChordServer::processFindSuccessorForFindSuccessor ENTER"); ChordCommon.IChordNode_Object iNode_Object = (ChordCommon.IChordNode_Object)(result.AsyncState); IChordNode successor = iNode_Object.node; IPAddress IP = successor.getIP(); Stack <Object> recAppState = (Stack <Object>)(iNode_Object.obj); Object origAppState = recAppState.Pop(); AsyncCallback findSuccessorCallBack = (AsyncCallback)(recAppState.Pop()); if (findSuccessorCallBack != null) { ChordCommon.IP_Object _IP_Object = new ChordCommon.IP_Object(); _IP_Object.IP = IP; _IP_Object.obj = origAppState; IAsyncResult res = new ChordCommon.IP_ObjectAsyncResult(_IP_Object, true, true); findSuccessorCallBack(res); } }
/* public Node findSuccessor(byte[] queryHashedKey, Node queryingNode) { if((Node)self<queryHashedKey && queryHashedKey<(Node)successor) return successor; else { Node closestPrecNode = findClosestPreceedingNode(queryHashedKey); if (closestPrecNode==self) return successor; else { return closestPrecNode.findSuccessor(queryHashedKey, queryingNode); } } } */ public void beginFindSuccessor(byte[] queryHashedKey, IChordNode queryingNode, AsyncCallback findSuccessorCallBack, Object appState, Guid relayTicket) { Console.WriteLine("Chord::engine::beginFindSuccessor ENTER"); ChordCommon.IChordNode_Object iNode_Object; lock (successorLock) { if ((ChordRealNode)self < queryHashedKey && queryHashedKey < (ChordRealNode)successor) { Console.WriteLine("Chord::engine::beginFindSuccessor query falls inbetween node and successor"); if (!(findSuccessorCallBack == null)) { iNode_Object = new ChordCommon.IChordNode_Object(); lock (successorLock) { iNode_Object.node = successor; } iNode_Object.obj = appState; IAsyncResult res = new ChordCommon.IChordNode_ObjectAsyncResult(iNode_Object, true, true); findSuccessorCallBack(res); } } else { Console.WriteLine("Chord::engine::beginFindSuccessor query DOES NOT fall inbetween node and successor"); IChordNode closestPrecNode = findClosestPreceedingNode(queryHashedKey); if (closestPrecNode == self) { Console.WriteLine("Chord::engine::beginFindSuccessor closestPrecNode==self"); if (!(findSuccessorCallBack == null)) { Console.WriteLine("Chord::engine::beginFindSuccessor if(!(findSuccessorCallBack==null))"); iNode_Object = new ChordCommon.IChordNode_Object(); lock (successorLock) { iNode_Object.node = successor; } iNode_Object.obj = appState; Console.WriteLine("Chord::engine::beginFindSuccessor before new IChordNode_ObjectAsyncResult"); IAsyncResult res = new ChordCommon.IChordNode_ObjectAsyncResult(iNode_Object, true, true); Console.WriteLine("Chord::engine::beginFindSuccessor before calling findSuccessorCallBack"); findSuccessorCallBack(res); } } else { Console.WriteLine("Chord::engine::beginFindSuccessor relaying request to closestPrecNode"); closestPrecNode.beginFindSuccessor(queryHashedKey, queryingNode, findSuccessorCallBack, appState, relayTicket); } } } Console.WriteLine("Chord::engine::beginFindSuccessor EXIT"); }
/* public Node getPredecessor() { return engine.getPredecessor(); } */ public void beginGetPredecessor(AsyncCallback getPredecessorCallBack, Object appState) { Console.WriteLine("ChordRealNode::beginGetPredecessor ENTER"); IChordNode predecessor = engine.getPredecessor(); ChordCommon.IChordNode_Object iNode_Object = new ChordCommon.IChordNode_Object(); iNode_Object.node = predecessor; iNode_Object.obj = appState; if(!(getPredecessorCallBack==null)) { IAsyncResult res = new ChordCommon.IChordNode_ObjectAsyncResult(iNode_Object, false,true); getPredecessorCallBack(res); } }
public override void notifyTwoWayReplyReceived(IPAddress fromIP, byte[] buffer, int offset, int size, AsyncCallback originalRequestCallBack, Object originalAppState) { Console.WriteLine("ChordProxyNode::notifyTwoWayReplyReceived ENTER"); String[] split = splitMsgBuffer(buffer, offset, size); if(String.Compare(split[0], "FIND_SUCCESSOR_REPLY") == 0) { Console.WriteLine("ChordProxyNode::notifyTwoWayReplyReceived FIND_SUCCESSOR_RECEIVED"); String strSuccessorIP = split[1]; Console.Write("ChordProxyNode::notifyTwoWayReplyReceived SuccessorIP = "); Console.WriteLine(strSuccessorIP); IPAddress successorIP = UtilityMethod.convertStrToIP(strSuccessorIP); ChordCommon.IChordNode_Object iNode_Object = new ChordCommon.IChordNode_Object(); iNode_Object.node = (IChordNode)(proxyController.getProxyNode(successorIP)); iNode_Object.obj = originalAppState; Tashjik.Common.ObjectAsyncResult objectAsyncResult = new Tashjik.Common.ObjectAsyncResult(iNode_Object, false, false); if(originalRequestCallBack != null) originalRequestCallBack(objectAsyncResult); } else if(String.Compare(split[0], "GET_PREDECESSOR_REPLY")==0) { Console.WriteLine("ChordProxyNode::notifyTwoWayReplyReceived GET_PREDECESSOR_RECEIVED"); String strPredecessorIP = split[1]; ChordCommon.IChordNode_Object iNode_Object = new ChordCommon.IChordNode_Object(); if(String.Compare(strPredecessorIP, "UNKNOWN_PREDECESSOR")==0) { Console.Write("ChordProxyNode::notifyTwoWayReplyReceived PREDECESSOR_UNKNOWN"); iNode_Object.node = null; } else { Console.Write("ChordProxyNode::notifyTwoWayReplyReceived PredecessorIP = "); Console.WriteLine(strPredecessorIP); IPAddress predecessorIP = UtilityMethod.convertStrToIP(strPredecessorIP); iNode_Object.node = (IChordNode)(proxyController.getProxyNode(predecessorIP)); } iNode_Object.obj = originalAppState; Tashjik.Common.ObjectAsyncResult objectAsyncResult = new Tashjik.Common.ObjectAsyncResult(iNode_Object, false, false); if(originalRequestCallBack != null) originalRequestCallBack(objectAsyncResult); } else if (String.Compare(split[0], "GET_FINGERTABLE_REPLY") == 0) { Console.WriteLine("ChordProxyNode::notifyTwoWayReplyReceived GET_FINGERTABLE_RECEIVED"); String strPredecessorIP = split[1]; IChordNode[] fingerTable = new IChordNode[split.Length - 1]; for (int i = 1; i < 161; i++) { if (split[i] == "NULL") fingerTable[i - 1] = null; else fingerTable[i - 1] = (IChordNode)(proxyController.getProxyNode(UtilityMethod.convertStrToIP(split[i].ToString()))); } ChordCommon.IChordNodeArray_Object iNodeArray_Object = new ChordCommon.IChordNodeArray_Object(); iNodeArray_Object.nodeArray = fingerTable; iNodeArray_Object.obj = originalAppState; Tashjik.Common.ObjectAsyncResult objectAsyncResult = new Tashjik.Common.ObjectAsyncResult(iNodeArray_Object, false, false); if (originalRequestCallBack != null) originalRequestCallBack(objectAsyncResult); } }
void processGetPredecessorForStabilize(IAsyncResult result) { Console.WriteLine("Chord::Engine::processGetPredecessorForStabilize ENTER"); ChordCommon.IChordNode_Object iNode_Object = (ChordCommon.IChordNode_Object)(result.AsyncState); Object appState = iNode_Object.obj; AsyncCallback callBack = ((Tashjik.Common.AsyncCallback_Object)appState).callBack; Object appState1 = ((Tashjik.Common.AsyncCallback_Object)appState).obj; IChordNode x = iNode_Object.node; if(x==null) { Console.WriteLine("Chord::Engine::processGetPredecessorForStabilize UNKNOWN_PREDECESSOR"); if(callBack != null) { iNode_Object = new ChordCommon.IChordNode_Object(); iNode_Object.node = null; iNode_Object.obj = appState1; IAsyncResult res = new ChordCommon.IChordNode_ObjectAsyncResult(iNode_Object, true, true); // callBack(res); } } else { Console.WriteLine("Chord::Engine::processGetPredecessorForStabilize before condition check"); lock (successorLock) { if ((self < (IChordNode)x) && ((ChordRealNode)x/*.getHashedIP()*/ < (successor))) successor = x; } Console.WriteLine("Chord::Engine::processGetPredecessorForStabilize before calling beginNotify on successor"); } lock (successorLock) { successor.beginPredecessorNotify(self, callBack, appState1); } }
public override void notifyTwoWayReplyReceived(IPAddress fromIP, byte[] buffer, int offset, int size, AsyncCallback originalRequestCallBack, Object originalAppState) { Console.WriteLine("ChordProxyNode::notifyTwoWayReplyReceived ENTER"); String[] split = splitMsgBuffer(buffer, offset, size); if (String.Compare(split[0], "FIND_SUCCESSOR_REPLY") == 0) { Console.WriteLine("ChordProxyNode::notifyTwoWayReplyReceived FIND_SUCCESSOR_RECEIVED"); String strSuccessorIP = split[1]; Console.Write("ChordProxyNode::notifyTwoWayReplyReceived SuccessorIP = "); Console.WriteLine(strSuccessorIP); IPAddress successorIP = UtilityMethod.convertStrToIP(strSuccessorIP); ChordCommon.IChordNode_Object iNode_Object = new ChordCommon.IChordNode_Object(); iNode_Object.node = (IChordNode)(proxyController.getProxyNode(successorIP)); iNode_Object.obj = originalAppState; Tashjik.Common.ObjectAsyncResult objectAsyncResult = new Tashjik.Common.ObjectAsyncResult(iNode_Object, false, false); if (originalRequestCallBack != null) { originalRequestCallBack(objectAsyncResult); } } else if (String.Compare(split[0], "GET_PREDECESSOR_REPLY") == 0) { Console.WriteLine("ChordProxyNode::notifyTwoWayReplyReceived GET_PREDECESSOR_RECEIVED"); String strPredecessorIP = split[1]; ChordCommon.IChordNode_Object iNode_Object = new ChordCommon.IChordNode_Object(); if (String.Compare(strPredecessorIP, "UNKNOWN_PREDECESSOR") == 0) { Console.Write("ChordProxyNode::notifyTwoWayReplyReceived PREDECESSOR_UNKNOWN"); iNode_Object.node = null; } else { Console.Write("ChordProxyNode::notifyTwoWayReplyReceived PredecessorIP = "); Console.WriteLine(strPredecessorIP); IPAddress predecessorIP = UtilityMethod.convertStrToIP(strPredecessorIP); iNode_Object.node = (IChordNode)(proxyController.getProxyNode(predecessorIP)); } iNode_Object.obj = originalAppState; Tashjik.Common.ObjectAsyncResult objectAsyncResult = new Tashjik.Common.ObjectAsyncResult(iNode_Object, false, false); if (originalRequestCallBack != null) { originalRequestCallBack(objectAsyncResult); } } else if (String.Compare(split[0], "GET_FINGERTABLE_REPLY") == 0) { Console.WriteLine("ChordProxyNode::notifyTwoWayReplyReceived GET_FINGERTABLE_RECEIVED"); String strPredecessorIP = split[1]; IChordNode[] fingerTable = new IChordNode[split.Length - 1]; for (int i = 1; i < 161; i++) { if (split[i] == "NULL") { fingerTable[i - 1] = null; } else { fingerTable[i - 1] = (IChordNode)(proxyController.getProxyNode(UtilityMethod.convertStrToIP(split[i].ToString()))); } } ChordCommon.IChordNodeArray_Object iNodeArray_Object = new ChordCommon.IChordNodeArray_Object(); iNodeArray_Object.nodeArray = fingerTable; iNodeArray_Object.obj = originalAppState; Tashjik.Common.ObjectAsyncResult objectAsyncResult = new Tashjik.Common.ObjectAsyncResult(iNodeArray_Object, false, false); if (originalRequestCallBack != null) { originalRequestCallBack(objectAsyncResult); } } }