src/ow/routing/impl/RecursiveRoutingDriver.java
private void prepareHandlers() {
		MessageHandler handler;

		// REC_ROUTE_{NONE,INVOKE,JOIN}
		handler = new ExtendedMessageHandler() {
			public Message process(Message msg) {
				return RecursiveRoutingDriver.this.recAckMessage;
			}

			public void postProcess(Message msg) {
				// parse the incoming message
				ID[] targets = ((AbstractRecRouteMessage)msg).target;
				RoutingContext[] routingContexts = ((AbstractRecRouteMessage)msg).cxt;
				IDAddressPair[] blackList = ((AbstractRecRouteMessage)msg).blackList;

				for (int i = 0; i < targets.length; i++) {
					if (routingContexts[i] == null) 
						routingContexts[i] = algorithm.initialRoutingContext(targets[i]);
						// In case of joining, routing contexts are initialized here.
				}

				// remove nodes in blacklist from routing table
				// Note: this removes nodes which this node itself has not contacted
				// and prone to be abused by a malicious node.
				if (blackList != null) {
					for (IDAddressPair p: blackList) {
						logger.log(Level.INFO, "REC_*calls fail: " + p.getAddress() + " on " + getSelfIDAddressPair().getAddress());

						fail(p);	// AbstractRoutingDriver#fail()
					}
				}

				// calculate next hop
				RoutingContext[] lastRoutingContexts = new RoutingContext[targets.length];

				boolean joining = (msg instanceof RecRouteJoinMessage);

				IDAddressPair[][] nextHopCands = new IDAddressPair[targets.length][];
				for (int i = 0; i < targets.length; i++) {
					if (routingContexts[i] != null)
						lastRoutingContexts[i] = routingContexts[i].clone();	// preserve last routing context

					nextHopCands[i] = algorithm.nextHopCandidates(
							targets[i], ((IDAddressPair)msg.getSource()).getID(), joining,
							config.getNumOfNextHopCandidatesRequested(), routingContexts[i]);
				}

				// forward
				RecursiveRoutingDriver.this.forwardOrReturnResult(
						msg, lastRoutingContexts, nextHopCands);
			}
		};
		addMessageHandler(RecRouteNoneMessage.class, handler);
		addMessageHandler(RecRouteInvokeMessage.class, handler);
		addMessageHandler(RecRouteJoinMessage.class, handler);

		// REC_RESULT
		handler = new MessageHandler() {
			public Message process(Message msg) {
				int routingID = ((RecResultMessage)msg).routingID;
				ID[] target = ((RecResultMessage)msg).target;
				IDAddressPair[] blackList = ((RecResultMessage)msg).blackList;

				synchronized (routeResultMsgTable) {
					if (target != null && target.length > 0) {
						for (ID id: target) {
							Message nullMsg = routeResultMsgTable.get(id.hashCode() ^ routingID);
							if (nullMsg != null && nullMsg instanceof NullMessage) {
								routeResultMsgTable.put(id.hashCode() ^ routingID, msg);
								synchronized (nullMsg) {
									nullMsg.notify();
								}
							}
						}
					}
				}

				// remove nodes in blacklist from routing table
				// Note: this removes nodes which this node itself has not contacted
				// and prone to be abused by a malicious node.
				if (blackList != null) {
					for (IDAddressPair p: blackList) {
						logger.log(Level.INFO, "REC_RESULT calls fail: " + p.getAddress()
								+ " on " + getSelfIDAddressPair().getAddress());

						fail(p);	// AbstractRoutingDriver#fail()
					}
				}

				// notify the routing algorithm
				//algorithm.touch(msg.getSource());
					// not necessary to call touch() because
					// the last entry in the returned route is same as msg.getSource()

				return null;
			}
		};
		addMessageHandler(RecResultMessage.class, handler);
	}
/**
	 * Prepare message handlers for received messages.
	 */
Prepare message handlers for received messages.
Prepare message handlers for received messages .
private void prepareHandlers() {
		MessageHandler handler;
		handler = new ExtendedMessageHandler() {
			public Message process(Message msg) {
				return RecursiveRoutingDriver.this.recAckMessage;
			}
			public void postProcess(Message msg) {
				ID[] targets = ((AbstractRecRouteMessage)msg).target;
				RoutingContext[] routingContexts = ((AbstractRecRouteMessage)msg).cxt;
				IDAddressPair[] blackList = ((AbstractRecRouteMessage)msg).blackList;
				for (int i = 0; i < targets.length; i++) {
					if (routingContexts[i] == null) 
						routingContexts[i] = algorithm.initialRoutingContext(targets[i]);
				}
				if (blackList != null) {
					for (IDAddressPair p: blackList) {
						logger.log(Level.INFO, "REC_*calls fail: " + p.getAddress() + " on " + getSelfIDAddressPair().getAddress());
						fail(p);	
					}
				}
				RoutingContext[] lastRoutingContexts = new RoutingContext[targets.length];
				boolean joining = (msg instanceof RecRouteJoinMessage);
				IDAddressPair[][] nextHopCands = new IDAddressPair[targets.length][];
				for (int i = 0; i < targets.length; i++) {
					if (routingContexts[i] != null)
						lastRoutingContexts[i] = routingContexts[i].clone();	
					nextHopCands[i] = algorithm.nextHopCandidates(
							targets[i], ((IDAddressPair)msg.getSource()).getID(), joining,
							config.getNumOfNextHopCandidatesRequested(), routingContexts[i]);
				}
				RecursiveRoutingDriver.this.forwardOrReturnResult(
						msg, lastRoutingContexts, nextHopCands);
			}
		};
		addMessageHandler(RecRouteNoneMessage.class, handler);
		addMessageHandler(RecRouteInvokeMessage.class, handler);
		addMessageHandler(RecRouteJoinMessage.class, handler);
		handler = new MessageHandler() {
			public Message process(Message msg) {
				int routingID = ((RecResultMessage)msg).routingID;
				ID[] target = ((RecResultMessage)msg).target;
				IDAddressPair[] blackList = ((RecResultMessage)msg).blackList;
				synchronized (routeResultMsgTable) {
					if (target != null && target.length > 0) {
						for (ID id: target) {
							Message nullMsg = routeResultMsgTable.get(id.hashCode() ^ routingID);
							if (nullMsg != null && nullMsg instanceof NullMessage) {
								routeResultMsgTable.put(id.hashCode() ^ routingID, msg);
								synchronized (nullMsg) {
									nullMsg.notify();
								}
							}
						}
					}
				}
				if (blackList != null) {
					for (IDAddressPair p: blackList) {
						logger.log(Level.INFO, "REC_RESULT calls fail: " + p.getAddress()
								+ " on " + getSelfIDAddressPair().getAddress());
						fail(p);	
					}
				}
				return null;
			}
		};
		addMessageHandler(RecResultMessage.class, handler);
	}
private void prepareHandlers ( ) { MessageHandler handler ; handler = new ExtendedMessageHandler ( ) { public Message process ( Message msg ) { return RecursiveRoutingDriver . this . recAckMessage ; } public void postProcess ( Message msg ) { ID [ ] targets = ( ( AbstractRecRouteMessage ) msg ) . target ; RoutingContext [ ] routingContexts = ( ( AbstractRecRouteMessage ) msg ) . cxt ; IDAddressPair [ ] blackList = ( ( AbstractRecRouteMessage ) msg ) . blackList ; for ( int i = 0 ; i < targets . length ; i ++ ) { if ( routingContexts [ i ] == null ) routingContexts [ i ] = algorithm . initialRoutingContext ( targets [ i ] ) ; } if ( blackList != null ) { for ( IDAddressPair p : blackList ) { logger . log ( Level . INFO , "REC_*calls fail: " + p . getAddress ( ) + " on " + getSelfIDAddressPair ( ) . getAddress ( ) ) ; fail ( p ) ; } } RoutingContext [ ] lastRoutingContexts = new RoutingContext [ targets . length ] ; boolean joining = ( msg instanceof RecRouteJoinMessage ) ; IDAddressPair [ ] [ ] nextHopCands = new IDAddressPair [ targets . length ] [ ] ; for ( int i = 0 ; i < targets . length ; i ++ ) { if ( routingContexts [ i ] != null ) lastRoutingContexts [ i ] = routingContexts [ i ] . clone ( ) ; nextHopCands [ i ] = algorithm . nextHopCandidates ( targets [ i ] , ( ( IDAddressPair ) msg . getSource ( ) ) . getID ( ) , joining , config . getNumOfNextHopCandidatesRequested ( ) , routingContexts [ i ] ) ; } RecursiveRoutingDriver . this . forwardOrReturnResult ( msg , lastRoutingContexts , nextHopCands ) ; } } ; addMessageHandler ( RecRouteNoneMessage . class , handler ) ; addMessageHandler ( RecRouteInvokeMessage . class , handler ) ; addMessageHandler ( RecRouteJoinMessage . class , handler ) ; handler = new MessageHandler ( ) { public Message process ( Message msg ) { int routingID = ( ( RecResultMessage ) msg ) . routingID ; ID [ ] target = ( ( RecResultMessage ) msg ) . target ; IDAddressPair [ ] blackList = ( ( RecResultMessage ) msg ) . blackList ; synchronized ( routeResultMsgTable ) { if ( target != null && target . length > 0 ) { for ( ID id : target ) { Message nullMsg = routeResultMsgTable . get ( id . hashCode ( ) ^ routingID ) ; if ( nullMsg != null && nullMsg instanceof NullMessage ) { routeResultMsgTable . put ( id . hashCode ( ) ^ routingID , msg ) ; synchronized ( nullMsg ) { nullMsg . notify ( ) ; } } } } } if ( blackList != null ) { for ( IDAddressPair p : blackList ) { logger . log ( Level . INFO , "REC_RESULT calls fail: " + p . getAddress ( ) + " on " + getSelfIDAddressPair ( ) . getAddress ( ) ) ; fail ( p ) ; } } return null ; } } ; addMessageHandler ( RecResultMessage . class , handler ) ; }
Prepare message handlers for received messages.
Prepare message handlers for received messages .
// REC_ROUTE_{NONE,INVOKE,JOIN} // parse the incoming message // In case of joining, routing contexts are initialized here. // remove nodes in blacklist from routing table // Note: this removes nodes which this node itself has not contacted // and prone to be abused by a malicious node. // AbstractRoutingDriver#fail() // calculate next hop // preserve last routing context // forward // REC_RESULT // remove nodes in blacklist from routing table // Note: this removes nodes which this node itself has not contacted // and prone to be abused by a malicious node. // AbstractRoutingDriver#fail() // notify the routing algorithm //algorithm.touch(msg.getSource()); // not necessary to call touch() because // the last entry in the returned route is same as msg.getSource()