@Override public int delete(Uri uri, String selection, String[] selectionArgs) { // Log.v(TAG,"delete method called"); String key = selection; if (CommonConstants.QUERY_LOCAL.equals(key)) { deleteLocalFiles(); } else if (CommonConstants.QUERY_GLOBAL.equals(key)) { deleteLocalFiles(); StringBuilder sb = new StringBuilder(); sb.append(CommonConstants.MSG_TYPE_DELETE) .append(CommonConstants.HASH_SEP) .append(localPort) .append(CommonConstants.HASH_SEP) .append(CommonConstants.QUERY_GLOBAL); String message = sb.toString(); for (Node node : dynamoNodes) { //// Log.v(TAG,"delete:: Forwarding delete global "+message +" to "+ node.getPortNum()); if (!node.getPortNum().equals(localPort)) { try { sendMessage(message, node.getPortNum()); } catch (Exception e) { // Log.v(TAG, "Error occured while deleting from port "+node.getPortNum()); } } } } else { int index = findSuccesssorIndex(key); int snd_cnt = 0; int num_nodes = dynamoNodes.size(); while (snd_cnt != NUM_REPLICAS) { Node node = dynamoNodes.get(index); //// Log.v(TAG, "Deleting specific key "+ key +" from "+node.getPortNum()); if (node.getPortNum().equals(localPort)) { deleteSingleLocalFile(key); } else { StringBuilder sb = new StringBuilder(); sb.append(CommonConstants.MSG_TYPE_DELETE) .append(CommonConstants.HASH_SEP) .append(localPort) .append(CommonConstants.HASH_SEP) .append(key); String message = sb.toString(); //// Log.v(TAG,"delete:: Forwarding delete specific key "+message+" to // "+node.getPortNum()); try { sendMessage(message, node.getPortNum()); } catch (Exception e) { // Log.v(TAG, "Error occured while deleting from port "+node.getPortNum()); } } index = (index + 1) % num_nodes; snd_cnt++; } } return 0; }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { //// Log.v(TAG,"Query method called for key "+selection); MatrixCursor cursor = null; String key = selection; synchronized (this) { if (CommonConstants.QUERY_LOCAL.equals(key)) { cursor = handleLocalAllQuery(); } else if (CommonConstants.QUERY_GLOBAL.equals(key)) { cursor = handleGlobalAllQuery(); } else { cursor = handleSingleKeyQuery(key); } } return cursor; }