Java Code Examples for it.sauronsoftware.cron4j.Scheduler#schedule()

The following examples show how to use it.sauronsoftware.cron4j.Scheduler#schedule() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JbootCron4jPlugin.java    From jboot with Apache License 2.0 5 votes vote down vote up
void schedule() {
    if (enable) {
        scheduler = new Scheduler();
        if (task instanceof Runnable) {
            scheduler.schedule(cron, (Runnable) task);
        } else if (task instanceof Task) {
            scheduler.schedule(cron, (Task) task);
        } else {
            scheduler = null;
            throw new IllegalStateException("Task 必须是 Runnable、ITask、ProcessTask 或者 Task 类型");
        }
        scheduler.setDaemon(daemon);
    }
}
 
Example 2
Source File: SchedulingService.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
public void startHouseKeeping() {
    houseKeepingScheduler = new Scheduler();
    String cronExpr = "* * * * *";
    if (PASchedulerProperties.SCHEDULER_AUTOMATIC_REMOVED_JOB_CRON_EXPR.isSet()) {
        cronExpr = PASchedulerProperties.SCHEDULER_AUTOMATIC_REMOVED_JOB_CRON_EXPR.getValueAsString();
    }
    houseKeepingScheduler.schedule(cronExpr, new HousekeepingRunner());
    houseKeepingScheduler.start();
}
 
Example 3
Source File: RMDBManager.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
public void startHouseKeeping() {
    houseKeepingScheduler = new Scheduler();
    if (PAResourceManagerProperties.RM_HISTORY_MAX_PERIOD.isSet() &&
        PAResourceManagerProperties.RM_HISTORY_MAX_PERIOD.getValueAsLong() > 0 &&
        PAResourceManagerProperties.RM_HISTORY_REMOVAL_CRONPERIOD.isSet()) {
        String cronExpr = PAResourceManagerProperties.RM_HISTORY_REMOVAL_CRONPERIOD.getValueAsString();
        houseKeepingScheduler.schedule(cronExpr, new HousekeepingRunner());
        houseKeepingScheduler.start();
    }

}
 
Example 4
Source File: DerbyMetadataServer.java    From chipster with MIT License 4 votes vote down vote up
/**
 * Initialises the server. If underlying embedded Derby SQL database is not initialised, it is 
 * initialised first.
 * 
 * @throws InstantiationException
 * @throws IllegalAccessException
 * @throws ClassNotFoundException
 * @throws SQLException
 * @throws IllegalConfigurationException 
 * @throws IOException 
 */
public DerbyMetadataServer() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, IOException, IllegalConfigurationException {
	
	Configuration configuration = DirectoryLayout.getInstance().getConfiguration();
	
	// initialise connection
	System.setProperty("derby.system.home", DB_ROOT);
	Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance(); // allows multiple connections in one JVM, but not from multiple JVM's
	
	String strUrl = "jdbc:derby:" + DB_NAME + ";";
	
	File metadataBackupDir = DirectoryLayout.getInstance().getFilebrokerMetadataBackupDir();
	String restorePath = configuration.getString("filebroker", "metadata-restore-path");
	String fullRestorePath = metadataBackupDir + File.separator + restorePath + File.separator + DB_NAME;
	
	if (restorePath != null && !restorePath.isEmpty()) {
		logger.info("restoring metadata database from " + fullRestorePath);
		File dbDir = new File(DB_ROOT, DB_NAME);
		if (dbDir.exists()) {
			throw new IllegalConfigurationException("metadata restore isn't allowed, because the database " + dbDir + " exists already");
		}
		// One way to restore a backup
		// See http://db.apache.org/derby/docs/10.1/adminguide/tadminhubbkup44.html
		strUrl += "restoreFrom=" + fullRestorePath;
	} else {
		strUrl += "create=true";
	}
		
	
	connection = DriverManager.getConnection(strUrl);
	
	// initialise database, if needed
	initialise();

	logger.info("metadata database started");
	
	
	// initialise metadata database backup
	if (configuration.getBoolean("filebroker", "enable-metadata-backups")) {
	
		// get backup configuration
		int metadataBackupKeepCount = configuration.getInt("filebroker", "metadata-backup-keep-count");
		String backupTime = configuration.getString("filebroker", "metadata-backup-time").trim();
		
		// schedule backup tasks
		Scheduler scheduler = new Scheduler();
		scheduler.schedule(backupTime, new MetadataBackupTimerTask(metadataBackupDir, metadataBackupKeepCount));
		scheduler.start();
		
		logger.info("metadata backups enabled at: " + backupTime);
	} else {
		logger.info("metadata backups disabled");
	}	
}