Coimbra JUG - 2º Encontro - O primeiro contacto com Java EE 7

1,148 views
1,192 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,148
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Coimbra JUG - 2º Encontro - O primeiro contacto com Java EE 7

  1. 1. 2º Encontro 13/02/2014 Departamento de Engenharia Informática - Faculdade de Ciências e Tecnologia Universidade de Coimbra
  2. 2. Objectivos • Promover a comunidade de Java na zona Centro através de eventos periódicos • Encorajar a participação de membros • Aprender e divertir-se
  3. 3. Contactos • Meetup - http://www.meetup.com/Coimbra-JUG/ • Mailing List - coimbra-jug-list@meetup.com • Youtube - http://www.youtube.com/user/coimbrajug
  4. 4. O primeiro contacto com Java EE 7
  5. 5. Roberto Cortez Freelancer twitter:! @radcortez! ! mail:! radcortez@yahoo.com! ! blog:! http://www.radcortez.com
  6. 6. Questões? Assim que tiverem!
  7. 7. Novas Especificações • Websockets • Batch Applications • Concurrency Utilities • JSON Processing
  8. 8. Melhorias • Simplificação API JMS • Default Resources • JAX-RS Client API • Transacções externas a EJB’s • Mais Anotações • Entity Graphs
  9. 9. Java EE 7 JSRs
  10. 10. Websockets • Suporta cliente e servidor • Declarativo e Programático
  11. 11. Websockets Chat Server @ServerEndpoint("/chatWebSocket")! public class ChatWebSocket {! private static final Set<Session> sessions = Collections.synchronizedSet(new HashSet<Session>());! ! @OnOpen! public void onOpen(Session session) {sessions.add(session);}! ! @OnMessage! public void onMessage(String message) {! for (Session session : sessions) { session.getAsyncRemote().sendText(message);}! }! ! @OnClose! public void onClose(Session session) {sessions.remove(session);}! }
  12. 12. Batch Applications • Ideal para processos massivos, longos e nãointeractivos • Execução sequencial ou paralela • Processamento orientado à tarefa ou em secções.
  13. 13. Batch Applications
  14. 14. Batch Applications - job.xml <job id="myJob" xmlns="http://xmlns.jcp.org/xml/ns/ javaee" version="1.0">! <step id="myStep" >! <chunk item-count="3">! <reader ref="myItemReader"/>! <processor ref="myItemProcessor"/>! <writer ref="myItemWriter"/>! </chunk>! ! </step>! </job>
  15. 15. Concurrency Utilities • Capacidades assíncronas para componentes Java EE • Extensão da API de Java SE Concurrency • API segura e propaga contexto.
  16. 16. Concurrency Utilities public class TestServlet extends HttpServlet {! @Resource(name = "concurrent/MyExecutorService")! ManagedExecutorService executor;! ! Future future = executor.submit(new MyTask());! ! class MyTask implements Runnable {! public void run() {! ! ! ! // do something! }! }! }
  17. 17. JSON Processing • API para ler, gerar e transformar JSON • Streaming API e Object Model API
  18. 18. JSON Processing JsonArray jsonArray = Json.createArrayBuilder()! .add(Json.createObjectBuilder()! .add("name", “Jack"))! .add("age", "30"))! .add(Json.createObjectBuilder()! .add("name", “Mary"))! .add("age", "45"))! .build();! ! [ {“name”:”Jack”, “age”:”30”}, ! {“name”:”Mary”, “age”:”45”} ]
  19. 19. JMS • Nova interface JMSContext • Modernização da API utilizando DI • AutoCloseable dos recursos • Simplificação no envio de mensagens
  20. 20. JMS @Resource(lookup = "java:global/jms/demoConnectionFactory")! ConnectionFactory connectionFactory;! @Resource(lookup = "java:global/jms/demoQueue")! Queue demoQueue;! ! public void sendMessage(String payload) {! try {! Connection connection = connectionFactory.createConnection();! try {! Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);! MessageProducer messageProducer = session.createProducer(demoQueue);! TextMessage textMessage = session.createTextMessage(payload);! messageProducer.send(textMessage);! } finally {! connection.close();! }! } catch (JMSException ex) {! Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);! }! }
  21. 21. JMS @Inject! private JMSContext context;! ! @Resource(mappedName = "jms/inboundQueue")! private Queue inboundQueue;! ! public void sendMessage (String payload) {! context.createProducer()! .setPriority(1)! .setTimeToLive(1000)! .setDeliveryMode(NON_PERSISTENT)! .send(inboundQueue, payload);! }
  22. 22. JAX-RS • Nova API para consumir serviços REST • Processamento assíncrono (cliente e servidor) • Filtros e Interceptors
  23. 23. JAX-RS String movie = ClientBuilder.newClient()! .target("http://www.movies.com/movie")! .request(MediaType.TEXT_PLAIN)! .get(String.class);
  24. 24. JPA • Geração do schema da BD • Stored Procedures • Entity Graphs • Unsynchronized Persistence Context
  25. 25. JPA <persistence-unit name="myPU" transaction-type="JTA">! <properties>! <property name="javax.persistence.schemageneration.database.action" value="drop-and-create"/>! <property name="javax.persistence.schema-generation.create-source" value="script"/>! <property name="javax.persistence.schema-generation.drop-source" value="script"/>! <property name="javax.persistence.schema-generation.create-scriptsource" value="META-INF/create.sql"/>! <property name="javax.persistence.schema-generation.drop-scriptsource" value="META-INF/drop.sql"/>! <property name="javax.persistence.sql-load-script-source" value="META-INF/load.sql"/>! </properties>! </persistence-unit>
  26. 26. JPA @Entity! @NamedStoredProcedureQuery(name="top10MoviesProcedure",! procedureName = "top10Movies")! public class Movie {}! ! StoredProcedureQuery query = entityManager.createNamedStoredProcedureQuery(! "top10MoviesProcedure");! query.registerStoredProcedureParameter(1, String.class, ParameterMode.INOUT);! query.setParameter(1, "top10");! query.registerStoredProcedureParameter(2, Integer.class, ParameterMode.IN);! query.setParameter(2, 100);! query.execute();! query.getOutputParameterValue(1);
  27. 27. JSF • Suporte HTML 5 • @FlowScoped e @ViewScoped • Componente para File Upload • Navegação de flow por convenção • Resource Library Contracts
  28. 28. Outros • JTA: @Transactional, @TransactionScoped • Servlet: Non-blocking I/O, Segurança • CDI: Automáticos para EJB’s e beans anotados (beans.xml opcional), @Vetoed • Interceptors: @Priority, @AroundConstruct • EJB: Passivation opcional • EL: Lambdas, API isolada • Bean Validator: Restrições nos parâmetros dos métodos e retornos
  29. 29. Servidores Certificados • Glassfish 4.0 • Wildfly 8.0.0 • TMAX JEUS 8
  30. 30. Futuro Java EE 8 • JCache • Logging • JSON-B • Security • Testability • Cloud? • Modularity? • NoSQL?
  31. 31. Materiais • Tutorial Java EE 7 - http://docs.oracle.com/javaee/ 7/tutorial/doc/home.htm • Exemplos Java EE 7 - https://github.com/javaeesamples/javaee7-samples
  32. 32. Obrigado!

×