org.apache.storm.utils.Utils.deserialize()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(173)

本文整理了Java中org.apache.storm.utils.Utils.deserialize()方法的一些代码示例,展示了Utils.deserialize()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.deserialize()方法的具体详情如下:
包路径:org.apache.storm.utils.Utils
类名称:Utils
方法名:deserialize

Utils.deserialize介绍

[英]Deserialize an object stored in a string. The String is assumed to be a base64 encoded string containing the bytes to actually deserialize.
[中]反序列化存储在字符串中的对象。该字符串被假定为base64编码的字符串,包含实际反序列化的字节。

代码示例

代码示例来源:origin: apache/storm

public static <T> T maybeDeserialize(byte[] serialized, Class<T> clazz) {
  if (serialized != null) {
    return Utils.deserialize(serialized, clazz);
  }
  return null;
}

代码示例来源:origin: apache/storm

/**
 * Deserialize an object stored in a string. The String is assumed to be a base64 encoded string containing the bytes to actually
 * deserialize.
 *
 * @param str   the encoded string.
 * @param clazz the thrift class we are expecting.
 * @param <T>   The type of clazz
 * @return the decoded object
 */
public static <T> T deserializeFromString(String str, Class<T> clazz) {
  return deserialize(Base64.getDecoder().decode(str), clazz);
}

代码示例来源:origin: apache/storm

/**
 * Get and deserialize the WorkerTokenInfo in the worker token.
 *
 * @param wt the token.
 * @return the deserialized info.
 */
public static WorkerTokenInfo getWorkerTokenInfo(WorkerToken wt) {
  return Utils.deserialize(wt.get_info(), WorkerTokenInfo.class);
}

代码示例来源:origin: apache/storm

@Override
  public String userName(String userName) {
    byte[] user = Base64.getDecoder().decode(userName);
    WorkerTokenInfo deser = Utils.deserialize(user, WorkerTokenInfo.class);
    return deser.get_userName();
  }
}

代码示例来源:origin: apache/storm

public static StormTopology readSupervisorStormCodeGivenPath(String stormCodePath, AdvancedFSOps ops) throws IOException {
  return Utils.deserialize(ops.slurp(new File(stormCodePath)), StormTopology.class);
}

代码示例来源:origin: apache/storm

@Override
public Optional<char[]> getPasswordFor(String userName) {
  if (keyCache == null) {
    return Optional.empty();
  }
  byte[] user = null;
  WorkerTokenInfo deser = null;
  try {
    user = Base64.getDecoder().decode(userName);
    deser = Utils.deserialize(user, WorkerTokenInfo.class);
  } catch (Exception e) {
    LOG.info("Could not decode {}, might just be a plain digest request...", userName, e);
    return Optional.empty();
  }
  try {
    byte[] password = getSignedPasswordFor(user, deser);
    return Optional.of(Base64.getEncoder().encodeToString(password).toCharArray());
  } catch (Exception e) {
    LOG.error("Could not get password for token {}/{}", deser.get_userName(), deser.get_topologyId(), e);
    return Optional.empty();
  }
}

代码示例来源:origin: apache/storm

@Override
public void run(String[] args, Map<String, Object> conf, String command) throws Exception {
  for (String arg: args) {
    System.out.println(arg + ":");
    StormTopology topo;
    File f = new File(arg);
    if (f.exists()) {
      topo = Utils.deserialize(FileUtils.readFileToByteArray(f), StormTopology.class);
    } else { //assume it is a topology id
      final String key = ConfigUtils.masterStormCodeKey(arg);
      try (BlobStore store = ServerUtils.getNimbusBlobStore(conf, NimbusInfo.fromConf(conf), null)) {
        topo = Utils.deserialize(store.readBlob(key, Nimbus.NIMBUS_SUBJECT), StormTopology.class);
      }
    }
    System.out.println(prettyPrint(topo));
  }
}

代码示例来源:origin: apache/storm

private static void handleGetCommand(IStateStorage cluster, String path) {
    String message;
    byte[] hb = cluster.get_worker_hb(path, false);
    if (hb != null) {
      Map<String, Object> heartbeatMap = StatsUtil.convertZkWorkerHb(Utils.deserialize(hb, ClusterWorkerHeartbeat.class));
      message = JSONValue.toJSONString(heartbeatMap);
    } else {
      message = "No Heartbeats found";
    }
    LOG.info(message);
  }
}

代码示例来源:origin: apache/storm

private Set<String> getTopologyDependencyKeys(Set<String> activeTopologyCodeKeys) {
  Set<String> activeTopologyDependencies = new TreeSet<>();
  Subject subject = ReqContext.context().subject();
  for (String activeTopologyCodeKey : activeTopologyCodeKeys) {
    try (InputStreamWithMeta blob = blobStore.getBlob(activeTopologyCodeKey, subject)) {
      byte[] blobContent = IOUtils.readFully(blob, new Long(blob.getFileLength()).intValue());
      StormTopology stormCode = Utils.deserialize(blobContent, StormTopology.class);
      if (stormCode.is_set_dependency_jars()) {
        activeTopologyDependencies.addAll(stormCode.get_dependency_jars());
      }
      if (stormCode.is_set_dependency_artifacts()) {
        activeTopologyDependencies.addAll(stormCode.get_dependency_artifacts());
      }
    } catch (AuthorizationException | KeyNotFoundException | IOException e) {
      LOG.error("Exception occurs while reading blob for key: "
           + activeTopologyCodeKey
           + ", exception: "
           + e, e);
      throw new RuntimeException("Exception occurs while reading blob for key: "
                    + activeTopologyCodeKey
                    + ", exception: " + e, e);
    }
  }
  return activeTopologyDependencies;
}

代码示例来源:origin: apache/storm

/**
 * Read a topology.
 * @param topoId the id of the topology to read
 * @param who who to read it as
 * @return the deserialized topology.
 * @throws IOException on any error while reading the blob.
 * @throws AuthorizationException if who is not allowed to read the blob
 * @throws KeyNotFoundException if the blob could not be found
 */
public StormTopology readTopology(final String topoId, final Subject who)
  throws KeyNotFoundException, AuthorizationException, IOException {
  final String key = ConfigUtils.masterStormCodeKey(topoId);
  WithAcl<StormTopology> cached = topos.get(topoId);
  if (cached == null) {
    //We need to read a new one
    StormTopology topo = Utils.deserialize(store.readBlob(key, who), StormTopology.class);
    ReadableBlobMeta meta = store.getBlobMeta(key, who);
    cached = new WithAcl<>(meta.get_settable().get_acl(), topo);
    WithAcl<StormTopology> previous = topos.putIfAbsent(topoId, cached);
    if (previous != null) {
      cached = previous;
    }
  } else {
    //Check if the user is allowed to read this
    aclHandler.hasPermissions(cached.acl, READ, who, key);
  }
  return cached.data;
}

代码示例来源:origin: apache/storm

continue;
ClusterWorkerHeartbeat cwh = Utils.deserialize(details, ClusterWorkerHeartbeat.class);
if (cwh != null && cwh.get_time_secs() > latest_time_secs) {
  latest_time_secs = cwh.get_time_secs();

代码示例来源:origin: org.apache.storm/storm-core

public static <T> T maybeDeserialize(byte[] serialized, Class<T> clazz) {
  if (serialized != null) {
    return Utils.deserialize(serialized, clazz);
  }
  return null;
}

代码示例来源:origin: org.apache.storm/storm-core

public static StormTopology readSupervisorStormCodeGivenPath(String stormCodePath, AdvancedFSOps ops) throws IOException {
  return Utils.deserialize(ops.slurp(new File(stormCodePath)), StormTopology.class);
}

代码示例来源:origin: org.apache.storm/storm-core

private Set<String> getTopologyDependencyKeys(Set<String> activeTopologyCodeKeys) {
  Set<String> activeTopologyDependencies = new TreeSet<>();
  Subject subject = ReqContext.context().subject();
  for (String activeTopologyCodeKey : activeTopologyCodeKeys) {
    try {
      InputStreamWithMeta blob = blobStore.getBlob(activeTopologyCodeKey, subject);
      byte[] blobContent = IOUtils.readFully(blob, new Long(blob.getFileLength()).intValue());
      StormTopology stormCode = Utils.deserialize(blobContent, StormTopology.class);
      if (stormCode.is_set_dependency_jars()) {
        activeTopologyDependencies.addAll(stormCode.get_dependency_jars());
      }
      if (stormCode.is_set_dependency_artifacts()) {
        activeTopologyDependencies.addAll(stormCode.get_dependency_artifacts());
      }
    } catch (AuthorizationException | KeyNotFoundException | IOException e) {
      LOG.error("Exception occurs while reading blob for key: " + activeTopologyCodeKey + ", exception: " + e, e);
      throw new RuntimeException("Exception occurs while reading blob for key: " + activeTopologyCodeKey +
          ", exception: " + e, e);
    }
  }
  return activeTopologyDependencies;
}

相关文章

微信公众号

最新文章

更多

Utils类方法