Saturday, August 27, 2011

Trip to FarMor's



We were invited to help harvest some garden vegetables.


Friday, August 26, 2011

dynaTrace evaluation

dynaTrace can monitor/profile .NET and Java code but I only worked with evaluation of the Java side.

Download the dynatrace full install for linux x86 and windows x86 here product download page

Obtain a license key for evaluation (file will have a name like dynaTrace_license_201107201015.key)

You must have a dynatrace account to download them (dynatrace-3.5.2.2393.msi, dynatrace-3.5.2.2393-linux-x86.jar, dynaTrace_license_201107201015.key)

page dedicated to installation

Define a dedicated VM for dynatrace server/collector, I put the full install jar on a RedHat VM which acted as my server (make sure it has 4GB of RAM)
Run this to install the jar:
java -jar dynatrace-3.5.2.2393-linux-x86.jar

With this extracted to a folder (I put it in ~\dynatrace..) you can start the dyna collector and server with these commands:

cd dynatrace
nohup ./dtserver &
nohup ./dtanalysisserver &
nohup ./dtcollector &
I then ran the install for dynatrace-3.5.2.2393.msi on my desktop, I only installed the dynatrace client on my desktop.

Now you need to copy the dynatrace/agent/lib folder to the servers you want to profile/monitor (do not copy the folder to a path with a space in it like "program files", I put them in c:\tools\dynatrace\agent\lib)

Now you can change the websphere application server JVM arguments to add the dynatrace agent :
-agentpath:"C:\Tools\dynaTrace\dynaTrace 3.5.2\agent\lib\dtagent.dll"=name=OCMWS,server=192.168.1.122
-agentpath:/root/dynatrace-3.5.2/agent/lib/libdtagent.so=name=OCM,server=192.168.1.122

Note: Edit the line above to match the path to where you copied the dynatrace agent dll/so, also give each JVM you are monitoring a different name, and finaly the IP address is the dynatrace server IP address which may be different for you.

To add this to the JVM startup on WebSphere open the IBM console and go to
Servers | application server | server1 | Java Process and Management | Process Definition | Java Virtual Machine | Generic JVM Arguments
prepent the full -agentpath value to the Generic JVM arguments
Click ok and Save your changes, double check that the save took place by entering the console again and checking the generic jvm argument for the new value.

You will have to restart WebSphere to have the JVM startup with the new startup JVM arguments.

Launch the dynaTrace client after doing the above, tools | settings | dynatrace server | connectivity | put in the host IP address.
default values for login are admin:admin, port 2021, test the connection, it should be a green arrow and say success.

Click License, attach the license .key file for dynatrace evaluation: dynaTrace_license_201107201015.key.

Use online videos to see how to use the client to slice and dice the data from the agents and profile your application.




There is no license for the client so you can export captured data and give it to anyone with the client installed and they can view the details of the session and use the client to troubleshoot and make changes.


Thursday, July 28, 2011

*nix/cygwin find commands

I need to keep a record of some Linux/cygwin "find" commands that I find useful. This is sort of a cookbook or quick reference of find commands that are handy to have around.

Print files which were modified within the last 10 days but and NOT in a "CVS", "build" or "classes" folder:
find . -type d -name CVS -prune -o -name build -prune -o -name classes -prune -o -mtime -10 \! -type d -print 

Print a sorted list of the largest files above 20000k minimum size
find . -type f -size +20000k -printf '%kk %p\n' | sort -n -r 

Print files with XML extensions containing the phrase "search string"
find . -type f -name "*.xml" -exec grep "search string" '{}' /dev/null \; -print       

Copy files newer than file X

Where file-x.txt is the file, and /tmp/copy-destination/ is the place you want to copy the files to:

find . -newer file-x.txt $1 | xargs -I {} cp -p $1{} /tmp/copy-destination/

Use OutputStreamWriter not FileWriter

Search your Java code for FileWriter and replace it with OutputStreamWriter... especially if you write UTF-8 encoded documents. You can run into a nasty problem where you develop your Java code on Linux and then when it runs on Windows, character encoding problems crop up. FileWriter uses a OS System setting to determine what encoding to use, so it will change depending on what OS runs the Java code!

Here is an example of how to use OutputStreamWriter for UTF-8 encoded output.
         OutputStreamWriter out = null;
try {
try {
out = new OutputStreamWriter(new FileOutputStream(outputFile),"UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e.getMessage,e);
}
try {
out.append(yourStringDataToWriteToOutputFile);
out.flush();
} catch (IOException e) {
throw new RuntimeException(e.getMessage,e);
}
} catch (FileNotFoundException e) {
throw new RuntimeException(e.getMessage,e);
} finally {
try {
out.close();
} catch (IOException e) {
throw new RuntimeException(e.getMessage,e);
}
}

Hope this helps you get past file character encoding bugs with Java. Here is a great link on various Java Anti-Patterns which should be avoided when writing enterprise class robust code:

Saturday, June 18, 2011

How do I use my web resource bundle within my Spring controller?



Here is how I did it:



In my controller:




import org.springframework.context.ApplicationContext; ...
@Autowired private ApplicationContext context;



In the resource bundle ApplicationResources.properties


gotocode.error.notfound=Sorry {0} is not recognized as a code. 



Back in the controller




public static final String GOTOCODE_NOTFOUND_KEY = "gotocode.error.notfound";
public
static final String CODE_NOT_FOUND_MESSAGE = "Sorry the entry {0} is not recognized as a code.";
...
public ModelAndView findNextInSeries(String code,..
String errorMessage = context.getMessage(
GOTOCODE_NOTFOUND_KEY, new Object[] { code }, CODE_NOT_FOUND_MESSAGE, Locale.getDefault());   

Previously my ApplicationResources.properties was configured in the web.xml







http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_1270163143862"></web-app>

<display-name>Sample Spring Resource Bundle
<distributable>

<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext
<param-value>ApplicationResources



As well as in the Spring Application context configuration (dispatcher-servlet.xml):

Setting up Eclipse TPTP for performance monitoring of Jetty run from Maven

This is a document to help you setup Eclipse TPTP plugin for performance monitoring of J2EE application deployed to Jetty using the jetty-maven-plugin.

Open MyEclipse Configuration center and search for TPTP, download the newest version of TPTP plugin, restart your IDE after the install finishes.

Next go to the TPTP homepage and download the Agent controller for your architecture (I downloaded windows IA32).

Extract the Agent controller zip to C:\Tools\agntctrl.win_ia32-TPTP-4.7.2

Edit your system environment variables and add

RASERVER_HOME=C:\Tools\agntctrl.win_ia32-TPTP-4.7.2 PATH=C:\Tools\agntctrl.win_ia32-TPTP-4.7.2\bin;%PATH%  Open a command prompt and goto agent controller cd C:\Tools\agntctrl.win_ia32-TPTP-4.7.2\bin SetConfig.bat 

This should display the following:

C:\Tools\agntctrl.win_ia32-TPTP-4.7.2\bin>SetConfig.bat Specify the fully qualified path of "javaw.exe" (e.g. c:\jdk1.4\jre\bin\javaw.ex e):   Default>"C:\Program Files\IBM\WebSphere\AppServer\java\jre\bin\javaw.exe" (Pre ss  to accept the default value)   New value> Network access mode (ALL=allow any host, LOCAL=allow only this host, CUSTOM=list  of hosts):   Default>"LOCAL" (Press  to accept the default value)   New value>ALL Security enabled. (true/false):   Default>"FALSE" (Press  to accept the default value)   New value> 

Start the Agent Controller by launching a command console window with Administrator privledges (Run as Admni..) The change your working directory to

cd C:\Tools\agntctrl.win_ia32-TPTP-4.7.2\bin
ACServer.exe

See this link for more agent controller info http://dev.eclipse.org/viewcvs/viewvc.cgi/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/packaging_md/windows/getting_started.html?root=TPTP_Project&view=co

This is also a link with good info on TPTP http://eclipse.sys-con.com/node/508048?page=0,2

Configure piAgent and start your application with Maven by adding this to MAVEN_OPTS environment variable:

-XrunpiAgent:server=enabled 

From eclipse navigate to Run | Profile Configurations... | Attach to Agent | New

ACServer should be running on localhost port 10002, check this with netstat -a -b -n command or test button in eclipse

Jetty JVM Agent should be detected on the Agent tab. select ONLY ONE of the profile probes, CPU --or-- MEMORY etc.. do NOT select more than one, treat them as mutually exclusive radio buttons rather than check boxes.

You can then perform tasks in your application and save the data captured. Also you can create new reports from the captured data with TPTP eclipse tools.

See http://www.eclipse.org/articles/Article-TPTP-Profiling-Tool/tptpProfilingArticle.html

Why your web browser should be updated often.

I was reading a book online about 20 things people should understand about the Internet. Number 7 is about keeping your browser updated. Here are the3 simple reasons given:

First, old browsers are vulnerable to attacks

Second, the web evolves quickly. Old browsers will miss out.

Third and last, old browsers slow down innovation on the web.


I wish I had this in mind when working with a client who insisted on a dynamic Web 2.0 look to the complex application but also demanded compatibility with IE7.

Delivering on both of these requirements (latest Internet bells and whistles like AJAX as well as backward compatibility with older browser versions) increases the difficulty level and cost of the site development considerably. First you have to test on these older browser versions in addition to testing on the common browsers, which increases the development time. Next you have to pare down features and functionality so that it works consistently everywhere, so you might have had a nice dynamic form or navigation control working in IE9 and FireFox 4, but it all gets tossed out when it cannot work in IE7 (see holding up innovation reason given above). Also for some "must have" site features or functionality: developers will usually have to code around older browser version quirks, so instead of writing code in one place to perform a task, it is written one place or one way for modern browsers and another place or another way for older browsers. This causes a code maintenance issue as you now have multiple places to check to fix problems or update code for a single feature or site behavior. This is a problem for HTML, CSS, and Javascript as all three can behave differently on different browsers. Yet another problem that can arise is your performance can vary widely in different browser flavors and versions, for example IE7 javascript benchmarks are miserably slow when compared with more recent versions of IE and other browsers like FireFox or Chrome. This can cause problems where failing to test on the required browser versions can really bite you. If a performance issue (or any browser version issue) is found late in the development cycle, either because the testing was not done along side development in that version or because developers only used modern browsers for their self verification and validation of the application, then the time to fix the problem is much larger and more difficult than if it had been caught earlier.
The best defense to this situation of having to develop Javascript for modern sites to be used by clunky old browser versions is to use a good library like GWT, jQuery or Dojo. These abstract away many of the browser specific cruft that would drive you mad when trying to implement your site. I am not sure of a solution for this problem as it relates to HTML/CSS however, cross browser CSS is a major pain in the you know what.



About Me

My photo
Lead Java Developer Husband and Father

Tags