Exemplo n.º 1
0
  private Map<TransportProtocolId, List<TransportConnectionInfo>> parseBootstrapServers(
      String serversStr) throws InvalidKeySpecException, NoSuchAlgorithmException {
    Map<TransportProtocolId, List<TransportConnectionInfo>> servers = new HashMap<>();
    String[] serversSplit = serversStr.split(";");

    for (String server : serversSplit) {
      if (server != null && !server.trim().isEmpty()) {
        String[] tokens = server.split(":");
        ProtocolMetaData md = new ProtocolMetaData();
        md.setAccessPointId(Integer.valueOf(tokens[0]));
        md.setProtocolVersionInfo(
            new ProtocolVersionPair(Integer.valueOf(tokens[1]), Integer.valueOf(tokens[2])));
        md.setConnectionInfo(ByteBuffer.wrap(base64.decodeBase64(tokens[3])));
        TransportProtocolId key =
            new TransportProtocolId(
                md.getProtocolVersionInfo().getId(), md.getProtocolVersionInfo().getVersion());
        List<TransportConnectionInfo> serverList = servers.get(key);
        if (serverList == null) {
          serverList = new ArrayList<TransportConnectionInfo>();
          servers.put(key, serverList);
        }
        serverList.add(new GenericTransportInfo(ServerType.BOOTSTRAP, md));
      }
    }
    return servers;
  }
Exemplo n.º 2
0
 @Override
 public EndpointObjectHash getProfileHash() {
   return EndpointObjectHash.fromBytes(
       base64.decodeBase64(
           state
               .getProperty(
                   PROFILE_HASH, new String(base64.encodeBase64(new byte[0]), Charsets.UTF_8))
               .getBytes(Charsets.UTF_8)));
 }
Exemplo n.º 3
0
  private boolean isSDKPropertiesUpdated(KaaClientProperties sdkProperties) {
    byte[] hashFromSDK = sdkProperties.getPropertiesHash();
    byte[] hashFromStateFile =
        base64.decodeBase64(
            state
                .getProperty(
                    PROPERTIES_HASH, new String(base64.encodeBase64(new byte[0]), Charsets.UTF_8))
                .getBytes(Charsets.UTF_8));

    return !Arrays.equals(hashFromSDK, hashFromStateFile);
  }
Exemplo n.º 4
0
 @SuppressWarnings("unchecked")
 private void parseNfSubscriptions() {
   if (state.getProperty(NF_SUBSCRIPTIONS) != null) {
     byte[] data = base64.decodeBase64(state.getProperty(NF_SUBSCRIPTIONS));
     ByteArrayInputStream is = new ByteArrayInputStream(data);
     try (ObjectInputStream ois = new ObjectInputStream(is)) {
       nfSubscriptions.putAll((Map<Long, Integer>) ois.readObject());
     } catch (Exception e) {
       LOG.error(
           "Unexpected exception occurred while reading subscription information from state", e);
     }
   } else {
     LOG.info("No subscription info found in state");
   }
 }
Exemplo n.º 5
0
 private void parseTopics() {
   if (state.getProperty(TOPIC_LIST) != null) {
     byte[] data = base64.decodeBase64(state.getProperty(TOPIC_LIST));
     BinaryDecoder decoder = DecoderFactory.get().binaryDecoder(data, null);
     SpecificDatumReader<Topic> avroReader = new SpecificDatumReader<>(Topic.class);
     try { // NOSONAR
       Topic decodedTopic;
       while (!decoder.isEnd()) {
         decodedTopic = avroReader.read(null, decoder);
         LOG.debug("Loaded {}", decodedTopic);
         topicMap.put(decodedTopic.getId(), decodedTopic);
       }
     } catch (Exception e) {
       LOG.error("Unexpected exception occurred while reading information from decoder", e);
     }
   } else {
     LOG.info("No topic list found in state");
   }
 }
Exemplo n.º 6
0
 public byte[] getDefaultConfigData() {
   String config = getProperty(KaaClientProperties.CONFIG_DATA_DEFAULT);
   return (config != null) ? base64.decodeBase64(config.getBytes(Charsets.UTF_8)) : null;
 }