session 6 - rmi and mail

27
Session 6 Remote Method Invocation JavaMail

Upload: le-duc-anh-toi

Post on 06-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 1/27

Session 6

Remote Method Invocation

JavaMail

Page 2: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 2/27

Slide 2/27

Introduction to I18N and L10N

Why need I18N and L10N?

How to implements?

Components of I18N and L10N

 Networking

Concept of Socket

Using of Socket Datagram and using Datagram

Page 3: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 3/27

Slide 3/27

Module 1 : Introduce to R MI

Module 2 : JavaMail API

Page 4: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 4/27

Slide 4/27

Introduction to R MI

R MI Architecture

Implement R MI

Page 5: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 5/27

Page 6: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 6/27

Slide 6/27

RMI

Client invokingmethods of remote

Java objects

RemoteJava Object

RemoteJava

Object

RemoteJava Object

RMI allows objects in one JVM toinvoke methods of objects in anotherJVM.

Distributed object systems require that objects running in different addressspaces be able to communicate witheach other.

Page 7: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 7/27

Slide 7/27

Although Java provides you with Socket Programming, it is

a low level technology which only transmits bytes and not

objects. R MI allows to serialize and transmit objects.

Allow developers can create distributed application using

 java.

Page 8: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 8/27

Slide 8/27

RMI architecture

Stub/ Skeleton layer

Remote reference layer

Transport layer

Stub proxy for remoteobject .Skeleton remote proxy

for object .

Remote reference layer -Supports communicationbetween stub and skeleton.

Transport Layer - Sets up andmanages connectionsbetween different JVMs.

Page 9: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 9/27

Slide 9/27

RMI architecture Contd«

Client Server

 Application

Stub Layer

Remote ReferenceLayer

Transport Layer

 Application

Skeleton Layer

Remote ReferenceLayer

Transport LayerNetwork

Page 10: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 10/27

Slide 10/27

The components of a R MI application are

Remote Interface

Implement class

Stub

Skeleton

Page 11: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 11/27

Slide 11/27

Define an interface which extends java.rmi.Remote

Declare the remote methods signatures

All these methods should be qualified to throw

 java.rmi.RemoteException

Page 12: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 12/27

Slide 12/27

Define a class which extends java.rmi.server.UnicastRemoteObject

Implement the remote interface(s)

Provide a constructor which throws RemoteException

Provide the implementation of all remote methods

Page 13: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 13/27

Page 14: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 14/27

Slide 14/27

Page 15: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 15/27

Slide 15/27

A R MI Client is any application which needs to invoke the

remote methods of a R MI Server.

Lookup in the R MIRegistry for the name

Use the Remote object reference to invoke methods

Use the Remote object reference to invoke methods

Page 16: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 16/27

Slide 16/27

Introduction to JavaMail APIs

JavaMail API

Steps for E-mail

Page 17: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 17/27

Slide 17/27

The JavaMail API is not a part of the core package. It is a

standard extension and has to be downloaded separately. The

JavaMail API is used to read, compose and send electronic

messages.

Mail Protocols

SMTP (Simple message transfer protocol

POP (Post Office Protocol)

IMAP (Internet Message Access Protocol)

MIME (Multipurpose Internet Mail Extensions)

Page 18: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 18/27

Slide 18/27

In the context of a mailing system, a session is lasting

connection between a user and a host, usually a server.

Session starts when the service is first provided and closes

when the service is ended.

The  javax.mail package provides a class Session to define a

 basic mail session.

Page 19: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 19/27

Slide 19/27

The Session class provides the following two methods to create osession

 public static Session getInstance(Properties props)

 public static session getDefaultInstance(Properties p)

Page 20: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 20/27

Slide 20/27

The  javax.mail.internet.MimeMessage class is a subclassof the Message class and is used to create a message object.

Create an empty message object from a session

Set the attributes required

Set the content type of the message

Set the content of the message

Page 21: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 21/27

Slide 21/27

The address is an Internet email address of a user for specificdomain. Generally the address is of the form

[email protected].

The  javax.mail.internet.InternetAddress is generally used

to create the address required for sender and its recipients.

Page 22: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 22/27

Slide 22/27

Once the message object is create and its required attributesare set, the final step involves sending the message. The

 javax.mail.Transport class is used to send the message to

all its recipients.

Page 23: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 23/27

Slide 23/27

send(Message msg)

send(Message msg, Address[] address)

Page 24: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 24/27

Slide 24/27

A mail service provider maintains a store which contains the

folder where your messages are kept. To retrieve a messagefrom email service, you have to gain access to the store first.

The POP3 protocol maintains its own store. Similarly, the

IMAP maintains its own store.

Page 25: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 25/27

Page 26: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 26/27

Slide 26/27

Folder is the namespace where your message are available.

For the protocol POP3 there is only one folder INBOX.

Retrieve the default folder 

 ± Folder getDefaultFolder()

From the default folder retrieve the INBOX

 ± Folder getFolder(String name)

Open the INBOX folder 

 ± open(int mode)

Retrieve the message ± Message[] getMessages()

Page 27: Session 6 - RMI and Mail

8/3/2019 Session 6 - RMI and Mail

http://slidepdf.com/reader/full/session-6-rmi-and-mail 27/27

Slide 27/27

Introduction to R MI

 Need for R MI Architecture

R MI Architecture

Working of R MI

Implement R MI Application

Introduction to JavaMail API

Components of JavaMail

Working of JavaMail