Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1) adding mapbinder-based configuration of StatsServlet > this facilitates application-specific additions of publishers 2) publishing a richer snapshot of data > moves from Map<String, String> to Map<StatDescriptor, Object> > this gives each publisher the name, description, and java value of a stat 3) adding tests for the new publishers Note: the description field is yet unused, but it's clear how it can now be used by a publisher, versus having been hidden before. Dependency changes: * this CL migrates from google-collections to guava * this CL introduces a dependency on google gson IML files: Note, because I'm using IJ 10, I'm not sure that my local edits are going to be backwards compatible. I left them out of this CL. This means that the guava and gson deps will need to be added to the .iml files for intellij to pick up the new deps (I'm not sure what the best thing to do here would have been). git-svn-id: http://google-sitebricks.googlecode.com/svn/trunk@196 c7392d14-1f41-11de-a108-cd2f117ce590
- Loading branch information
ffaber
committed
Jan 12, 2011
1 parent
4ffaeb0
commit c7f596f
Showing
14 changed files
with
537 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
stat/src/main/java/com/google/inject/stat/HtmlStatsPublisher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright (C) 2011 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.google.inject.stat; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
|
||
import java.io.PrintWriter; | ||
import java.util.Map; | ||
|
||
/** | ||
* This implementation of {@link StatsPublisher} publishes snapshots as html. | ||
* | ||
* @author ffaber@gmail.com (Fred Faber) | ||
*/ | ||
class HtmlStatsPublisher extends StatsPublisher { | ||
|
||
@Override String getContentType() { | ||
return "text/html"; | ||
} | ||
|
||
@Override void publish( | ||
ImmutableMap<StatDescriptor, Object> snapshot, PrintWriter writer) { | ||
writer.println("<html><head><style>"); | ||
writer.println("body { font-family: monospace; }"); | ||
writer.println("</style></head><body>"); | ||
for (Map.Entry<StatDescriptor, Object> entry : snapshot.entrySet()) { | ||
StatDescriptor statDescriptor = entry.getKey(); | ||
writer.print("<b>"); | ||
writer.print(statDescriptor.getName()); | ||
writer.print(":</b> "); | ||
writer.print(entry.getValue()); | ||
writer.println("<br/>"); | ||
} | ||
writer.println("</body></html>"); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
stat/src/main/java/com/google/inject/stat/JsonStatsPublisher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Copyright (C) 2011 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.google.inject.stat; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.collect.Maps; | ||
import com.google.gson.Gson; | ||
|
||
import java.io.PrintWriter; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
|
||
/** | ||
* This implementation of {@link StatsPublisher} publishes a snapshot as JSON. | ||
* | ||
* @author ffaber@gmail.com (Fred Faber) | ||
*/ | ||
class JsonStatsPublisher extends StatsPublisher { | ||
|
||
@Override String getContentType() { | ||
return "application/json"; | ||
} | ||
|
||
@Override void publish( | ||
ImmutableMap<StatDescriptor, Object> snapshot, PrintWriter writer) { | ||
Gson gson = new Gson(); | ||
Map<String, Object> valuesByName = Maps.newLinkedHashMap(); | ||
for (Entry<StatDescriptor, Object> entry : snapshot.entrySet()) { | ||
valuesByName.put(entry.getKey().getName(), entry.getValue()); | ||
} | ||
|
||
String gsonString = gson.toJson(valuesByName); | ||
writer.write(gsonString); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.