protected StringBuilder getCurrentMasterNode(final String appId, final int iteration) { return getMasterNode(appId, iteration); }
protected StringBuilder getCurrentWorkerNode(final String appId, final String containerId, final int iteration) { return getWorkerNode(appId, containerId, iteration); }
/** * Close resources like zookeeper, thread pool */ protected void close() throws InterruptedException { if(this.zkHeartBeatEnabled) { stopHeartBeat(); } if(getZooKeeper() != null) { getZooKeeper().close(); } // shut down thread pool this.threadPool.shutdownNow(); this.threadPool.awaitTermination(2, TimeUnit.SECONDS); }
if(getZooKeeper() == null) { try { String zkServers = props.getProperty(GuaguaConstants.GUAGUA_ZK_SERVERS); props.getProperty(GuaguaConstants.GUAGUA_ZK_RETRY_WAIT_MILLS), GuaguaConstants.GUAGUA_ZK_DEFAULT_RETRY_WAIT_MILLS); setZooKeeper(new GuaguaZooKeeper(zkServers, sessionTimeout, maxRetryAttempts, retryWaitMsecs, this)); this.getZkConnLatch().await(); } catch (IOException e) { throw new GuaguaRuntimeException(e); startHeartbeat();
/** * Coordinator initialization. */ protected void initialize(Properties props) { this.zkHeartBeatEnabled = Boolean.TRUE.toString().equalsIgnoreCase( props.getProperty(GuaguaConstants.GUAGUA_ZK_HEARTBEAT_ENABLED, Boolean.FALSE.toString())); checkAndSetZooKeeper(props); setSleepTime(NumberFormatUtils.getLong(props.getProperty(GuaguaConstants.GUAGUA_COORDINATOR_SLEEP_UNIT), WAIT_SLOT_MILLS)); setFixedTime(Boolean.TRUE.toString().equalsIgnoreCase( props.getProperty(GuaguaConstants.GUAGUA_COORDINATOR_FIXED_SLEEP_ENABLE, GuaguaConstants.GUAGUA_COORDINATOR_FIXED_SLEEP))); this.threadPool = Executors.newFixedThreadPool(Integer.parseInt(props.getProperty( "guagua.master.result.thread.number", 8 + ""))); }
protected StringBuilder getBaseMasterElectionNode(final String appId) { return new StringBuilder(20).append(getAppNode(appId)).append(GuaguaConstants.ZOOKEEPER_SEPARATOR) .append(GuaguaConstants.GUAGUA_MASTER_ELECTION); }
protected StringBuilder getMasterNode(final String appId, final int iteration) { return new StringBuilder(50).append(getMasterBaseNode(appId)).append(GuaguaConstants.ZOOKEEPER_SEPARATOR) .append(iteration); }
protected StringBuilder getWorkerBaseNode(final String appId, final int iteration) { return new StringBuilder(50).append(getWorkerBaseNode(appId)).append(GuaguaConstants.ZOOKEEPER_SEPARATOR) .append(iteration); }
byte[] data = getZooKeeper().getData(znode, null, null); if(data != null) { return data; final List<String> children = getZooKeeper().getChildrenExt(splitZnode, false, true, new ChildrenComparator()); if(children == null || children.size() == 0) { return null; for(int i = 0; i < children.size(); i++) { final int index = i; completionService.submit(new GetSplitBytes(getZooKeeper(), index, children.get(index)));
protected StringBuilder getMasterElectionNode(final String appId, final long sessionId) { return new StringBuilder(40).append(getBaseMasterElectionNode(appId)) .append(GuaguaConstants.ZOOKEEPER_SEPARATOR).append(sessionId); }
protected StringBuilder getAppNode(final String appId) { return new StringBuilder(20).append(getRootNode()).append(GuaguaConstants.ZOOKEEPER_SEPARATOR).append(appId); }
@Override public void process(final WatchedEvent event) { LOG.debug("process: Got a new event, path = {}, type = {}, state = {}", event.getPath(), event.getType(), event.getState()); if((event.getPath() == null) && (event.getType() == EventType.None)) { if(event.getState() == KeeperState.SyncConnected) { LOG.info("process: Asynchronous connection complete."); this.getZkConnLatch().countDown(); } else { LOG.warn("process: Got unknown null path event {}.", event); } return; } }
protected StringBuilder getMasterBaseNode(final String appId) { return new StringBuilder(50).append(getAppNode(appId)).append(GuaguaConstants.ZOOKEEPER_SEPARATOR) .append(GuaguaConstants.GUAGUA_ZK_MASTER_NODE); }
protected StringBuilder getCurrentMasterSplitNode(final String appId, final int iteration) { return new StringBuilder(50).append(getMasterBaseNode(appId)).append(GuaguaConstants.ZOOKEEPER_SEPARATOR) .append(GuaguaConstants.GUAGUA_ZK_SPLIT_NODE).append(GuaguaConstants.ZOOKEEPER_SEPARATOR) .append(iteration); }
protected StringBuilder getWorkerNode(final String appId, final String containerId, final int iteration) { return new StringBuilder(50).append(getWorkerBaseNode(appId, iteration)) .append(GuaguaConstants.ZOOKEEPER_SEPARATOR).append(containerId); }
if(bytes.length > zkDataLimit) { getZooKeeper().createExt(splitZnode, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, true); int childrenSize = (bytes.length % zkDataLimit == 0) ? (bytes.length / zkDataLimit) : (bytes.length / zkDataLimit) + 1; getZooKeeper().createExt(znode, null, Ids.OPEN_ACL_UNSAFE, createNode, false); return true; } else { getZooKeeper().createExt(znode, bytes, Ids.OPEN_ACL_UNSAFE, createNode, false); return false;
protected StringBuilder getWorkerBaseNode(final String appId) { return new StringBuilder(50).append(getAppNode(appId)).append(GuaguaConstants.ZOOKEEPER_SEPARATOR) .append(GuaguaConstants.GUAGUA_ZK_WORKERS_NODE); }
protected StringBuilder getLastMasterNode(final String appId, final int iteration) { return getMasterNode(appId, iteration - 1); }
protected StringBuilder getLastWorkerNode(String appId, String containerId, int iteration) { return getWorkerNode(appId, containerId, iteration - 1); }
protected StringBuilder getCurrentWorkerSplitNode(final String appId, final String containerId, final int iteration) { return new StringBuilder(50).append(getAppNode(appId)).append(GuaguaConstants.ZOOKEEPER_SEPARATOR) .append(GuaguaConstants.GUAGUA_ZK_WORKERS_NODE).append(GuaguaConstants.ZOOKEEPER_SEPARATOR) .append(GuaguaConstants.GUAGUA_ZK_SPLIT_NODE).append(GuaguaConstants.ZOOKEEPER_SEPARATOR) .append(iteration).append(GuaguaConstants.ZOOKEEPER_SEPARATOR).append(containerId); }