ChordKey getKey(String name) { return (ChordKey) keyFactory.newKey(name); }
/** * Constructor of the class. Receives a reference of the chord node and * initializes the size, pointer next and the fingers table. * * @param nodeChord The reference of the chord node. */ FingersTable(ChordNode nodeChord, KeyFactory keyFactory) { this.size = keyFactory.getKeyLength(); this.chordNode = nodeChord; this.next = 0; this.fingersTable = new ChordKey[size]; this.keyFactory = keyFactory; }
Key getFileKey(String name) { return keyFactory.newKey(name); }
/** * Called always for <code>FingersTable.fixFingers</code> * <p> * Create the <code>i-th</code> entry to be test in the fingers table. The * next entry is given by * <code>(node.key + 2^(next-1)) mod 2^(size), 1<=k<=m</code> * * @param key Node's key * @return {@link Key} The key to be test in the fingers table. */ ChordKey createNext(ChordKey key) { Key nextKey; BigInteger nextValue; BigInteger twoPow; BigInteger maxValue; twoPow = new BigInteger("2"); twoPow = twoPow.pow(next); nextValue = new BigInteger(key.getHashing().toByteArray()); nextValue = nextValue.add(twoPow); maxValue = new BigInteger("2"); maxValue = maxValue.pow(size); nextValue = nextValue.mod(maxValue); nextKey = keyFactory.newKey(nextValue); return (ChordKey) nextKey; }
@Override public void update(Observable observable, Object object) { if (object instanceof Message) { Message message = (Message) object; log.info("Update: " + message); if (message.getMessageType().getName().equals(RE_ASSIGN)) { try { dHashNode.relocateAllResources(keyFactory.newKey(message.getParam(PREDECESSOR)), (name, current, size) -> { }); } catch (StorageException e) { log.error("Problem relocating files", e); } } } } }
/** * Process message of type is SET_PREDECESSOR * * @param message Message SET_PREDECESSOR */ private Message processSetPredecessor(Message message) { ChordKey nodePredecessor; nodePredecessor = (ChordKey) keyFactory.newKey(message .getParam(SetPredecessorParams.PREDECESSOR.name())); chordNode.setPredecessor(nodePredecessor); return null; }
/** * Process message of type is SET_SUCCESSOR * * @param message Message SET_SUCCESSOR */ private Message processSetSuccessor(Message message) { ChordKey nodeSucessor; nodeSucessor = (ChordKey) keyFactory.newKey(message.getParam(SetSuccessorParams.SUCCESSOR .name())); chordNode.setSuccessor(nodeSucessor); return null; }
/** * Process message of type is NOTIFY * * @param message Message NOTIFY */ private Message processNotify(Message message) { if (!message.isMessageFromMySelf()) { ChordKey node; node = (ChordKey) keyFactory.newKey(message.getAddress().getSource()); chordNode.notify(node); } return null; }
boolean putSync(Resource resource, ProgressStatus progressStatus) throws StorageException { progressStatus.status("put", 0L, 1L); progressStatus.status("overlay-node-lookup", 0L, 1L); Key key = keyFactory.newKey(resource.getId()); log.debug("Resource to put: [" + resource.getId() + "] Hashing: [" + key.getHashing() + "]"); Key lookupKey = overlayNode.lookUp(key); progressStatus.status("overlay-node-lookup", 1L, 1L); if (lookupKey == null) { log.error("Impossible to do put the resource: " + resource.getId() + " in this moment"); throw new StorageException("Impossible to do put the resource: " + resource.getId() + " in this moment"); } log.debug("Lookup key for " + key.getHashing() + ": [" + lookupKey.getValue() + "]"); boolean success = put(resource, lookupKey, true, progressStatus); progressStatus.status("put", 1L, 1L); return success; }
/** * Called periodically in {@link StableRing }. * <p> * Fixes the successor list by asking node's successor its successor list. */ public void fixSuccessors() { String successorList; ChordKey successor = keyList[0]; Message getSuccessorListMesssage; getSuccessorListMesssage = Message.builder() .id(sequenceGenerator.newId()) .sendType(Message.SendType.REQUEST) .messageType(Protocol.GET_SUCCESSOR_LIST) .address(Address.builder() .destination(successor.getValue()) .source(chordNode.getKey().getValue()) .build()) .build(); successorList = communicationManager.send( getSuccessorListMesssage, String.class); if (successorList == null) return; String[] successors = successorList.split(SEPARATOR); for (int i = 1; i < Math.min(size, successors.length); i++) { keyList[i] = (ChordKey) keyFactory.newKey(successors[i - 1]); } log.debug("Node: " + chordNode.getKey().getValue() + " Successors: " + toString()); }
ChordKey id; id = (ChordKey) keyFactory.newKey(new BigInteger(message.getParam(LookupParams.HASHING .name())));
Key lookupKey = overlayNode.lookUp(keyFactory.newKey(id));