1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 package org.ogf.graap.wsag.server.monitoring;
36
37 import java.util.Map;
38
39 import org.apache.log4j.Logger;
40 import org.ogf.graap.wsag.api.types.AbstractAgreementType;
41 import org.ogf.schemas.graap.wsAgreement.AgreementStateDefinition;
42 import org.ogf.schemas.graap.wsAgreement.AgreementStateType;
43 import org.quartz.Job;
44 import org.quartz.JobExecutionContext;
45 import org.quartz.JobExecutionException;
46
47
48
49
50
51
52
53 public class AgreementMonitorJob implements Job
54 {
55 private static final Logger LOG = Logger.getLogger( AgreementMonitorJob.class );
56
57
58
59
60 public static final String WSAG4J_AGREEMENT_INSTANCE = "wsag4j.agreement.instance";
61
62
63
64
65 public static final String WSAG4J_MONITORING_CONTEXT = "wsag4j.agreement.monitoring.context";
66
67
68
69
70 @SuppressWarnings( "unchecked" )
71 public void execute( JobExecutionContext context ) throws JobExecutionException
72 {
73
74 Map<Object, Object> jobData = context.getJobDetail().getJobDataMap();
75 AbstractAgreementType agreementInstance =
76 (AbstractAgreementType) jobData.get( WSAG4J_AGREEMENT_INSTANCE );
77 IMonitoringContext monitoringContext = (IMonitoringContext) jobData.get( WSAG4J_MONITORING_CONTEXT );
78
79 AgreementMonitor monitor = new AgreementMonitor();
80 monitor.setAgreementInstance( agreementInstance );
81 monitor.setMonitoringContext( monitoringContext );
82
83 try
84 {
85 monitor.updateStates();
86 }
87 catch ( Exception e )
88 {
89 LOG.debug( e.getMessage(), e );
90 throw new JobExecutionException( "Error updating agreement states.", e );
91 }
92
93 try
94 {
95 AgreementStateType state = monitor.getAgreementInstance().getState();
96 if ( ( state.getState() == AgreementStateDefinition.COMPLETE )
97 || ( state.getState() == AgreementStateDefinition.TERMINATED ) )
98 {
99
100
101
102
103
104 context.getScheduler().unscheduleJob( context.getJobDetail().getName(),
105 context.getJobDetail().getGroup() );
106 }
107 }
108 catch ( Exception e )
109 {
110 throw new JobExecutionException( "Error unscheduling monitoring job.", e );
111 }
112 }
113
114 }