private String buildSolrId(K key) { JsonObject jsonKey = new JsonObject(); if (key instanceof String) { jsonKey.putString("C", "S"); jsonKey.putString("V", (String) key); } else { jsonKey.putString("C", key.getClass().getName()); jsonKey.putString("V", JsonObject.toJson(key)); } String id = _mapName + ":" + jsonKey.encode(); return id; }
private void solrStore(K key, V value) throws Exception { JsonObject doc = new JsonObject(); doc.putString(SolrTools.F_ID, buildSolrId(key)); doc.putNumber(SolrTools.F_VERSION, 0); // =0 Don’t care (normal overwrite if exists) doc.putString( SolrTools.F_HZ_CTIME, SolrTools.solrDateFormat.format(new java.util.Date(System.currentTimeMillis()))); doc.putString(SolrTools.F_HZ_CLASS, value.getClass().getName()); doc.putString(SolrTools.F_HZ_DATA, JsonObject.toJson(value)); JsonObject jsonResponse = null; Exception ex = null; for (int i = 0; i < _urlUpdates.size(); i++) { try { jsonResponse = SolrTools.updateDoc(getSolrUpdateUrl(), _connectTimeout, _readTimeout, doc); if (SolrTools.getStatus(jsonResponse) == 0) { ex = null; break; } } catch (Exception e) { ex = e; try { Thread.sleep(100); } catch (InterruptedException e1) { } } } if (ex != null) { throw ex; } if (SolrTools.getStatus(jsonResponse) != 0) { throw new RuntimeException(jsonResponse.encodePrettily()); } }