SlideShare una empresa de Scribd logo
1 de 42
Descargar para leer sin conexión
<Insert Picture
     Here>




HK2, GlassFish, WLS and beyond
Jerome Dochez
GlassFish Architect
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.




                                                        2
Current State of affairs

GlassFish
 –V3 released December 2009
  • Java EE 6 support
  • Modular application server based on OSGi
  • Support for some OSGi RFCs.
  • Developer focused release (fast startup,
    iterative deployment features)
 –V3.1 work in progress
  • Adding cluster support
  • Adding session replication support
  • Finishing OSGi RFCs implementation

                                               3
Current State of affairs

WebLogic Server
 –10.3.3 released May 2010
   • JRockit Flight Recorder
   • Coherence Integration
   • SCA, New security plugins, ...
 –10.3.4 ~ CY '10
   • Exalogic / Middleware Machine
   • RAC Datasources
   • Build Env / Developer Experience – Maven, etc.
 –CY '11/'12
   • Next Fusion Middleware
   • EE6 (Profiles)
   • Hk2 Integration / Microkernel convergence

                                                      4
What is HK2


HK2 is a separate open source project to help
build modular server side software.
 –Used to build GlassFish V3
 –Provide an abstraction to a module subsystem like an
  OSGi runtime
  • Bindings to Felix, Equinox and Knopplerfish
  • Can be used in static mode, with no module
    subsystem
 –Provide a simple yet powerful dependency injection
  • No XML
  • Purely annotation based
  • Lazy instantiation/resolution


                                                         5
GlassFish V3 Runtime


                   GlassFish V3



                         HK2

       Felix, Equinox
         Bindings
                                   Static
                                  Binding
       OSGi runtime


                        JDK 6


                                            6
Shared Architecture Vision


• No OSGi dependency in code
 – e.g Embedded GlassFish does not require OSGi.
 – Simplified programming model
 – Fixed some OSGi design patterns not applicable to server side
   software :
    • Focus on dynamic modules (ability to load/unload modules at
      runtime)
    • Lazy loading/resolving rather than Activator/Extender patterns
      that often require immediate resolution of modules
• Modules are not off the shelves components




                                                                       7
GlassFish distinctions


• Modules are created to support GlassFish
  use cases
 • Fast startup : move away code that we don't
   necessarily need on startup.
 • Container isolation : ability to create distributions
   with various capabilities (no EJB container or no
   Web container).
 • Extensibility : ability to add or remove entire set of
   components in an installed image.
• Code relationships based on Services.


                                                            8
HK2 and WLS


• WLS and GlassFish are both Java EE
  application servers offered by Oracle

• So where does it intersects ?
 • WLS 12c is targeted to support :
  • Java EE 6 platform specifications
  • Java EE profiles...
  • HK2 micro-kernel
  • Dependency Injection
  • RunLevelService



                                          9
Iteration one of integration


                     GlassFish and
     GlassFish                          WLS Server
                      WLS Clients



                        HK2



    Felix, Equinox
      Bindings                        Static
                                     Binding

    OSGi Runtime


                       JDK 6

                                                     10
HK2 Features

• Abstraction to the module subsystem
• Service Based Architecture
 • Services can be looked up or injected
 • Services annotated with @Service implements
   interfaces annotated with @Contract
 • Disambiguate using name
 • With scopes (singleton, per lookup, per thread)
• Configuration handling
 • Binding to XML files
 • Transactional access
 • Support Validation APIs and MBeans/REST

                                                     11
Example


Contract Definition
@Contract
public interface SomeContract {
 void someMethod();
 }
                                       POJO
                                  implements POJI
Service implementation
@Service
public class SomeService implements SomeContract {..}




                                                    12
Dependency Injection

•Service implementation
 @Service
 public class Simple implements SomeContract {
   public void someMethod() {..}
 }
•Simple client
  @Service
   public class AnotherManagedService {
     @Inject
     SomeContract svc;
...
      svc.someMethod();

                                                 13
“Flavors” of D.I.


•By Contract
 @Inject AnInterface aInterface;


•By Name & Contract
 @Inject(name=“foo”) AnInterface anInterface;


•By Type
 @Inject AnImplementation aImpl;




                                                14
Service Based Runtime


• Contracts implementations annotated with
  @Service
 • Optional name
 • Scope (singleton, perLookup, threaded)
 • No scope annotation = singleton
• Habitat contains all the services
 List<Startup> list = habitat.getAllByContract
 (Startup.class);
• Current GlassFish startup code (simplified)
 for (Startup s : habitat.getAllByContract(Startup.class)) {
  
    Logger.info(“Started “ + s);
 }
                                                               15
Component


• Services are components, with a scope
  (lifecycle), have dependencies providing
  contracts implementation
• Dependencies are expressed with
@Inject
• Injected resources can be resources
  themselves
• Service allocation cascading based on D.I.
• Injected resources are looked up from the
  habitat.
                                               16
Server Initialization


• On startup, hk2-jars are introspected :
 • List of available contracts (indexes)
 • List of services implementing such contracts.
• Lazy lookup of services.
• No class-loader is created until a service is
  actually requested!
• Experimenting with ASM to be able to use
  normal jar rather than enforcing hk2-jar
  (presence of the inhabitant file is mandatory
  so far).
                                                   17
Component Lifecycle


• PostContruct
–Interface implemented to have a postConstruct
 method called after injection is performed.
–Constructor cannot be intercepted.
–After postConstruct is called, service is installed in the
 habitat.
• PreDestroy
–Interface called when service is removed from the
 habitat.
–Hook for cleanup.


                                                              18
Tricks to remember

• Nobody calls services any more, they call
  contracts implementation.
• Services are dynamic, remove an optional
  jar from the modules directory and its
  services are not available.
• Services use injection to get initialized, very
  little explicit lookup.
• Services initialization will result in multiple
  sub services cascade initialization :
 • No multi-threading
 • No circular references support
                                                    19
GlassFish approach to Config

• Special type of components to read/write
  configuration data to the domain.xml
• Mapping defined via interfaces (kind of like
  JAXB)
• Interfaces are annotated with @Configured
  annotation
 • Fields are annotated with @Attribute
 • Sub-elements are annotated with @Element
• Supports subclassing and extensibility
• Configuration mapping for WLS not finalized
  yet.
                                                 20
Configuration Example

@Configured public interface Server extends …
{

    @Attribute(key=true) String name();
    @Attribute String description();
    @Element Replication replication;
}
@Configured
public interface Replication extends ... {...}


<server name=”foo” description=”some server”>
  <replication .../>
</server>

                                                 21
Configuration extensibility

@Configured
 interface Server extends … {
      @Element(“*”)
      public List<Module> modules
 }

@Configured
 interface RailsModule extends Module {
      @Attribute String name();
 }

@Configured
 public interface WebModule extends Module
 {...}

                                             22
Configuration Extensibility (2)


<server>
    <rails-module name=”foo”/>
    <rails-module name=”bar”/>
    <web-module name=”xyz”/>
</server>




                                  23
Configuration implementation


• Based on streaming parser
• One class implements all @Configured
  interface (Dom.java)
• Each instance of Dom creates a proxy view
  of the data, the proxy type is the
  @Configured annotated type.
• User's code use interface based access, all
  configuration data is stored in a network of
  Dom instances.

                                                 24
Transactions

• Simple transactions must be started to change
  configuration objects.
• Mutated object must be identified to the tx.
• Concurrent transactions can happen as long as
  they don't mutate the same config instances.
• Transaction are either committed or rollbacked.
• Committed transaction are written to the
  domain.xml and listeners are notified
• Transactions can be rejected by the system.
• Some transactions require restart of server.

                                               25
wait ! there is more

• Bean Validation
• Mbeans
 –All configured interfaces instances can be
  automatically registered in the mbean server.
• Generic admin commands
 –CRUD style commands with no extra code.
• REST
 –All configured interfaces instances available through
  REST interface
 –@RestRedirect when rest commands trigger a
  command invocation rather than just changing the
  configuration (e.g. deploy).
                                                          26
Hk2Runner – JUnit Integration


@RunWith(Hk2Runner.class)
public class RunLevelServiceTest {
  @Inject
  Habitat h;

  @Inject(name="default")
  RunLevelService<?> rls;

  @Test
  void testSomething() {...};




                                     27
Hk2 Microkernel
Beyond GlassFish
How and why WebLogic Server is converging
                on Hk2.




                                            28
WLS Convergence on Hk2


•WebLogic Server
 • High-end, enterprise features
 • Very mature product (circa 1998)
 • Established design
 • Complex interdependencies between infrastructure
   components




                                                      29
Snapshot of some of the
startup services

              XMLService                      TransactionService

      MessageInterceptionService                 JDBCService

         MigratableRMIService              StoreDeploymentService

           EditAccessService             CustomResourceServerService

    CompatibilityMBeanServerService       CacheProviderServerService

         HealthMonitorService                EJBContainerService

      MigratableServerServiceImpl           J2EEConnectorService

            MigrationService                 ConfiguratorService

         T3InitializationService                 JMSService

           T3BindableService             DeploymentShutdownService

       CSharpInitializationService        ApplicationShutdownService

        ChannelRuntimeService            AppClientDeploymentService

    TransactionRecoveryFailBackService            FileService

    TransactionRecoveryNoOpService               TimerService

          DefaultStoreService               HeartbeatHelperService



                                                                       30
Startup Services (cont)
          BridgeService            DeploymentRegistrationService
           SAFService              PersistenceRegistrationService
     ServletContainerService
                                        RegistrationService
       ConversationService
                                         ValidationService
    WTCServerLifeCycleService
                                 DeploymentPreStandbyServerService
       WebServicesService
                                                 …
     WSATTransactionService

      RuntimeServerService

        EditServerService

      DomainRuntimeService

        HarvesterService

     ClassDeploymentService

      ServerLifeCycleService

   EnableAdminListenersService

    ConfigImageSourceService

           PathService

   SNMPAgentDeploymentService



                                                                     31
Complex Interdependencies


• Each of the services can represent a
  subsystem

• Each of the services require lifecycle

• Ordering of startup / shutdown is important
 –Previously used an ordinal numbering scheme, but
  that was problematic.
 –Each of the services on the previous diagram are
  now annotated with a “RunLevel” phase...

                                                     32
WLS Lifecycle




                33
Motivation
• The Obvious (I.e., we wanted / needed a
  microkernel)
 • Model dependencies & lifecycle controls (internal motivation)
 • Service-oriented approach (internal motivation)
 • IoC / DI mechanism included (internal motivation)
 • More flexibility in profile creation (external and internal
   motivations)
• DM vs HK2
 • Hk2   / GlassFish was out there in customer’s hands!
 • Hk2 abstracted the underlying module system whereas DM
 assumed OSGi
 • Hk2’s fast start-up and on-demand loading impressed
                                                                 34
Notable…

• No “rewrites”
• No restarts
 • Currently working out config details
• No change to the way JVMs are started
• Server is “primed” at startup, no 1st request
  delays
• Desire to blend best of breed components

=> Hk2 would need to support new features
 for WLS…

                                                  35
New Features in Hk2


• The RunLevelService

• Habitat Listeners & Trackers

• Hk2Runner

• ...



                                 36
The RunLevelService

• An annotation based approach for dealing
  with service start levels integrated into the
  DI machinery
• One default RunLevelService instance for
  the “platform”.
 • extensible for any one else to extend or use for
   subcomponent lifecycle processing.
• “Creates demand” for services (I.e., Eager
  initialization).
 • The default is lazy and not something the WLS PM's
   said they wanted.


                                                        37
The RunLevelService (cont)

@Contract
public interface RunLevelService<T> {
  ...

    /**
     * Causes this RunLevelService to move to
     * the specified run level …
     */
    void proceedTo(int runLevel);
}




                                                38
The RunLevelService (cont)


• The @Admin Meta Annotation
@Retention(RUNTIME)
@Target(TYPE)
@org.jvnet.hk2.annotations.RunLevel(value=ServerStates.SRVR_ADMIN)
public @interface Admin {}


• Each WLS meta annotation correlates to
existing ServerStates
  •   @Immediate
  •   @Starting
  •   @Running
  •   @StandBy



                                                                     39
Example ServerService – Boot Service

@Starting
@Service (name=ServerServiceTags.KERNEL)
public class BootService extends AbstractServerService {
 @Inject (name=ServerServiceTags.IMAGE_MANAGER_SERVICE_NAME)
 private ServerService imageManagerService;

 public void start() throws ServiceFailureException
 public void stop()
 public void halt()



 • Ordering dictated by
   • Injection
   • RunLevel
 • Constraint Checking

                                                               40
Modular Server Services

• Externalize Server Profiles

• A new service is as simple as adding an annotation

• Dynamically creates the services start structure based on
  the selected server profile

• Keep existing WLS outward appearance
 • Outward Logging
 • Current Server State and Lifecycle Changed
 • Continues use of the Server Services Interface and programming
   paradigms




                                                                    41
Challenges


• Past challenges:
 –Teasing out dependencies between the subsystems
  (ordinal start ordering -> dependency based start
  ordering).
• Future challenges:
 –Parallelization of startup ServerServices (RLS)
 –Dynamic & Configuration Driven Services – Hot
  Rewiring
 –Hk2 “omni presence” in products - N x Clients & Tools
 –Visualization of the dependency graph (tooling)
 –Convergence with JSR-299 / 330

                                                          42

Más contenido relacionado

La actualidad más candente

OSGi and Java EE in GlassFish - Tech Days 2010 India
OSGi and Java EE in GlassFish - Tech Days 2010 IndiaOSGi and Java EE in GlassFish - Tech Days 2010 India
OSGi and Java EE in GlassFish - Tech Days 2010 IndiaArun Gupta
 
SHARE 2014, Pittsburgh CICS and Liberty applications
SHARE 2014, Pittsburgh CICS and Liberty applicationsSHARE 2014, Pittsburgh CICS and Liberty applications
SHARE 2014, Pittsburgh CICS and Liberty applicationsnick_garrod
 
2020 pre fosdem mysql clone
2020 pre fosdem   mysql clone2020 pre fosdem   mysql clone
2020 pre fosdem mysql cloneGeorgi Kodinov
 
MyFaces CODI and JBoss Seam3 become Apache DeltaSpike
MyFaces CODI and JBoss Seam3 become Apache DeltaSpikeMyFaces CODI and JBoss Seam3 become Apache DeltaSpike
MyFaces CODI and JBoss Seam3 become Apache DeltaSpikeos890
 
Turn you Java EE Monoliths into Microservices with WildFly Swarm
Turn you Java EE Monoliths into Microservices with WildFly SwarmTurn you Java EE Monoliths into Microservices with WildFly Swarm
Turn you Java EE Monoliths into Microservices with WildFly SwarmDimitris Andreadis
 
Oracle SOA suite and Coherence dehydration
Oracle SOA suite and  Coherence dehydrationOracle SOA suite and  Coherence dehydration
Oracle SOA suite and Coherence dehydrationMichel Schildmeijer
 
WildFly BOF and V9 update @ Devoxx 2014
WildFly BOF and V9 update @ Devoxx 2014WildFly BOF and V9 update @ Devoxx 2014
WildFly BOF and V9 update @ Devoxx 2014Dimitris Andreadis
 
5 steps to take setting up a streamlined container pipeline
5 steps to take setting up a streamlined container pipeline5 steps to take setting up a streamlined container pipeline
5 steps to take setting up a streamlined container pipelineMichel Schildmeijer
 
JBoss EAP / WildFly, State of the Union
JBoss EAP / WildFly, State of the UnionJBoss EAP / WildFly, State of the Union
JBoss EAP / WildFly, State of the UnionDimitris Andreadis
 
Glassfish An Introduction
Glassfish An IntroductionGlassfish An Introduction
Glassfish An IntroductionJumping Bean
 
Java EE 6, Eclipse @ EclipseCon
Java EE 6, Eclipse @ EclipseConJava EE 6, Eclipse @ EclipseCon
Java EE 6, Eclipse @ EclipseConLudovic Champenois
 
GlassFish 3.1 – Simplifying your Java EE 6 Development and Deployment @ JAX L...
GlassFish 3.1 – Simplifying your Java EE 6 Development and Deployment @ JAX L...GlassFish 3.1 – Simplifying your Java EE 6 Development and Deployment @ JAX L...
GlassFish 3.1 – Simplifying your Java EE 6 Development and Deployment @ JAX L...Arun Gupta
 
OSGi-enabled Java EE applications in GlassFish
OSGi-enabled Java EE applications in GlassFishOSGi-enabled Java EE applications in GlassFish
OSGi-enabled Java EE applications in GlassFishArun Gupta
 
Introduction to Role Based Administration in WildFly 8
Introduction to Role Based Administration in WildFly 8Introduction to Role Based Administration in WildFly 8
Introduction to Role Based Administration in WildFly 8Dimitris Andreadis
 
MyFaces Universe at ApacheCon
MyFaces Universe at ApacheConMyFaces Universe at ApacheCon
MyFaces Universe at ApacheConos890
 

La actualidad más candente (19)

OSGi and Java EE in GlassFish - Tech Days 2010 India
OSGi and Java EE in GlassFish - Tech Days 2010 IndiaOSGi and Java EE in GlassFish - Tech Days 2010 India
OSGi and Java EE in GlassFish - Tech Days 2010 India
 
SHARE 2014, Pittsburgh CICS and Liberty applications
SHARE 2014, Pittsburgh CICS and Liberty applicationsSHARE 2014, Pittsburgh CICS and Liberty applications
SHARE 2014, Pittsburgh CICS and Liberty applications
 
2020 pre fosdem mysql clone
2020 pre fosdem   mysql clone2020 pre fosdem   mysql clone
2020 pre fosdem mysql clone
 
MyFaces CODI and JBoss Seam3 become Apache DeltaSpike
MyFaces CODI and JBoss Seam3 become Apache DeltaSpikeMyFaces CODI and JBoss Seam3 become Apache DeltaSpike
MyFaces CODI and JBoss Seam3 become Apache DeltaSpike
 
SSL Everywhere!
SSL Everywhere!SSL Everywhere!
SSL Everywhere!
 
Turn you Java EE Monoliths into Microservices with WildFly Swarm
Turn you Java EE Monoliths into Microservices with WildFly SwarmTurn you Java EE Monoliths into Microservices with WildFly Swarm
Turn you Java EE Monoliths into Microservices with WildFly Swarm
 
Oracle SOA suite and Coherence dehydration
Oracle SOA suite and  Coherence dehydrationOracle SOA suite and  Coherence dehydration
Oracle SOA suite and Coherence dehydration
 
WildFly BOF and V9 update @ Devoxx 2014
WildFly BOF and V9 update @ Devoxx 2014WildFly BOF and V9 update @ Devoxx 2014
WildFly BOF and V9 update @ Devoxx 2014
 
Devoxx 2013, WildFly BOF
Devoxx 2013, WildFly BOFDevoxx 2013, WildFly BOF
Devoxx 2013, WildFly BOF
 
WebLogic and GraalVM
WebLogic and GraalVMWebLogic and GraalVM
WebLogic and GraalVM
 
5 steps to take setting up a streamlined container pipeline
5 steps to take setting up a streamlined container pipeline5 steps to take setting up a streamlined container pipeline
5 steps to take setting up a streamlined container pipeline
 
JBoss EAP / WildFly, State of the Union
JBoss EAP / WildFly, State of the UnionJBoss EAP / WildFly, State of the Union
JBoss EAP / WildFly, State of the Union
 
Maven
MavenMaven
Maven
 
Glassfish An Introduction
Glassfish An IntroductionGlassfish An Introduction
Glassfish An Introduction
 
Java EE 6, Eclipse @ EclipseCon
Java EE 6, Eclipse @ EclipseConJava EE 6, Eclipse @ EclipseCon
Java EE 6, Eclipse @ EclipseCon
 
GlassFish 3.1 – Simplifying your Java EE 6 Development and Deployment @ JAX L...
GlassFish 3.1 – Simplifying your Java EE 6 Development and Deployment @ JAX L...GlassFish 3.1 – Simplifying your Java EE 6 Development and Deployment @ JAX L...
GlassFish 3.1 – Simplifying your Java EE 6 Development and Deployment @ JAX L...
 
OSGi-enabled Java EE applications in GlassFish
OSGi-enabled Java EE applications in GlassFishOSGi-enabled Java EE applications in GlassFish
OSGi-enabled Java EE applications in GlassFish
 
Introduction to Role Based Administration in WildFly 8
Introduction to Role Based Administration in WildFly 8Introduction to Role Based Administration in WildFly 8
Introduction to Role Based Administration in WildFly 8
 
MyFaces Universe at ApacheCon
MyFaces Universe at ApacheConMyFaces Universe at ApacheCon
MyFaces Universe at ApacheCon
 

Similar a Java onebrazil hk2

What's new in the OSGi Enterprise Release 5.0
What's new in the OSGi Enterprise Release 5.0What's new in the OSGi Enterprise Release 5.0
What's new in the OSGi Enterprise Release 5.0David Bosschaert
 
Cloud compiler - Minor Project by students of CBPGEC
Cloud compiler - Minor Project by students of CBPGEC  Cloud compiler - Minor Project by students of CBPGEC
Cloud compiler - Minor Project by students of CBPGEC vipin kumar
 
What’s new in WSO2 Enterprise Integrator 6.6
What’s new in WSO2 Enterprise Integrator 6.6What’s new in WSO2 Enterprise Integrator 6.6
What’s new in WSO2 Enterprise Integrator 6.6WSO2
 
Distributed & Highly Available server applications in Java and Scala
Distributed & Highly Available server applications in Java and ScalaDistributed & Highly Available server applications in Java and Scala
Distributed & Highly Available server applications in Java and ScalaMax Alexejev
 
Sysco Oracle Tour 2016 - What's new in FMW 12.2.1?
Sysco Oracle Tour 2016 - What's new in FMW 12.2.1?Sysco Oracle Tour 2016 - What's new in FMW 12.2.1?
Sysco Oracle Tour 2016 - What's new in FMW 12.2.1?Jon Petter Hjulstad
 
Gustavo Garnica: Evolución de la Plataforma Java y lo que Significa para Ti
Gustavo Garnica: Evolución de la Plataforma Java y lo que Significa para TiGustavo Garnica: Evolución de la Plataforma Java y lo que Significa para Ti
Gustavo Garnica: Evolución de la Plataforma Java y lo que Significa para TiSoftware Guru
 
Service Discovery in OSGi: Beyond the JVM using Docker and Consul
Service Discovery in OSGi: Beyond the JVM using Docker and ConsulService Discovery in OSGi: Beyond the JVM using Docker and Consul
Service Discovery in OSGi: Beyond the JVM using Docker and ConsulFrank Lyaruu
 
What You Should Know About WebLogic Server 12c (12.2.1.2) #oow2015 #otntour2...
What You Should Know About WebLogic Server 12c (12.2.1.2)  #oow2015 #otntour2...What You Should Know About WebLogic Server 12c (12.2.1.2)  #oow2015 #otntour2...
What You Should Know About WebLogic Server 12c (12.2.1.2) #oow2015 #otntour2...Frank Munz
 
Apache Tomcat 7 by Filip Hanik
Apache Tomcat 7 by Filip HanikApache Tomcat 7 by Filip Hanik
Apache Tomcat 7 by Filip HanikEdgar Espina
 
Development with JavaFX 9 in JDK 9.0.1
Development with JavaFX 9 in JDK 9.0.1Development with JavaFX 9 in JDK 9.0.1
Development with JavaFX 9 in JDK 9.0.1Wolfgang Weigend
 
.NET Core Apps: Design & Development
.NET Core Apps: Design & Development.NET Core Apps: Design & Development
.NET Core Apps: Design & DevelopmentGlobalLogic Ukraine
 
MVC 6 - the new unified Web programming model
MVC 6 - the new unified Web programming modelMVC 6 - the new unified Web programming model
MVC 6 - the new unified Web programming modelAlex Thissen
 
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...OpenBlend society
 
What's new in the OSGi Enterprise Release 5.0 - David Bosschaert and Tim Diek...
What's new in the OSGi Enterprise Release 5.0 - David Bosschaert and Tim Diek...What's new in the OSGi Enterprise Release 5.0 - David Bosschaert and Tim Diek...
What's new in the OSGi Enterprise Release 5.0 - David Bosschaert and Tim Diek...mfrancis
 

Similar a Java onebrazil hk2 (20)

What's new in the OSGi Enterprise Release 5.0
What's new in the OSGi Enterprise Release 5.0What's new in the OSGi Enterprise Release 5.0
What's new in the OSGi Enterprise Release 5.0
 
Cloud compiler - Minor Project by students of CBPGEC
Cloud compiler - Minor Project by students of CBPGEC  Cloud compiler - Minor Project by students of CBPGEC
Cloud compiler - Minor Project by students of CBPGEC
 
Liferay (DXP) 7 Tech Meetup for Developers
Liferay (DXP) 7 Tech Meetup for DevelopersLiferay (DXP) 7 Tech Meetup for Developers
Liferay (DXP) 7 Tech Meetup for Developers
 
Enterprise service bus part 2
Enterprise service bus part 2Enterprise service bus part 2
Enterprise service bus part 2
 
What’s new in WSO2 Enterprise Integrator 6.6
What’s new in WSO2 Enterprise Integrator 6.6What’s new in WSO2 Enterprise Integrator 6.6
What’s new in WSO2 Enterprise Integrator 6.6
 
Distributed & Highly Available server applications in Java and Scala
Distributed & Highly Available server applications in Java and ScalaDistributed & Highly Available server applications in Java and Scala
Distributed & Highly Available server applications in Java and Scala
 
Sysco Oracle Tour 2016 - What's new in FMW 12.2.1?
Sysco Oracle Tour 2016 - What's new in FMW 12.2.1?Sysco Oracle Tour 2016 - What's new in FMW 12.2.1?
Sysco Oracle Tour 2016 - What's new in FMW 12.2.1?
 
Gustavo Garnica: Evolución de la Plataforma Java y lo que Significa para Ti
Gustavo Garnica: Evolución de la Plataforma Java y lo que Significa para TiGustavo Garnica: Evolución de la Plataforma Java y lo que Significa para Ti
Gustavo Garnica: Evolución de la Plataforma Java y lo que Significa para Ti
 
Service Discovery in OSGi: Beyond the JVM using Docker and Consul
Service Discovery in OSGi: Beyond the JVM using Docker and ConsulService Discovery in OSGi: Beyond the JVM using Docker and Consul
Service Discovery in OSGi: Beyond the JVM using Docker and Consul
 
JavaCro'15 - Service Discovery in OSGi Beyond the JVM using Docker and Consul...
JavaCro'15 - Service Discovery in OSGi Beyond the JVM using Docker and Consul...JavaCro'15 - Service Discovery in OSGi Beyond the JVM using Docker and Consul...
JavaCro'15 - Service Discovery in OSGi Beyond the JVM using Docker and Consul...
 
What You Should Know About WebLogic Server 12c (12.2.1.2) #oow2015 #otntour2...
What You Should Know About WebLogic Server 12c (12.2.1.2)  #oow2015 #otntour2...What You Should Know About WebLogic Server 12c (12.2.1.2)  #oow2015 #otntour2...
What You Should Know About WebLogic Server 12c (12.2.1.2) #oow2015 #otntour2...
 
Apache Tomcat 7 by Filip Hanik
Apache Tomcat 7 by Filip HanikApache Tomcat 7 by Filip Hanik
Apache Tomcat 7 by Filip Hanik
 
Development with JavaFX 9 in JDK 9.0.1
Development with JavaFX 9 in JDK 9.0.1Development with JavaFX 9 in JDK 9.0.1
Development with JavaFX 9 in JDK 9.0.1
 
.NET Core Apps: Design & Development
.NET Core Apps: Design & Development.NET Core Apps: Design & Development
.NET Core Apps: Design & Development
 
MVC 6 - the new unified Web programming model
MVC 6 - the new unified Web programming modelMVC 6 - the new unified Web programming model
MVC 6 - the new unified Web programming model
 
OUGF - OSGi / Flex
OUGF - OSGi / FlexOUGF - OSGi / Flex
OUGF - OSGi / Flex
 
OUGF OSGi/Flex
OUGF OSGi/FlexOUGF OSGi/Flex
OUGF OSGi/Flex
 
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
 
ASP.NET vNext
ASP.NET vNextASP.NET vNext
ASP.NET vNext
 
What's new in the OSGi Enterprise Release 5.0 - David Bosschaert and Tim Diek...
What's new in the OSGi Enterprise Release 5.0 - David Bosschaert and Tim Diek...What's new in the OSGi Enterprise Release 5.0 - David Bosschaert and Tim Diek...
What's new in the OSGi Enterprise Release 5.0 - David Bosschaert and Tim Diek...
 

Java onebrazil hk2

  • 1. <Insert Picture Here> HK2, GlassFish, WLS and beyond Jerome Dochez GlassFish Architect
  • 2. 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. 2
  • 3. Current State of affairs GlassFish –V3 released December 2009 • Java EE 6 support • Modular application server based on OSGi • Support for some OSGi RFCs. • Developer focused release (fast startup, iterative deployment features) –V3.1 work in progress • Adding cluster support • Adding session replication support • Finishing OSGi RFCs implementation 3
  • 4. Current State of affairs WebLogic Server –10.3.3 released May 2010 • JRockit Flight Recorder • Coherence Integration • SCA, New security plugins, ... –10.3.4 ~ CY '10 • Exalogic / Middleware Machine • RAC Datasources • Build Env / Developer Experience – Maven, etc. –CY '11/'12 • Next Fusion Middleware • EE6 (Profiles) • Hk2 Integration / Microkernel convergence 4
  • 5. What is HK2 HK2 is a separate open source project to help build modular server side software. –Used to build GlassFish V3 –Provide an abstraction to a module subsystem like an OSGi runtime • Bindings to Felix, Equinox and Knopplerfish • Can be used in static mode, with no module subsystem –Provide a simple yet powerful dependency injection • No XML • Purely annotation based • Lazy instantiation/resolution 5
  • 6. GlassFish V3 Runtime GlassFish V3 HK2 Felix, Equinox Bindings Static Binding OSGi runtime JDK 6 6
  • 7. Shared Architecture Vision • No OSGi dependency in code – e.g Embedded GlassFish does not require OSGi. – Simplified programming model – Fixed some OSGi design patterns not applicable to server side software : • Focus on dynamic modules (ability to load/unload modules at runtime) • Lazy loading/resolving rather than Activator/Extender patterns that often require immediate resolution of modules • Modules are not off the shelves components 7
  • 8. GlassFish distinctions • Modules are created to support GlassFish use cases • Fast startup : move away code that we don't necessarily need on startup. • Container isolation : ability to create distributions with various capabilities (no EJB container or no Web container). • Extensibility : ability to add or remove entire set of components in an installed image. • Code relationships based on Services. 8
  • 9. HK2 and WLS • WLS and GlassFish are both Java EE application servers offered by Oracle • So where does it intersects ? • WLS 12c is targeted to support : • Java EE 6 platform specifications • Java EE profiles... • HK2 micro-kernel • Dependency Injection • RunLevelService 9
  • 10. Iteration one of integration GlassFish and GlassFish WLS Server WLS Clients HK2 Felix, Equinox Bindings Static Binding OSGi Runtime JDK 6 10
  • 11. HK2 Features • Abstraction to the module subsystem • Service Based Architecture • Services can be looked up or injected • Services annotated with @Service implements interfaces annotated with @Contract • Disambiguate using name • With scopes (singleton, per lookup, per thread) • Configuration handling • Binding to XML files • Transactional access • Support Validation APIs and MBeans/REST 11
  • 12. Example Contract Definition @Contract public interface SomeContract { void someMethod(); } POJO implements POJI Service implementation @Service public class SomeService implements SomeContract {..} 12
  • 13. Dependency Injection •Service implementation @Service public class Simple implements SomeContract { public void someMethod() {..} } •Simple client @Service public class AnotherManagedService { @Inject SomeContract svc; ... svc.someMethod(); 13
  • 14. “Flavors” of D.I. •By Contract @Inject AnInterface aInterface; •By Name & Contract @Inject(name=“foo”) AnInterface anInterface; •By Type @Inject AnImplementation aImpl; 14
  • 15. Service Based Runtime • Contracts implementations annotated with @Service • Optional name • Scope (singleton, perLookup, threaded) • No scope annotation = singleton • Habitat contains all the services List<Startup> list = habitat.getAllByContract (Startup.class); • Current GlassFish startup code (simplified) for (Startup s : habitat.getAllByContract(Startup.class)) { Logger.info(“Started “ + s); } 15
  • 16. Component • Services are components, with a scope (lifecycle), have dependencies providing contracts implementation • Dependencies are expressed with @Inject • Injected resources can be resources themselves • Service allocation cascading based on D.I. • Injected resources are looked up from the habitat. 16
  • 17. Server Initialization • On startup, hk2-jars are introspected : • List of available contracts (indexes) • List of services implementing such contracts. • Lazy lookup of services. • No class-loader is created until a service is actually requested! • Experimenting with ASM to be able to use normal jar rather than enforcing hk2-jar (presence of the inhabitant file is mandatory so far). 17
  • 18. Component Lifecycle • PostContruct –Interface implemented to have a postConstruct method called after injection is performed. –Constructor cannot be intercepted. –After postConstruct is called, service is installed in the habitat. • PreDestroy –Interface called when service is removed from the habitat. –Hook for cleanup. 18
  • 19. Tricks to remember • Nobody calls services any more, they call contracts implementation. • Services are dynamic, remove an optional jar from the modules directory and its services are not available. • Services use injection to get initialized, very little explicit lookup. • Services initialization will result in multiple sub services cascade initialization : • No multi-threading • No circular references support 19
  • 20. GlassFish approach to Config • Special type of components to read/write configuration data to the domain.xml • Mapping defined via interfaces (kind of like JAXB) • Interfaces are annotated with @Configured annotation • Fields are annotated with @Attribute • Sub-elements are annotated with @Element • Supports subclassing and extensibility • Configuration mapping for WLS not finalized yet. 20
  • 21. Configuration Example @Configured public interface Server extends … { @Attribute(key=true) String name(); @Attribute String description(); @Element Replication replication; } @Configured public interface Replication extends ... {...} <server name=”foo” description=”some server”> <replication .../> </server> 21
  • 22. Configuration extensibility @Configured interface Server extends … { @Element(“*”) public List<Module> modules } @Configured interface RailsModule extends Module { @Attribute String name(); } @Configured public interface WebModule extends Module {...} 22
  • 23. Configuration Extensibility (2) <server> <rails-module name=”foo”/> <rails-module name=”bar”/> <web-module name=”xyz”/> </server> 23
  • 24. Configuration implementation • Based on streaming parser • One class implements all @Configured interface (Dom.java) • Each instance of Dom creates a proxy view of the data, the proxy type is the @Configured annotated type. • User's code use interface based access, all configuration data is stored in a network of Dom instances. 24
  • 25. Transactions • Simple transactions must be started to change configuration objects. • Mutated object must be identified to the tx. • Concurrent transactions can happen as long as they don't mutate the same config instances. • Transaction are either committed or rollbacked. • Committed transaction are written to the domain.xml and listeners are notified • Transactions can be rejected by the system. • Some transactions require restart of server. 25
  • 26. wait ! there is more • Bean Validation • Mbeans –All configured interfaces instances can be automatically registered in the mbean server. • Generic admin commands –CRUD style commands with no extra code. • REST –All configured interfaces instances available through REST interface –@RestRedirect when rest commands trigger a command invocation rather than just changing the configuration (e.g. deploy). 26
  • 27. Hk2Runner – JUnit Integration @RunWith(Hk2Runner.class) public class RunLevelServiceTest { @Inject Habitat h; @Inject(name="default") RunLevelService<?> rls; @Test void testSomething() {...}; 27
  • 28. Hk2 Microkernel Beyond GlassFish How and why WebLogic Server is converging on Hk2. 28
  • 29. WLS Convergence on Hk2 •WebLogic Server • High-end, enterprise features • Very mature product (circa 1998) • Established design • Complex interdependencies between infrastructure components 29
  • 30. Snapshot of some of the startup services XMLService TransactionService MessageInterceptionService JDBCService MigratableRMIService StoreDeploymentService EditAccessService CustomResourceServerService CompatibilityMBeanServerService CacheProviderServerService HealthMonitorService EJBContainerService MigratableServerServiceImpl J2EEConnectorService MigrationService ConfiguratorService T3InitializationService JMSService T3BindableService DeploymentShutdownService CSharpInitializationService ApplicationShutdownService ChannelRuntimeService AppClientDeploymentService TransactionRecoveryFailBackService FileService TransactionRecoveryNoOpService TimerService DefaultStoreService HeartbeatHelperService 30
  • 31. Startup Services (cont) BridgeService DeploymentRegistrationService SAFService PersistenceRegistrationService ServletContainerService RegistrationService ConversationService ValidationService WTCServerLifeCycleService DeploymentPreStandbyServerService WebServicesService … WSATTransactionService RuntimeServerService EditServerService DomainRuntimeService HarvesterService ClassDeploymentService ServerLifeCycleService EnableAdminListenersService ConfigImageSourceService PathService SNMPAgentDeploymentService 31
  • 32. Complex Interdependencies • Each of the services can represent a subsystem • Each of the services require lifecycle • Ordering of startup / shutdown is important –Previously used an ordinal numbering scheme, but that was problematic. –Each of the services on the previous diagram are now annotated with a “RunLevel” phase... 32
  • 34. Motivation • The Obvious (I.e., we wanted / needed a microkernel) • Model dependencies & lifecycle controls (internal motivation) • Service-oriented approach (internal motivation) • IoC / DI mechanism included (internal motivation) • More flexibility in profile creation (external and internal motivations) • DM vs HK2 • Hk2 / GlassFish was out there in customer’s hands! • Hk2 abstracted the underlying module system whereas DM assumed OSGi • Hk2’s fast start-up and on-demand loading impressed 34
  • 35. Notable… • No “rewrites” • No restarts • Currently working out config details • No change to the way JVMs are started • Server is “primed” at startup, no 1st request delays • Desire to blend best of breed components => Hk2 would need to support new features for WLS… 35
  • 36. New Features in Hk2 • The RunLevelService • Habitat Listeners & Trackers • Hk2Runner • ... 36
  • 37. The RunLevelService • An annotation based approach for dealing with service start levels integrated into the DI machinery • One default RunLevelService instance for the “platform”. • extensible for any one else to extend or use for subcomponent lifecycle processing. • “Creates demand” for services (I.e., Eager initialization). • The default is lazy and not something the WLS PM's said they wanted. 37
  • 38. The RunLevelService (cont) @Contract public interface RunLevelService<T> { ... /** * Causes this RunLevelService to move to * the specified run level … */ void proceedTo(int runLevel); } 38
  • 39. The RunLevelService (cont) • The @Admin Meta Annotation @Retention(RUNTIME) @Target(TYPE) @org.jvnet.hk2.annotations.RunLevel(value=ServerStates.SRVR_ADMIN) public @interface Admin {} • Each WLS meta annotation correlates to existing ServerStates • @Immediate • @Starting • @Running • @StandBy 39
  • 40. Example ServerService – Boot Service @Starting @Service (name=ServerServiceTags.KERNEL) public class BootService extends AbstractServerService { @Inject (name=ServerServiceTags.IMAGE_MANAGER_SERVICE_NAME) private ServerService imageManagerService; public void start() throws ServiceFailureException public void stop() public void halt() • Ordering dictated by • Injection • RunLevel • Constraint Checking 40
  • 41. Modular Server Services • Externalize Server Profiles • A new service is as simple as adding an annotation • Dynamically creates the services start structure based on the selected server profile • Keep existing WLS outward appearance • Outward Logging • Current Server State and Lifecycle Changed • Continues use of the Server Services Interface and programming paradigms 41
  • 42. Challenges • Past challenges: –Teasing out dependencies between the subsystems (ordinal start ordering -> dependency based start ordering). • Future challenges: –Parallelization of startup ServerServices (RLS) –Dynamic & Configuration Driven Services – Hot Rewiring –Hk2 “omni presence” in products - N x Clients & Tools –Visualization of the dependency graph (tooling) –Convergence with JSR-299 / 330 42