當前位置: 首頁>>代碼示例>>Java>>正文


Java NodeData類代碼示例

本文整理匯總了Java中org.apache.twill.zookeeper.NodeData的典型用法代碼示例。如果您正苦於以下問題:Java NodeData類的具體用法?Java NodeData怎麽用?Java NodeData使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


NodeData類屬於org.apache.twill.zookeeper包,在下文中一共展示了NodeData類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: watchNode

import org.apache.twill.zookeeper.NodeData; //導入依賴的package包/類
/**
 * Starts watching for the max. of smaller node.
 */
private void watchNode(final String nodePath, Watcher watcher) {
  OperationFuture<NodeData> watchFuture = zkClient.getData(nodePath, watcher);
  Futures.addCallback(watchFuture, new FutureCallback<NodeData>() {
    @Override
    public void onSuccess(NodeData nodeData) {
      if (state != State.CANCELLED) {
        becomeFollower();
      }
    }

    @Override
    public void onFailure(Throwable t) {
      // On any kind of failure, just rerun the election.
      LOG.debug("Exception while setting watch on node {}. Retry.", nodePath, t);
      runElection();
    }
  }, executor);
}
 
開發者ID:apache,項目名稱:twill,代碼行數:22,代碼來源:LeaderElection.java

示例2: instanceNodeUpdated

import org.apache.twill.zookeeper.NodeData; //導入依賴的package包/類
@Override
protected void instanceNodeUpdated(NodeData nodeData) {
  if (nodeData == null ||  nodeData.getData() == null) {
    LOG.warn("Instance node was updated but data is null.");
    return;
  }
  try {
    Gson gson = new Gson();
    JsonElement json = gson.fromJson(new String(nodeData.getData(), Charsets.UTF_8), JsonElement.class);
    if (json.isJsonObject()) {
      JsonElement data = json.getAsJsonObject().get("data");
      if (data != null) {
        this.liveData = gson.fromJson(data, ContainerLiveNodeData.class);
        LOG.info("Container LiveNodeData updated: " + new String(nodeData.getData(), Charsets.UTF_8));
      }
    }
  } catch (Throwable t) {
    LOG.warn("Error deserializing updated instance node data", t);
  }
}
 
開發者ID:apache,項目名稱:twill,代碼行數:21,代碼來源:TwillContainerLauncher.java

示例3: getData

import org.apache.twill.zookeeper.NodeData; //導入依賴的package包/類
@Override
public OperationFuture<NodeData> getData(String path, Watcher watcher) {
  SettableOperationFuture<NodeData> result = SettableOperationFuture.create(path, eventExecutor);
  getZooKeeper().getData(path, wrapWatcher(watcher), Callbacks.DATA, result);

  return result;
}
 
開發者ID:apache,項目名稱:twill,代碼行數:8,代碼來源:DefaultZKClientService.java

示例4: processResult

import org.apache.twill.zookeeper.NodeData; //導入依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
  SettableOperationFuture<NodeData> result = (SettableOperationFuture<NodeData>) ctx;
  KeeperException.Code code = KeeperException.Code.get(rc);
  if (code == KeeperException.Code.OK) {
    result.set(new BasicNodeData(data, stat));
    return;
  }
  result.setException(KeeperException.create(code, result.getRequestPath()));
}
 
開發者ID:apache,項目名稱:twill,代碼行數:12,代碼來源:DefaultZKClientService.java

示例5: getData

import org.apache.twill.zookeeper.NodeData; //導入依賴的package包/類
@Override
public OperationFuture<NodeData> getData(final String path, final Watcher watcher) {
  final SettableOperationFuture<NodeData> result = SettableOperationFuture.create(path, Threads.SAME_THREAD_EXECUTOR);
  Futures.addCallback(super.getData(path, watcher),
                      new OperationFutureCallback<NodeData>(OperationType.GET_DATA, System.currentTimeMillis(),
                                                            path, result, new Supplier<OperationFuture<NodeData>>() {
                        @Override
                        public OperationFuture<NodeData> get() {
                          return FailureRetryZKClient.super.getData(path, watcher);
                        }
                      }));
  return result;
}
 
開發者ID:apache,項目名稱:twill,代碼行數:14,代碼來源:FailureRetryZKClient.java

示例6: equals

import org.apache.twill.zookeeper.NodeData; //導入依賴的package包/類
@Override
public boolean equals(Object o) {
  if (this == o) {
    return true;
  }
  if (o == null || !(o instanceof NodeData)) {
    return false;
  }

  BasicNodeData that = (BasicNodeData) o;

  return stat.equals(that.getStat()) && Arrays.equals(data, that.getData());
}
 
開發者ID:apache,項目名稱:twill,代碼行數:14,代碼來源:BasicNodeData.java

示例7: data

import org.apache.twill.zookeeper.NodeData; //導入依賴的package包/類
private void data() {
  Futures.addCallback(client.getData(path, this), new FutureCallback<NodeData>() {
    @Override
    public void onSuccess(NodeData result) {
      Object oldResult = lastResult.getReference();
      lastResult.compareAndSet(oldResult, null, true, false);

      if (!result.equals(oldResult)) {
        // Whenever something changed, treated it as data changed.
        process(new WatchedEvent(Event.EventType.NodeDataChanged, Event.KeeperState.SyncConnected, path));
      }
    }

    @Override
    public void onFailure(Throwable t) {
      if (RetryUtils.canRetry(t)) {
        data();
        return;
      }

      lastResult.set(null, false);
      if (t instanceof KeeperException) {
        KeeperException.Code code = ((KeeperException) t).code();
        if (code == KeeperException.Code.NONODE) {
          // Node deleted
          process(new WatchedEvent(Event.EventType.NodeDeleted, Event.KeeperState.SyncConnected, path));
          return;
        }
      }
      LOG.error("Fail to re-set watch on getData for path " + path, t);
    }
  });
}
 
開發者ID:apache,項目名稱:twill,代碼行數:34,代碼來源:RewatchOnExpireWatcher.java

示例8: decode

import org.apache.twill.zookeeper.NodeData; //導入依賴的package包/類
/**
 * Decodes the {@link ApplicationMasterLiveNodeData} from the given ZK node data.
 *
 * @return the {@link ApplicationMasterLiveNodeData} or {@code null} if failed to decode.
 */
@Nullable
static ApplicationMasterLiveNodeData decode(@Nullable NodeData nodeData) {
  byte[] data = nodeData == null ? null : nodeData.getData();
  if (data == null) {
    return null;
  }

  JsonElement json = GSON.fromJson(new String(data, Charsets.UTF_8), JsonElement.class);
  if (!json.isJsonObject()) {
    LOG.warn("Unable to decode live data node.");
    return null;
  }

  JsonObject jsonObj = json.getAsJsonObject();
  json = jsonObj.get("data");
  if (json == null || !json.isJsonObject()) {
    LOG.warn("Property data not found in live data node.");
    return null;
  }

  try {
    return GSON.fromJson(json, ApplicationMasterLiveNodeData.class);
  } catch (Exception e) {
    LOG.warn("Failed to decode application live node data.", e);
    return null;
  }
}
 
開發者ID:apache,項目名稱:twill,代碼行數:33,代碼來源:ApplicationMasterLiveNodeDecoder.java

示例9: updateController

import org.apache.twill.zookeeper.NodeData; //導入依賴的package包/類
private void updateController(final String appName, final RunId runId, final AtomicBoolean cancelled) {
  String instancePath = String.format("/%s/instances/%s", appName, runId.getId());

  // Fetch the content node.
  Futures.addCallback(zkClientService.getData(instancePath), new FutureCallback<NodeData>() {
    @Override
    public void onSuccess(NodeData result) {
      if (cancelled.get()) {
        return;
      }

      ApplicationMasterLiveNodeData amLiveNodeData = ApplicationMasterLiveNodeDecoder.decode(result);
      if (amLiveNodeData == null) {
        return;
      }

      synchronized (YarnTwillRunnerService.this) {
        if (!controllers.contains(appName, runId)) {
          ZKClient zkClient = ZKClients.namespace(zkClientService, "/" + appName);
          YarnAppClient yarnAppClient = new VersionDetectYarnAppClientFactory().create(new Configuration(yarnConfig));

          YarnTwillController controller = listenController(
            new YarnTwillController(appName, runId, zkClient, amLiveNodeData, yarnAppClient));
          controllers.put(appName, runId, controller);
          controller.start();
        }
      }
    }

    @Override
    public void onFailure(Throwable t) {
      LOG.warn("Failed in fetching application instance node.", t);
    }
  }, Threads.SAME_THREAD_EXECUTOR);
}
 
開發者ID:apache,項目名稱:twill,代碼行數:36,代碼來源:YarnTwillRunnerService.java

示例10: instanceNodeUpdated

import org.apache.twill.zookeeper.NodeData; //導入依賴的package包/類
@Override
protected void instanceNodeUpdated(NodeData nodeData) {
  ApplicationMasterLiveNodeData data = ApplicationMasterLiveNodeDecoder.decode(nodeData);
  if (data != null) {
    amLiveNodeData = data;
  }
}
 
開發者ID:apache,項目名稱:twill,代碼行數:8,代碼來源:YarnTwillController.java

示例11: processMessage

import org.apache.twill.zookeeper.NodeData; //導入依賴的package包/類
private void processMessage(final String path, final String messageId) {
  Futures.addCallback(zkClient.getData(path), new FutureCallback<NodeData>() {
    @Override
    public void onSuccess(NodeData result) {
      Runnable messageRemover = createMessageRemover(path, result.getStat().getVersion());

      Message message = MessageCodec.decode(result.getData());
      if (message == null) {
        LOG.error("Failed to decode message for {} in {}", messageId, path);
        messageRemover.run();
        return;
      }
      if (LOG.isDebugEnabled()) {
        LOG.debug("Message received from {}: {}", path, new String(MessageCodec.encode(message), Charsets.UTF_8));
      }

      // Handle the stop message
      if (handleStopMessage(message, messageRemover)) {
        return;
      }
      // Otherwise, delegate to the child class to handle the message
      handleMessage(messageId, message, messageRemover);
    }

    @Override
    public void onFailure(Throwable t) {
      LOG.error("Failed to fetch message content from {}", path, t);
    }
  }, messageCallbackExecutor);
}
 
開發者ID:apache,項目名稱:twill,代碼行數:31,代碼來源:AbstractTwillService.java

示例12: decodeNodeData

import org.apache.twill.zookeeper.NodeData; //導入依賴的package包/類
/**
 * Gson decode the NodeData into object.
 * @param nodeData The data to decode
 * @param type Object class to decode into.
 * @param <T> Type of the object.
 * @return The decoded object or {@code null} if node data is null.
 */
private <T> T decodeNodeData(NodeData nodeData, Class<T> type) {
  byte[] data = nodeData == null ? null : nodeData.getData();
  if (data == null) {
    return null;
  }
  return GSON.fromJson(new String(data, Charsets.UTF_8), type);
}
 
開發者ID:apache,項目名稱:twill,代碼行數:15,代碼來源:ZKBrokerService.java

示例13: getController

import org.apache.twill.zookeeper.NodeData; //導入依賴的package包/類
private TwillController getController(ZKClient zkClient, String appName, RunId runId) {
  AbstractTwillController controller = new AbstractTwillController(appName, runId,
                                                                   zkClient, false, ImmutableList.<LogHandler>of()) {

    @Override
    public void kill() {
      // No-op
    }

    @Override
    protected void instanceNodeUpdated(NodeData nodeData) {
      // No-op
    }

    @Override
    protected void instanceNodeFailed(Throwable cause) {
      // Shutdown if the instance node goes away
      if (cause instanceof KeeperException.NoNodeException) {
        forceShutDown();
      }
    }

    @Override
    public ResourceReport getResourceReport() {
      return null;
    }
  };
  controller.startAndWait();
  return controller;
}
 
開發者ID:apache,項目名稱:twill,代碼行數:31,代碼來源:ControllerTest.java

示例14: updateController

import org.apache.twill.zookeeper.NodeData; //導入依賴的package包/類
private void updateController(final String appName, final RunId runId, final AtomicBoolean cancelled) {
  String instancePath = String.format("/%s/instances/%s", appName, runId.getId());

  // Fetch the content node.
  Futures.addCallback(zkClientService.getData(instancePath), new FutureCallback<NodeData>() {
    @Override
    public void onSuccess(NodeData result) {
      if (cancelled.get()) {
        return;
      }
      ApplicationId appId = getApplicationId(result);
      if (appId == null) {
        return;
      }

      synchronized (YarnTwillRunnerService.this) {
        if (!controllers.contains(appName, runId)) {
          ZKClient zkClient = ZKClients.namespace(zkClientService, "/" + appName);
          YarnTwillController controller = listenController(
            new YarnTwillController(appName, runId, zkClient,
                                    Callables.returning(yarnAppClient.createProcessController(appId))));
          controllers.put(appName, runId, controller);
          controller.start();
        }
      }
    }

    @Override
    public void onFailure(Throwable t) {
      LOG.warn("Failed in fetching application instance node.", t);
    }
  }, Threads.SAME_THREAD_EXECUTOR);
}
 
開發者ID:chtyim,項目名稱:incubator-twill,代碼行數:34,代碼來源:YarnTwillRunnerService.java

示例15: getApplicationId

import org.apache.twill.zookeeper.NodeData; //導入依賴的package包/類
/**
 * Decodes application ID stored inside the node data.
 * @param nodeData The node data to decode from. If it is {@code null}, this method would return {@code null}.
 * @return The ApplicationId or {@code null} if failed to decode.
 */
private ApplicationId getApplicationId(NodeData nodeData) {
  byte[] data = nodeData == null ? null : nodeData.getData();
  if (data == null) {
    return null;
  }

  Gson gson = new Gson();
  JsonElement json = gson.fromJson(new String(data, Charsets.UTF_8), JsonElement.class);
  if (!json.isJsonObject()) {
    LOG.warn("Unable to decode live data node.");
    return null;
  }

  JsonObject jsonObj = json.getAsJsonObject();
  json = jsonObj.get("data");
  if (!json.isJsonObject()) {
    LOG.warn("Property data not found in live data node.");
    return null;
  }

  try {
    ApplicationMasterLiveNodeData amLiveNode = gson.fromJson(json, ApplicationMasterLiveNodeData.class);
    return YarnUtils.createApplicationId(amLiveNode.getAppIdClusterTime(), amLiveNode.getAppId());
  } catch (Exception e) {
    LOG.warn("Failed to decode application live node data.", e);
    return null;
  }
}
 
開發者ID:chtyim,項目名稱:incubator-twill,代碼行數:34,代碼來源:YarnTwillRunnerService.java


注:本文中的org.apache.twill.zookeeper.NodeData類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。