• 검색 결과가 없습니다.

자바네트워크 제9주

N/A
N/A
Protected

Academic year: 2022

Share "자바네트워크 제9주"

Copied!
33
0
0

로드 중.... (전체 텍스트 보기)

전체 글

(1)

자바네트워크 제9주

NIO 개요

(2)

제12장 NIO 개요

필요성

자바IO는 느리다?

블록킹 자바 IO

IO 향상을 위한 운영체제 수준의 기술

자바의 새로운 변화

논의

(3)

필요성

자바 IO는 native 보다 상대적으로 느렸다.

Nonblocking IO 기능

(4)

자바 IO는 느리다?

자바가 느린 부분은 swing과 IO 이다.

사용이 간편하다.

(5)

블록킹 자바 IO

IO의 흐름

버퍼 프로세스 유저영역

버퍼 버퍼

커널영역

read() DMA

디스크 하드웨어

(6)

IO 향상을 위한 운영체제수준 의 기술

Buffer

One byte read

Using buffer

Full buffer(enough size)

Scatter/Gather

버퍼

버퍼 버퍼

버퍼

(7)

가상 메모리(Virtual Memory)

버퍼 프로세스 유저영역

버퍼 버퍼

커널영역

read() DMA

디스크 하드웨어

(8)

메모리 맵 파일

버퍼 프로세스 유저영역

버퍼 버퍼

커널영역

read() 페이지 매핑

디스크 하드웨어

(9)

파일 락

Shared lock

Exclusive lock

(10)

자바의 새로운 변화

자바의 포인터 버퍼 도입

DiectByteBuffer

네이티브 IO서비스를 제공해주는 채널 도입

셀렉터 도입

(11)

Contents

An Example Client

An Example Server

Buffers

Channels

Readiness Selection

(12)

Introduction

Network communication is very slow

Use Buffering and Threads to overcome

Channel : an open connection to hardware device, file, network, program component

RFC864 Chargen protocol

(13)

Basic operation

Channel is a connection to any type of hardware

It can be operated as blocking or non-blocking mode

(14)

An Example Client

Open a SocketChannel

Read data using ByteBuffer (blocking mode)

(15)

An Example Client

Read data using ByteBuffer (non-blocking mode)

(16)

Sample output

(17)

An Example Server

Selector

Server Channel(OP_ACCEPT)

Client Channel(OP_READ)

Client Channel(OP_READ)

Channel Pool

register

OP_CONNECT OP_READ

select

watch

(18)

Server Algorithm

Select prepared Channel

Do appropriate job for ready channels start

Yes Prepare character set

end Prepare ServerChannel

Prepare Selector Register ServerChannel

to Selector

Is

IOException No

(19)

Prepare Characterset

(20)

Prepeare channel and selector

(21)

Selection loop

(22)

For accept operation

(23)

For write operation

(24)

Buffers

Stream is stream based

Channel is block based using buffer

ByteBuffer, CharBuffer, ShortBuffer, IntBuffer, LongBuffer, FloatBuffer, DoubleBuffer

Network program uses ByteBuffer

(25)

Buffers

clear() : remove all data

rewind() : reset the position to be zero

flip() : set limit as the current position and reset the current position to be zero

hasRemaining() : return true if there is some data between current position and the limit

allocate() : generate fixed size buffer

put(), get() : fill or get data buffer

order() : LITTLE_ENDIAN, BIG_ENDIAN

(26)

ViewBuffer

asShortBuffer()

asCharBuffer()

asIntBuffer()

asLongBuffer()

asFloatBuffer()

asDoubleBuffer()

(27)

Buffer compactification

Move remaining data to front part of the buffer

compact()

(28)

Buffer duplication

Can be used to send the same content to more than two channels

duplicate()

slice()

mark()

reset()

(29)

SocketChannel

(30)

ServerSocketChannel

(31)

Selector

(32)

SelectionKey

(33)

논의

• 시스템 관련 기능 사용

참조

관련 문서

mark 동일한 메모리 참조,

• 파일락킹은 JVM내의 프로세스사이의 관계가 아니라 JVM 외부의 프로세스(다른 프로그램)과의 관계를

• 모든 자바 입출력 클래스는 궁극적으로 바이트단위 입출력 을

소켓 으로 부터 InputStream과 OutputStream 생성 소켓 을 이용한 통신.. 소켓

소켓 으로 부터 InputStream과 OutputStream 생성 소켓 을 이용한 통싞. 소켓

• Serializable 하지 않은 것은 저장되지 않는다..

• If the earbuds do not connect to a mobile device, the connection pop-up window does not appear, or your mobile device cannot find the earbuds, store them in the charging

•  A network added between a protected network and an external network, in order to provide an additional layer of security.!. •  허용할 network 접속과 허용하지