本文整理匯總了Java中org.quartz.JobDataMap.getString方法的典型用法代碼示例。如果您正苦於以下問題:Java JobDataMap.getString方法的具體用法?Java JobDataMap.getString怎麽用?Java JobDataMap.getString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.quartz.JobDataMap
的用法示例。
在下文中一共展示了JobDataMap.getString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: execute
import org.quartz.JobDataMap; //導入方法依賴的package包/類
public void execute(JobExecutionContext context)
throws JobExecutionException {
JobDataMap data = context.getMergedJobDataMap();
String command = data.getString(PROP_COMMAND);
String parameters = data.getString(PROP_PARAMETERS);
if (parameters == null) {
parameters = "";
}
boolean wait = true;
if(data.containsKey(PROP_WAIT_FOR_PROCESS)) {
wait = data.getBooleanValue(PROP_WAIT_FOR_PROCESS);
}
boolean consumeStreams = false;
if(data.containsKey(PROP_CONSUME_STREAMS)) {
consumeStreams = data.getBooleanValue(PROP_CONSUME_STREAMS);
}
Integer exitCode = this.runNativeCommand(command, parameters, wait, consumeStreams);
context.setResult(exitCode);
}
示例2: jobToBeExecuted
import org.quartz.JobDataMap; //導入方法依賴的package包/類
public void jobToBeExecuted(final JobExecutionContext context) {
final JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
String targetObject = jobDataMap.getString("targetObject");
String targetMethod = jobDataMap.getString("targetMethod");
if (logger.isInfoEnabled()) {
logger.info("定時任務開始執行:{}.{}", targetObject, targetMethod);
}
// 保存日誌
TaskFireLog log = new TaskFireLog();
log.setStartTime(context.getFireTime());
log.setGroupName(targetObject);
log.setTaskName(targetMethod);
log.setStatus(JOBSTATE.INIT_STATS);
log.setServerHost(NativeUtil.getHostName());
log.setServerDuid(NativeUtil.getDUID());
schedulerService.updateLog(log);
jobDataMap.put(JOB_LOG, log);
}
示例3: executeInternal
import org.quartz.JobDataMap; //導入方法依賴的package包/類
@Override
protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
JobKey key = jobExecutionContext.getJobDetail().getKey();
System.out.println("Cron Job started with key :" + key.getName() + ", Group :"+key.getGroup() + " , Thread Name :"+Thread.currentThread().getName() + " ,Time now :"+new Date());
System.out.println("======================================");
System.out.println("Accessing annotation example: "+jobService.getAllJobs());
List<Map<String, Object>> list = jobService.getAllJobs();
System.out.println("Job list :"+list);
System.out.println("======================================");
//*********** For retrieving stored key-value pairs ***********/
JobDataMap dataMap = jobExecutionContext.getMergedJobDataMap();
String myValue = dataMap.getString("myKey");
System.out.println("Value:" + myValue);
System.out.println("Thread: "+ Thread.currentThread().getName() +" stopped.");
}
示例4: execute
import org.quartz.JobDataMap; //導入方法依賴的package包/類
public void execute(JobExecutionContext context) throws JobExecutionException {
long start = System.currentTimeMillis();
JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
String taskType = jobDataMap.getString("taskType");
String targetObject = jobDataMap.getString("targetObject");
String targetMethod = jobDataMap.getString("targetMethod");
logger.info("定時任務開始執行: [{}.{}]", targetObject, targetMethod);
try {
ApplicationContext applicationContext = (ApplicationContext) context.getScheduler().getContext()
.get("applicationContext");
if (TaskType.local.equals(taskType)) {
Object refer = applicationContext.getBean(targetObject);
refer.getClass().getDeclaredMethod(targetMethod).invoke(refer);
} else if (TaskType.dubbo.equals(taskType)) {
String system = jobDataMap.getString("targetSystem");
BaseProvider provider = (BaseProvider) DubboUtil.refer(applicationContext, system);
provider.execute(new Parameter(targetObject, targetMethod));
}
double time = (System.currentTimeMillis() - start) / 1000.0;
logger.info("定時任務[{}.{}]用時:{}s", targetObject, targetMethod, time);
} catch (Exception e) {
throw new JobExecutionException(e);
}
}
示例5: execute
import org.quartz.JobDataMap; //導入方法依賴的package包/類
public void execute(JobExecutionContext context) throws JobExecutionException {
long start = System.currentTimeMillis();
JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
String taskType = jobDataMap.getString("taskType");
String targetObject = jobDataMap.getString("targetObject");
String targetMethod = jobDataMap.getString("targetMethod");
logger.info("定時任務開始執行: [{}.{}]", targetObject, targetMethod);
try {
ApplicationContext applicationContext = (ApplicationContext) context.getScheduler().getContext()
.get("applicationContext");
if (TaskType.local.equals(taskType)) {
Object object = applicationContext.getBean(targetObject);
MethodAccess methodAccess = MethodAccess.get(object.getClass());
methodAccess.invoke(object, targetMethod);
} else if (TaskType.dubbo.equals(taskType)) {
// Object object = DubboUtil.refer(applicationContext, targetObject);
// MethodAccess methodAccess = MethodAccess.get(object.getClass());
// methodAccess.invoke(object, targetMethod);
}
double time = (System.currentTimeMillis() - start) / 1000.0;
logger.info("定時任務[{}.{}]用時:{}s", targetObject, targetMethod, time);
} catch (Exception e) {
throw new JobExecutionException(e);
}
}
示例6: execute
import org.quartz.JobDataMap; //導入方法依賴的package包/類
public void execute(JobExecutionContext context) throws JobExecutionException {
long start = System.currentTimeMillis();
JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
String taskType = jobDataMap.getString("taskType");
String targetObject = jobDataMap.getString("targetObject");
String targetMethod = jobDataMap.getString("targetMethod");
String key = targetMethod + "." + targetObject;
try {
logger.info("定時任務[{}.{}]開始", targetObject, targetMethod);
if (CacheUtil.getCache().lock(key)) {
try {
ApplicationContext applicationContext = (ApplicationContext)context.getScheduler().getContext()
.get("applicationContext");
if (TaskType.local.equals(taskType)) {
Object refer = applicationContext.getBean(targetObject);
refer.getClass().getDeclaredMethod(targetMethod).invoke(refer);
} else if (TaskType.dubbo.equals(taskType)) {
BaseProvider provider = (BaseProvider)applicationContext
.getBean(jobDataMap.getString("targetSystem"));
provider.execute(new Parameter(targetObject, targetMethod));
}
Double time = (System.currentTimeMillis() - start) / 1000.0;
logger.info("定時任務[{}.{}]用時:{}s", targetObject, targetMethod, time.toString());
} finally {
unLock(key);
}
}
} catch (Exception e) {
throw new JobExecutionException(e);
}
}
示例7: jobWasExecuted
import org.quartz.JobDataMap; //導入方法依賴的package包/類
public void jobWasExecuted(final JobExecutionContext context, JobExecutionException exp) {
Timestamp end = new Timestamp(System.currentTimeMillis());
final JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
String targetObject = jobDataMap.getString("targetObject");
String targetMethod = jobDataMap.getString("targetMethod");
if (logger.isInfoEnabled()) {
logger.info("定時任務執行結束:{}.{}", targetObject, targetMethod);
}
// 更新任務執行狀態
final TaskFireLog log = (TaskFireLog) jobDataMap.get(JOB_LOG);
if (log != null) {
log.setEndTime(end);
if (exp != null) {
logger.error("定時任務失敗: [" + targetObject + "." + targetMethod + "]", exp);
String contactEmail = jobDataMap.getString("contactEmail");
if (StringUtils.isNotBlank(contactEmail)) {
String topic = String.format("調度[%s.%s]發生異常", targetMethod, targetMethod);
sendEmail(new Email(contactEmail, topic, exp.getMessage()));
}
log.setStatus(JOBSTATE.ERROR_STATS);
log.setFireInfo(exp.getMessage());
} else {
if (log.getStatus().equals(JOBSTATE.INIT_STATS)) {
log.setStatus(JOBSTATE.SUCCESS_STATS);
}
}
}
executorService.submit(new Runnable() {
public void run() {
if (log != null) {
try {
schedulerService.updateLog(log);
} catch (Exception e) {
logger.error("Update TaskRunLog cause error. The log object is : " + JSON.toJSONString(log), e);
}
}
}
});
}
示例8: execute
import org.quartz.JobDataMap; //導入方法依賴的package包/類
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
String pluginName = jobDataMap.getString("pluginName");
try {
JMXPlugin jmxPlugin = (JMXPlugin) jobDataMap.get("pluginObject");
String jmxServerName = jobDataMap.getString("jmxServerName");
List<JMXMetricsValueInfo> jmxMetricsValueInfos = JMXManager.getJmxMetricValue(jmxServerName,jmxPlugin);
//設置agentSignName
for (JMXMetricsValueInfo jmxMetricsValueInfo : jmxMetricsValueInfos) {
if (AgentConfiguration.INSTANCE.isDockerRuntime()){
//容器環境直接取 JavaExecCommandInfo.appName
jmxMetricsValueInfo.getJmxConnectionInfo().setName(jmxMetricsValueInfo.getJmxConnectionInfo().getConnectionServerName());
}else {
String agentSignName = jmxPlugin.agentSignName(jmxMetricsValueInfo,
jmxMetricsValueInfo.getJmxConnectionInfo().getPid());
if ("{jmxServerName}".equals(agentSignName)) {
//設置變量
jmxMetricsValueInfo.getJmxConnectionInfo().setName(jmxServerName);
}else{
jmxMetricsValueInfo.getJmxConnectionInfo().setName(agentSignName);
}
}
}
MetricsCommon jmxMetricsValue = new JMXMetricsValue(jmxPlugin,jmxMetricsValueInfos);
ReportMetrics.push(jmxMetricsValue.getReportObjects());
} catch (Exception e) {
log.error("插件 {} 運行異常",pluginName,e);
}
}
示例9: getInitialContext
import org.quartz.JobDataMap; //導入方法依賴的package包/類
private InitialContext getInitialContext(JobDataMap jobDataMap)
throws NamingException {
Hashtable params = new Hashtable(2);
String initialContextFactory =
jobDataMap.getString(INITIAL_CONTEXT_FACTORY);
if (initialContextFactory != null) {
params.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
}
String providerUrl = jobDataMap.getString(PROVIDER_URL);
if (providerUrl != null) {
params.put(Context.PROVIDER_URL, providerUrl);
}
String principal = jobDataMap.getString(PRINCIPAL);
if ( principal != null ) {
params.put( Context.SECURITY_PRINCIPAL, principal );
}
String credentials = jobDataMap.getString(CREDENTIALS);
if ( credentials != null ) {
params.put( Context.SECURITY_CREDENTIALS, credentials );
}
return (params.size() == 0) ? new InitialContext() : new InitialContext(params);
}
示例10: execute
import org.quartz.JobDataMap; //導入方法依賴的package包/類
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
long timestamp = System.currentTimeMillis() / 1000;
JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
String pluginName = jobDataMap.getString("pluginName");
try {
DetectPlugin detectPlugin = (DetectPlugin) jobDataMap.get("pluginObject");
MetricsCommon metricsValue = new DetectMetricsValue(detectPlugin,timestamp);
//可能會涉及到外網的連接,采用異步方式
ExecuteThreadUtil.execute(new JobThread(metricsValue,"detect job thread"));
} catch (Exception e) {
log.error("插件 {} 運行異常",pluginName,e);
}
}
示例11: executeInternal
import org.quartz.JobDataMap; //導入方法依賴的package包/類
@Override
protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
JobKey key = jobExecutionContext.getJobDetail().getKey();
System.out.println("Simple Job started with key :" + key.getName() + ", Group :"+key.getGroup() + " , Thread Name :"+Thread.currentThread().getName());
System.out.println("======================================");
System.out.println("Accessing annotation example: "+jobService.getAllJobs());
List<Map<String, Object>> list = jobService.getAllJobs();
System.out.println("Job list :"+list);
System.out.println("======================================");
//*********** For retrieving stored key-value pairs ***********/
JobDataMap dataMap = jobExecutionContext.getMergedJobDataMap();
String myValue = dataMap.getString("myKey");
System.out.println("Value:" + myValue);
//*********** For retrieving stored object, It will try to deserialize the bytes Object. ***********/
/*
SchedulerContext schedulerContext = null;
try {
schedulerContext = jobExecutionContext.getScheduler().getContext();
} catch (SchedulerException e1) {
e1.printStackTrace();
}
YourClass yourClassObject = (YourClass) schedulerContext.get("storedObjectKey");
*/
while(toStopFlag){
try {
System.out.println("Test Job Running... Thread Name :"+Thread.currentThread().getName());
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("Thread: "+ Thread.currentThread().getName() +" stopped.");
}
示例12: getInitialContext
import org.quartz.JobDataMap; //導入方法依賴的package包/類
public static InitialContext getInitialContext(final JobDataMap jobDataMap) throws NamingException
{
Hashtable params = new Hashtable(2);
String initialContextFactory =
jobDataMap.getString(INITIAL_CONTEXT_FACTORY);
if (initialContextFactory != null) {
params.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
}
String providerUrl = jobDataMap.getString(PROVIDER_URL);
if (providerUrl != null) {
params.put(Context.PROVIDER_URL, providerUrl);
}
String principal = jobDataMap.getString(PRINCIPAL);
if ( principal != null ) {
params.put( Context.SECURITY_PRINCIPAL, principal );
}
String credentials = jobDataMap.getString(CREDENTIALS);
if ( credentials != null ) {
params.put( Context.SECURITY_CREDENTIALS, credentials );
}
if (params.size() == 0) {
return new InitialContext();
} else {
return new InitialContext(params);
}
}
示例13: execute
import org.quartz.JobDataMap; //導入方法依賴的package包/類
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
JobDataMap jobDataMap = context.getMergedJobDataMap();
String botId = jobDataMap.getString("bot");
String channelId = jobDataMap.getString("channel");
String content = jobDataMap.getString("content");
if (botId != null && channelId != null && content != null) {
Optional<IDiscordClient> client = clientRegistry.getClients().entrySet().stream()
.filter(entry -> botId.equals(entry.getKey().getId())
|| botId.equals(entry.getKey().getName())
|| (entry.getValue().isReady() && botId.equals(entry.getValue().getOurUser().getStringID())))
.map(Map.Entry::getValue)
.findAny();
if (client.isPresent()) {
IChannel channel = client.get().getChannelByID(snowflake(channelId));
if (channel != null) {
sendMessage(channel, content);
} else {
throw new JobExecutionException("Channel " + channelId + " is not known by the bot");
}
} else {
throw new JobExecutionException("No bot exists with identifier: " + botId);
}
} else {
throw new JobExecutionException("Job requires bot, channel and content parameters");
}
}
示例14: executeRemind
import org.quartz.JobDataMap; //導入方法依賴的package包/類
private void executeRemind(JobDataMap map) {
String taskId=map.getString("taskId");
String messageSenders=map.getString("messageSenders");
String principal=map.getString("principal");
String messageTemplateId=map.getString("messageTemplateId");
TaskReminderMessageSender sender=ContextHolder.getBean(TaskReminderMessageSender.BEAN_ID);
sender.sendReminderMessage(taskId, principal, messageTemplateId, messageSenders.split(","));
}
示例15: sendEmail
import org.quartz.JobDataMap; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private void sendEmail(JobDataMap map) {
String subject = map.getString("subject");
String messageBody = map.getString("messageBody");
List<String> to = (List<String>) map.get("to");
List<String> cc = (List<String>) map.get("cc");
List<String> bcc = (List<String>) map.get("bcc");
MimeMessage message = mailSender.createMimeMessage();
try {
MimeMessageHelper helper = new MimeMessageHelper(message, false);
for(String receipient : to) {
helper.setFrom("[email protected]", "Julius from Dynamic Quartz");
helper.setTo(receipient);
helper.setSubject(subject);
helper.setText(messageBody);
if(!isEmpty(cc))
helper.setCc(cc.stream().toArray(String[]::new));
if(!isEmpty(bcc))
helper.setBcc(bcc.stream().toArray(String[]::new));
mailSender.send(message);
}
} catch (MessagingException | UnsupportedEncodingException e) {
log.error("An error occurred: {}", e.getLocalizedMessage());
}
}