Skip to content

Commit

Permalink
mass reformat of the code. checked in project specific eclipse settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
lookfirst committed Jan 25, 2012
1 parent 0f1d731 commit 8dfe779
Show file tree
Hide file tree
Showing 46 changed files with 2,489 additions and 2,143 deletions.
282 changes: 282 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions .settings/org.eclipse.jdt.ui.prefs
@@ -0,0 +1,4 @@
#Tue Jan 24 16:58:35 PST 2012
eclipse.preferences.version=1
formatter_profile=_Jmxtrans
formatter_settings_version=12
105 changes: 53 additions & 52 deletions src/com/googlecode/jmxtrans/JmxTransformer.java
Expand Up @@ -44,10 +44,10 @@
import com.googlecode.jmxtrans.util.WatchedCallback;

/**
* Main() class that takes an argument which is the directory
* to look in for files which contain json data that defines
* queries to run against JMX servers.
*
* Main() class that takes an argument which is the directory to look in for
* files which contain json data that defines queries to run against JMX
* servers.
*
* @author jon
*/
public class JmxTransformer extends SignalInterceptor implements WatchedCallback {
Expand All @@ -68,16 +68,15 @@ public class JmxTransformer extends SignalInterceptor implements WatchedCallback

private List<Server> masterServersList = new ArrayList<Server>();


/** */
public static void main(String[] args) throws Exception {
JmxTransformer transformer = new JmxTransformer();

// Register signal handlers
transformer.registerQuietly("HUP");
transformer.registerQuietly("INT");
transformer.registerQuietly("ABRT");
transformer.registerQuietly("KILL");
transformer.registerQuietly("HUP");
transformer.registerQuietly("INT");
transformer.registerQuietly("ABRT");
transformer.registerQuietly("KILL");
transformer.registerQuietly("TERM");

// Start the process
Expand All @@ -93,9 +92,9 @@ private void doMain(String[] args) throws Exception {
}

try {
this.startupScheduler();
this.startupScheduler();

this.startupWatchdir();
this.startupWatchdir();

this.setupObjectPooling();

Expand All @@ -115,51 +114,52 @@ private void doMain(String[] args) throws Exception {
* Startup the watchdir service.
*/
private void startupWatchdir() throws Exception {
File dirToWatch = null;
if (this.getJsonDirOrFile().isFile()) {
dirToWatch = new File(FilenameUtils.getFullPath(this.getJsonDirOrFile().getAbsolutePath()));
} else {
dirToWatch = this.getJsonDirOrFile();
}

// start the watcher
this.watcher = new WatchDir(dirToWatch, this);
this.watcher.start();
File dirToWatch = null;
if (this.getJsonDirOrFile().isFile()) {
dirToWatch = new File(FilenameUtils.getFullPath(this.getJsonDirOrFile().getAbsolutePath()));
} else {
dirToWatch = this.getJsonDirOrFile();
}

// start the watcher
this.watcher = new WatchDir(dirToWatch, this);
this.watcher.start();
}

/**
* start the server scheduler which loops over all the Server jobs
*/
private void startupScheduler() throws Exception {
StdSchedulerFactory serverSchedFact = new StdSchedulerFactory();
InputStream stream = null;
if (QUARTZ_SERVER_PROPERTIES == null) {
QUARTZ_SERVER_PROPERTIES = "/quartz.server.properties";
stream = JmxTransformer.class.getResourceAsStream(QUARTZ_SERVER_PROPERTIES);
} else {
stream = new FileInputStream(QUARTZ_SERVER_PROPERTIES);
}
serverSchedFact.initialize(stream);
this.serverScheduler = serverSchedFact.getScheduler();
this.serverScheduler.start();
StdSchedulerFactory serverSchedFact = new StdSchedulerFactory();
InputStream stream = null;
if (QUARTZ_SERVER_PROPERTIES == null) {
QUARTZ_SERVER_PROPERTIES = "/quartz.server.properties";
stream = JmxTransformer.class.getResourceAsStream(QUARTZ_SERVER_PROPERTIES);
} else {
stream = new FileInputStream(QUARTZ_SERVER_PROPERTIES);
}
serverSchedFact.initialize(stream);
this.serverScheduler = serverSchedFact.getScheduler();
this.serverScheduler.start();
}

/**
* Handy method which runs the JmxProcess
*/
public void executeStandalone(JmxProcess process) throws Exception {
this.masterServersList = process.getServers();
this.masterServersList = process.getServers();

this.startupScheduler();
this.setupObjectPooling();
this.startupScheduler();
this.setupObjectPooling();

this.processServersIntoJobs(this.serverScheduler);
this.processServersIntoJobs(this.serverScheduler);

// Sleep for 10 seconds to wait for jobs to complete.
// There should be a better way, but it seems that way isn't working right now.
Thread.sleep(10 * 1000);
// Sleep for 10 seconds to wait for jobs to complete.
// There should be a better way, but it seems that way isn't working
// right now.
Thread.sleep(10 * 1000);

this.handle("TERM");
this.handle("TERM");
}

/**
Expand Down Expand Up @@ -232,7 +232,7 @@ private void processFilesIntoServers(List<File> jsonFiles) throws LifecycleExcep

/**
* Processes all the Servers into Job's
*
*
* Needs to be called after processFiles()
*/
private void processServersIntoJobs(Scheduler scheduler) throws LifecycleException {
Expand All @@ -249,7 +249,8 @@ private void processServersIntoJobs(Scheduler scheduler) throws LifecycleExcepti
}
}

// Now validate the setup of each of the OutputWriter's per query.
// Now validate the setup of each of the OutputWriter's per
// query.
this.validateSetup(server.getQueries());

// Now schedule the jobs for execution.
Expand Down Expand Up @@ -281,9 +282,9 @@ private void scheduleJob(Scheduler scheduler, Server server) throws ParseExcepti

if ((server.getCronExpression() != null) && CronExpression.isValidExpression(server.getCronExpression())) {
trigger = new CronTrigger();
((CronTrigger)trigger).setCronExpression(server.getCronExpression());
((CronTrigger)trigger).setName(server.getHost() + ":" + server.getPort() + "-" + Long.valueOf(System.currentTimeMillis()).toString());
((CronTrigger)trigger).setStartTime(new Date());
((CronTrigger) trigger).setCronExpression(server.getCronExpression());
((CronTrigger) trigger).setName(server.getHost() + ":" + server.getPort() + "-" + Long.valueOf(System.currentTimeMillis()).toString());
((CronTrigger) trigger).setStartTime(new Date());
} else {
Trigger minuteTrigger = TriggerUtils.makeSecondlyTrigger(SECONDS_BETWEEN_SERVER_JOB_RUNS);
minuteTrigger.setName(server.getHost() + ":" + server.getPort() + "-" + Long.valueOf(System.currentTimeMillis()).toString());
Expand Down Expand Up @@ -320,8 +321,8 @@ private void deleteAllJobs(Scheduler scheduler) throws Exception {
}

/**
* If this is true, then this class will execute the main()
* loop and then wait 60 seconds until running again.
* If this is true, then this class will execute the main() loop and then
* wait 60 seconds until running again.
*/
public void setRunEndlessly(boolean runEndlessly) {
this.runEndlessly = runEndlessly;
Expand Down Expand Up @@ -399,9 +400,9 @@ public File getJsonDirOrFile() {
}

/**
* If getJsonFile() is a file, then that is all we load. Otherwise,
* look in the jsonDir for files.
*
* If getJsonFile() is a file, then that is all we load. Otherwise, look in
* the jsonDir for files.
*
* Files must end with .json as the suffix.
*/
private List<File> getJsonFiles() {
Expand Down Expand Up @@ -448,9 +449,9 @@ protected boolean handle(String signame) {
for (Entry<String, KeyedObjectPool> entry : this.getObjectPoolMap().entrySet()) {
try {
entry.getValue().close();
log.debug("Closed object pool factory: " + entry.getKey());
log.debug("Closed object pool factory: " + entry.getKey());
} catch (Exception ex) {
log.error("Error closing object pool factory: " + entry.getKey());
log.error("Error closing object pool factory: " + entry.getKey());
}
}

Expand Down
80 changes: 43 additions & 37 deletions src/com/googlecode/jmxtrans/OutputWriter.java
Expand Up @@ -12,45 +12,51 @@
import com.googlecode.jmxtrans.util.ValidationException;

/**
* Interface which defines a writer for taking jmx data and
* writing it out in whatever format you want.
*
* Note that this class uses a feature of Jackson to serialize
* anything that implements this as a "@class". That way, when
* Jackson deserializes implementations of this interface, it is
* done with new objects that implement this interface.
*
* Interface which defines a writer for taking jmx data and writing it out in
* whatever format you want.
*
* Note that this class uses a feature of Jackson to serialize anything that
* implements this as a "@class". That way, when Jackson deserializes
* implementations of this interface, it is done with new objects that implement
* this interface.
*
* @author jon
*/
@JsonSerialize(include=Inclusion.NON_NULL)
@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, property="@class")
@JsonSerialize(include = Inclusion.NON_NULL)
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class")
public interface OutputWriter {

public void start() throws LifecycleException;
public void stop() throws LifecycleException;

public void doWrite(Query query) throws Exception;

/**
* Settings allow you to configure your Writers with whatever they might need.
*/
public Map<String, Object> getSettings();

/**
* Settings allow you to configure your Writers with whatever they might need.
*/
public void setSettings(Map<String, Object> settings);

/**
* This is run when the object is instantiated. You want to get the settings and validate them.
*/
public void validateSetup(Query query) throws ValidationException;

/**
* Some writers, like GraphiteWriter will use this for object pooling. Things like
* Socket connections to remote servers that we are writing to are ripe for pooling.
*
* This is super extensible as a map because we could have multiple object pools.
*/
public void setObjectPoolMap(Map<String, KeyedObjectPool> poolMap);
public void start() throws LifecycleException;

public void stop() throws LifecycleException;

public void doWrite(Query query) throws Exception;

/**
* Settings allow you to configure your Writers with whatever they might
* need.
*/
public Map<String, Object> getSettings();

/**
* Settings allow you to configure your Writers with whatever they might
* need.
*/
public void setSettings(Map<String, Object> settings);

/**
* This is run when the object is instantiated. You want to get the settings
* and validate them.
*/
public void validateSetup(Query query) throws ValidationException;

/**
* Some writers, like GraphiteWriter will use this for object pooling.
* Things like Socket connections to remote servers that we are writing to
* are ripe for pooling.
*
* This is super extensible as a map because we could have multiple object
* pools.
*/
public void setObjectPoolMap(Map<String, KeyedObjectPool> poolMap);
}
18 changes: 9 additions & 9 deletions src/com/googlecode/jmxtrans/example/ActiveMQ.java
Expand Up @@ -10,11 +10,11 @@

/**
* This example shows how to query an ActiveMQ server for some information.
*
*
* The point of this example is to show that * works as part of the objectName.
* It also shows that you don't have to set an attribute to get for a query.
* jmxtrans will get all attributes on an object if you don't specify any.
*
*
* @author jon
*/
public class ActiveMQ {
Expand All @@ -28,7 +28,7 @@ public static void main(String[] args) throws Exception {
server.setAlias("w2_activemq_1105");
GraphiteWriter gw = new GraphiteWriter();
gw.addSetting(BaseOutputWriter.HOST, GW_HOST);
// gw.addSetting(GraphiteWriter.HOST, "localhost");
// gw.addSetting(GraphiteWriter.HOST, "localhost");
gw.addSetting(BaseOutputWriter.PORT, 2003);

// use this to add data to GW path
Expand Down Expand Up @@ -143,13 +143,13 @@ public static void main(String[] args) throws Exception {

JmxProcess process = new JmxProcess(server);
JmxUtils.prettyPrintJson(process);
JmxTransformer transformer = new JmxTransformer();
transformer.executeStandalone(process);
JmxTransformer transformer = new JmxTransformer();
transformer.executeStandalone(process);

// for (int i = 0; i < 160; i++) {
// JmxUtils.processServer(server);
// Thread.sleep(1000);
// }
// for (int i = 0; i < 160; i++) {
// JmxUtils.processServer(server);
// Thread.sleep(1000);
// }

}
}
14 changes: 7 additions & 7 deletions src/com/googlecode/jmxtrans/example/ActiveMQ2.java
Expand Up @@ -10,11 +10,11 @@

/**
* This example shows how to query an ActiveMQ server for some information.
*
*
* The point of this example is to show that * works as part of the objectName.
* It also shows that you don't have to set an attribute to get for a query.
* jmxtrans will get all attributes on an object if you don't specify any.
*
*
* @author jon
*/
public class ActiveMQ2 {
Expand Down Expand Up @@ -68,12 +68,12 @@ public static void main(String[] args) throws Exception {
JmxUtils.prettyPrintJson(process);

JmxTransformer transformer = new JmxTransformer();
transformer.executeStandalone(process);
transformer.executeStandalone(process);

// for (int i = 0; i < 160; i++) {
// JmxUtils.processServer(server);
// Thread.sleep(1000);
// }
// for (int i = 0; i < 160; i++) {
// JmxUtils.processServer(server);
// Thread.sleep(1000);
// }

}
}

0 comments on commit 8dfe779

Please sign in to comment.