الاثنين، 29 نوفمبر 2010

commserver life cycle(client-server sockets)


the basics of sockets

Open a socket.
Open an input stream and output stream to the socket.
Read from and write to the stream according to the server's protocol.
Close the streams.
Close the socket
 =======================
Server
StartServer àcreate new  memberDataObject
          Initialize static strings
memberDataObject.connect ()à do the following
read from file properties and assign values to static strings.
new ConManager (sql_url, sql_userName, sql_password) create
sql_url = "jdbc:microsoft:sqlserver:// sds-2003:1433;DatabaseName= CHILD_help";
sql_userName=sa;
sql_password=sa;
ConManager.makeConnectionPool ();à create pool of 10 connection, closed
ConManager.getConnection ();à take url, username, password, return opened connection

Parse acdconfig=D:\\TeleContact\\Server\\config\\ACDConfig.xml  using saxparse
Add the content of file in array list.
check in debugLevel àconsole or log

StartServerà create new AbstractServer(Integer.parseInt(memberDataObject.port.trim()), 100,
            "com.RequestHandelerClass",mberDataObject.maxQueueLength,
memberDataObject.maxThreads, memberDataObject.maxThreads)
AbstractServer extends Thread

Constructor do :
1)
port=1984
backlog=100     The number of requests to backlog if threads are busy
requestHandlerClassName= com.RequestHandelerClass
maxQueueLength=20
minThreads=20
maxThreads=20
 (2
Create new RequestQueue(requestHandlerClassName,maxQueueLength,               minThreads, maxThreads)
Create the minimum number of threads and but them(Threads) in List/pool
The thread pool that is servicing this request
// so till now for the server run 20 threads started in the background to handle the client requests

AbstractServer.startServer()

Create our Server Socket and start our Thread

In run()
Make socket Accept the next connection
// Listens for a connection to be made to this socket and accepts it. The method blocks until //    a connection is made.
// Log some debugging information

// Add the socket to the RequestQueue (add it to linked list/end of queue thread)

Adds a new object to the end of the queue
See if we have an available thread (from the 20 thread running) to process the request

Yes->notify thread(wake up)    invoke run()   RequestThread
On run()->
 Handle the request
     this.requestHandler.handleRequest(socket);         

AbstractServer->Abstract super class for creating servers
RequestQueue->accepts new requests and processes them with its associated thread pool
RequestThread->extends Thread  / handles incoming requests
agent -->implements Serializable / bean id,name,ext,password,type,user
data  -->implements Serializable / bean code,command,result


RequestHandelerClass-> handel requests from client
            it's instance fields initialized from memberDataObject class that originally loaded from the property file

then get data from objectInputStream from socket then get data.getCode()
and switch

case 1,2,4:  
int updateDatabase(sql),set send data fields
case 3:
ArrayList<bean> select(sql)
Set send instance fields
Case 5:
String getWavePath(int agent_id)
Set send instance fields
Case 6:
Check if file needed to delete is exist or not
Set send instance fields
Case 7:
Check if file exist or not, and if exist check if there are available memory to copy file if yes->
Object getwave(String path)
Set send instance fields
Case 8:
agent getXml(String agent_code)
print agent attributes
Set send instance fields
Case 9:
int fileExist(String wavePath)
Set send instance fields
Case10:
String createFile(String id)
Set send instance fields
Case 11:
int saveAdviceFile(adviceBean advice)
Set send instance fields
Case 12:
Parse url for ACD Config by sax parser and print how many agent have
Set send instance fields
Case 13:
Set send instance fields(and set result=enable)
Case 14:
Change path of file
Set send instance fields
Case 15:
String createFile(String id)               Create file voicemail at internal path
Set send instance fields
Case 16:
int transefer_smdr()
int transeferSmdrFile(String source, String desti)
String increment(String date) increament version

Set send instance fields

Case 17:
Print server time is requested from client
Set send instance fields

Case 18:
client  sent advice text file to be saved in DB advices table
int saveAdviceTextFile(adviceBean advice)
Set send instance fields

Case 19:
client  sent advice text file to be saved server directory
int saveAdviceFile1(adviceBean advice)
Set send instance fields

Case 20:
Client sent wave bean to be saved  in the server
int saveWaveBean(waveBean filewave)
Set send instance fields

Case 21:
Client    request wave file from server
Object getwave(String path)
Set send instance fields

then out.writeObject(send)

==================================
for client Test email me


ليست هناك تعليقات:

إرسال تعليق