Dec 18, 2007

Sticky Note

http://www.greeneclipse.com/stickypad.html

Dec 16, 2007

Change Language in Oracle in Windows

- run
- regedit
-Change value of HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\HOMEID\NLS_LANG

NLS_LANG = LANGUAGE_TERRITORY.CHARACTER_SET

English

AMERICAN_AMERICA.WE8MSWIN1252

Japanese

JAPANESE_JAPAN.JA16SJIS



Dec 14, 2007

Change Language in JDeveloper

Change in JDEV_HOME/jdev/bin/jdev.conf
Add following:
AddVMOption -Duser.language=en
AddVMOption -Duser.country=US
or
Modify
AddVMOption -Doracle.translated.locales=en

Dec 6, 2007

Delete duplicate rows in Table - Oracle

delete from TABLE_NAME t1
where t1.rowid >
( select min(t2.rowid) from TABLE_NAME t2
where t1.COLUMN_1 = t2.COLUMN_1
and t1.COLUMN_2 = t2.COLUMN_2);

Oct 20, 2007

Create Procedure

Procedure:
create or replace procedure hello is
begin
DBMS_OUTPUT.PUT_LINE('hello');
end hello;
Call:
SET SERVEROUTPUT ON;
begin
hello;
end;
/

Oct 19, 2007

Connect to SQL*PLUS

C\:>sqlplus
input username, password
or run
SQL commandline from Oracle menu.
Simple SQL:
SQL>select * from table;
Simple PL/SQL:
SQL>SET SERVEROUTPUT ON;
2 BEGIN
3 DBMS_OUTPUT.PUT_LINE('hello');
4 END;
5 /

Oct 12, 2007

Proxy

Download proxy from
http://sourceforge.net/projects/proxy/
Installation
$ tar xzvf proxy.tar.gz
$ cd proxy
$ make
$ ./proxy -s 8080 -S 192.168.1.39 -d 80 -D nhungnguoibantot.net

Oct 9, 2007

Delete Linux User

Using to find user's files
Firstly
$ find / -user username
Manually delete or
$ find / -user username > log.txt
$ rm -rf `cat log.txt`
Finally
$ userdel username

Using iMacros to interactive with browser

Using iMacros add-on to interactive with brownser: automatically input text, redirect...
https://addons.mozilla.org/ja/firefox/addon/3863
very useful for page with many input boxs, many times access.

Oct 3, 2007

Text based browser

In Linux
Installation
$ yum install w3m
Running
$ w3m http://google.com

Tiếng việt trên Fedora

Sử dụng scim cho nhu cầu soạn thảo tiếng việt trên linux
$ yum install scim scim-m17n m17n-db m17n-lib m17n-db-vietnamese
$ cd /usr/share/m17n
$ wget http://vnlinux.org/vi-telex.mim

Oct 2, 2007

Decompress CHM

Using archmage to convert ebook from CHM format to html format
$ yum -y install archmage
$ archmage file.chm directory

Sep 26, 2007

TCP/IP Protocol







4. Application DNS, TFTP, TLS/SSL, FTP, Gopher, HTTP, IMAP, IRC, NNTP, POP3, SIP, SMTP, SNMP, SSH, TELNET, ECHO, BitTorrent, RTP, PNRP, rlogin, ENRP, …
Routing protocols like BGP, which for a variety of reasons run over TCP, may also be considered part of the application or network layer.
3. Transport TCP, UDP, DCCP, SCTP, IL, RUDP, …
2. Internet Routing protocols like OSPF, which run over IP, are also to be considered part of the network layer, as they provide path selection. ICMP and IGMP run over IP and are considered part of the network layer, as they provide control information.
IP (IPv4, IPv6)
ARP and RARP operate underneath IP but above the link layer so they belong somewhere in between.
1. Network access Ethernet, Wi-Fi, token ring, PPP, SLIP, FDDI, ATM, Frame Relay, SMDS, …

OSI

OSI Model

Data unit Layer Function
Host
layers
Data 7. Application Network process to application
6. Presentation Data representation and encryption
5. Session Interhost communication
Segments 4. Transport End-to-end connections and reliability (TCP)
Media
layers
Packets 3. Network Path determination and logical addressing (IP)
Frames 2. Data link Physical addressing (MAC & LLC)
Bits 1. Physical Media, signal and binary transmission

TCP/IP & Internet

1969 ARPA (Advanced Research Projects Agency) funded a research and development project to create ARPAnet network.
1975 Converted from an experimental network to an operational network.
1983 TCP/IP protocols were adopted as Military Standards (MIL STD)
Internet: MILNET plus ARPAnet

Sep 18, 2007

Convert string to html table

#!/bin/sh
sed -e '/^[A-Za-z0-9]*[^\:]$/{
d
}' < source_file > tmp_file
echo "<table>" > destination_file.html
sed -e '/:/{
s/^/<tr><td>/g
s/\:/<\/td><td>/g
s/$/<\/td><\/tr>/g
}' < tmp_file >> destination_file.html
echo "</table>" >> destination_file.html

Sep 14, 2007

Replace file contents by perl

#!/usr/bin/perl -w
# use strict;

sub replace_str($$$)
{
my $line = shift;
my $old_string = shift;
my $new_string = shift;

if($line =~ m/($old_string)/)
{
$line =~ s/$old_string/$new_string/;
}
return $line;
}

open (SOURCE_FILE, "source.txt");
open (DESTINATION_FILE, '>>destination.txt');

while ($line = <source_file>) {
$line = replace_str($line,"2","3");
print DESTINATION_FILE $line;
}

close(SOURCE_FILE);
close (DESTINATION_FILE);

SED notes

Replace in sed
sed -e '/pattern/{
s/old1/new1/g
s/old2/new2/g
}' < source_file > destination_file

Aug 14, 2007

Date in shell script

Date in shell script
"date +%d" -->"31"
"date +%y" -->"02"
"date +%m" -->"03"
"date +%a" --> "Sun"
"date +%b" --> "Mar"
"date +%c" -->"03/31/02 00:50:08"
"date +%h" -->"Mar"
"date +%j" -->"090"
"date +%l" -->"12"
"date +%p" -->"AM"
"date +%r" -->"12:54:29 AM"
"date +%s" -->"1017536118"
"date +%w" -->"0"
"date +%x" -->"03/31/02"

Aug 12, 2007

Change hostname and ip

Change hostname and ip as /etc/hosts file of linux
C:\WINDOWS\system32\drivers\etc\

Aug 6, 2007

Design Pattern - Thiết kế theo mô hình mẫu

- Phạm Đình Trường-
Trong phát triển phần mềm hiện đại, kiến trúc tổng thể của dự án đóng một vai trò quan trọng, đặc biệt với bộ khung (framework) và mẫu thiết kế (design pattern). Bài viết này sẽ giúp các bạn hiểu được một cách tổng quan về pattern cũng như cách thức thiết kế một số pattern tiêu biểu.

PATTERN là gì?

Pattern mô tả một giải pháp chung đối với một vấn đề nào đó trong thiết kế thường được “lặp lại” trong nhiều dự án. Nói một cách khác, một pattern có thể được xem như một “khuôn mẫu” có sẵn áp dụng được cho nhiều tình huống khác nhau để giải quyết một vấn đề cụ thể. Trong bất kỳ hệ thống phần mềm hướng đối tượng nào chúng ta cũng có thể bắt gặp các vấn đề lặp lại.

Đặc điểm chung:

• Pattern được hiểu theo nghĩa tái sử dụng ý tưởng hơn là mã lệnh. Pattern cho phép các nhà thiết kế có thể cùng ngồi lại với nhau và cùng giải quyết một vấn đề nào đó mà không phải mất nhiều thời gian tranh cãi. Trong rất nhiều trường hợp, dự án phần mềm thất bại là do các nhà phát triển không có được sự hiểu biết chung trong các vấn đề về kiến trúc phần mềm. Ngoài ra, pattern cũng cung cấp những thuật ngữ và khái niệm chung trong thiết kế. Nói một cách đơn giản, khi đề cập đến một pattern nào đấy, bất kỳ ai biết pattern đó đều có thể nhanh chóng hình dung ra “bức tranh” của giải pháp. Và cuối cùng, nếu áp dụng pattern hiệu quả thì việc bảo trì phần mềm cũng được tiến hành thuận lợi hơn, nắm bắt kiến trúc hệ thống nhanh hơn.

• Pattern hỗ trợ tái sử dụng kiến trúc và mô hình thiết kế phần mềm theo quy mô lớn. Cần phân biệt design pattern với framework. Framework hỗ trợ tái sử dụng mô hình thiết kế và mã nguồn ở mức chi tiết hơn. Trong khi đó, design pattern được vận dụng ở mức tổng quát hơn, giúp các nhà phát triển hình dung và ghi nhận các cấu trúc tĩnh và động cũng như quan hệ tương tác giữa các giải pháp trong quá trình thiết kế ứng dụng đối với một chuyên khu riêng biệt.

• Pattern đa tương thích. Pattern không phụ thuộc vào ngôn ngữ lập trình, công nghệ hoặc các nền tảng lớn như J2EE của Sun hay Microsoft .NET Framework.

Tiềm năng ứng dụng của pattern là rất lớn. Các thiết kế dựa trên pattern được sử dụng khá nhiều ở các phần mềm mã nguồn mở, trong nền tảng J2EE hoặc .NET... Trong các dạng ứng dụng này, có thể dễ dàng nhận ra một số tên lớp chứa các tiền tố hoặc hậu tố như Factory, Proxy, Adapter...

PHÂN LOẠI PATTERN

Pattern được phân loại ra làm 3 nhóm chính sau đây:

Nhóm cấu thành (Creational Pattern): Gồm Factory, Abstract Factory, Singleton, Prototype, Builder... Liên quan đến quá trình khởi tạo đối tượng cụ thể từ một định nghĩa trừu tượng (abstract class, interface).

Nhóm cấu trúc tĩnh (Structural Pattern): Gồm Proxy, Adapter, Wrapper, Bridge, Facade, Flyweight, Visitor... Liên quan đến vấn đề làm thế nào để các lớp và đối tượng kết hợp với nhau tạo thành các cấu trúc lớn hơn.

Nhóm tương tác động (Behavioral Pattern): Gồm Observer, State, Command, Iterator... Mô tả cách thức để các lớp hoặc đối tượng có thể giao tiếp với nhau.

Dưới đây chúng ta sẽ tìm hiểu chi tiết một số pattern tiêu biểu nhất: Factory, Abstract Factory, Singleton, Proxy, Adapter và Wrapper. Chúng ta quy ước với nhau rằng “giao diện lớp” được hiểu như interface hoặc abstract class vì đây đơn thuần là các định nghĩa lớp.

FACTORY PATTERN

Định nghĩa

Factory Pattern định nghĩa một lớp (interface, abstract, class) đóng vai trò như một “nhà xưởng” có nhiệm vụ khởi tạo đối tượng “cụ thể” khi ứng dụng chạy. Tại thời điểm thiết kế đối tượng này được định nghĩa trừu tượng.

Đặc điểm

Kiểm soát được các hoạt động trong suốt chu kỳ sống của đối tượng, như khởi tạo đối tượng, huỷ đối tượng... Đảm bảo cho các đối tượng được thực thi an toàn. Nắm được thông tin về những đối tượng nào được tạo ra và được khởi tạo ra sao. Nói cách khác, các đối tượng được quản lý tốt hơn và an toàn hơn với Factory Pattern.

Đối tượng Factory thường được đặt tên theo những chuẩn khác nhau nhưng vẫn có thể dễ dàng nhận ra thiết kế Factory Pattern ẩn chứa trong đó. Ví dụ: BankFactory,...

Tính chất đóng gói (encapsulation) thể hiện rõ trong Factory Pattern; các thông tin liên quan đến truy cập đối tượng được che giấu trong Factory. Thiết kế Factory luôn có một thủ tục khởi tạo đối tượng, ví dụ createObject().

Factory Pattern tuân thủ nguyên tắc thiết kế DIP (Dependency Inversion Principle): không nên phụ thuộc vào những thứ quá cụ thể.

Phân loại

Factory Pattern được thiết kế theo một trong hai cách sau đây:

Based-class Factory Pattern: Mẫu này sử dụng tính chất thừa kế để phân loại các đối tượng được tạo ra.

Based-object Factory Pattern: Sử dụng mối quan hệ kết hợp để tham chiếu tới một đối tượng sẽ được tạo ra. Đối tượng được tạo ra sẽ trở thành một phần hay thuộc tính của lớp Factory. Chúng ta thường hay gặp loại này trong Abstract Factory Pattern được trình bày ở phần tiếp theo.

ABSTRACT FACTORY PATTERN

Định nghĩa

Abstract Factory cung cấp một giao diện lớp có chức năng tạo ra một tập hợp các đối tượng liên quan hoặc phụ thuộc lẫn nhau mà không chỉ ra đó là những lớp cụ thể nào tại thời điểm thiết kế.

Về bản chất, Abstract Factory Pattern chỉ khác Factory Pattern ở chỗ bản thân đối tượng Factory không được chỉ ra cụ thể tại thời điểm thiết kế, tức nó là một giao diện hoặc lớp trừu tượng (interface, abstract). Nếu như Factory Patttern phân loại đối tượng dựa trên tham số đầu vào thì đối với Abstract Factory Pattern, thủ tục createObject() còn phụ thuộc thêm vào các yếu tố phụ khác như môi trường hệ điều hành chẳng hạn. Ứng với mỗi yếu tố phụ thứ hai ta có một lớp Factory cụ thể.

Thiết kế động với Abstract Factory
Một trong những vấn đề gặp phải là khung giao diện Abstract Factory thường hay bị sửa đổi, thí dụ như bổ sung thủ tục chẳng hạn, khi đó các lớp cụ thể thực thi giao diện này sẽ phải được dịch và triển khai lại. Để giảm nhẹ vấn đề này người ta thường thiết kế giao diện Abstract Factory một cách linh động.

SINGLETON PATTERN
(Static Factory Pattern)

Định nghĩa

Singleton Pattern đảm bảo một lớp chỉ có một thực thể (instance) duy nhất được tạo ra và đồng thời cung cấp một truy cập toàn cục đến đối tượng được tạo ra.
Chúng ta xét trường hợp có nhiều đối tượng có cùng chung một số tính chất nào đó được tạo ra ứng với mỗi một yêu cầu từ các đối tượng khách (client), lúc này độ phức tạp sẽ tăng lên và ứng dụng sẽ chiếm dụng nhiều vùng nhớ hơn. Singleton Pattern là một giải pháp đặc biệt của Factory Pattern ở chỗ đối tượng sinh ra là điểm truy cập toàn cục “duy nhất” đối với mọi chương trình gọi đến, hay nói một cách khác tất cả các đối tượng khách gọi đến đều chia sẻ đối tượng được tạo ra.

Ứng dụng rõ rệt nhất của Singleton Pattern có thể thấy trong dịch vụ web khi triệu gọi các đối tượng từ xa, ở đó đối tượng nằm trên server hoặc sẽ phục vụ chung cho tất cả các ứng dụng khách (singleton) hoặc sẽ chỉ đáp ứng một ứng dụng khách riêng lẻ nào đó rồi tự bị phá huỷ sau đó (single call).

Về các mẫu thiết kế tiêu biểu trong nhóm cấu thành: Factory, Abstract Factory và Singleton, các bạn có thể tham khảo thêm tài liệu về phương pháp xây dựng cụ thể cũng như mã nguồn chương trình viết bằng C#.NET tại địa chỉ:

http://www.codeproject.com/gen/design/CSharpClassFactory.asp

PROXY PATTERN

Định nghĩa

Proxy Pattern là mẫu thiết kế mà ở đó tất cả các truy cập trực tiếp một đối tượng nào đó sẽ được chuyển hướng vào một đối tượng trung gian (Proxy Class).
Nếu như Factory Pattern giúp quản lý đối tượng tốt hơn thì Proxy Pattern lại có nhiệm vụ bảo vệ việc truy cập một đối tượng thông qua Proxy, hay còn gọi là truy cập gián tiếp. Proxy được ủy quyền về phía ứng dụng khách cho phép tương tác với đối tượng đích theo những cách khác nhau; như gửi yêu cầu một dịch vụ nào đó, theo dõi trạng thái và vòng đời đối tượng, xây dựng lớp vỏ bảo vệ đối tượng... Thí dụ chúng ta phát hiện ra một đối tượng trong một thư viện DLL có thể bị khai thác truy cập vào một số trường quan trọng, khi đó chúng ta không thể mở mã nguồn thư viện đã được dịch để vá lỗ hổng, giải pháp lúc này là xây dựng một proxy ngăn chặn truy cập các trường đó và cuối cùng biên dịch lại thành một DLL mới.

Phân loại

Độ phức tạp của giải pháp sử dụng Proxy Pattern phụ thuộc vào tình huống bài toán đưa ra, chúng ta sẽ lần lượt tìm hiểu nguyên tắc làm việc của các proxy dưới đây:
Remote Proxy: Client truy cập qua remote proxy để tham chiếu tới một đối tượng được bảo vệ nằm bên ngoài ứng dụng (trên cùng máy hoặc máy khác) như dịch vụ Windows, dịch vụ web, ứng dụng ở xa... Mô hình này "che giấu" đối tượng được triệu gọi đang nằm ở rất xa đâu đó và client có vẻ như truy cập vào đối tượng nằm trên cùng một chuyên khu làm việc (domain).

Virtual Proxy: Virtual Proxy tạo ra một đối tượng trung gian mỗi khi có yêu cầu tại thời điểm thực thi ứng dụng, nhờ đó làm tăng hiệu suất của ứng dụng.

Monitor Proxy: Monitor Proxy sẽ thiết lập các ràng buộc bảo mật trên đối tượng cần bảo vệ, ngăn không cho client truy cập một số trường quan trọng của đối tượng.

Protection Proxy: Đối với proxy này thì phạm vi truy cập của các client khác nhau sẽ khác nhau. Protection Proxy sẽ kiểm tra các quyền truy cập của client khi có một dịch vụ được yêu cầu.

Cache Proxy: Cung cấp không gian lưu trữ tạm thời cho các kết quả trả về từ đối tượng nào đó, kết quả này sẽ được tái sử dụng cho các client chia sẻ chung một yêu cầu gửi đến và do đó làm tăng đáng kể hiệu suất chương trình.

Firewall Proxy: Bảo vệ đối tượng từ chối các yêu cầu xuất xứ từ các client không tín nhiệm.

Smart Reference Proxy: Là nơi kiểm soát các hoạt động bổ sung mỗi khi đối tượng được tham chiếu, ví dụ như kiểm soát vòng đời của đối tượng, lưu lại số lần tham chiếu vào đối tượng...

Synchronization Proxy: Đảm bảo nhiều client có thể truy cập vào cùng một đối tượng mà không gây ra xung đột. Thực tế có rất nhiều tình huống khiến chúng ta phải nghĩ đến thiết kế này. Một synchronization proxy được thiết lập có thể kiểm soát được nhiều yêu cầu cập nhật dữ liệu một cách đồng thời, tại thời điểm bắt đầu cập nhật chỉ có một client với mức ưu tiên cao nhất giành được khoá để đánh dấu rằng các client khác cần phải chờ đến lượt.

Synchronization proxy hoạt động rất hiệu quả và phổ biến trong thiết kế các bài toán đa tuyến. Một hiện tượng hay xảy ra với thiết kế này là khi một client nào đó chiếm dụng khoá khá lâu (và thậm chí là mãi mãi) khiến cho số lượng các client trong danh sách hàng đợi cứ tăng lên, và do đó hoạt động của hệ thống bị ngừng trệ, có thể dẫn đến hiện tượng “tắt nghẽn” là hiện tượng khoá được giữ vô thời hạn bởi một đối tượng nào đó. Trong trường hợp này người ta cải tiến thành mẫu thiết kế phức tạp hơn, đó là Copy-On-Write Proxy.

Copy-On-Write Proxy: Cope-On-Write Proxy đảm bảo rằng sẽ không có client nào phải chờ vô thời hạn. Thiết kế này rất phức tạp do đó chỉ nên ứng dụng Copy-On-Write Proxy thay thế Synchronization Proxy khi hệ thống được dự đoán sẽ thường xuyên bị ngừng trệ hoặc có hiện tượng “tắt nghẽn” xảy ra.

Đặc điểm chung

Proxy Pattern có những đặc điểm chung sau đây:

• Cung cấp mức truy cập gián tiếp vào một đối tượng.

• Tham chiếu vào đối tượng đích và chuyển tiếp các yêu cầu đến đối tượng đó.

• Cả proxy và đối tượng đích đều kế thừa hoặc thực thi chung một lớp giao diện. Mã máy dịch cho lớp giao diện thường “nhẹ” hơn các lớp cụ thể và do đó có thể giảm được thời gian tải dữ liệu giữa server và client.

ADAPTER PATTERN

Định nghĩa

Adapter Pattern biến đổi giao diện của một lớp thành một giao diện khác mà các đối tượng client có thể hiểu được. Lớp với giao diện được tạo ra đó gọi là Adapter. Nguyên tắc cơ bản của Adapter Pattern nằm ở chỗ làm thế nào để các lớp với các giao diện không tương thích có thể làm việc được với nhau.

Nguyên lý xây dựng Adapter Pattern khá đơn giản: chúng ta xây dựng một lớp với một giao diện mong muốn sao cho lớp đó giao tiếp được với một lớp cho trước ứng với một giao diện khác.

Adapter Pattern không quản lý tập trung các đối tượng gần giống nhau như Factory Pattern, mà kết nối với nhiều lớp không có liên quan gì với nhau. Ví dụ lớp A sau khi thực thi giao diện của nó và vẫn muốn bổ sung các phương thức từ một lớp B nào đó, chúng ta có thể kết nối A với B thông qua hình thức kế thừa hoặc liên kết đối tượng như một thành phần. Adapter Pattern có sự giống nhau một chút với Proxy Pattern ở chỗ nó tận dụng tối đa tính chất “uỷ quyền” (delegation); lớp Adapter sẽ kết nối với một đối tượng nào đó gọi là Adaptee và Adapter sẽ được uỷ quyền truy cập vào Adaptee, lớp Adapter đóng vai trò như một kênh trung gian để client truy cập vào một số các thành phần quan trọng của lớp Adaptee.

Đặc điểm

• Adapter Pattern hướng tập trung vào giải quyết sự tương thích giữa hai giao diện đang tồn tại, giảm công sức viết lại mã lệnh xuống mức tối thiểu có thể được.

• Tái sử dụng giao diện cũ và Adapter Pattern chỉ thực sự cần thiết khi mọi thứ đã được thiết kế từ trước.

Phạm vi ứng dụng

Adapter Pattern được ứng dụng trong các trường hợp:

• Cần tích hợp một vài module vào chương trình.

• Không thể sát nhập trực tiếp module vào chương trình (ví dụ như module thư viện đã được dịch ra .DLL, .CLASS...).

• Module đang tồn tại không có giao diện mong muốn như:

- Cần nhiều hơn phương thức cho module đó.

- Một số phương thức có thể được nạp chồng.

WRAPPER PATTERN

Wrapper Pattern là một trường hợp đặc biệt của Adapter Pattern. Nếu một Adapter chỉ đơn thuần là “nhúng” (wrap) các lớp với các giao diện không tương thích với nhau để chúng có thể hoạt động cùng nhau thì có thể được gọi bằng tên riêng Wrapper Pattern. Khi đó lớp Adapter còn được gọi là lớp Wrapper. Đây là quan hệ “có một”, tức là một giao diện không tương thích có thể được nhúng vào thành một phần của một giao diện khác.

Đặc điểm

Đối tượng Wrapper mô phỏng tất cả các hành vi (hàm, thủ tục) của giao diện được nhúng bởi các hành vi với tên y hệt. Thí dụ nếu lớp được nhúng A có thủ tục SpecificRequest() thì lớp Wrapper cũng phải có thủ tục SpecificRequest() tham chiếu đến thủ tục cùng tên của A. (Ngoài ra đối tượng Wraper có thể được bổ sung các phương thức khác nếu cần thiết). Đặc điểm này được đưa ra dựa trên nguyên tắc thiết kế “Law of Demeter” nói rằng không nên tham chiếu một đối tượng sâu hơn một lớp.

Các phương thức trong Adaptee được “nhúng” trong Wrapper bằng cách truyền lời gọi cùng với các tham số tới phương thức tương ứng trong Adaptee, và trả về kết quả giống như vậy. Các thành viên (thuộc tính, trường, sự kiện) được nhúng trong Wrapper có tính chất giống hệt như trong các lớp được nhúng (tên, kiểu dữ liệu, phạm vi truy cập...).

Từ các đặc điểm ở trên, có thể thấy rằng Wrapper Pattern cho phép một module chương trình tương tác được trong một môi trường khác biệt với môi trường phát triển của module đó (ví dụ C++ và Java).

Khác biệt giữa Wrapper Pattern và Adapter Pattern

Sự khác biệt giữa Wrapper và Adapter nằm ở mục đích sử dụng: Adapter Pattern định hướng cho một đối tượng đang tồn tại có thể làm việc được với các đối tượng khác và biến đổi logic theo một cách thức nào đó, trong khi Wrapper Pattern chỉ đơn thuần cung cấp một giao diện kết hợp các đối tượng được xây dựng từ cùng một ngôn ngữ hoặc khác ngôn ngữ, trên cùng một hệ điều hành hoặc trên những hệ điều hành khác nhau.

Proxy Adapter Pattern

Nếu một lớp Adapter đóng thêm vai trò như một proxy bảo vệ cho Adaptee thì ta có mô hình Proxy Adapter Pattern, trong trường hợp này chúng ta có thể đặt tên lớp với nghĩa kết hợp, ví dụ BankProxyAdapter.

Lời kết

Bài viết này đưa ra một số mẫu thiết kế tiêu biểu giúp các bạn thấy được tầm quan trọng của design pattern trong việc nâng cao chất lượng phần mềm ở các yếu tố: hiệu suất ứng dụng, độ ổn định, tái sử dụng, tính bảo mật... Các bạn có thể tìm hiểu thêm về các mẫu thiết kế cao cấp khác ở rất nhiều tài liệu thiết kế phần mềm.

Aug 4, 2007

Alert new mail plugin for Thunderbird

https://addons.mozilla.org/en-US/thunderbird/addon/2610

Aug 3, 2007

Japanese font for Linux

Download language package from
http://www.adobe.com/products/acrobat/acrrasianfontpack.html
And
$ tar xzf FontPack708_jpn_i386-linux.tar.gz
$ cd JPNKIT/
$ ./INSTALL

Aug 1, 2007

Subversion command line

Some basic command should remember
svn add — Add files and directories.
$ svn add testdir
svn checkout — Check out a working copy from a repository.
$ svn co http://mangmaytinh.biz.tm/repos/
svn commit — Send changes from your working copy to the repository.
$ svn ci -m "commit"
svn cleanup — Recursively clean up the working copy.
svn delete — Delete an item from a working copy or the repository.
svn diff — Display the differences between two paths.
svn update — Update your working copy.

SSH with cryptography

About public key cryptography
Public key cryptography uses a public key to encrypt data and a private key to decrypt it.
It is save to send your public key (~/.ssh/id_rsa.pub) to install in remove site (~/.ssh/authorized_keys file in other host).
For anyone to actually gain access they need the corresponding private key (~/.ssh/id_rsa) to identify themselves.
Creating authentication key
Creating authentication key
$ ssh-keygen -t rsa
enter pass phrase more difficult more good but you must remember it.
We can create multiple key for multiple accounts.
Changing pass phrase
$ ssh-keygen -p
Authorizing access
$ cd ~/.ssh
$ cp id_rsa.pub authorized_keys
$ scp -p ~/.ssh/authorized_keys remote_host:.ssh/
Note: Directory and file permission
If access to the remote system is still denied you should check the permissions
drwx------ 2 huusan huusan 4096 2007-08-01 16:43 .ssh
-rw-r--r-- 1 huusan huusan 410 2007-08-01 16:43 authorized_keys
Logging into remote systems
$ ssh remote_host
or
$ slogin remote_host
if change user
$ ssh -l username remote_host
Keeping authentication keys in memory
Add key to memory
$ ssh-add
type your pass phrase
Delete key
$ ssh-add -d ~/.ssh/id_rsa
Delete all key
$ ssh-add -D
List key in memory
$ ssh-add -l

Install Subversion with Apache

After your system is up to date go get apache 2.0, subversion and webdav module

yum install httpd
yum install subversion
yum install mod_dav_svn
Now we need to create the directory for the repository:

mkdir /usr/local/svn

Now we need to create the repository

svnadmin create --fs-type fsfs /usr/local/svn
svn import /tmp/webqs/ file:///usr/local/svn/webqs/ -m "Initial import"
We need to configure apache
vi /etc/httpd/conf/httpd.conf

add
<location /repos>
DAV svn
SVNPath /usr/local/svn

# how to authenticate a user
AuthType Basic
AuthName "Subversion repository"
AuthUserFile /etc/svn-auth-file

# For any operations other than these, require an authenticated user.
<LimitExcept GET PROPFIND OPTIONS REPORT>
Require valid-user
</Location>
Create a user and password (if you want to create more users leave out the -c switch, just use -m)

htpasswd -cm /etc/svn-auth-file huusan
New password: *****
Re-type new password: *****
Adding password for user huusan

Restart httpd service
# service httpd restart
After it boots back up open a web browser to your subversion machine (http://127.0.0.1/repos) it will prompt you for your user name and password and there you go.

Jul 18, 2007

Directory Server

What is a Directory Server?

A directory server provides a centralized directory service for your intranet, network, and extranet information. Directory Server integrates with existing systems and acts as a centralized repository for the consolidation of employee, customer, supplier, and partner information. You can extend Directory Server to manage user profiles and preferences, as well as extranet user authentication.

How is a Directory Server different from a Relational Database?

An LDAP directory server stores information in a tree-like heirarchical structure.

The characteristics of an LDAP server are:

  • very fast read operations

  • fairly static data

  • hierarchical

  • clients use standard LDAP protocol

  • loosely coupled replication

The characteristics of an RDMBS are:

  • very fast write operations (think TPS)

  • dynamic data

  • tables with rows and columns, with key relations between tables

  • no standard on the wire protocol - vendors must provide ODBC or JDBC drivers

  • tightly coupled replication - Two Phase Commit

What is LDAP?

LDAP provides a common language that client applications and servers use to communicate with one another.

What is Fedora Directory Server?

A secure, highly scalable, robust LDAP server.

Install Fedora-ds

$ wget http://directory.fedoraproject.org/download/fedora-ds-1.0.4-1.FC6.i386.opt.rpm

$ rpm -ihv *.rpm

$ cd /opt/fedora-fs

$ ./setup/setup

Installation guide in

(http://directory.fedoraproject.org/wiki/Install_Guide)

Run

$ ./startconsole -u admin -a http://domain.com:28365/

Jul 17, 2007

netstat command

netstat -anp | grep 60000
Answer for question: Have any program run on port 60000

Jul 8, 2007

VirtualHost in Apache Sample

Create two virtual host anh.biz.tm and mangmaytinh.biz.tm
Append to the end of file /etc/httpd/conf/httpd.conf

NameVirtualHost *:80
<
VirtualHost *:80>
ServerAdmin onlyyoumakemesmile@gmail.com
DocumentRoot /var/www/html/anh.biz.tm/simpleviewer
ServerName anh.biz.tm
ErrorLog logs/anh.biz.tm-error_log
CustomLog logs/anh.biz.tm-access_log common
</
VirtualHost>

<VirtualHost *:80>
ServerAdmin onlyyoumakemesmile@gmail.com
DocumentRoot /var/www/html/mangmaytinh.biz.tm/wordpress
ServerName mangmaytinh.biz.tm
ErrorLog logs/mangmaytinh.biz.tm-error_log
CustomLog logs/mangmaytinh.biz.tm-access_log common
</VirtualHost >


Test syntax using
$ httpd -S

Install VNCserver in Fedora Core 7

- Installation
$ yum -y install vnc*
- Starting with no configuration file
$ vncserver :1
Only xterm interface
$ vncserver -kill :1
to kill display 1
- Configuration
$ vi ~/.vnc/xstartup
Comment
twm &
And append
init 5
startkde &

Note: init 5 is necessary only when your server start with runlevel other than 5

Install and config MySQL

Installation
yum install mysql
yum install mysql-server
yum install mysql-administrator
Configuration
chkconfig --levels 235 mysqld on
Starting
/etc/init.d/mysqld start
Changing the root password
mysqladmin -u root password your_root_sql_password
Backup
One database
mysqldump --single-transaction nhungnguoibantot_db > backup_nhungnguoibantot_db.sql -p
All databases
mysqldump --single-transaction --all-databases > backup_all_databases.sql -p
Restore
One databases
mysql > create database nhungnguoibantot_db;
mysql -u root -p < backup_nhungnguoibantot_db.sql
All databases
mysql -u root -p <
backup_all_databases.sql
Show all databases
mysql>show databases;
Connect to database
connect database_name;
Show all tables of a database
mysql>show tables;
Create a new user to manage database
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
ON database_name
TO 'username'@'localhost'
IDENTIFIED BY 'password';

Configure PostgreSQL

To connect from other host than locahost
- In file postgresql.conf (/var/lib/pgsql/data/postgresql.conf)
Change or add
listen_addresses = "*"
- In file pg_hba.conf
Allow connect from localhost
host all all 192.168.1.0/24 trust
Allow connect from internet
host all all 0.0.0.0/0 trust

note
0.0.0.0/a mean that IP in a range of 0.0.0.0 with a bits is fixed

Installing inadyn as afraid.org Dynamic DNS client

Install by yum
# yum -y install inadyn.i386
Configure
# vi /etc/inadyn.conf

dyndns_system default@freedns.afraid.org
username userpublic
password passpublic
alias mangmaytinh.biz.tm,Um9ALVNVTVRTTUlBQUNzb21ZMDoyMTcwNTE0
update_period 60000
log_file /var/log/inadyn.log
background

with "Um9ALVNVTVRTTUlBQUNzb21ZMDoyMTcwNTE0" is hash(Direct URL http://freedns.afraid.org/dynamic/update.php?Um9ALVNVTVRTTUlBQUNzb21ZMDoyMTcwNTE0) that you can get it from http://freedns.afraid.org/dynamic/ after you regist a subdomain
Configure start up daemon
# chkconfig --level 345 inadyn on
Start service
# service inadyn start
Check daemon run
# vi /var/log/inadyn.log
Debug
# inadyn --dyndns_system default@freedns.afraid.org -a mangmaytinh.biz.tm,Um9ALVNVTVRTTUlBQUNzb21ZMDoyMTcwNTE0 -u userpublic -p passpublic --verbose 5
add --verbose 5 to see detail error

Jul 7, 2007

Find computer in LAN

Find computer in LAN
Using the PCFinder

Switching from GDM to KDM

Check for GDM and KDE available
# kde-menu --version
# gdm --version
Run KDE
# startkde --replace
Run GDM
# gdm start
in /etc/sysconfig/desktop append
DISPLAYMANAGER="KDE"

Jul 4, 2007

rpm

Check what postgres packages are installed:
rpm -qa | grep -i postgres
Uninstall postgres:
rpm -e --nodeps `rpm -qa| grep -i postgres`

Jun 25, 2007

Cài đặt Unikey trên Fedora

Download Unikey (*.rpm file) từ http://www.unikey.org/linux.php
# rpm -ihv *.rpm
Sau khi cài đặt Unikey, hãy đăng xuất (log out) rồi đăng nhập (login) trở lại. Chạy "unikey", bạn sẽ sử dụng được Unikey ngay lập tức mà không phải làm gì nữa. Nếu không ở trong trường hợp này, hãy thử các bước sau:

- Thêm các dòng sau vào tập tin ~/.bash_profile hoặc ~/.bashrc:
export XMODIFIERS="@im=unikey"
export GTK_IM_MODULE="xim"
- Đăng nhập lại
- Chạy unikey
# unikey
Chú ý:
Sau khi bạn cài đặt Unikey sẽ ảnh hưởng đến môi trường tiếng nhật bạn đang dùng

Jun 18, 2007

Managing Storage

Managing Storage

Overview of Storage Hardware

Device files

the device files for disk drives appear in the /dev/ directory.

Device type

sd – the device is SCSI-based

hd – the device is ATA-based

The first hard drive on system may appear as hda or sda

Unit

Following the two-letter device type are one or two letters denoting the specific unit

Partition

the partition on the device is represented by number in the end of device name

/dev/hda1 (ATA drive)

/dev/sdad4 (SCSI device)

Mounting file system

Mounting point

Basically, mounting points are where you mount your file systems or devices.

Seeing What is Mounted

Viewing /etc/mtab

# vi /etc/mtab

The /etc/mtab file is meant to be used to display the status of currently-mounted file systems only. It should not be manually modified.

Viewing /proc/mounts

# vi /proc/mounts

(The Proc psuedo file system is a real time, memory resident file system that tracks the processes running on your machine and the state of your system.)

df – command

Lets we know what file systems are currently mounted and the amount of free space on them.

Filesystem 1K-ブロック 使用 使用可 使用% マウント位置

/dev/mapper/VolGroup00-LogVol00

99636632 10652432 83841264 12% /

/dev/sda1 101086 16258 79609 17% /boot

/dev/mapper/VolGroup00-LogVol02

49611460 1517004 45533640 4% /data

tmpfs 511684 0 511684 0% /dev/shm

Network-Accessible Storage Under Linux

NFS (Network File System)

is a file system that may be accessed via a network connection.

The file systems an NFS server makes available to clients is controlled by the configuration file /etc/exports.

SMB (Server Message Block)

is the name for the communications protocol used by various operating systems produced by Microsoft.

Red Hat Linux supports SMB via the Samba server program.

Mounting File systems automatically with /etc/fstab

#vi /etc/fstab

Mornitoring Disk Space

df – command

# df

-h option for understand by human

Automated Monitoring Using diskcheck

Automatically check disk and send email to administrator.

Adding/Removing Storage

Adding Storage

  • Partitioning

    • Using the command-line fdisk utility program

    • Using parted, another command-line utility program

  • Formatting the partition(s)

    # mkfs

  • Updating /etc/fstab

    to automatically mount to system.

Removing Storage

  • Remove the disk drive's partition from /etc/fstab

  • Unmount the disk drive's active partitions.

    # umount path

  • Erase the contents of the disk drive.

    # badblocks -ws

Disk Quotas

Disk quotas under Red Hat Linux have the following features:

  • Per-file-system implementation

  • Per-user space accounting

  • Per-group space accounting

  • Tracks disk block usage

  • Tracks disk inode usage

  • Hard limits

  • Soft limits

  • Grace periods

Physical and Virtual Memory

Storage Access Patterns

  • Access tends to be sequential

If address N is accessed by the CPU, it it highly likely that address N+1 will be accessed next.

  • Access tends to be localized

If address X is accessed, it is likely that other addresses surrounding X will also be accessed in the future.

The Storage Spectrum

Storage technologies:

  • CPU registers

  • Cache memory

  • Ram

  • Hard drives

  • Off-line backup storage (tape, optical disk, etc.)

Virtual Memory

Virtual memory is a portion of the hard disk that operation system uses to application programs to meet the require exceeds the amount of physical memory available.

Paging occurs when an active process requires more memory than what is accessible in physical memory. Portions of the process are moved to disk so the physical memory can be used for something else.

Swapping is done by the kernel. When memory space is running low the kernel looks for a process that isn't likely to run in the near future. That process is written entirely to disk, and the newly-freed memory is reassigned to another process or job.

Virtual Memory in Redhat Linux

    Using free to get a concise overview of memory and swap utilization.

$ free

total used free shared buffers cached

Mem: 1023368 1004148 19220 0 14544 277328

-/+ buffers/cache: 712276 311092

Swap: 2031608 198436 1833172

System has 1G of RAM, about ~1004 MB is actually in use. ~198 MB of swap is in use.

sar [-a] [-A] [-b] [-c] [-d] [-g] [-k] [-m] [-p] [-q] [-r] [-u] [-v] [-w] [-y ] [ -o filename ] t [ n ]

Viewing result of sar -r

091712LINUX RESTART
09
2002 kbmemfree kbmemused %memused kbbuffers kbcached kbswpfree kbswpused %swpused kbswpcad
09
300235432 987936 96.54 30024 523368 2031444 164 0.01 0
09
400133080 990288 96.77 37776 512900 2031444 164 0.01 0
09
500113600 1009768 98.67 45868 516460 2031444 164 0.01 0
10
000157096 966272 94.42 52216 469420 2031444 164 0.01 0
平均値
: 34802 988566 96.60 41471 505537 2031444 164 0.01 0
kb: Kilobytes of memory allocated to
sar -W

091712LINUX RESTART
09
2002pswpin/s pswpout/s
09
30020.00 0.07
09
40010.00 0.00
09
50010.00 0.00
10
00010.00 0.00
平均値
: 0.00 0.02

page swap in per second (pswpin/s)
page swap out per second (pswpout/s)

Jun 13, 2007

Resource Monitoring

All systems have the following resources available:
  • CPU power
  • Bandwidth
  • Memory
  • Storage
Purpose of Resouce mornitoring:
+ System have problem, can we improve its performence? (system performence monitoring)
+ System run well now, can we keep it later? (monitoring system capacity)
  • System performence monitoring
    • Determine the cause of problem
    • Analyze the the data that produced from monitoring, to solve the problem
    • Ensure the performence problem has been resolved
  • Monitoring system capacity
Monitoring CPU Power
Monitoring Bandwidth
Monitoring Memory
Monitoring Storage
Tools for resource monitoring
free
Display amount of free and used memory in the system
# free
total used free shared buffers cached
Mem: 1023368 966064 57304 0 24704 247628
-/+ buffers/cache: 693732 329636
Swap: 2031608 164 2031444

Mem row: displays the physical memory utilization.
Swap row: displays the utilization of the system swap space.
+/- buffers/cache row: display the amount of physical memory currently devoted to system buffers.
to view it change with time using
#watch free
#watch -n 1 -d free
-n to set delay time, -d to highline the change

top
Display a lot of things.
#top
#gnome-system-monitor
vmstat
To get an overview of process, memory, swap, I/O, system, and CPU activity in one line of numbers:
# vmstat
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 164 68416 10204 251848 0 0 47 38 1121 1038 8 2 89 1 0
Procs
r: The number of runnable processes waiting for access to the CPU
b: The number of processes in an uninterrupible sleep state
Memory
swpd: The amount of virtual memory used
free: The amount of free memory
buff: The amount of memory used for buffers
cache: The amount of memory used as page cache
Swap
si: The amount of memory swapped in from disk
so: The amount of memory swapped out to disk
IO
bi: Blocks sent to a block device
bo: Blocks received from a block device
System
in: The number of interrupts per second
cs: The number context switches per second
CPU
us: The percentage of the time the CPU ran user-level code
sy: The percentage of the time of CPU ran system-level code
id: The percentage of the time the CPU was idle
wa: The percentage of the time spent running non-kernel code
st: The percentage of the time stolen from a virtual machine
The Sysstat Suite of Resource Monitoring Tools
#yum -y install sysstat.i386
iostat
Display an overview of CPU utilization, along with I/O statistics for one or more disk devices
mpstat
Display more in-depth CPU statistics.
sadc (/usr/lib/sa/sadc), sar generate the reports interactively.

1. The Philosophy of System Administration

Although the specifics of being a system administrator may change from platform to platform, there are underlying themes that do not.
  • Automate everything
  • Document everything
  • Communicate as much as possible
  • Know your resources
  • Know your users
  • Know your business
  • Security cannot be an afterthought
  • Plan ahead
  • Expect the unexpected
http://www.tripwire.org/ — The Tripwire homepage.
  • crontab(1) and crontab(5) man pages — Command and file format documentation for using cron.
  • at(1) man page — Schedule commands and scripts for execution at a later time with this utility.
  • bash(1) man page — Learn more about the default shell (and shell script writing) with this documentation.
  • perl(1) man page — View pointers to the many man pages that make up perl’s online documentation.
  • gedit(1) man page and Help menu entry — Learn how to edit text files with this graphical text editor.
  • emacs(1) man page — Information (including instructions for running an online tutorial) on how to use this text editor.
  • vim(1) man page — Learn how to use this text-based editor.
  • mozilla(1) man page and Help Contents menu entry — Learn how to edit HTML files, read mail, and browse the Web.
  • Quanta Handbook menu entry — Learn how to edit HTML files with this graphical HTML editor.
  • evolution(1) man page and Help menu entry — Learn how to manage your email with this graphical email client.
  • pine(1) man page and ? menu entry — Learn how to manage your email with this text-based email client.
  • mutt(1) man page and files in /usr/share/doc/mutt-¤ version — Learn how to manage your email with this text-based email client.
  • pam(8) man page and files in /usr/share/doc/pam-¤ version — Learn how authentication takes place under Red Hat Linux.
  • tripwire(8) man page — Learn how to configure and run this intrusion detection software.

[Red Hat Linux System Administration Primer book]

Hack 2 Scan for SUID and SGID Programs

Quickly check for potential root-exploitable programs and backdoors.
What is SUID? SUID stands for set user id. When a SUID file executed, the process which runs it is granted access to system resources based on the user who owns the file and not the user who created the process.
What is SGID? SGID stands for set group id. When looking at files SGID they behave much the same as SUID files, and must be executable for it to have any effect.
Scanning systems for SUID and SGID binaries
# find / \( -perm -4000 -o -perm -2000 \) -type f -exec ls -la {} \;

Hack 1 Secure Mount Points

Using mount command to mount a new partition
#mount -o ro,nodev,noexec,nosuid partition mountpoint
example
#mount -o ro,nodev,noexec,nosuid /dev/mapper/VolGroup00-LogVol02 /data
-o (option) place any option following here
Consider the minimum permision for each mountpoint.

umount command
#umount /data


May 22, 2007

What is a Web Service

Why SOA?

SOA architecture enables seamless Enterprise Information Integration. Here are some of the Benefits of the Service Oriented Architecture:

  • Due to its platform independence, it allows companies to use the software and hardware of their choice .
  • There is no threat of vendor lock-in
  • SOA enables incremental development, deployment, and maintenance.
  • Companies can use the existing software (investments) and use SOA to build applications without replacing existing applications
  • The training costs are low, so the available labor pool can be used for running the applications

Connections

Connections means the link connecting these self-contained distributed services with each other, it enable client to Services communications. In case of Web services SOAP over HTTP is used to communicate the between services

Services

A service is a function or some processing logic or business processing that is well-defined, self-contained, and does not depend on the context or state of other services.

Well Defined

An expression is called "well defined" (or unambiguous) if its definition assigns it a unique interpretation or value.

Loose coupling

Loose coupling describes a resilient relationship between two or more systems or organizations with some kind of exchange relationship.
In Web Services or Service Oriented Architecture, loose coupling may mean simply that the implementation is hidden from the caller.

Electronic Data Interchange (EDI)

Electronic Data Interchange (EDI) is widely-used technology for the automated exchange of documents between dissimilar applications. It allows value chain partners to exchange purchase orders, invoices, advance ship notices and other business documents directly from one business system to the other, without human intervention. Proven advantages are fewer errors, lower administrative costs, and faster order-to-cash cycles.

May 21, 2007

Technical Summary

1. Java
2. Struts
3. Spring
4. SOA
5. JSF
6.

JSF Overview

What is JSF?

JSF is new standard framework , developed through Java Community Process (JCP) , that makes it easy to build user interfaces for java web applications by assembling reusable components in a page.

JSF includes mainly:

  1. Set of APIs to represent and manage state of components that helps server side validation, event handling, page navigation, data conversion etc.
  2. JSP custom tag library to create UI components in a view page.
Goal of JSF is to create web applications faster and easier.

Conclusion:
JSF is a framework, that makes its easy to build user interfaces for java web applications by assembling reusable components in a page.

Spring Overview

What is Spring?
Spring is an open source framework created by Rod Johnson to address the complexity of enterprise application development. One of the chief advantages of the Spring framework is its layered architecture, which allows you to be selective about which of its components you use while also providing a cohesive framework for J2EE application development.
Mission
Spring's main aim is to make J2EE easier. It does this by enabling a POJO-based programming model that is applicable in a wide range of environments.

Conclusion:
Spring is an open source framework for J2EE, use for complexity of of enterprise application development.
Its layered architecture allows you to select which of its components use for you application.

Struts Overview

Struts is an open source framework used for developing J2EE web applications using Model View Controller (MVC) design pattern.
Struts framework provides three key components:
  1. A request handler provided by the application developer that is used to mapped to a particular URI.
  2. A response handler which is used to transfer the control to another resource which will be responsible for completing the response.
  3. A tag library which helps developers to create the interactive form based applications with server pages.
The Controller : This is the heart of the container. Most Struts application will have only one controller that is ActionServlet which is responsible for directing several Actions.
Model : The model is basically a business logic part which takes the response from the user and stores the result for the duration of the process.
View : The view in struts framework is mainly a jsp page which is responsible for producing the output to the user.
Conclution:
Struts is a open source framework used for developing J2EE application using Model View Controller (MVC) design pattern.

SOA Overview

Service Oriented Architecture or SOA for short is a new software architecture for the development of loosely coupled distributed applications.
In fact service-oriented architecture is collection of many services in the network. These services communicate with each other and the communications involves data exchange & even service coordination.
Broadly SOA can be classified into two terms: Services and Connections.

Java Overview

What's Java?
  1. Java is an object-oriented applications programming language developed by Sun Microsystems in the early 1990s.
  2. Java applications are typically compiled to bytecode, although compilation to native machine code is also possible.
  3. At runtime, bytecode is usually either interpreted or compiled to native code for execution.
History
  1. Java started as a project called "Oak".
  2. The first public implementation was Java 1.0 in 1995.
  3. 2006, Sun released parts of Java as free/open source software, under the GNU General Public License (GPL)
Features
Java=> Java bytecode: portable
Java=>Native code: fast
Java=> Java bytecode: JIT compilation and dynamic recompilation allow Java programs to take advantage of the speed of native code without losing portability.
  • Automatic garbage collection

Extensions and related architectures

  • Java EE (previously J2EE) (Java Platform, Enterprise Edition—for distributed enterprise applications)
  • Java ME (previously J2ME) (Java Platform, Micro Edition—for PDAs and cellular phones)
  • JMF (Java Media Framework)
  • JNDI (Java Naming and Directory Interface)
  • JSML (Java Speech API Markup Language)
  • JDBC (Java DataBase Connectivity)
  • JDO (Java Data Objects)
  • JAI (Java Advanced Imaging)
  • JAIN (Java API for Integrated Networks)
  • JDMK (Java Dynamic Management Kit)
  • Jini (a network architecture for the construction of federated distributed systems)
  • Jiro
  • Java Card (Java for smart cards)
  • JavaSpaces
  • JML (Java Modeling Language)
  • JMI (Java Metadata Interface)
  • JMX (Java Management Extensions)
  • JSP (JavaServer Pages)
  • JSF (JavaServer Faces)
  • JNI (Java Native Interface)
  • JXTA (Open Protocols for Peer-to-Peer (P2P) Virtual Network)
  • Java 3D (A high level API for 3D graphics programming)
  • JOGL (Java OpenGL—A low level API for 3D graphics programming, using OpenGL)
  • LWJGL (Light Weight Java Game Library—A low level API providing access to OpenGL, OpenAL and various input devices)
  • OSGi (Dynamic Service Management and Remote Maintenance)
  • JMonkey Engine (High performance scene graph based 3D engine)

May 18, 2007

Applying aspect-oriented programming

Aspect-oriented programming, or AOP, is a programming technique that allows programmers to modularize crosscutting concerns, or behavior that cuts across the typical divisions of responsibility, such as logging and transaction management. The core construct of AOP is the aspect, which encapsulates behaviors affecting multiple classes into reusable modules.

Conclusion:
Aspect-oriented programming is a programming technique that allows programmers to separate application business logic from system services

Understanding inversion of control

The basic concept of the Inversion of Control pattern (also known as dependency injection) is that you do not create your objects but describe how they should be created. You don't directly connect your components and services together in code but describe which services are needed by which components in a configuration file. A container (in the case of the Spring framework, the IOC container) is then responsible for hooking it all up.
Conclusion:
Do not create objects directly but describe how they should be create.

Spring Module

The Spring framework is made up of seven well-defined modules (figure 1.1).The core container
Spring’s core container provides the fundamental functionality of the Spring framework. In this module you’ll find Spring’s BeanFactory, the heart of any Spring-based application. A BeanFactory is an implementation of the factory pattern that applies IoC to separate your application’s configuration and dependency specifications from the actual application code.
Application context module
The core module’s BeanFactory makes Spring a container, but the context module is what makes it a framework. (The Spring context is a configuration file that provides context information to the Spring framework). This module extends the concept of Bean-Factory, adding support for internationalization (I18N) messages, application life cycle events, and validation.
In addition, this module supplies many enterprise services such as e-mail, JNDI access, EJB integration, remoting, and scheduling. Also included is support for integration with templating frameworks such as Velocity and FreeMarker.
Spring’s AOP module
Spring provides rich support for aspect-oriented programming in its AOP module. This module serves as the basis for developing your own aspects for your Spring-enabled application.
JDBC abstraction and the DAO module
Working with JDBC often results in a lot of boilerplate code that gets a connection, creates a statement, processes a result set, and then closes the connection.
Object/relational mapping integration module
For those who prefer using an object/relational mapping (ORM) tool over straight JDBC, Spring provides the ORM module. Spring doesn’t attempt to implement its own ORM solution, but does provide hooks into several popular ORM frameworks, including Hibernate, JDO, and iBATIS SQL Maps.
Spring’s web module
The web context module builds on the application context module, providing a context that is appropriate for web-based applications.
The Spring MVC framework
Spring comes with a full-featured Model/View/Controller (MVC) framework for building web applications. Although Spring can easily be integrated with other MVC frameworks, such as Struts, Spring’s MVC framework uses IoC to provide for a clean separation of controller logic from business objects.