public void forwardSerMsg(Message message) { List<Neighbor> neighbors = Configuration.getNeighbors(); Iterator<Neighbor> neighborsIterator = neighbors.iterator(); while (neighborsIterator.hasNext()) { Neighbor temp = neighborsIterator.next(); if (!message.ip_from.matches(temp.getIpAddress()) || message.port_from != temp.getPortNumber()) { Message serMsg = new SERMessage( message.query, message.hops + 1, message.ip_from, message.port_from, temp.getIpAddress(), temp.getPortNumber()); noOfFwdMsg++; System.out.println( "Forwarded query : " + message.ip_from + ":" + message.port_from + " TO " + temp.getIpAddress() + ":" + temp.getPortNumber()); myMsgTransfer.sendMessage(serMsg); } } }
public void printMessageDetail(String cmd) { String[] fp = cmd.split(" "); writeToFile("", fp[1]); writeToFile("RCV: " + noOfRcvMsg, fp[1]); writeToFile("FWD: " + noOfFwdMsg, fp[1]); writeToFile("ANS: " + noOfAnsMsg, fp[1]); writeToFile("Table Size: " + Configuration.getNeighbors().size(), fp[1]); System.out.println("RCV: " + noOfRcvMsg); System.out.println("FWD: " + noOfFwdMsg); System.out.println("ANS: " + noOfAnsMsg); System.out.println("Table Size: " + Configuration.getNeighbors().size()); noOfAnsMsg = 0; noOfFwdMsg = 0; noOfRcvMsg = 0; }
public void leaveDSSystem() { List<Neighbor> neighbors = Configuration.getNeighbors(); Iterator<Neighbor> neighborsIterator = neighbors.iterator(); while (neighborsIterator.hasNext()) { Neighbor temp = neighborsIterator.next(); Message leaveMsg = new LEAVEMessage(temp.getIpAddress(), temp.getPortNumber()); myMsgTransfer.sendMessage(leaveMsg); } }
public void checkForZeroNeighbors() { if (Configuration.getNeighbors().size() == 0) { if (Configuration.getBackUpNeighbors().size() > 0) { List<Neighbor> neighbors = Configuration.getBackUpNeighbors(); Configuration.setNeighbor( neighbors.get(0).getIpAddress(), neighbors.get(0).getPortNumber()); } else { System.out.println("This node has no connections."); } } }
public void printConnectedNeighbors() { System.out.println("Connected Neighbors:"); List<Neighbor> neighbors = Configuration.getNeighbors(); Iterator<Neighbor> neighborsIterator = neighbors.iterator(); while (neighborsIterator.hasNext()) { Neighbor temp = neighborsIterator.next(); System.out.println(temp.toString()); } }