@Override public void stop() throws ServerConnectorException { if (pollingTaskRunner != null) { pollingTaskRunner.terminate(); } }
@Override protected void endMaintenance() { if (pollingTaskRunner != null) { pollingTaskRunner.start(); } }
/** * The start polling method which should be called when starting the polling with given interval. * @throws ServerConnectorException if a error happen while starting the connector. */ @Override public void start() throws ServerConnectorException { String strCronExpression = getProperties().get(Constants.CRON_EXPRESSION); if (strCronExpression != null) { cronExpression = strCronExpression; } String pollingInterval = getProperties().get(Constants.POLLING_INTERVAL); if (pollingInterval != null) { try { this.interval = Long.parseLong(pollingInterval); } catch (NumberFormatException e) { throw new ServerConnectorException( "Could not parse parameter: " + Constants.POLLING_INTERVAL + " to numeric type: Long", e); } } pollingTaskRunner = new PollingTaskRunner(this); pollingTaskRunner.start(); }
@Override public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { SchedulerContext schedulerContext = null; try { schedulerContext = jobExecutionContext.getScheduler().getContext(); } catch (SchedulerException e1) { log.debug("Exception occurred while getting scheduler context", e1); } if (schedulerContext == null) { log.error("Scheduler context is null"); return; } PollingServerConnector connector = (PollingServerConnector) schedulerContext.get("connector"); // Run the poll cycles log.debug("Executing the polling task for server connector ID: " + connector.getId()); try { connector.poll(); } catch (Exception e) { log.error("Error executing the polling cycle for server connector ID: " + connector.getId(), e); } log.debug("Exit the polling task running loop for server connector ID: " + connector.getId()); } }
@Override public void start(EmailMessageListener emailMessageListener) throws EmailConnectorException { consumer.setEmailMessageListener(emailMessageListener); try { super.start(); } catch (Exception e) { throw new EmailConnectorException("Error is encountered while initializing the polling cycle" + " for email server connector for service:" + id, e); } }
/** * Start a new scheduler and schedule a new job. */ public void start() { String group = "carbon.connector.quartz"; JobDetail job = JobBuilder.newJob(PollingJob.class) .withIdentity("Job - " + RANDOM.nextLong(), group).build(); Trigger trigger; if (connector.cronExpression != null) { // Trigger the job to run on the next round minute trigger = TriggerBuilder.newTrigger().withIdentity("Trigger - " + RANDOM.nextLong(), group) .withSchedule(CronScheduleBuilder.cronSchedule(connector.cronExpression)).build(); } else { // Trigger the job to run on the next round minute trigger = TriggerBuilder.newTrigger().withIdentity("ScheduledPollingTrigger - " + RANDOM.nextLong(), group) .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInMilliseconds(connector.interval) .repeatForever()).build(); } // Schedule the job try { scheduler = new StdSchedulerFactory(getSchedulerProperties("polling-task-runner")).getScheduler(); scheduler.getContext().put("connector", connector); scheduler.start(); scheduler.scheduleJob(job, trigger); } catch (SchedulerException e) { log.error("Exception occurred while scheduling job", e); } }
@Override public void stop() throws EmailConnectorException { try { super.stop(); } catch (ServerConnectorException e) { throw new EmailConnectorException("Error is encountered while trying to stop the Email server Connector" + "for service: " + id, e); } if (consumer != null) { this.startUIDNumber = consumer.getStartUIDNumber(); } }
/** * The start polling method which should be called when starting the polling with given interval. * @throws ServerConnectorException if a error happen while starting the connector. */ @Override public void start() throws ServerConnectorException { String strCronExpression = getProperties().get(Constants.CRON_EXPRESSION); if (strCronExpression != null) { cronExpression = strCronExpression; } String pollingInterval = getProperties().get(Constants.POLLING_INTERVAL); if (pollingInterval != null) { try { this.interval = Long.parseLong(pollingInterval); } catch (NumberFormatException e) { throw new ServerConnectorException( "Could not parse parameter: " + Constants.POLLING_INTERVAL + " to numeric type: Long", e); } } pollingTaskRunner = new PollingTaskRunner(this); pollingTaskRunner.start(); }
@Override public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { SchedulerContext schedulerContext = null; try { schedulerContext = jobExecutionContext.getScheduler().getContext(); } catch (SchedulerException e1) { log.debug("Exception occurred while getting scheduler context", e1); } if (schedulerContext == null) { log.error("Scheduler context is null"); return; } PollingServerConnector connector = (PollingServerConnector) schedulerContext.get("connector"); // Run the poll cycles log.debug("Executing the polling task for server connector ID: " + connector.getId()); try { connector.poll(); } catch (Exception e) { log.error("Error executing the polling cycle for server connector ID: " + connector.getId(), e); } log.debug("Exit the polling task running loop for server connector ID: " + connector.getId()); } }
@Override protected void beginMaintenance() { if (pollingTaskRunner != null) { pollingTaskRunner.terminate(); } }
@Override protected void endMaintenance() { if (pollingTaskRunner != null) { pollingTaskRunner.start(); } }
@Override public void start() throws ServerConnectorException { try { consumer = new FileConsumer(id, getProperties(), messageProcessor); super.start(); } catch (RuntimeException e) { throw new ServerConnectorException("Failed to start File Server Connector for service: " + id, e); } }
/** * Start a new scheduler and schedule a new job. */ public void start() { String group = "carbon.connector.quartz"; JobDetail job = JobBuilder.newJob(PollingJob.class) .withIdentity("Job - " + RANDOM.nextLong(), group).build(); Trigger trigger; if (connector.cronExpression != null) { // Trigger the job to run on the next round minute trigger = TriggerBuilder.newTrigger().withIdentity("Trigger - " + RANDOM.nextLong(), group) .withSchedule(CronScheduleBuilder.cronSchedule(connector.cronExpression)).build(); } else { // Trigger the job to run on the next round minute trigger = TriggerBuilder.newTrigger().withIdentity("scheduledPoll", "group1").withSchedule( SimpleScheduleBuilder.simpleSchedule().withIntervalInMilliseconds(connector.interval) .repeatForever()).build(); } // Schedule the job try { scheduler = new StdSchedulerFactory(getSchedulerProperties("polling-task-runner")).getScheduler(); scheduler.getContext().put("connector", connector); scheduler.start(); scheduler.scheduleJob(job, trigger); } catch (SchedulerException e) { log.error("Exception occurred while scheduling job", e); } }
@Override protected void beginMaintenance() { if (pollingTaskRunner != null) { pollingTaskRunner.terminate(); } }
@Override public void stop() throws ServerConnectorException { if (pollingTaskRunner != null) { pollingTaskRunner.terminate(); } }