Enterprise javabeans
This presentation is the property of its rightful owner.
Sponsored Links
1 / 22

Enterprise JavaBeans PowerPoint PPT Presentation


  • 82 Views
  • Uploaded on
  • Presentation posted in: General

Enterprise JavaBeans. EJB Container Services. EJB container. Enterprise JavaBeans are deployed in an EJB container within the application server EJB container manages the execution of enterprise beans for Java EE applications

Download Presentation

Enterprise JavaBeans

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Enterprise javabeans

Enterprise JavaBeans

EJB Container Services


Ejb container

EJB container

  • Enterprise JavaBeans are deployed in an EJB container within the application server

  • EJB container manages the execution of enterprise beans for Java EE applications

  • EJB benefit - container is charged with the task of making system services available to EJB components


J2ee components and container

J2EE Components and Container

http://java.sun.com/blueprints/guidelines/designing_enterprise_applications/platform_technologies/component/index.html


Ejb container services

EJB container services

Container-provided services:

  • Persistence

  • Transactions

  • Security

  • JNDI

  • Distribution

  • Concurrency

  • Multi-threading

  • Component pooling

  • Component life cycle

  • Timer service

  • Interceptors


Persistence

Persistence

Java Persistence API

  • @Entity

  • public class Customer {

  • @Id private int id;

  • private String name;

  • @OneToMany

  • private List<Account>accounts;

  • . . .

  • }

  • @Entity

  • public class Account {

  • @Id

  • private int id;

  • . . .

  • }


Transactions

Transactions

  • A transaction is a group of activities performed as a single unit

  • Transaction demarcation types:

    • Container-managed

      • Declarative, default

    • Bean-managed

      • User transaction API

  • Annotation @TransactionManagement

    • Is applied to bean class

    • Values: CONTAINER or BEAN


Example container managed

Example: Container-managed

@TransactionAttribute(MANDATORY)

@Stateless

public class ShopBean implements Shop {

public void setPrice(int prodId, int price){

...

}

@TransactionAttribute(REQUIRED)

public int getPrice(int prodId){

...

}

}


Transaction attribute definitions

Transaction Attribute Definitions

http://java.sys-con.com/read/325149.htm


Example bean managed

Example: Bean-managed

@TransactionManagement(BEAN)

@Stateless

public class ShopBean implements Shop {

@Resource UserTransaction tx;

@PersistenceContext EntityManager productMgr;

public void setPrice(int prodId, int price){

tx.begin();

productMgr.find(Product.class, prodId).setPrice(price);

tx.commit();

}

}


Security

Security

  • Security is very important in the enterprise environment

    • Authentication

    • Authorization

  • Security annotations

    • @DeclareRoles

    • @DenyAll

    • @PermitAll

    • @RolesAllowed

    • @RunAs


Example security

Example: Security

@Stateless

@DeclareRoles({“javaee"})

public class HelloEJB implements Hello {

@PermitAll

public String hello1(String msg) {

return "1: Hello, " + msg;

}

@RolesAllowed("javaee")

public String hello2(String msg) {

return "2: Hello, " + msg;

}

@DenyAll

public String hello3(String msg) {

return "3: Hello, " + msg;

}

}


Example security1

Example: Security

@Stateless

@DeclareRoles({"A", "B"})

public class HelloEJB implements Hello {

@Resource private SessionContext sc;

public String hello(String msg) {

if (sc.isCallerInRole("A") && !sc.isCallerInRole("B")){

...

} else {

...

}

}

}


Enterprise javabeans

JNDI

  • JNDI = Java Naming and Directory Interface

  • API that provides naming and directory functionality to applications

    • store and retrieve named Java objects of any type

    • associate attributes with objects and search for objects using their attributes

  • A naming service helps organize an enterprise application by acting as a central registry for components


Naming and directory services

Naming and Directory services

  • JNDI is independent of any specific directory service implementation

    • LDAP, DNS, NIS, RMI, CORBA

http://www.javaworld.com/javaworld/jw-01-2000/jw-01-howto.html

http://www.javaworld.com/javaworld/jw-02-2000/jw-02-howto.html


Jndi functions

JNDI functions

  • void bind(String stringName, Object object)

    • Binds a name to an object

  • Object lookup(String stringName)

    • Returns the specified object

import javax.naming.Context;import javax.naming.InitialContext;

Context ctx = new InitialContext();

Calculator calculatorRemote =

(Calculator).lookup("CalculatorBean/remote");


Jndi architecture

JNDI architecture

http://java.sun.com/products/jndi/tutorial/getStarted/overview/index.html


Bean pooling

Bean pooling

  • To reduce memory consumption and processing, containers pool resources and manage the lifecycles of all the beans very carefully

  • When a bean is not being used, a container will place it in a pool to be reused by another client

  • The container copies data into or out of these pooled instances as necessary

  • The best thing - client application is completely unaware of the resource management activities


Bean pooling benefits

Bean pooling benefits

  • Reduces the resource requirements for a single server

    • pooled beans are context switched as required

  • Dynamic growth pool can be expanded/contracted as demand requires

  • Pooled objects are instantiated on startup instead of every time

    • may be expensive to instantiate

  • Fine-grained control of resources able to set max/min beans


Bean lifecycle management

Bean lifecycle management

  • Two strategies to perform lifecycle management:

    • instance pooling

    • passivation/activation

  • Passivation is a technique to temporarily serialize a bean and store it to some persistent store

  • Containers free up resources by passivating a bean and then re-activating it when resources are available


Stateless session bean lifecycle

Stateless Session bean lifecycle

Source: Sun J2EE tutorial


Stateful session bean lifecycle

Stateful Session bean lifecycle

Source: Sun J2EE tutorial


References

References

  • Transactions http://java.sys-con.com/read/325149.htm

  • Security

    http://java.sun.com/developer/technicalArticles/J2EE/security_annotation/

  • JNDI

    http://www.java2s.com/Article/Java/J2EE/JNDI.htm


  • Login