44
44
import com .googlecode .jmxtrans .util .WatchedCallback ;
45
45
46
46
/**
47
- * Main() class that takes an argument which is the directory
48
- * to look in for files which contain json data that defines
49
- * queries to run against JMX servers.
50
- *
47
+ * Main() class that takes an argument which is the directory to look in for
48
+ * files which contain json data that defines queries to run against JMX
49
+ * servers.
50
+ *
51
51
* @author jon
52
52
*/
53
53
public class JmxTransformer extends SignalInterceptor implements WatchedCallback {
@@ -68,16 +68,15 @@ public class JmxTransformer extends SignalInterceptor implements WatchedCallback
68
68
69
69
private List <Server > masterServersList = new ArrayList <Server >();
70
70
71
-
72
71
/** */
73
72
public static void main (String [] args ) throws Exception {
74
73
JmxTransformer transformer = new JmxTransformer ();
75
74
76
75
// Register signal handlers
77
- transformer .registerQuietly ("HUP" );
78
- transformer .registerQuietly ("INT" );
79
- transformer .registerQuietly ("ABRT" );
80
- transformer .registerQuietly ("KILL" );
76
+ transformer .registerQuietly ("HUP" );
77
+ transformer .registerQuietly ("INT" );
78
+ transformer .registerQuietly ("ABRT" );
79
+ transformer .registerQuietly ("KILL" );
81
80
transformer .registerQuietly ("TERM" );
82
81
83
82
// Start the process
@@ -93,9 +92,9 @@ private void doMain(String[] args) throws Exception {
93
92
}
94
93
95
94
try {
96
- this .startupScheduler ();
95
+ this .startupScheduler ();
97
96
98
- this .startupWatchdir ();
97
+ this .startupWatchdir ();
99
98
100
99
this .setupObjectPooling ();
101
100
@@ -115,51 +114,52 @@ private void doMain(String[] args) throws Exception {
115
114
* Startup the watchdir service.
116
115
*/
117
116
private void startupWatchdir () throws Exception {
118
- File dirToWatch = null ;
119
- if (this .getJsonDirOrFile ().isFile ()) {
120
- dirToWatch = new File (FilenameUtils .getFullPath (this .getJsonDirOrFile ().getAbsolutePath ()));
121
- } else {
122
- dirToWatch = this .getJsonDirOrFile ();
123
- }
124
-
125
- // start the watcher
126
- this .watcher = new WatchDir (dirToWatch , this );
127
- this .watcher .start ();
117
+ File dirToWatch = null ;
118
+ if (this .getJsonDirOrFile ().isFile ()) {
119
+ dirToWatch = new File (FilenameUtils .getFullPath (this .getJsonDirOrFile ().getAbsolutePath ()));
120
+ } else {
121
+ dirToWatch = this .getJsonDirOrFile ();
122
+ }
123
+
124
+ // start the watcher
125
+ this .watcher = new WatchDir (dirToWatch , this );
126
+ this .watcher .start ();
128
127
}
129
128
130
129
/**
131
130
* start the server scheduler which loops over all the Server jobs
132
131
*/
133
132
private void startupScheduler () throws Exception {
134
- StdSchedulerFactory serverSchedFact = new StdSchedulerFactory ();
135
- InputStream stream = null ;
136
- if (QUARTZ_SERVER_PROPERTIES == null ) {
137
- QUARTZ_SERVER_PROPERTIES = "/quartz.server.properties" ;
138
- stream = JmxTransformer .class .getResourceAsStream (QUARTZ_SERVER_PROPERTIES );
139
- } else {
140
- stream = new FileInputStream (QUARTZ_SERVER_PROPERTIES );
141
- }
142
- serverSchedFact .initialize (stream );
143
- this .serverScheduler = serverSchedFact .getScheduler ();
144
- this .serverScheduler .start ();
133
+ StdSchedulerFactory serverSchedFact = new StdSchedulerFactory ();
134
+ InputStream stream = null ;
135
+ if (QUARTZ_SERVER_PROPERTIES == null ) {
136
+ QUARTZ_SERVER_PROPERTIES = "/quartz.server.properties" ;
137
+ stream = JmxTransformer .class .getResourceAsStream (QUARTZ_SERVER_PROPERTIES );
138
+ } else {
139
+ stream = new FileInputStream (QUARTZ_SERVER_PROPERTIES );
140
+ }
141
+ serverSchedFact .initialize (stream );
142
+ this .serverScheduler = serverSchedFact .getScheduler ();
143
+ this .serverScheduler .start ();
145
144
}
146
145
147
146
/**
148
147
* Handy method which runs the JmxProcess
149
148
*/
150
149
public void executeStandalone (JmxProcess process ) throws Exception {
151
- this .masterServersList = process .getServers ();
150
+ this .masterServersList = process .getServers ();
152
151
153
- this .startupScheduler ();
154
- this .setupObjectPooling ();
152
+ this .startupScheduler ();
153
+ this .setupObjectPooling ();
155
154
156
- this .processServersIntoJobs (this .serverScheduler );
155
+ this .processServersIntoJobs (this .serverScheduler );
157
156
158
- // Sleep for 10 seconds to wait for jobs to complete.
159
- // There should be a better way, but it seems that way isn't working right now.
160
- Thread .sleep (10 * 1000 );
157
+ // Sleep for 10 seconds to wait for jobs to complete.
158
+ // There should be a better way, but it seems that way isn't working
159
+ // right now.
160
+ Thread .sleep (10 * 1000 );
161
161
162
- this .handle ("TERM" );
162
+ this .handle ("TERM" );
163
163
}
164
164
165
165
/**
@@ -232,7 +232,7 @@ private void processFilesIntoServers(List<File> jsonFiles) throws LifecycleExcep
232
232
233
233
/**
234
234
* Processes all the Servers into Job's
235
- *
235
+ *
236
236
* Needs to be called after processFiles()
237
237
*/
238
238
private void processServersIntoJobs (Scheduler scheduler ) throws LifecycleException {
@@ -249,7 +249,8 @@ private void processServersIntoJobs(Scheduler scheduler) throws LifecycleExcepti
249
249
}
250
250
}
251
251
252
- // Now validate the setup of each of the OutputWriter's per query.
252
+ // Now validate the setup of each of the OutputWriter's per
253
+ // query.
253
254
this .validateSetup (server .getQueries ());
254
255
255
256
// Now schedule the jobs for execution.
@@ -281,9 +282,9 @@ private void scheduleJob(Scheduler scheduler, Server server) throws ParseExcepti
281
282
282
283
if ((server .getCronExpression () != null ) && CronExpression .isValidExpression (server .getCronExpression ())) {
283
284
trigger = new CronTrigger ();
284
- ((CronTrigger )trigger ).setCronExpression (server .getCronExpression ());
285
- ((CronTrigger )trigger ).setName (server .getHost () + ":" + server .getPort () + "-" + Long .valueOf (System .currentTimeMillis ()).toString ());
286
- ((CronTrigger )trigger ).setStartTime (new Date ());
285
+ ((CronTrigger ) trigger ).setCronExpression (server .getCronExpression ());
286
+ ((CronTrigger ) trigger ).setName (server .getHost () + ":" + server .getPort () + "-" + Long .valueOf (System .currentTimeMillis ()).toString ());
287
+ ((CronTrigger ) trigger ).setStartTime (new Date ());
287
288
} else {
288
289
Trigger minuteTrigger = TriggerUtils .makeSecondlyTrigger (SECONDS_BETWEEN_SERVER_JOB_RUNS );
289
290
minuteTrigger .setName (server .getHost () + ":" + server .getPort () + "-" + Long .valueOf (System .currentTimeMillis ()).toString ());
@@ -320,8 +321,8 @@ private void deleteAllJobs(Scheduler scheduler) throws Exception {
320
321
}
321
322
322
323
/**
323
- * If this is true, then this class will execute the main()
324
- * loop and then wait 60 seconds until running again.
324
+ * If this is true, then this class will execute the main() loop and then
325
+ * wait 60 seconds until running again.
325
326
*/
326
327
public void setRunEndlessly (boolean runEndlessly ) {
327
328
this .runEndlessly = runEndlessly ;
@@ -399,9 +400,9 @@ public File getJsonDirOrFile() {
399
400
}
400
401
401
402
/**
402
- * If getJsonFile() is a file, then that is all we load. Otherwise,
403
- * look in the jsonDir for files.
404
- *
403
+ * If getJsonFile() is a file, then that is all we load. Otherwise, look in
404
+ * the jsonDir for files.
405
+ *
405
406
* Files must end with .json as the suffix.
406
407
*/
407
408
private List <File > getJsonFiles () {
@@ -448,9 +449,9 @@ protected boolean handle(String signame) {
448
449
for (Entry <String , KeyedObjectPool > entry : this .getObjectPoolMap ().entrySet ()) {
449
450
try {
450
451
entry .getValue ().close ();
451
- log .debug ("Closed object pool factory: " + entry .getKey ());
452
+ log .debug ("Closed object pool factory: " + entry .getKey ());
452
453
} catch (Exception ex ) {
453
- log .error ("Error closing object pool factory: " + entry .getKey ());
454
+ log .error ("Error closing object pool factory: " + entry .getKey ());
454
455
}
455
456
}
456
457
0 commit comments