public static void main(String args[]) {
    try {
      // 启动Netty RPC
      // new RpcServer(CommonConstants.RPC_CLIENT_PORT).run();
      // ConsumerUtil.startup("10.58.50.204:9876;10.58.50.205:9876",
      // CommonConstants.TOPIC_CLOVER_SERVER, IpUtil.getLocalIP().replace(".", "-"));
    } catch (Exception e) {

    }
    ModuleSchedulerClient client = ModuleSchedulerClient.getInstance();
    JobDetail jobDetail =
        newJob(TestSchedulerWithInsertMongoDB.class)
            .withIdentity("TestSchedulerJob1", Scheduler.DEFAULT_GROUP)
            .requestRecovery(true)
            .build();
    Trigger trigger =
        newTrigger()
            .withIdentity("trigger1", Scheduler.DEFAULT_GROUP)
            .withSchedule(cronSchedule("0/10 * * * * ?"))
            .build();
    ClientJob clientJob =
        ClientJobFactory.builder(jobDetail, trigger, ClientJob.JobType.REMOTE, null, null)
            .jobClass(TestSchedulerWithInsertMongoDB.class)
            .build();
    String jobInfoStr = Base64.encodeBase64String(ClassUtil.ObjectToBytes(clientJob));
    BasicDBObject document = new BasicDBObject();
    document.put(DBTableInfo.COL_JOB_KEY, "jobKey1");
    document.put(DBTableInfo.COL_JOB_INFO, jobInfoStr);
    document.put(DBTableInfo.COL_IP, IpUtil.getLocalIP());
    document.put(DBTableInfo.COL_STATUS, CommonConstants.JOB_STATUS_1);
    document.put(DBTableInfo.COL_TS, DateUtil.currentDateTime());
    MongoDBUtil.INSTANCE.insertOrUpdate(document, DBTableInfo.TBL_CLOVER_JOB);
  }
Пример #2
0
 public boolean stop() {
   scheduler.stop();
   try {
     ZKManager zkManager = new ZKManager(PropertiesUtil.loadProperties());
     String serverPathStr = CommonConstants.ZK_ROOT_PATH + "/server";
     List<String> serverNodeList = zkManager.getZooKeeper().getChildren(serverPathStr, false);
     for (int i = 0; (serverNodeList != null) && (i < serverNodeList.size()); i++) {
       String id = serverNodeList.get(i);
       String c = zkManager.getData(serverPathStr + "/" + id);
       if (c == null) {
         continue;
       }
       BasicDBObject record = (BasicDBObject) com.mongodb.util.JSON.parse(c);
       String ip = (String) record.get(CommonConstants.IP);
       if (!StringUtil.isEmpty(ip) && IpUtil.getLocalIP().equals(ip)) {
         zkManager.delete(serverPathStr + "/" + id);
       }
     }
     zkManager.close();
   } catch (Exception e) {
     if (logger.isDebugEnabled()) e.printStackTrace();
     logger.error("ModuleSchedulerServer-->>stop() error ", e);
   }
   return true;
 }
Пример #3
0
 /**
  * 启动 Server端服务
  *
  * @param isRegisterToZK 是否注册到ZK(默认开启)
  * @param isStartupMQ 是否启动MQ(默认开启)
  * @param isReloadJobFromDB 是否从DB中ReloadJob(默认开启)
  * @param systemId System ID(默认clover)
  * @return
  */
 public boolean startup(
     boolean isRegisterToZK,
     boolean isStartupMQ,
     boolean isStartupNetty,
     boolean isReloadJobFromDB,
     String systemId) {
   try {
     scheduler.start(); // start scheduler
     String serverIp = IpUtil.getLocalIP();
     if (isRegisterToZK) {
       registerToZK(
           CommonConstants.MODULE_TYPE_SERVER,
           serverIp,
           null,
           CommonConstants.ZMQ_SERVER_PORT,
           systemId);
     }
     if (isStartupNetty) {
       // new ObjectRespServer().bind(CommonConstants.NETTY_SERVER_PORT);
       new ObjectRespServer().start(CommonConstants.NETTY_SERVER_PORT);
     }
     if (isStartupMQ) {
       // AsyncStartZeroMQ.startup(CommonConstants.ZMQ_SERVER_PORT);
     }
     if (isReloadJobFromDB) {
       reloadJobFromDB(CommonConstants.MODULE_TYPE_SERVER, serverIp); // 从DB中恢复已注册的REMOTE任务
     }
     // ServerHeartBeat.INSTNACE.startup();
     // resetJobExecuteTime(null,serverIp);
     return true;
   } catch (Exception e) {
     logger.error("ModuleSchedulerServer-->>start() error", e);
     return false;
   }
 }
Пример #4
0
 public boolean handlerJob(ServerJob serverJob) {
   if (serverJob == null) return false;
   serverJob.setServerIp(IpUtil.getLocalIP());
   logger.error("handlerJob >>> getExecuteType :::" + serverJob.getExecuteType());
   switch (serverJob.getExecuteType()) {
     case ADD:
       return addJob(serverJob);
     case DELETE:
       return deleteJob(serverJob);
     case UPDATE:
       return updateJob(serverJob);
     default:
       return false;
   }
 }