public Boolean update(String path){ return update(path, (byte[])null); }
public Boolean update(String path, Integer data){ return update(path, data.toString()); }
public Boolean update(String path, Object data){ return update(path, JSON.toJSONString(data)); }
public Boolean update(String path, String data){ try { return update(path, data.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new ZkException(e); } }
/** * Update the job fire time info * @param appName the app name * @param jobClass the job class * @param jobFireTime the job fire time * @return return true if update successfully, or false */ public Boolean updateJobFireTime(String appName, String jobClass, JobFireTime jobFireTime) { String jobFireTimeNode = ZkPaths.pathOfJobFireTime(appName, jobClass); zk.client().mkdirs(jobFireTimeNode); return zk.client().update(jobFireTimeNode, JSON.toJSONString(jobFireTime)); }
/** * Update the job's scheudler * @param appName the app name * @param jobClass the job class * @param scheduler the scheduler * @return return true if update successfully, or false */ public Boolean updateJobScheduler(String appName, String jobClass, String scheduler) { String jobSchedulerNode = ZkPaths.pathOfJobScheduler(appName, jobClass); zk.client().mkdirs(jobSchedulerNode); return zk.client().update(jobSchedulerNode, scheduler); }
@Override public void isLeader() { Logs.info("The server {} become the leader.", host.get()); // start the client failover clientFailover.start(); // start the zk cleaner zkCleaner.start(); // set the lead's host zk.client().update(ZkPaths.LEADER, host.get()); // start the leader check task // avoid that the leader disconnect, because of network jitter scheduler = Executors.newScheduledThreadPool(1); scheduler.scheduleAtFixedRate(new LeaderCheckTask(), 1, 5, TimeUnit.SECONDS); } });
/** * Update the job running state directly * @param appName the app name * @param jobClass the job class * @param state the target state * @return return true if update successfully, or false */ public Boolean updateJobStateDirectly(String appName, String jobClass, JobState state){ String jobStateNode = ZkPaths.pathOfJobState(appName, jobClass); zk.client().mkdirs(jobStateNode); return zk.client().update(jobStateNode, state.value()); }
/** * Update the job running state safely, will be constrained by statemachine * @param appName the app name * @param jobClass the job class * @param targetState the new state * @return return true if update successfully, or throw JobStateTransferInvalidException * @see SimpleJobStateMachine * @see JobStateTransferInvalidException */ public Boolean updateJobStateSafely(String appName, String jobClass, JobState targetState){ JobState currentState = getJobState(appName, jobClass); if(!SimpleJobStateMachine.get().allow(currentState, targetState)){ throw new JobStateTransferInvalidException(appName + "/" + jobClass, currentState, targetState); } String jobStateNode = ZkPaths.pathOfJobState(appName, jobClass); return zk.client().update(jobStateNode, targetState.value()); }