Samstag, 30. Januar 2010

VisualVM Plugins for Visual GC and OSGi Management

VisualVm is a management console based on the netbeans platform. For VisualVM exists a nice plugin called Visual GC for visualization of the Java GC.

 The Visual GC Plugin for VisualVM

Also a Plugin for OSGi management exists which provides basic management function for an OSGi container e.g. equinox. To use the plugin a bundle, which exports the management functions, must also installed in the OSGi container.

OSGi Managment Plugin for Visual VM
For more info’s about VisualVM and the plugins look on the VisualVM page.

Links:

GWT Events and DeferredCommand - setFocus

To run code after all event handler in GWT are invoked the class DeferredCommand can be used. A example for such a command could be to set a focus for a text field ...

Example code for set a focus:
DeferredCommand.addCommand(new Command() {
 public void execute() {
           testField.setFocus(true);
 }
});


Links:

Eclipse Hot Deployment Mode For Spring DM Web Bundle

For developing web application in eclipse with spring dynamic modules (spring OSGi) there is no mode in which the web resource like JSP etc. will be refresh automatically in the tomcat container.

At the moment I must restart a war bundle when a resource changed and the war bundle will be redeployed by spring web bundle. The restart (redeploy) can be done in eclipse automatic when a resource in the eclipse project change with the STS features, see my previous post about STS (Spring Tool Suite). This is nice for Java classes but not for web resources like JSPs, CSS, etc.

How does the spring web bundle work? The bundle deploys (unzip) the war in a temp directory (can be specifiy by the system property java.io.tmpdir) and then start the deployment method of the container (context) e.g. tomcat in my case.

 
Example eclipse development project structure of a webapp for running in a OSGi container with spring web bundle.

At the development time e.g. in eclipse, normally we have no archive war or jar, we have a eclipse projects, with a war directory structure (see screenshot). So my idea was to patch the TomcatWarDeployer from the Spring Web bundle and put a hot deployment mode into it (Next step could be a own HotTomcatWarDeployer bundle).  In the hot deployment mode the war must installed from a directory (not as jar or war archive) in the OSGi container (in my case the eclipse project folder). The TomcatWarDeploy then do not deploy the files in temp folder the deployer runs the webapp in the project folder e.g. in the eclipse project.

Here is the original spring code (class org.springframework.osgi.web.deployer.tomcat.TomcatWarDeployer )for the base directory:
private String createDocBase(Bundle bundle, String contextPath) throws IOException {
        File tmpFile = File.createTempFile("tomcat-" + contextPath.substring(1), ".osgi");
 tmpFile.delete();
 tmpFile.mkdir();

 String path = tmpFile.getCanonicalPath();
 if (log.isDebugEnabled())
  log.debug("Unpacking bundle [" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "] to folder [" + path
    + "]...");

 Utils.unpackBundle(bundle, tmpFile);

 return path;
}

And here the patched code (method createDocBase from the class org.springframework.osgi.web.deployer.tomcat.TomcatWarDeployer) with the hot deployment mode for tomcat:
private String createDocBase(Bundle bundle, String contextPath) throws IOException {
 try
 {
  String hotdeployMode = System.getProperty(TOMCAT_HOTDEPLOY);
  if(hotdeployMode != null && hotdeployMode.toLowerCase().equals("true")){
   if (log.isDebugEnabled())
    log.debug("HOT Deployment mode is active. Use this feature only for developing!");
   String workspace = System.getProperty(TOMCAT_WORKSPACE);
   if(workspace != null){
    if (log.isDebugEnabled())
     log.debug("HOT Deployment workspace is set to: " + workspace);
    File workspaceFile = new File(workspace);
    if(workspaceFile.exists()){
     String projectName = bundle.getSymbolicName();
     if (log.isDebugEnabled())
      log.debug("HOT Deployment project name is: " + projectName);
     File projectFile = new File(workspaceFile, projectName);
     if(projectFile.exists() && projectFile.isDirectory()){
      if (log.isDebugEnabled())
       log.debug("HOT Deployment project path is: " + projectFile.getCanonicalPath());
      return projectFile.getCanonicalPath();
     }else{
      if (log.isDebugEnabled())
       log.debug("HOT Deployment project does not exists!");
     }
    }
    else{
     if (log.isDebugEnabled())
      log.debug("HOT Deployment workspace does not exists!");
    }
   }
   else{
    if (log.isDebugEnabled())
     log.debug("HOT Deployment workspace path is not set, please set system property " + TOMCAT_WORKSPACE);
   }
  }
 } catch(Exception exp) {
  if (log.isDebugEnabled()){
   log.debug("Error initializing HOT Deployment!");
   log.debug(exp);
  }
 }
  
 if (log.isDebugEnabled())
  log.debug("Use the normal spring deploymode with temp directory.");
  
 File tmpFile = File.createTempFile("tomcat-" + contextPath.substring(1), ".osgi");
 tmpFile.delete();
 tmpFile.mkdir();

 String path = tmpFile.getCanonicalPath();
 if (log.isDebugEnabled())
  log.debug("Unpacking bundle [" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "] to folder [" + path
    + "]...");

 Utils.unpackBundle(bundle, tmpFile);

 return path;
} 

That means you can change our web resources like JSPs etc. and the changes take directly effect. I think that’s the mode how I like to develop webapps no redeployment or file synch.

To use my patched spring web bundle you must install the patched bundle instead the normal spring web bundle (Version 1.2.1) in your OSGi container. Also the two system properties “org.springframework.osgi.web.deployer.tomcat.hotdeploy” and “org.springframework.osgi.web.deployer.tomcat.workspace” must be set see the screenshot.



So the solution is not very nice with the two system properties but at the moment it works for me. When you have ideas feel free for comments. I have also committed this idea in the spring dynamic modules (spring osgi) project JIRA see ticket http://jira.springframework.org/browse/OSGI-800.

Here you can get my example patched spring web bundle http://dl.dropbox.com/u/532968/spring-osgi-web-1.2.1-patched.jar

Have fun with the patch

Christian

Dienstag, 26. Januar 2010

Workshop – Building OSGi based applications - Darmstadt 15.04.2010

Jochen Hiller and I are organizing for the OSGi User Forum Germany a workshop with the title “Building OSGi based applications”.  The workshop location is Darmstadt and the date is 15.04.2010. You can now submit talks by sending a short abstract as email at workshop-germany@osgiusers.org, deadline for submit a talk is 01.03.2010.

More Information about the workshop see the workshop website: (German)
http://germany.osgiusers.org/Main/WorkshopBuildingOSGiApplication

For the workshop we provide an OSGi sample application, which is provided on GitHub: http://github.com/tux2323/osgi-kasse-example/

The follow YouTube Video (German) shows how-to import and run the sample application in eclipse.



So we will be happy to see you at the workshop in Darmstadt...

Christian

Dienstag, 19. Januar 2010

Eclipse Tipp - SpringSource Tool Suite - Auto Restart an OSGi Bundle in Eclipse

SpringSource Tool Suite TM (STS) is a free (not open source) set of developing tools for spring based applications, it is eclipse based (an eclipse distribution, but can also installed as plugins in your eclipse instance).

The Spring Tool Suite comes with a very cool feature for developing OSGi based applications, the STS adds a listener to your eclipse project resource and when something changed (saved) the effected bundle will be automatic restarted. This is very cool for developing OSGi based application. To activate the feature you must enable the „Spring Dynamic Modules OSGi Bundle Updater“ see the screenshot.



The Option can be found under the project setting of your bundle. After activating the Bundle Updater in the project setting, add the follow argument “-console ${osgi.console.port}” to the command line arguments of your launch configuration.


Links:
http://www.springsource.com/products/sts

Samstag, 16. Januar 2010

Painting by Hand with Bamboo

I played around with BAMBOO, I tryed to draw a class diagram by hand. The idea to have a alternative to a Flip Chart in a meeting or workshop. But I think drawing on paper is much faster :-( ...

Here my first drawing with ArtRage (Demo Version) and Bamboo:

Do not Paint Work with Textual DSL instead

A better option can be to use a DSL instead of hand drawing stuff, e.g. in a brainstorming meeting. Here a example DSL for the picture bellow made with yUML:

[Seller]+1-0..*[Position]
[Sale]+->1..*[Position]
[Position]->1[PositionKey]

[Seller Repository]->[Seller]
[Position Repository]->[Position]
[Sale Service]->[Sale]

[Basar Kasse Service]->[Seller Repository]
[Basar Kasse Service]->[Position Repository]
[Basar Kasse Service]->[Sale Service]

And here the diagramm made by yUML from the DSL:


But I will work on my drawing skills, with BAMBOO, so maybe it will be come a alternative for me to get things fast on a screen ...

Links:
- yUML - http://yuml.me
- ArtRage - http://www.artrage.com/
- BAMBOO - http://www.wacom.eu/

Dienstag, 5. Januar 2010

Eclipse - PDE Incubator Dependency Visualization Plugin

The PDE „Dependency Visualization“ plugin for eclipse is a very cool plugin to get a overview of the dependencies of a OSGi application.  I think the plugin give a much clearer overview of the direct and indirect dependencies of an OSGi bundle then the old tree based PDE plugin does.

Example: Old PDE Dependency Plugin Tree Based:


Example: New PDE Dependency Visualization Plugin - Dependencies as Visualization:



Here the project website of the PDE Incubator Dependency Visualization plugin.

Eclipse - 3D Software Visualization

Codstruction is a 3D software visualization tool more information on the project website.

Screenshot - Eclipse Equinox DS Implementation:

Montag, 4. Januar 2010

Eclipse - Software Visualization

XRay is a nice eclipse plugin which does software visualization. It is not free for commerical use see the XRay page for more details.

Example: Package Dependency of eclipse equinox ds implementation


Example: Class Dependency of eclipse equinox ds implementation

For more information about software visualization in general have a look at the SE-Radio episode 130: Code Visualization with Michele Lanza.

Samstag, 2. Januar 2010

Example - JMockContext - JUnit 4.7 Rule Support

JMock now contains in the SVN trunk (http://svn.codehaus.org/jmock/trunk/jmock2) a class org.jmock.integration.junit4.JMockContext, the class is a JUnit 4.7 rule. With this new JUnit rule for JMock no JUnit runner is needed to use JMock in JUnit tests.

Here a small example test which use the new JMockContext rule:
import java.util.Observer;

import org.jmock.Expectations;
import org.jmock.auto.Mock;
import org.jmock.integration.junit4.JMockContext;
import org.junit.Rule;
import org.junit.Test;

// JUH @RunWith is not needed 
public class ExampleJMockContextTest {
    
    @Rule public JMockContext context = new JMockContext();
    
    @Mock Observer mockObserver;
    
    @Test public void expectNoException(){
        context.checking(new Expectations(){{
            oneOf(mockObserver).update(null, null);
        }});
        
        mockObserver.update(null, null);
    }
    
    @Test(expected=RuntimeException.class)  
    public void expectExceptionInSUT() throws Exception {
        
        context.checking(new Expectations(){{
            oneOf(mockObserver).update(null, null);
        }});
        
        mockObserver.update(null, null);
        
        throw new RuntimeException("Exception in SUT");
    }
    
    @Test(expected=RuntimeException.class) 
    public void expectExceptionInMockObjectTest(){
        
        context.checking(new Expectations(){{
            oneOf(mockObserver).update(null, null);
            will(throwException(new RuntimeException("Observer unavailable")));
        }});
        
        mockObserver.update(null, null);
    }
    
}