public static ObjectMapper jsonMapper() { return ObjectMapperFactory.getThreadLocal(); }
@Override public PropertyAdmin deserialize(String path, byte[] content) throws Exception { return ObjectMapperFactory.getThreadLocal().readValue(content, PropertyAdmin.class); } };
@Override public LoadReport deserialize(String key, byte[] content) throws Exception { return ObjectMapperFactory.getThreadLocal().readValue(content, LoadReport.class); } };
@Override public ClusterData deserialize(String path, byte[] content) throws Exception { return ObjectMapperFactory.getThreadLocal().readValue(content, ClusterData.class); } };
@Override public Map<String, String> deserialize(String key, byte[] content) throws Exception { return ObjectMapperFactory.getThreadLocal().readValue(content, HashMap.class); } };
@Override public NamespaceEphemeralData deserialize(String path, byte[] content) throws Exception { return ObjectMapperFactory.getThreadLocal().readValue(content, NamespaceEphemeralData.class); } };
@Override public Policies deserialize(String path, byte[] content) throws Exception { return ObjectMapperFactory.getThreadLocal().readValue(content, Policies.class); } };
@Override public LoadReport deserialize(String key, byte[] content) throws Exception { return ObjectMapperFactory.getThreadLocal().readValue(content, LoadReport.class); } };
private static <T> T readJson(final byte[] data, final Class<T> clazz) throws IOException { return ObjectMapperFactory.getThreadLocal().readValue(data, clazz); }
@Override public Map<String, String> deserialize(String key, byte[] content) throws Exception { return ObjectMapperFactory.getThreadLocal().readValue(content, HashMap.class); } };
@Override public LocalBrokerData deserialize(String key, byte[] content) throws Exception { return ObjectMapperFactory.getThreadLocal().readValue(content, LocalBrokerData.class); } };
@Override public LocalPolicies deserialize(String path, byte[] content) throws Exception { return ObjectMapperFactory.getThreadLocal().readValue(content, LocalPolicies.class); }
/** * Get the JSON of this object as a String. * * @return A String of this object's JSON. * @throws JsonProcessingException */ @JsonIgnore public String getJsonString() throws JsonProcessingException { return ObjectMapperFactory.getThreadLocal().writeValueAsString(this); } }
/** * Get the JSON of this object as a byte[]. * * @return A byte[] of this object's JSON. * @throws JsonProcessingException */ @JsonIgnore public byte[] getJsonBytes() throws JsonProcessingException { return ObjectMapperFactory.getThreadLocal().writeValueAsBytes(this); }
@Override @SuppressWarnings("unchecked") public NamespaceIsolationPolicies deserialize(String path, byte[] content) throws Exception { return new NamespaceIsolationPolicies((Map<String, NamespaceIsolationData>) ObjectMapperFactory .getThreadLocal().readValue(content, new TypeReference<Map<String, NamespaceIsolationData>>() { })); } };
CompletableFuture<PartitionedTopicMetadata> getPartitionedTopicMetadata(DiscoveryService service, DestinationName destination, String role) { CompletableFuture<PartitionedTopicMetadata> metadataFuture = new CompletableFuture<>(); try { checkAuthorization(service, destination, role); final String path = path(PARTITIONED_TOPIC_PATH_ZNODE, destination.getProperty(), destination.getCluster(), destination.getNamespacePortion(), "persistent", destination.getEncodedLocalName()); // gets the number of partitions from the zk cache globalZkCache .getDataAsync(path, (key, content) -> getThreadLocal().readValue(content, PartitionedTopicMetadata.class)) .thenAccept(metadata -> { // if the partitioned topic is not found in zk, then the topic // is not partitioned if (metadata.isPresent()) { metadataFuture.complete(metadata.get()); } else { metadataFuture.complete(new PartitionedTopicMetadata()); } }).exceptionally(ex -> { metadataFuture.completeExceptionally(ex); return null; }); } catch (Exception e) { metadataFuture.completeExceptionally(e); } return metadataFuture; }
private void setDynamicConfigurationToZK(String zkPath, Map<String, String> settings) throws IOException { byte[] settingBytes = ObjectMapperFactory.getThreadLocal().writeValueAsBytes(settings); try { if (pulsar.getLocalZkCache().exists(zkPath)) { pulsar.getZkClient().setData(zkPath, settingBytes, -1); } else { ZkUtils.createFullPathOptimistic(pulsar.getZkClient(), zkPath, settingBytes, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } } catch (Exception e) { log.warn("Got exception when writing to ZooKeeper path [{}]:", zkPath, e); } }
T data = ObjectMapperFactory.getThreadLocal().readValue(response.getResponseBodyAsBytes(), clazz); future.complete(data); } catch (Exception e) {
/** * update new bundle-range to LocalZk (create a new node if not present) * * @param nsname * @param nsBundles * @param callback * @throws Exception */ private void updateNamespaceBundles(NamespaceName nsname, NamespaceBundles nsBundles, StatCallback callback) throws Exception { checkNotNull(nsname); checkNotNull(nsBundles); String path = joinPath(LOCAL_POLICIES_ROOT, nsname.toString()); Optional<LocalPolicies> policies = pulsar.getLocalZkCacheService().policiesCache().get(path); if (!policies.isPresent()) { // if policies is not present into localZk then create new policies this.pulsar.getLocalZkCacheService().createPolicies(path, false).get(cacheTimeOutInSec, SECONDS); policies = this.pulsar.getLocalZkCacheService().policiesCache().get(path); } policies.get().bundles = getBundlesData(nsBundles); this.pulsar.getLocalZkCache().getZooKeeper().setData(path, ObjectMapperFactory.getThreadLocal().writeValueAsBytes(policies.get()), -1, callback, null); }
if (configurationMap != null) { configurationMap.put(configName, configValue); byte[] content = ObjectMapperFactory.getThreadLocal().writeValueAsBytes(configurationMap); dynamicConfigurationCache.invalidate(BROKER_SERVICE_CONFIGURATION_PATH); serviceConfigZkVersion = localZk() configurationMap = Maps.newHashMap(); configurationMap.put(configName, configValue); byte[] content = ObjectMapperFactory.getThreadLocal().writeValueAsBytes(configurationMap); ZkUtils.createFullPathOptimistic(localZk(), BROKER_SERVICE_CONFIGURATION_PATH, content, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);