My own msn robot was born

Source: Internet
Author: User

There were too many things in the company in the first two weeks. I had to sort it out, but now I have a preliminary result.
Jmsn robots (Version 1.0.0) Instructions

1. Features
(1) Support starting Multiple Robots
(2) provides a simple database connection pool. Considering that robots need to serve multiple users at the same time, database access needs to be pooled.
(3) A worker thread pool with multiple users talking to the robot at the same time. It is necessary to improve the concurrent response capability. At the same time, it is not allowed to open new threads without limit, resulting in the consumption of system resources.
(4) self-developed response content programs

2. Runtime Environment
Jre 1.4.1.2 or above is required
3. Installation and directory description
[Bin] \ run. bat run. The classpath settings of jmsn robots are in this file.
The [lib] Directory contains the necessary runtime libraries. Msnm1-2-0b2.jar is jmsnlib library, I modified the source code, added the timed ping notification sever function, solve the nat device will automatically cut idle connection, causing the robot to go offline.
The [config] Directory stores the configuration file. Robots. xml is the configuration file of robots. You can see it at a glance. Cn_pool.xml is the configuration file of the database connection pool. It is mainly used for accessing the database when you develop a robot conversation processing program. Of course, you can also use other connection pools by yourself. Cn_pool.sam is an example.

4. configuration file description
(1) config. properties under the [bin] Directory. Please modify it according to your actual situation. The parameters are as follows:

Jmsn_robot_home = C: \ main directory of the JMSNRobots-1.0.0-a System (note \\)
Connection_pool_enabled = false whether the connection pool is required. If it is set to true, read the configuration according to the connection_pool_config_file file.
Thread_process = 20 Capacity of the thread working pool
Robot_config_file = robots. xml robot configuration file
Connection_pool_config_file = configuration file of the cn_pool.xml database connection pool

(2) robots. xml robot configuration file under the [config] Directory
<JMSNRobot>
<ROBOT id = "1" loginname = "" password = "" robot_name = "" service = "org. enhydraboy. msnrobots. SampleRobot"/>
</JMSNRobot>
You can understand it at a glance.
(3) cn_pool.sam under the [config] Directory, which is easy to understand.

5. How to develop your own robot content processing program
(1) development content processing code

In fact, it is very simple. You only need to inherit an interface. This interface is org. enhydraby. jmsnrobot. develop. commandDispatcher. The system stores the received message in a class of MSNInputMessage. getMsgbody () can get the message content sent to you. Note, the message content is JAVA's default iso-8859 encoding. GetSender () can get the sender's email address.

Below is a simple piece of code

Package org. enhydraboy. msnrobots;

Import org. enhydraby. jmsnrobot. develop .*;

/**
* <P> Title: </p>
* <P> Description: </p>
* <P> Copyright: Copyright (c) 2004 </p>
* <P> Company: </p>
* @ Author unascribed
* @ Version 1.0
*/

Public class SampleRobot extends commandDispatcher {

Public SampleRobot (){
}

Public String ProcessCommand (MSNInputMessage msg ){
String ret = "";
If (msg. getMsgbody (). toLowerCase (). equals ("hello ")){
Ret = "hello" + msg. getFriendlyName ();
Ret = ret + "your email is" + msg. getSender ();
}
Return ret;
}
}

(2) deployment. Modify robots. xml, where service = "org. enhydraboy. msnrobots. SampleRobot", you should understand it.
(3) Use of the connection pool.
ConnectionFactory cf = ConnectionFactory. getInstance ();
DataSource ds = null;
Try {
Ds = cf. lookup ("Sybase"); // obtain a data source
} Catch (Exception e ){
E. printStackTrace ();
}

Connection conn = ds. getConnection (); // obtain a Connection

.....
Conn. close // return the connection pool

This is just my interest. I spent some time organizing it, mainly to help you compile your own msn robot.

And thanks to the open source jmsnlib class library. I just did a little work on the basis of it.

You can contact me ....
Enhydraboy@yahoo.com.cn

2004

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.