Published on

Slides for the talk on Embedded GlassFish at Java One Hyderabad

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


  1. 2. <ul>Boosting Productivity using Embedded GlassFish </ul><ul>Prasad Subramanian Software Engineering Manager </ul>
  2. 3. <ul>The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle </ul>
  3. 4. <ul>Agenda </ul><ul><li>Demo
  4. 5. What did we do here ?
  5. 6. How did we do it
  6. 7. What is Embedded GlassFish </li><ul><li>API
  7. 8. Distributions
  8. 9. Maven plugin </li></ul><li>Use case for Embedded GlassFish
  9. 10. State of Embedded GlassFish </li></ul>
  10. 11. <ul>What did we do here </ul><ul><li>Started GlassFish within our test program
  11. 12. Deployed an application which was not in an archive form
  12. 13. Access the Servlet from the test program
  13. 14. Undeployed the application
  14. 15. Stopped GlassFish
  15. 16. All this happened in the VM in which the test program was runnning </li></ul>
  16. 17. <ul>How did we do that ? </ul><ul>We “embedded” GlassFish in our test program using a set of APIs collectively known as Embedded GlassFish APIs </ul><ul>Embedded GlassFish allows us to start GlassFish within a JVM or bundle GlassFish as a library along with our applications </ul>
  17. 18. <ul>What is Embedded GlassFish </ul><ul><li>A set of APIs </li><ul><ul><li>To configure, manage GlassFish and its container from a host program </li></ul></ul><li>A distribution </li><ul><ul><li>To provide the GlassFish runtime to the users </li></ul></ul><li>Plugins for maven </li><ul><ul><li>Tooling support for embedding GlassFish using maven </li></ul></ul></ul>
  18. 19. <ul>API </ul>
  19. 20. <ul>The Embedded APIs </ul><ul><li>Bootstrap API </li><ul><li>An API to manage the lifecycle of GlassFish and configure it </li></ul><li>Scattered Archive </li><ul><li>API to abstract an archive out of distributed content </li></ul><li>Web Container API </li><ul><li>API to manage and configure the Web Container specific artifacts </li></ul><li>Advanced Plugabbility </li><ul><li>SPI to allow plugging in of custom GlassFish runtime </li></ul><li>Embedded EJB API </li><ul><li>API exposed by the EJB specification to manage an Embedded EJB container alone </li></ul></ul>
  20. 21. <ul>Bootstrap API </ul><ul><li>Scope </li></ul><ul><ul><li>Obtain an instance of a GlassFish runtime
  21. 22. Manage the lifecycle ( start / stop)
  22. 23. Allow configuration
  23. 24. Allow deploy and undeploy operations </li></ul></ul><ul><li>Package </li></ul><ul>org.glassfish.embeddable </ul>
  24. 25. <ul>Bootstrap API </ul><ul><li>Key interfaces </li></ul><ul><ul><li>Glassfish </li></ul></ul><ul><ul><ul><li>Represents a GlassFish instance & allows lifecycle operations </li></ul></ul></ul><ul><ul><li>Deployer </li></ul></ul><ul><ul><ul><li>Provides the deployer to deploy applications </li></ul></ul></ul><ul><ul><li>CommandRunner </li></ul></ul><ul><ul><ul><li>Programmatic interface for the CLI 'asadmin' </li></ul></ul></ul><ul><ul><li>CommandResult </li></ul></ul><ul><ul><ul><li>Encapsulates the result of the command run via CommandRunner </li></ul></ul></ul>
  25. 26. Bootstrap API <ul><li>Key classes </li></ul><ul><ul><li>GlassFishRuntime </li><ul><li>Represents the runtime environment. Factory class for GlassFish instances </li></ul><li>BootstrapProperties </li><ul><li>Encapsulates the properties for configuring the GlassFishRuntime </li></ul><li>GlassFishProperties </li><ul><li>Encapsulates the properties for configuring GlassFish instance </li></ul></ul></ul>
  26. 27. <ul>Code sample </ul><ul>A code sample sums it up </ul><ul>// Set the properties to configure GlassFish instance </ul><ul>GlassFishProperties gfProps = new GlassFishProperties(); gfProps.setPort(&quot;http-listener&quot;, 8080); </ul><ul>// Get the GlassFishRuntime and get a GlassFish instance </ul><ul>GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(gfProps); </ul><ul>//Start the GlassFish </ul><ul>glassfish.start(); </ul><ul>//get a Deployer instance and deploy the application </ul><ul>Deployer deployer = glassfish.getDeployer(); deployer.deploy(new File(&quot;simple.war&quot;)); </ul><ul>// Stops the GlassFish instance </ul><ul>glassfish.stop(); </ul>
  27. 28. <ul>Code Sample </ul><ul>Use of the CommandRunner </ul><ul>// Set the properties to configure GlassFish instance </ul><ul>CommandRunner commandRunner = glassfish.getCommandRunner(); CommandResult commandResult = commandRunner.run(&quot;create-jdbc-resource&quot;, &quot;--connectionpoolid=DerbyPool&quot;, &quot;jdbc/DerbyPool&quot;); </ul>
  28. 29. <ul>Setting Install Root and Instance Root </ul><ul>Install Root - location of GlassFish binaries Instance Root – location of domain specific configuration </ul><ul>// Bootstrap the GlassFish runtime pointing to 3.1 installation </ul><ul>BootstrapProperties bsProps = new BootstrapProperties(); bsProps.setInstallRoot(System.getenv(&quot;GF_INSTALLATION&quot;)); GlassFishRuntime gfRuntime = GlassFishRuntime.bootstrap(bsProps); </ul><ul>// Point the GlassFish instance to the domain named domain1 </ul><ul>GlassFishProperties gfProps = new GlassFishProperties(); gfProps.setInstanceRoot(System.getEnv(&quot;GF_INSTALLATION&quot;) + &quot;/domains/domain1&quot;); GlassFish glassfish = gfRuntime.newGlassFish(gfProps); </ul>
  29. 30. <ul>Key methods in GlassFish </ul><ul><li>getService(ServiceType, ServiceName) </li></ul><ul><ul><li>Returns an instance of a service like web container or deployer </li></ul></ul><ul><li>getStatus() </li></ul><ul><ul><li>Returns the status of GlassFish instance
  30. 31. Valid values DISPOSED, INIT, STARTED, STARTIN, STOPPED, STOPPING </li></ul></ul><ul><li>dispose() </li></ul><ul><ul><li>Cleans up any temporary files created by GlassFish
  31. 32. Once dispose() is called, further invocations of start() throw an exception </li></ul></ul>
  32. 33. <ul>Scattered Archive API </ul><ul><li>Package : org.glassfish.embeddable.archive
  33. 34. Abstracts archive contents distributed across directories.
  34. 35. Key classes </li></ul><ul><ul><li>ScatteredArchive </li></ul></ul><ul><ul><ul><li>Abstraction for a Scattered Java EE module </li></ul></ul></ul><ul><ul><li>ScatteredEnterprise Archive </li></ul></ul><ul><ul><ul><li>Abstraction for a Scattered Java EE application </li></ul></ul></ul><ul><ul><li>ScatteredArchiveType </li></ul></ul><ul><ul><ul><li>Enumeration values for the scattered Java EE module types
  35. 36. Valid values are RAR | WAR | JAR </li></ul></ul></ul>
  36. 37. <ul>Web Container API </ul><ul><li>Package org.glassfish.embeddable.web
  37. 38. Set of classes and interfaces that represent an embeddable web container
  38. 39. Allows for configuration of virtual servers, context and protocol listeners </li></ul>
  39. 40. <ul>Web Container API </ul><ul><li>Key interfaces </li></ul><ul><ul><li>WebContainer </li></ul></ul><ul><ul><ul><li>Represents embedded web container, which supports the programmatic creation of </li></ul></ul></ul><ul><ul><ul><ul><li>web protocol listeners
  40. 41. virtual servers
  41. 42. static and dynamic web resources </li></ul></ul></ul></ul><ul><ul><li>VirtualServer </li></ul></ul><ul><ul><ul><li>Representation of a virtual server </li></ul></ul></ul><ul><ul><li>WebListener </li></ul></ul><ul><ul><ul><li>Interface for protocol listeners </li></ul></ul></ul><ul><ul><li>Context </li></ul></ul><ul><ul><ul><li>Representation of a web application </li></ul></ul></ul><ul><ul><li>Lifecycle </li></ul></ul><ul><ul><ul><li>Interface for lifecycle event </li></ul></ul></ul>
  42. 43. <ul>Web Container API </ul><ul><li>Key classes </li></ul><ul><ul><li>WebListenerBase
  43. 44. HttpListener
  44. 45. HttpsListener
  45. 46. AJPListener </li></ul></ul>
  46. 47. <ul>Pluggability SPI </ul><ul><li>Package org.glassfish.embeddable.spi
  47. 48. Support for plugging in custom runtime
  48. 49. Key interface </li></ul><ul><ul><li>RuntimeBuilder </li></ul></ul><ul><ul><ul><li>Allows users to plugin a custom runtime for GlassFish </li></ul></ul></ul><ul>// Returns a custom GlassFish runtime </ul><ul>GlassFishRuntime gfr = runtimeBuilder.build(bsProps); </ul>
  49. 50. <ul>EJB Container API </ul><ul><li>Support for an Embedded EJB container
  50. 51. Package javax.ejb.embeddable </li></ul>
  51. 52. <ul>Distributions </ul>
  52. 53. <ul>Distributions </ul><ul><li>How do I get GlassFish in an Embedded mode ?
  53. 54. Autonomous </li></ul><ul><ul><li>Standalone distributions
  54. 55. Distributed as a self contained jars </li></ul></ul><ul><li>Implanted </li></ul><ul><ul><li>Uses an existing GlassFish installation </li></ul></ul>
  55. 56. <ul>Distributions </ul><ul><li>Autonomous </li></ul><ul><ul><li>Add the jar in your classpath
  56. 57. Standalone distribution different from GlassFish distributions
  57. 58. Unzips to a temporary directory where the binaries and domain data are installed
  58. 59. A custom domain.xml can be specified </li></ul></ul><ul>glassfish-embedded-all.jar </ul><ul>glassfish-embedded-web.jar </ul><ul>glassfish-embedded-nucleus.jar </ul>
  59. 60. <ul>Distributions </ul><ul><li>Implanted </li></ul><ul><ul><li>Uses glassfish-embedded-static-shell.jar
  60. 61. Existing GlassFish installation is used
  61. 62. glassfish-embedded-static-shell.jar is available with standard GlassFish distributions
  62. 63. Domain data and application data are stored in the installation
  63. 64. A custom domain.xml can be specified </li></ul></ul>
  64. 65. <ul>Maven Plugin </ul>
  65. 66. <ul>Maven plugin </ul><ul><li>Maven plugins for running glassfish within a test
  66. 67. Provides goals for </li></ul><ul><ul><li>run
  67. 68. start
  68. 69. stop
  69. 70. deploy
  70. 71. undeploy
  71. 72. admin </li></ul></ul><ul><li>Artifact id – org.glassfish:maven-embedded-glassfish-plugin:3.1 </li></ul>
  72. 73. <ul>Use cases </ul><ul><li>Did you say boost in the productivity ? </li></ul><ul><ul><li>Leaner and faster unit tests that require an application server
  73. 74. Maven plugin eliminates the need for Java code for standard operations
  74. 75. Facilitates GlassFish embedded in an IDE </li></ul></ul><ul><li>Applications that need to bundle GlassFish </li></ul><ul><ul><li>OEMs </li></ul></ul>
  75. 76. <ul>State of Embedded GlassFish </ul><ul><li>API design is done
  76. 77. Implementation is ready
  77. 78. Shipped to the community as a part of the 3.1 community release
  78. 79. Adding tests to verify fidelity with standalone GlassFish
  79. 80. Working on passing TCKs to claim compliance fidelity with standalone GlassFish </li></ul>
  80. 81. <ul>Resources </ul><ul><li>Blogs </li><ul><li>http://www.java.net/author/bhavanishankar-s </li></ul><li>One Pager ( technical specification) </li><ul><li>http://wikis.sun.com/display/glassfish/3.1EmbeddedOnePager </li></ul><li>Documentation </li><ul><li>http://download.oracle.com/docs/cd/E18930_01/html/821-2424/index.html </li></ul><li>Javadocs </li><ul><li>http://embedded-glassfish.java.net/nonav/apidocs/ </li></ul></ul>
  81. 82. <ul>Boosting your productivity using Embedded GlassFish </ul>