University
Of
Science,
VNU,
HCMC
1
CÁC
HỆ
THỐNG
PHÂN
TÁN
ĐỒ
ÁN
MÔN
HỌC
-‐
CÁC
KỸ
THUẬT
PHÂN
TÁN
XỬ
LÝ
QUẢN
LÝ
KHO
HÀNG
Ngày:
22/1/2013
Môn
học:
Các
hệ
thống
phân
tán
GVLT:
TS.
Hồ
Bảo
Quốc
TA:
Nguyễn
Trường
Sơn
(
[email protected])
Lê
Nguyễn
Hoài
Nam
(
[email protected])
Mục
lục
MÔ
HÌNH
HOẠT
ĐỘNG
.............................................................................................................................
2
TÀI
LIỆU
THAM
KHẢO
.............................................................................................................................
4
CORBA
Tutorial
...........................................................................................................................................
5
JAVA
RMI
Tutorial
......................................................................................................................................
9
University
Of
Science,
VNU,
HCMC
2
CÁC
HỆ
THỐNG
PHÂN
TÁN
MÔ
HÌNH
HOẠT
ĐỘNG
CLIENT
KHO
HÀNG
KHO
HÀNG
CLIENT
(Người
quản
lý)
CLIENT
KHO
HÀNG
Thủ
kho,
NV
giao
hàng,
Admin
Giới
thiệu
CLIENT
Siêu
thị
ABC
có
nhiều
kho
hàng
(SERVER).
Có
nhiều
phân
hệ
nhân
viên
liên
quan
đến
việc
quản
lý
kho
hàng:
-‐
Thủ
kho:
Mỗi
thủ
kho
phụ
trách
quản
lý
một
kho
hàng,
thủ
kho
có
trách
nhiệm
quản
lý
sản
phẩm
và
quản
lý
việc
nhập
kho.
-‐
Người
quản
lý:
Có
thể
phụ
trách
trên
nhiều
kho
hàng,
quản
lý
có
khả
năng
xem
lịch
sử
nhập
kho
của
các
kho,
tìm
kiếm
sản
phẩm
trên
nhiều
kho,
lập
báo
cáo,
…
-‐
Nhân
viên
giao
hàng:
Mỗi
nhân
viên
giao
hàng
phụ
trách
1
kho.
University
Of
Science,
VNU,
HCMC
3
CÁC
HỆ
THỐNG
PHÂN
TÁN
Nhân
viên
giao
hàng
có
nhiệm
vụ
lập
các
phiếu
xuất
kho.
-‐
Admin:
Mỗi
admin
phụ
trách
quản
lý
tài
khoản
người
dùng
trên
một
kho
hàng.
Các
chức
năng
của
các
người
dùng
cần
phải
chứng
thực
khi
thực
hiện.
Các
chức
Thủ
kho:
năng
chính
-‐
Thêm,
xóa,
cập
nhật
thông
tin
sản
phẩm
trên
phân
-‐
Quản
lý
nhập
kho
hệ
CLIENT
Quản
lý:
1
-‐
Xem
lịch
sử
nhập
kho
-‐
Tìm
kiếm
sản
phẩm
trên
tất
cả
các
kho,
trên
một
số
kho
-‐
Xem
thông
tin
chi
tiết
sản
phẩm
Admin:
-‐
Quản
lý
người
dùng
Nhân
viên
giao
hàng:
Kỹ
thuật
-‐
Lập
phiếu
xuất
kho
-‐
Sử
dụng
ít
nhất
02
KỸ
THUẬT
TRONG
SỐ
các
kỹ
thuật
sau:
và
Phân
o 0-‐JAVA
RMI
công
o 1-‐CORBA
o 2-‐DCOM
-‐
Nếu
mã
nhóm
là
N
thì
kỹ
thuật
được
phân
công
là:
N%3
và
(N+1)%3.
Ví
dụ
Nhóm
20
thì
sẽ
được
phân
công
sử
dụng
2
kỹ
thuật:
20%3
=
2
(DCOM)
và
(20+1)%3=0
(JAVA
RMI)
Loại
ứng
-‐
Tối
thiểu
02
CLIENT
(Desktop
hoặc
Web)
cho
2
nhóm
nhân
viên.
dụng
-‐
Tối
thiểu
03
SERVER
CSDL
-‐
MySQL
hoặc
SQL
Server
1
Các
chức
năng
của
SERVER:
Server
cài
đặt
các
chức
năng
(các
hàm
từ
xa)
sao
cho
phục
vụ
tốt
nhu
cầu
của
các
CLIENT.
University
Of
Science,
VNU,
HCMC
4
CÁC
HỆ
THỐNG
PHÂN
TÁN
Deadline
6
tuần
[4/3/2012]
Nhóm
2-‐3
học
viên
/
nhóm.
Đăng
ký
nhóm
và
lấy
thông
tin
Mã
nhóm
trên
Google
Docs.
(Link
đăng
ký
ở
cuối
trang)
Nội
dung
1.
Mã
nguồn
của
chương
trình
[Source
code,
Script
tạo
dữ
liệu
nộp
2.
Báo
cáo
gồm:
•
Thông
tin
nhóm
•
Bảng
phân
công
công
việc
•
Các
công
việc
đã
hoàn
thành
•
Hướng
dẫn
sử
dụng
chương
trình
Đăng
ký
nhóm
trên
GOOGLE
DOCS:
https://docs.google.com/spreadsheet/ccc?key=0AmXmXsN1pUbydHhWTGRIWDgt
Ti15VElaMkktcGpTcmc
TÀI
LIỆU
THAM
KHẢO
CORBA:
1. http://docs.oracle.com/javase/1.4.2/docs/guide/idl/jidlExample.html
2. http://docs.oracle.com/javase/1.4.2/docs/guide/idl/mapping/jidlMapping.
html
RMI:
3. http://www.eg.bucknell.edu/~cs379/DistributedSystems/rmi_tut.html#clie
nt
DCOM:
4. http://www.codeproject.com/Articles/38254/A-‐Beginner-‐Tutorial-‐for-‐
Writing-‐Simple-‐COM-‐ATL-‐DLL
HẾT
University
Of
Science,
VNU,
HCMC
5
CÁC
HỆ
THỐNG
PHÂN
TÁN
HƯỚNG
DẪN
CORBA
Tutorial
Nội
dung:
Viết
chương
trình
giao
tiếp
giữa
Client
và
Server
trong
đó:
Server
cung
cấp
hàm
sayHello()
và
Client
gọi
thực
hiện
hàm
sayHello().
Bước
1:
Viết
tập
tin
Hello.idl
Hello.idl
module
HelloApp
{
interface
Hello
{
string
sayHello();
long
calc(in
long
a,
in
long
b);
oneway
void
shutdown();
};
};
Tham
khảo
http://docs.oracle.com/javase/1.4.2/docs/guide/idl/mapping/jidlMapping.html
để
biết
một
số
kiểu
dữ
liệu
sử
dụng
trong
IDL.
Bước
2:
Tạo
các
mã
nguồn
để
giao
tiếp
với
IDL
file
theo
một
ngôn
ngữ
nào
đó.
Với
JAVA
thì
sử
dụng
trình
công
cụ
IDL
to
JAVA
(jdlj)
idlj
-‐fall
Hello.idl
Lệnh
này
sẽ
tạo
ra
các
stubs
và
skeletons
theo
mã
nguồn
JAVA
tương
ứng
với
Interface
vừa
tạo.
Bước
3:
Cài
đặt
Server
HelloServer.java
//
HelloServer.java
//
Copyright
and
License
import
HelloApp.*;
University
Of
Science,
VNU,
HCMC
6
CÁC
HỆ
THỐNG
PHÂN
TÁN
import
org.omg.CosNaming.*;
import
org.omg.CosNaming.NamingContextPackage.*;
import
org.omg.CORBA.*;
import
org.omg.PortableServer.*;
import
org.omg.PortableServer.POA;
import
java.util.Properties;
class
HelloImpl
extends
HelloPOA
{
private
ORB
orb;
public
void
setORB(ORB
orb_val)
{
orb
=
orb_val;
}
//
implement
sayHello()
method
public
String
sayHello()
{
return
"\nHello
world
!!\n";
}
//
implement
shutdown()
method
public
void
shutdown()
{
orb.shutdown(false);
}
}
public
class
HelloServer
{
public
static
void
main(String
args[])
{
try{
//
create
and
initialize
the
ORB
ORB
orb
=
ORB.init(args,
null);
//
get
reference
to
rootpoa
&
activate
the
POAManager
POA
rootpoa
=
POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
rootpoa.the_POAManager().activate();
//
create
servant
and
register
it
with
the
ORB
HelloImpl
helloImpl
=
new
HelloImpl();
helloImpl.setORB(orb);
//
get
object
reference
from
the
servant
org.omg.CORBA.Object
ref
=
rootpoa.servant_to_reference(helloImpl);
Hello
href
=
HelloHelper.narrow(ref);
//
get
the
root
naming
context
//
NameService
invokes
the
name
service
org.omg.CORBA.Object
objRef
=
orb.resolve_initial_references("NameService");
//
Use
NamingContextExt
which
is
part
of
the
Interoperable
//
Naming
Service
(INS)
specification.
NamingContextExt
ncRef
=
NamingContextExtHelper.narrow(objRef);
//
bind
the
Object
Reference
in
Naming
University
Of
Science,
VNU,
HCMC
7
CÁC
HỆ
THỐNG
PHÂN
TÁN
String
name
=
"Hello";
NameComponent
path[]
=
ncRef.to_name(
name
);
ncRef.rebind(path,
href);
System.out.println("HelloServer
ready
and
waiting
...");
//
wait
for
invocations
from
clients
orb.run();
}
catch
(Exception
e)
{
System.err.println("ERROR:
"
+
e);
e.printStackTrace(System.out);
}
System.out.println("HelloServer
Exiting
...");
}
}
Bước
4:
Cài
đặt
Client
HelloClient.java
import
HelloApp.*;
import
org.omg.CosNaming.*;
import
org.omg.CosNaming.NamingContextPackage.*;
import
org.omg.CORBA.*;
public
class
HelloClient
{
static
Hello
helloImpl;
public
static
void
main(String
args[])
{
try{
//
create
and
initialize
the
ORB
ORB
orb
=
ORB.init(args,
null);
//
get
the
root
naming
context
org.omg.CORBA.Object
objRef
=
orb.resolve_initial_references("NameService");
//
Use
NamingContextExt
instead
of
NamingContext.
This
is
//
part
of
the
Interoperable
naming
Service.
NamingContextExt
ncRef
=
NamingContextExtHelper.narrow(objRef);
//
resolve
the
Object
Reference
in
Naming
String
name
=
"Hello";
helloImpl
=
HelloHelper.narrow(ncRef.resolve_str(name));
System.out.println("Obtained
a
handle
on
server
object:
"
+
helloImpl);
System.out.println(helloImpl.sayHello());
helloImpl.shutdown();
}
catch
(Exception
e)
{
System.out.println("ERROR
:
"
+
e)
;
e.printStackTrace(System.out);
University
Of
Science,
VNU,
HCMC
8
CÁC
HỆ
THỐNG
PHÂN
TÁN
}
}
}
Bước
5:
Chạy
chương
trình
1. Biên
dịch
tất
cả
các
mã
nguồn
java
bao
gồm
các
tập
tin
java
trong
thư
mục
HelloApp
và
các
tập
tin
HelloServer.java,
HelloClient.java
javac
*.java
HelloApp/*.java
2. Khởi
động
orbd
To
start
orbd
from
a
UNIX
command
shell,
enter:
orbd
-‐ORBInitialPort
1050&
From
an
MS-‐DOS
system
prompt
(Windows),
enter:
start
orbd
-‐ORBInitialPort
1050
3. Khởi
động
HelloServer
To
start
the
Hello
server
from
a
UNIX
command
shell,
enter:
java
HelloServer
-‐ORBInitialPort
1050
-‐ORBInitialHost
localhost&
From
an
MS-‐DOS
system
prompt
(Windows),
enter:
start
java
HelloServer
-‐ORBInitialPort
1050
-‐ORBInitialHost
localhost
University
Of
Science,
VNU,
HCMC
9
CÁC
HỆ
THỐNG
PHÂN
TÁN
4. Chạy
Client
java
HelloClient
-‐ORBInitialPort
1050
-‐ORBInitialHost
localhost
JAVA
RMI
Tutorial
Nội
dung:
Viết
chương
trình
giao
tiếp
giữa
Client
và
Server
trong
đó:
Server
cung
cấp
hàm
say
()
và
Client
gọi
thực
hiện
hàm
say
().
Bước
1:
Tạo
Interface
định
nghĩa
giao
diện
các
hàm
để
thực
hiện
gọi
từ
xa
HelloInterface.java
import
java.rmi.*;
/**
*
Remote
Interface
for
the
"Hello,
world!"
example.
*/
public
interface
HelloInterface
extends
Remote
{
/**
University
Of
Science,
VNU,
HCMC
10
CÁC
HỆ
THỐNG
PHÂN
TÁN
*
Remotely
invocable
method.
*
@return
the
message
of
the
remote
object,
such
as
"Hello,
world!".
*
@exception
RemoteException
if
the
remote
invocation
fails.
*/
public
String
say()
throws
RemoteException;
}
Bước
2:
Xây
dựng
lớp
Hello
(là
cài
đặt
của
HelloInterface
)
cài
đặt
nội
dung
các
hàm
Hello.java
import
java.rmi.*;
import
java.rmi.server.*;
/**
*
Remote
Class
for
the
"Hello,
world!"
example.
*/
public
class
Hello
extends
UnicastRemoteObject
implements
HelloInterface
{
private
String
message;
/**
*
Construct
a
remote
object
*
@param
msg
the
message
of
the
remote
object,
such
as
"Hello,
world!".
*
@exception
RemoteException
if
the
object
handle
cannot
be
constructed.
*/
public
Hello
(String
msg)
throws
RemoteException
{
message
=
msg;
}
/**
*
Implementation
of
the
remotely
invocable
method.
*
@return
the
message
of
the
remote
object,
such
as
"Hello,
world!".
*
@exception
RemoteException
if
the
remote
invocation
fails.
*/
public
String
say()
throws
RemoteException
{
return
message;
}
}
Bước
3:
Biên
dịch
các
lớp
ở
trên
(*.java).
Sau
đó
tạo
các
stubs
và
skeletons
theo
cú
pháp
sau:
rmic
Hello
Bước
4:
Xây
dựng
Server
HelloServer.java
import
java.rmi.*;
public
class
HelloServer{
public
static
void
main
(String[]
argv)
{
try
{
Naming.rebind
("Hello",
new
Hello
("Hello,
world!"));
University
Of
Science,
VNU,
HCMC
11
CÁC
HỆ
THỐNG
PHÂN
TÁN
System.out.println
("Hello
Server
is
ready.");
}
catch
(Exception
e)
{
System.out.println
("Hello
Server
failed:
"
+
e);
}
}
}
Bước
5:
Xây
dựng
Client
HelloClient.java
import
java.rmi.*;
public
class
HelloClient{
public
static
void
main
(String[]
argv)
{
try
{
HelloInterface
hello
=
(HelloInterface)
Naming.lookup
("//localhost/Hello");
System.out.println
(hello.say());
}
catch
(Exception
e)
{
System.out.println
("HelloClient
exception:
"
+
e);
}
}
}
Bước
6:
Biên
dịch
các
file
HelloClient.java,
HelloServer.java
Bước
7:
Chạy
chương
trình
ở
Client-‐
Server
Đầu
tiên
Khởi
động
Object
Registry
theo
cú
pháp:
rmiregistry
&
Sau
đó,
chạy
chương
trình
ở
Server
:
java
HelloServer
&
University
Of
Science,
VNU,
HCMC
12
CÁC
HỆ
THỐNG
PHÂN
TÁN
Sau
đó,
chạy
chương
trình
ở
Client:
java
HelloClient
HẾT