1. final class A {}; // Define a final class:
- Cannot be subclass. (String is a final class)
- The methods in the class are also final => run twice faster than normal method!
-Extends: abstract class b{}: an abstract class with can have methods
interface class b{}:
2. volatile int b; // an indicator to Thread that do not cache value of this variable
3.
2011年12月29日 星期四
2011年12月14日 星期三
websphere: broker programming
1. compute node:
Compute Mode: - LocalEnvironemnt => pass whole message but not the LocalEnvironment
- Message => pass whole LocalEnvironmentbut not the Message
input: InputRoot, InputLocalEnvironment;
output: OutputRoot, OutputLocalEnvironment;
=============================================
- Collector, Trace node only has ${Root}, not ${InputRoot}
- OutputRoot.MQMD should be set before OutputRoot.XMLNSC & OutputRoot.BLOB
- InputLocalEnvironment.WrittenDestination.MQ.DestinationData.msgId contain the msgId from MQOutput node
Compute Mode: - LocalEnvironemnt => pass whole message but not the LocalEnvironment
- Message => pass whole LocalEnvironmentbut not the Message
input: InputRoot, InputLocalEnvironment;
output: OutputRoot, OutputLocalEnvironment;
=============================================
- Collector, Trace node only has ${Root}, not ${InputRoot}
- OutputRoot.MQMD should be set before OutputRoot.XMLNSC & OutputRoot.BLOB
- InputLocalEnvironment.WrittenDestination.MQ.DestinationData.msgId contain the msgId from MQOutput node
2011年12月4日 星期日
java programming: vector, hashtable, ThreadPoolExecutor
1. Java.util.Vector
- 是一種JDK 內建的 API,它的定義就是一種能夠自動長大或縮小的陣列形態,其最大的用途就是彌補Array 的彈性不足,在宣告的時後,可以不必宣告其大小,等到物件一個個的加入時,容量不足時就會自動加大容量。使用的方式如下
Vector v=new Vector();
v.addElement("line 1");
v.addElement("line 2");
v.addElement("line 3");
v.addElement("line 4");
2.Java.util.Hashtable
- 顧名思義來說,就是資料結構中,搜尋這個章節所提到的雜湊表。
Hashtable h=new Hashtable();
h.put("a","line 1");
h.put("b","line 2");
h.put("c","line 3");
h.put("d","line 4");
3.ThreadPoolExecutor and CompletionService
[ref: http://vivyzer.wordpress.com/2009/01/08/use-javautilconcurrent-threadpoolexecutor-and-completionservice-to-know-the-status-of-thread-execution/]
- 是一種JDK 內建的 API,它的定義就是一種能夠自動長大或縮小的陣列形態,其最大的用途就是彌補Array 的彈性不足,在宣告的時後,可以不必宣告其大小,等到物件一個個的加入時,容量不足時就會自動加大容量。使用的方式如下
Vector v=new Vector();
v.addElement("line 1");
v.addElement("line 2");
v.addElement("line 3");
v.addElement("line 4");
2.Java.util.Hashtable
- 顧名思義來說,就是資料結構中,搜尋這個章節所提到的雜湊表。
Hashtable h=new Hashtable();
h.put("a","line 1");
h.put("b","line 2");
h.put("c","line 3");
h.put("d","line 4");
3.ThreadPoolExecutor and CompletionService
[ref: http://vivyzer.wordpress.com/2009/01/08/use-javautilconcurrent-threadpoolexecutor-and-completionservice-to-know-the-status-of-thread-execution/]
標籤:
code,
hashtable,
java,
ThreadPoolExecutor,
vector
2011年12月1日 星期四
websphere: concept
1. load balancing
-load balancing in cluster is effective for PER connection, not PER message sent
-load balancing in cluster is effective for PER connection, not PER message sent
websphere: command
1. dspmq
(display the mq status)
2.setmqaut -m MQ.T.GW1 -n Q.TEST.IN2 -t queue -p user1 +all
(set permission for user user1 on the MQ.T.GW1/Q.TEST.IN2)
-When the queue is deleted and recreate, the permission is lost.
-P.S. user1 reuire connect permission on MQ.T.GW1 in order to write message to TEST.IN2
3. crtmqm -q mq / dltmqm mq
(create mq / delete mq)
4. strmqm mq / endmqm [-i] mq
(start mq/ stop [force to stop] mq)
5. runmqsc mq
(enter mq command status)
6.dspmqrte -m MQ.T.BRG1 -q Q.TEST.IN -qm MQ.T.MB1
(trace message routing, -m: Qmgr for input, -qm:target Qmgr, q: target Q)??
7.endmqlsr -m MQ.T.BRG1
(stop listener on MQ.T.BRG1)
(display the mq status)
2.setmqaut -m MQ.T.GW1 -n Q.TEST.IN2 -t queue -p user1 +all
(set permission for user user1 on the MQ.T.GW1/Q.TEST.IN2)
-When the queue is deleted and recreate, the permission is lost.
-P.S. user1 reuire connect permission on MQ.T.GW1 in order to write message to TEST.IN2
3. crtmqm -q mq / dltmqm mq
(create mq / delete mq)
4. strmqm mq / endmqm [-i] mq
(start mq/ stop [force to stop] mq)
5. runmqsc mq
(enter mq command status)
6.dspmqrte -m MQ.T.BRG1 -q Q.TEST.IN -qm MQ.T.MB1
(trace message routing, -m: Qmgr for input, -qm:target Qmgr, q: target Q)??
7.endmqlsr -m MQ.T.BRG1
(stop listener on MQ.T.BRG1)
2011年11月30日 星期三
websphere: Queue
1. Queue
2. Remote Queue
3. Clustered Queue
4.Queue Manager Alias
-Remote Queue without Queue Name
5.Transmission Queue
-Local Queue with usage = XMITQ
6.Replay-to-Queue Alias
- Remote Queue without defining transmit Queue?
2. Remote Queue
3. Clustered Queue
4.Queue Manager Alias
-Remote Queue without Queue Name
5.Transmission Queue
-Local Queue with usage = XMITQ
6.Replay-to-Queue Alias
- Remote Queue without defining transmit Queue?
2011年11月29日 星期二
Websphere: sending message
1.Java Code for sending message through JMS :
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.QueueReceiver;
import javax.jms.Session;
import com.ibm.jms.JMSTextMessage;
import com.ibm.mq.jms.JMSC;
import com.ibm.mq.jms.MQQueue;
import com.ibm.mq.jms.MQQueueConnection;
import com.ibm.mq.jms.MQQueueConnectionFactory;
import com.ibm.mq.jms.MQQueueReceiver;
import com.ibm.mq.jms.MQQueueSender;
import com.ibm.mq.jms.MQQueueSession;
public class z_JMS_Test {
/**
* Main method
*
* @param args
*/
public static void main(String[] args) {
try {
for(int i=0; i<10;i++){
MQQueueConnectionFactory cf = new MQQueueConnectionFactory();
// config connection
cf.setHostName("HOSTNAME");//host name
cf.setPort(20001);//QM port
cf.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);
cf.setChannel("SYSTEM.ADMIN.SVRCONN"); //channel for connection
cf.setQueueManager("MQ.T.GW1");
MQQueueConnection connection = (MQQueueConnection) cf.createQueueConnection();
//create session
MQQueueSession session = (MQQueueSession) connection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
//create sender & receiver queue
MQQueue sendqueue = (MQQueue) session.createQueue("queue:///Q.TEST.IN");
MQQueueSender sender = (MQQueueSender) session.createSender(sendqueue);
MQQueue receivequeue=(MQQueue) session.createQueue("queue:///Q.TEST.OUT");
QueueReceiver queueReceiver = session.createReceiver(receivequeue);
//create message
JMSTextMessage message = (JMSTextMessage) session.createTextMessage("test");
// message.setJMSCorrelationID("id1234567");
// message.setJMSDeliveryMode()
//setJMSReplyTo(reply);
connection.start();
sender.send(message);
System.out.println("\n Send SUCCESS\n");
Message inMessage = queueReceiver.receive(1000);
System.out.println(inMessage);
sender.close();
session.close();
}
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("\nFAILURE\n");
}
}
}
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.QueueReceiver;
import javax.jms.Session;
import com.ibm.jms.JMSTextMessage;
import com.ibm.mq.jms.JMSC;
import com.ibm.mq.jms.MQQueue;
import com.ibm.mq.jms.MQQueueConnection;
import com.ibm.mq.jms.MQQueueConnectionFactory;
import com.ibm.mq.jms.MQQueueReceiver;
import com.ibm.mq.jms.MQQueueSender;
import com.ibm.mq.jms.MQQueueSession;
public class z_JMS_Test {
/**
* Main method
*
* @param args
*/
public static void main(String[] args) {
try {
for(int i=0; i<10;i++){
MQQueueConnectionFactory cf = new MQQueueConnectionFactory();
// config connection
cf.setHostName("HOSTNAME");//host name
cf.setPort(20001);//QM port
cf.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);
cf.setChannel("SYSTEM.ADMIN.SVRCONN"); //channel for connection
cf.setQueueManager("MQ.T.GW1");
MQQueueConnection connection = (MQQueueConnection) cf.createQueueConnection();
//create session
MQQueueSession session = (MQQueueSession) connection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
//create sender & receiver queue
MQQueue sendqueue = (MQQueue) session.createQueue("queue:///Q.TEST.IN");
MQQueueSender sender = (MQQueueSender) session.createSender(sendqueue);
MQQueue receivequeue=(MQQueue) session.createQueue("queue:///Q.TEST.OUT");
QueueReceiver queueReceiver = session.createReceiver(receivequeue);
//create message
JMSTextMessage message = (JMSTextMessage) session.createTextMessage("test");
// message.setJMSCorrelationID("id1234567");
// message.setJMSDeliveryMode()
//setJMSReplyTo(reply);
connection.start();
sender.send(message);
System.out.println("\n Send SUCCESS\n");
Message inMessage = queueReceiver.receive(1000);
System.out.println(inMessage);
sender.close();
session.close();
}
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("\nFAILURE\n");
}
}
}
標籤:
code,
JMS,
receive message,
sample,
send message,
Websphere
2011年11月8日 星期二
learning - linux command
-TYPE: find where the command from:
-ECHO: return the value of environment variable
-env: list all the environment variables
-set: list local environment variables
-export xxx: set xxx be the global environment variable
-read: read a line from conso
-alias lm "ls -ltr": let lm perform same operation as "ls -ltr"
-cmd ; cmd (不考慮指令相關性的連續指令下達)
-$? (指令回傳值) 與 && 或 ||
cmd1 && cmd2 ==> 1若 cmd1 執行完畢且正確執行($?=0),則開始執行 cmd2。
bash-4.1$ type ls
ls is hashed (/usr/bin/ls)
-ECHO: return the value of environment variable
bash-4.1$ echo $PATH
/opt/IBM/mqsi/6.1/jre15/ppc64/bin:/opt/IBM/mqsi/6.1/bin:/usr/bin
-env: list all the environment variables
-set: list local environment variables
-export xxx: set xxx be the global environment variable
-read: read a line from conso
-alias lm "ls -ltr": let lm perform same operation as "ls -ltr"
-cmd ; cmd (不考慮指令相關性的連續指令下達)
-$? (指令回傳值) 與 && 或 ||
cmd1 && cmd2 ==> 1若 cmd1 執行完畢且正確執行($?=0),則開始執行 cmd2。
- standard output 與 standard error output
簡單的說,標準輸出指的是『指令執行所回傳的正確的訊息』,而標準錯誤輸出可理解為『 指令執行失敗後,所回傳的錯誤訊息』。舉個簡單例子來說,我們的系統預設有 /etc/crontab 但卻無 /etc/vbirdsay, 此時若下達『 cat /etc/crontab /etc/vbirdsay 』這個指令時,cat 會進行:
- 標準輸出:讀取 /etc/crontab 後,將該檔案內容顯示到螢幕上;
- 標準錯誤輸出:因為無法找到 /etc/vbirdsay,因此在螢幕上顯示錯誤訊息
不管正確或錯誤的資料都是預設輸出到螢幕上,所以螢幕當然是亂亂的!那能不能透過某些機制將這兩股資料分開呢? 當然可以啊!那就是資料流重導向的功能啊!資料流重導向可以將 standard output (簡稱 stdout) 與 standard error output (簡稱 stderr) 分別傳送到其他的檔案或裝置去,而分別傳送所用的特殊字元則如下所示:
- 標準輸入 (stdin) :代碼為 0 ,使用 <(以file輸入) 或 << (以keyboard輸入,直到遇到"<
- 標準輸出 (stdout):代碼為 1 ,使用 > 或 >> ;
- 標準錯誤輸出(stderr):代碼為 2 ,使用 2> 或 2>> ;
2011年11月1日 星期二
Java Curl
Linux
1. install curl
yum install curl curl-devle
2. Download the source code and compile
http://curl.haxx.se/libcurl/java/
3.Compile the code:
gunzip curl-java-0.2.2.tar.gz
tar xvf curl-java-0.2.2.tar
cd curl-java-0.2.2
make
windows:
1. Download the source code and compile to dll
http://curl.haxx.se/libcurl/java/
compiled dll: http://www.gknw.de/mirror/curl/curl_java/
2.Copy to system32
3. or set the VM args in eclipse
ie Window->Preferences->Java->Installed JREs. Then choose your current JRE(JDK) and click Edit. Fill Default VM Arguments: -Djava.library.path=/usr/local/xuggler/lib.
ref: StackOverflow
Java Code
try {
// Loading up the shared JNI
System.loadLibrary("javacurl");
} catch (Exception e) {
e.printStackTrace();
}
test.java
// This test application accesses the Web site from Banco Santander, a Mexican bank, performs a login
// over SSL, receives a cookie and obtain the balance of a bank account, all using libcurl from Java
// import CurlGlue;
// import CurlWrite;
class test extends CurlIO {
public int handleString(byte s[])
{
/* output everything */
System.out.println("IIIIIIIIIII -------------- OOOOOOOOOOOOOOOOOOO");
try {
System.out.write(s);
}
catch (java.io.IOException moo) {
// nothing
}
return 0;
}
public static void main(String[] args)
{
// Bank account number and PIN - fake of course :)
String account = new String("1234567");
String pinCode = new String("1234");
CurlGlue cg;
try {
test cw = new test();
// Register callback write function
cg = new CurlGlue();
cg.setopt(CurlGlue.CURLOPT_WRITEFUNCTION, cw);
// Login to the bank's secure Web site, posting account number and PIN code
cg.setopt(CurlGlue.CURLOPT_URL, "https://www.santander.com.mx/SuperNetII/servlet/Login");
cg.setopt(CurlGlue.CURLOPT_SSLVERSION, 3);
cg.setopt(CurlGlue.CURLOPT_SSL_VERIFYPEER, 0); // attention! Insecure mode!!
cg.setopt(CurlGlue.CURLOPT_VERBOSE, 1);
cg.setopt(CurlGlue.CURLOPT_FOLLOWLOCATION, 1);
cg.setopt(CurlGlue.CURLOPT_POST, 1);
cg.setopt(CurlGlue.CURLOPT_COOKIEJAR, "cookie.txt");
cg.setopt(CurlGlue.CURLOPT_POSTFIELDS, "pag=login&pagErr=/index.html&usuario="+account+"&clave="+pinCode+"&irAmodulo=1");
cg.perform();
// Access the bank account balance re-using the session ID stored in memory inside a cookie
cg.setopt(CurlGlue.CURLOPT_URL, "https://www.santander.com.mx/SuperNetII/servlet/Cchequeras");
cg.setopt(CurlGlue.CURLOPT_SSLVERSION, 3);
cg.setopt(CurlGlue.CURLOPT_SSL_VERIFYPEER, 0); // attention! Insecure mode!!
cg.setopt(CurlGlue.CURLOPT_VERBOSE, 1);
cg.setopt(CurlGlue.CURLOPT_FOLLOWLOCATION, 1);
cg.setopt(CurlGlue.CURLOPT_COOKIEFILE, "cookie.txt");
cg.perform();
// The cookie.txt file is actually created now
cg.finalize();
} catch (Exception e) {
e.printStackTrace();
}
}
}
useful websit:http://chimpler.blogspot.com/2009/03/logging-to-ebay-with-java-curl.html
1. install curl
yum install curl curl-devle
2. Download the source code and compile
http://curl.haxx.se/libcurl/java/
3.Compile the code:
gunzip curl-java-0.2.2.tar.gz
tar xvf curl-java-0.2.2.tar
cd curl-java-0.2.2
make
windows:
1. Download the source code and compile to dll
http://curl.haxx.se/libcurl/java/
compiled dll: http://www.gknw.de/mirror/curl/curl_java/
2.Copy to system32
3. or set the VM args in eclipse
ie Window->Preferences->Java->Installed JREs. Then choose your current JRE(JDK) and click Edit. Fill Default VM Arguments: -Djava.library.path=/usr/local/xuggler/lib.
ref: StackOverflow
Java Code
try {
// Loading up the shared JNI
System.loadLibrary("javacurl");
} catch (Exception e) {
e.printStackTrace();
}
test.java
// This test application accesses the Web site from Banco Santander, a Mexican bank, performs a login
// over SSL, receives a cookie and obtain the balance of a bank account, all using libcurl from Java
// import CurlGlue;
// import CurlWrite;
class test extends CurlIO {
public int handleString(byte s[])
{
/* output everything */
System.out.println("IIIIIIIIIII -------------- OOOOOOOOOOOOOOOOOOO");
try {
System.out.write(s);
}
catch (java.io.IOException moo) {
// nothing
}
return 0;
}
public static void main(String[] args)
{
// Bank account number and PIN - fake of course :)
String account = new String("1234567");
String pinCode = new String("1234");
CurlGlue cg;
try {
test cw = new test();
// Register callback write function
cg = new CurlGlue();
cg.setopt(CurlGlue.CURLOPT_WRITEFUNCTION, cw);
// Login to the bank's secure Web site, posting account number and PIN code
cg.setopt(CurlGlue.CURLOPT_URL, "https://www.santander.com.mx/SuperNetII/servlet/Login");
cg.setopt(CurlGlue.CURLOPT_SSLVERSION, 3);
cg.setopt(CurlGlue.CURLOPT_SSL_VERIFYPEER, 0); // attention! Insecure mode!!
cg.setopt(CurlGlue.CURLOPT_VERBOSE, 1);
cg.setopt(CurlGlue.CURLOPT_FOLLOWLOCATION, 1);
cg.setopt(CurlGlue.CURLOPT_POST, 1);
cg.setopt(CurlGlue.CURLOPT_COOKIEJAR, "cookie.txt");
cg.setopt(CurlGlue.CURLOPT_POSTFIELDS, "pag=login&pagErr=/index.html&usuario="+account+"&clave="+pinCode+"&irAmodulo=1");
cg.perform();
// Access the bank account balance re-using the session ID stored in memory inside a cookie
cg.setopt(CurlGlue.CURLOPT_URL, "https://www.santander.com.mx/SuperNetII/servlet/Cchequeras");
cg.setopt(CurlGlue.CURLOPT_SSLVERSION, 3);
cg.setopt(CurlGlue.CURLOPT_SSL_VERIFYPEER, 0); // attention! Insecure mode!!
cg.setopt(CurlGlue.CURLOPT_VERBOSE, 1);
cg.setopt(CurlGlue.CURLOPT_FOLLOWLOCATION, 1);
cg.setopt(CurlGlue.CURLOPT_COOKIEFILE, "cookie.txt");
cg.perform();
// The cookie.txt file is actually created now
cg.finalize();
} catch (Exception e) {
e.printStackTrace();
}
}
}
useful websit:http://chimpler.blogspot.com/2009/03/logging-to-ebay-with-java-curl.html
2011年10月26日 星期三
seven smooth steps to superb grids
http://www.sachagreif.com/seven-smooth-steps-to-superb-grids/
960.gs example
http://www.designinfluences.com/fluid960gs/16/fixed/mootools/
2011年10月20日 星期四
Java SE notes
notes for: http://download.oracle.com/javase/tutorial/java/TOC.html
1. emun type
public enum Day {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
THURSDAY, FRIDAY, SATURDAY
}
use:
System.Out.Println("%d",Day.SUNDAY); //output 0;
2.Annotations
@Deprecated: indicate that element is deprecated. Compiler will give warning if this is used.
@SuppressWarnings: force compiler to stop compiling is this elements is used.
3.Interfaces
-are contracts; force class to implement the method.
-[used as type] ie. public CharSequence subSequence(int start, int end);
-are not part of the class hierarchy.
-interface can only be extended by other interfaces.
-can only be implemented by other classes.
-only contains constants and method
-cannot be instantiated
4.Inheritance
-Polymorphism
5.generics
-define type parameter names that prevent runtime error(passing wrong type to object)
-type parameter names are single, uppercase letters (commonly use only)
-Common type
* E - Element (used extensively by the Java Collections Framework)
* K - Key
* N - Number
* T - Type
* V - Value
* S,U,V etc. - 2nd, 3rd, 4th types
-<<<<<<>>>>>
public class Box {
private T t; // T stands for "Type"
public void add(T t) {
this.t = t;
}
public T get() {
return t;
}
case 1
Box box=new Box();
box.add("1"); //able to compile. Have runtime error as it pass String instead of Integer.
case 2
Box box=new Box();
box.add("1"); //compiler will find this error.
6.Wildcards
7.Packages
-you can write your own classes that contain constants and static methods that you use frequently, and then use the static import statement.
ie: import static mypackage.MyConstants.*;
interface VS abstract class:
ref:http://www.cnblogs.com/oomusou/archive/2007/05/07/738311.html
-interface: methods & constants only.
-abstract: can have body. the abstract must be overrided by subclass.
1. emun type
public enum Day {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
THURSDAY, FRIDAY, SATURDAY
}
use:
System.Out.Println("%d",Day.SUNDAY); //output 0;
2.Annotations
@Deprecated: indicate that element is deprecated. Compiler will give warning if this is used.
@SuppressWarnings: force compiler to stop compiling is this elements is used.
3.Interfaces
-are contracts; force class to implement the method.
-[used as type] ie. public CharSequence subSequence(int start, int end);
-are not part of the class hierarchy.
-interface can only be extended by other interfaces.
-can only be implemented by other classes.
-only contains constants and method
-cannot be instantiated
4.Inheritance
-Polymorphism
5.generics
-define type parameter names that prevent runtime error(passing wrong type to object)
-type parameter names are single, uppercase letters (commonly use only)
-Common type
* E - Element (used extensively by the Java Collections Framework)
* K - Key
* N - Number
* T - Type
* V - Value
* S,U,V etc. - 2nd, 3rd, 4th types
-<<<<<<
public class Box
private T t; // T stands for "Type"
public void add(T t) {
this.t = t;
}
public T get() {
return t;
}
case 1
Box box=new Box();
box.add("1"); //able to compile. Have runtime error as it pass String instead of Integer.
case 2
Box
box.add("1"); //compiler will find this error.
6.Wildcards
7.Packages
-you can write your own classes that contain constants and static methods that you use frequently, and then use the static import statement.
ie: import static mypackage.MyConstants.*;
interface VS abstract class:
ref:http://www.cnblogs.com/oomusou/archive/2007/05/07/738311.html
-interface: methods & constants only.
-abstract: can have body. the abstract must be overrided by subclass.
訂閱:
文章 (Atom)