Tuesday, August 02, 2011

Low memory in Cloud Bees

I've noticed that memory goes low at Cloud Bees RUN@CLOUD service. As I wrote earlier, about near-real time physical memory monitoring, this application works, but sometimes it's just not available. This is the image I've faced 5 min before writing this post :

Friday, July 08, 2011

Adobe Flex Mobile On Android - first application

I think that new feature of Adobe Flex 4.5.1 Mobile is really cool stuff !!! I was able to convert existent application from my previous blog post to application for Android platform. Didn't tryed iOS support yet, but for Android platform things looks good.

So, few words about app. I have free CloudBees run@cloud account. Application from my previous blog post showing live data feed about physical RAM memory usage on server, one frame per second. Long AMF pooling used there to fetch fresh data. And Flex charting for visualization.

I have to admit that in mobile version plain AMF pooling is used, because I had no luck with long AMF pooling.

You can pick up this application from here -> Memory monitoring Adobe Flex Mobile App.

Maybe CloudBees will want to have it ? :)

Wednesday, July 06, 2011

Memory monitoring on CloudBees RUN@cloud instance

I've been playing with RUN@cloud for some time. In fact it's former Stax service provider. Friendly speaking I was disappointed a little because they decided to decrease amount of RAM available for Tomcat from 256 Mb to 128 Mb for free account. It doesn't affected my playground apps there, but the fact... From other point they have something good for Open Source projects. Maybe I'll try it soon.

So, regarding this changes, I've desided to write RIA application for live RAM monitoring. I mean not JVM memory, but actual RAM amount. I believe this makes sense, even for all things which are even not Java related. Yep, I know there are a lot of them available for free, some of them are commercial. The key feature of my application here is that we have near real time memory charts - 1 second between measuring times + some network roundtrips time + time for rendering. And all this in fancy Adobe Flex client.

Next thing I'm going to do is to create the same kind of application, but for Android. It's possible with Adobe Flash builder 4.5. Among tons of games, organaizers and other stuff this application could be useful for admins, support team, whatever.

You can take a look at my app here : http://monitoring.daoway.staxapps.net/

Any feedback apprececiated. Thanks.

Wednesday, May 25, 2011

Loading Spring Beans based on environment

In complex deployment environments it makes sense to keep web application monolith war file and provide appropriate instructions for deployment team. It's possible only if your application have flexible configurability strategy, so that at least you can switch from DEV to UAT, from UAT to PROD environments and be sure that only thing has been changed is environment specific stuff. Forget about unpacking and patching war-file, it could be prohibited at all because of non-trivial distribution mechanism.

For Spring-based applications all this could look a little bit scary for a first look, you have your applicationContext.xml with placeholders, which is ok, or JNDI for enviromnent-specific resource lookup. Great, but what you are going to do if some of the parts of resources are present in one env. and absent in another ? For example +1 in dev, -1 in uat and +1 in prod ? Maybe there is not only one way to do it, but I came across the following solution for this.

It's based on combination of servlet context init params and Spring bean re-definition at runtume. Thanks to Spring it's possible. In terms of configurability servlet init params is very flexible thing. You can define one in web.xml, and then redefine it in context setup. I mean externally, so, your war file is still don't need to be patched. Other stuff is technical details for this - key point to implement this is Spring bean which implements both ServletContextAware and ApplicationContextAware interfaces. First makes possible to access Servlet context, second - Spring application context. Runtime re-defintion is not so hard - take a look here.

Complete source code you can find here.

Thursday, April 28, 2011

How to turn off popup page preview in Google search results

Did you enjoyed this feature ? This fancy useless annoing popup page preview images ? Ohh yeess... There is no way to turn it of using some kind of chekbox, so here is the solution for this.

1) Install Firefox extenstion called Grasemonkey - https://addons.mozilla.org/ru/firefox/addon/greasemonkey/

2) Install script for Grasemonkey that will disable this shit - http://userscripts.org/scripts/show/90222 just click on install button at this page.

3) Say goodbye to page preview popups. Enjoy.

I believe it's hard to implement this kind of feature from technical perspective. I mean preview of web page. You have to deal with rendering HTML, CSS, JavaScript... a lot of work, but...

From user's perspective it's useless bullshit !

Friday, April 15, 2011

Java code block in JIRA

This is just small hint on JIRA usage.

If you want to post some source code example in JIRA issue, please use code blocks ! Other vice you'll have a chance to see fancy smiles instead of certain pieces of code. I saw it few times, very annoying...

It's not hard at all:

{code} public static void main(String[] args)  {code}

Other languages are also supported.

Friday, February 25, 2011

Precompile JSP with Maven 2

There are situations where JDK is banned in production and only JRE allowed for use. In this case if you are using JSP there is only one option to use - precompile JSP. Here is example how to achieve that. Nothing very special, but I guess this can save some time and effort for somebody )


WarSourceExcludes will not package original JSPs - really makes no sence since they are just classes and appropriate servlet mappins in web.xml now.

Saturday, February 19, 2011

Mock JNDI in jUnit

JNDI is very useful technology. But... not everywhere. If there is the need to deploy your application on variety of different environments, for example databases with sensitive data and you are not a person who is suitable to deploy application for a bunch of reasons - segregation of concepts, separate production team, etc - JNDI is what you need. If you are with JNDI, only thing you have to provide is JNDI names with example config, so that person responsible for deployment could figure out how to deal with it. Just imagine the mess when you need to deploy war file for ~10 different Oracle databases and the same number of WebSphere MQ queues without JNDI. Think for 1 min :)

But, in development is not so pleasant to have a deal with JNDI, since container required in this case to perform actual lookup of resources. From the other point of view not all so bad, since there is a way in 10 lines of code to mock required JNDI datasource. In fact it could be any other resource, but data source seems to be the most popular.

Key point here is the use of the calss from SpringSource -

Here is the complete example how to use it -

import com.blogspot.ostas.cxf.SimpleDao;
import oracle.jdbc.pool.OracleDataSource;
import org.apache.log4j.Logger;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.jndi.SimpleNamingContextBuilder;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.naming.NamingException;
import java.sql.SQLException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class DaoTestCase{
static Logger logger = Logger.getLogger(DaoTestCase.class.getName());
public static void setUp(){
OracleDataSource ods = null;
try {
ods = new OracleDataSource();
} catch (SQLException e) {
SimpleNamingContextBuilder builder = null;
try {
builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
} catch (NamingException e) {
SimpleDao simpleDao;
public void testInjectBean() throws Exception
logger.debug("Bean : >>> " + simpleDao);
public void testDBconnection() throws Exception{

As you can see from this code, actual mock is just

SimpleNamingContextBuilder builder = null;
try {
builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
} catch (NamingException e) {
ods - just plain DataSource. From Spring point jdbc/db looks llike this -

<bean id="dataSource"
<property name="jndiName">

The last thing I have to mention here is Maven2 dependency for use SimpleNamingContextBuilder class -